Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions UDef-ARP.py
Original file line number Diff line number Diff line change
Expand Up @@ -2927,7 +2927,6 @@ def __init__(self):
self.risk30_vp = None
self.expected_deforestation = None
self.max_iterations = None
self.time = None
self.image1 = None
self.image2 = None
self.file_path_directory = None
Expand Down Expand Up @@ -3024,12 +3023,12 @@ def process_data3(self):

expected_deforestation = self.expected_entry.text()
if not expected_deforestation:
QMessageBox.critical(self, "Error", "Please enter the expected deforestation value!")
QMessageBox.critical(self, "Error", "Please enter the expected annual jurisdictional activity!")
return
try:
self.expected_deforestation = float(expected_deforestation)
except ValueError:
QMessageBox.critical(self, "Error", "Expected deforestation value should be a valid number!")
QMessageBox.critical(self, "Error", "Expected annual jurisdictional activity should be a valid number!")
return

out_fn1 = self.image1_entry.text()
Expand Down Expand Up @@ -3062,16 +3061,6 @@ def process_data3(self):
QMessageBox.critical(self, "Error", "Max iteration value should be a valid number!")
return

time = self.year_entry.text()
if not time:
QMessageBox.critical(self, "Error", "Please enter the number of years in the VP! ")
return
try:
self.time = int(time)
except ValueError:
QMessageBox.critical(self, "Error", "The number of years in the VP should be a valid number!")
return

# Show "Processing" message
processing_message = "Processing data..."
self.progressDialog = QProgressDialog(processing_message, None, 0, 100, self)
Expand All @@ -3093,8 +3082,7 @@ def process_data3(self):
self.csv,
self.municipality,
self.expected_deforestation,
self.risk30_vp, out_fn1,out_fn2,
self.time)
self.risk30_vp, out_fn1,out_fn2)

if id_difference.size > 0:
QMessageBox.warning(self, " Warning ", f"Modeling Region ID {','.join(map(str, id_difference))} do not exist in the Historical Reference Period. A new CSV has been created for the HRP where relative frequencies for missing bins have been estimated from corresponding vulnerability zones over the entire jurisdiction.")
Expand Down
35 changes: 2 additions & 33 deletions allocation_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,37 +325,6 @@ def adjusted_prediction_density_map (self, prediction_density_arr, risk30_vp, AR

return

def adjusted_prediction_density_map_annual (self, prediction_density_arr, risk30_vp, AR, out_fn2, time):
'''
Create adjusted prediction density map for annual
:param prediction_density_arr:modeled deforestation (MD)
:param risk30_vp: risk30_vp image
:param AR:Adjustment Ratio
:param out_fn2: user input
:return:
'''

# Calculate the maximum density
# Calculate areal_resolution_of_map_pixels
in_ds4 = gdal.Open(risk30_vp)
P1 = in_ds4.GetGeoTransform()[1]
P2 = abs(in_ds4.GetGeoTransform()[5])
maximum_density = P1 * P2 / 10000

# Adjusted_Prediction_Density_Map = AR x Prediction_Density _Map
adjusted_prediction_density_arr=AR*prediction_density_arr

# Reclassify all pixels greater than the maximum (e.g., 0.09) to be the maximum
adjusted_prediction_density_arr[adjusted_prediction_density_arr > maximum_density] = maximum_density

# Convert the result back to an annual rate by dividing by the number of years in the VP
adjusted_prediction_density_arr_annual=adjusted_prediction_density_arr/time

# Create imagery
self.array_to_image(risk30_vp, out_fn2, adjusted_prediction_density_arr_annual, gdal.GDT_Float32, -1)

return

def replace_ref_system(self, in_fn, out_fn):
'''
RST raster format: correct reference system name in rdc file
Expand Down Expand Up @@ -473,7 +442,7 @@ def execute_workflow_cnf(self, directory, max_iterations, csv, municipality, def

return id_difference , iteration_count

def execute_workflow_vp(self, directory,max_iterations, csv, municipality, expected_deforestation, risk30_vp, out_fn1, out_fn2, time):
def execute_workflow_vp(self, directory,max_iterations, csv, municipality, expected_deforestation, risk30_vp, out_fn1, out_fn2):
'''
Create workflow function for VP
:param max_iterations: maximum number of iterations
Expand Down Expand Up @@ -511,7 +480,7 @@ def execute_workflow_vp(self, directory,max_iterations, csv, municipality, expec
# Emitting progress based on the current iteration_count and max_iterations
if iteration_count <= int(max_iterations):
selected_density_arr = new_prediction_density_arr if new_prediction_density_arr is not None else prediction_density_arr
self.adjusted_prediction_density_map_annual(selected_density_arr, risk30_vp, AR, out_fn2, time)
self.adjusted_prediction_density_map(selected_density_arr, risk30_vp, AR, out_fn2)
self.replace_ref_system(municipality, out_fn2)
else:
print("Maximum number of iterations reached. Please reset the maximum number of iterations.")
Expand Down
49 changes: 3 additions & 46 deletions data/at_pre_vp_screen.ui
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ color: rgb(125, 169, 172);
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
</property>
<property name="text">
<string>Expected Jurisdictional Activity (ha)</string>
<string>Expected Annual Jurisdictional Activity (ha/year)</string>
</property>
</widget>
<widget class="QLabel" name="label_10">
Expand Down Expand Up @@ -366,31 +366,6 @@ color: rgb(125, 169, 172);
<string>Maximum Iterations for Solution Convergence</string>
</property>
</widget>
<widget class="QLabel" name="label_11">
<property name="geometry">
<rect>
<x>20</x>
<y>230</y>
<width>531</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<family>AvenirNext LT Pro Cn</family>
<pointsize>10</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
</property>
<property name="text">
<string>Length of the VP in years</string>
</property>
</widget>
<widget class="QLineEdit" name="municipality_entry">
<property name="geometry">
<rect>
Expand Down Expand Up @@ -463,22 +438,6 @@ font: 9pt;</string>
<string>3</string>
</property>
</widget>
<widget class="QLineEdit" name="year_entry">
<property name="geometry">
<rect>
<x>570</x>
<y>230</y>
<width>531</width>
<height>31</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255); font: 9pt;</string>
</property>
<property name="text">
<string>6</string>
</property>
</widget>
<widget class="QPushButton" name="municipality_button">
<property name="geometry">
<rect>
Expand Down Expand Up @@ -533,7 +492,7 @@ font: 9pt;</string>
<x>0</x>
<y>0</y>
<width>1281</width>
<height>281</height>
<height>251</height>
</rect>
</property>
<property name="font">
Expand Down Expand Up @@ -564,7 +523,7 @@ color: rgb(125, 169, 172);
<property name="geometry">
<rect>
<x>0</x>
<y>290</y>
<y>260</y>
<width>1291</width>
<height>111</height>
</rect>
Expand Down Expand Up @@ -725,13 +684,11 @@ color: rgb(125, 169, 172);
<zorder>label_5</zorder>
<zorder>label_7</zorder>
<zorder>label_10</zorder>
<zorder>label_11</zorder>
<zorder>municipality_entry</zorder>
<zorder>csv_entry</zorder>
<zorder>risk30_vp_entry</zorder>
<zorder>expected_entry</zorder>
<zorder>iteration_entry</zorder>
<zorder>year_entry</zorder>
<zorder>municipality_button</zorder>
<zorder>csv_button</zorder>
<zorder>risk30_vp_button</zorder>
Expand Down