Skip to content

Commit 697069e

Browse files
authored
Merge pull request #41 from ClarkCGA/yayao
Enhance Vulnerability Mapping with Mask Input, UI Updates, and Documentation Revision
2 parents 0979dc4 + f3f13ec commit 697069e

23 files changed

+330
-163
lines changed

UDef-ARP.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ def process_data2(self):
270270
QMessageBox.critical(self, "Error", "Please select the working directory!")
271271
return
272272

273-
if not self.in_fn:
274-
QMessageBox.critical(self, "Error", "Please select the input file!")
273+
if not self.in_fn or not self.mask:
274+
QMessageBox.critical(self, "Error", "Please select all input files!")
275275
return
276276

277277
NRT = self.nrt_entry.text()
@@ -329,7 +329,7 @@ def process_data2(self):
329329

330330
try:
331331
self.vulnerability_map.set_working_directory(directory)
332-
mask_arr = self.vulnerability_map.geometric_classification(self.in_fn, NRT, n_classes)
332+
mask_arr = self.vulnerability_map.geometric_classification(self.in_fn, NRT, n_classes, self.mask)
333333
self.vulnerability_map.array_to_image(self.in_fn, out_fn, mask_arr, gdal.GDT_Int16, -1)
334334
self.vulnerability_map.replace_ref_system(self.in_fn, out_fn)
335335

@@ -828,6 +828,7 @@ def __init__(self):
828828
self.doc_button = self.tab1.findChild(QWidget, "doc_button")
829829
self.select_folder_button = self.tab1.findChild(QWidget, "select_folder_button")
830830
self.fd_button = self.tab1.findChild(QWidget, "fd_button")
831+
self.mask_button = self.tab1.findChild(QWidget, "mask_button")
831832
self.ok_button2 = self.tab1.findChild(QWidget, "ok_button2")
832833

833834
self.doc_button_2 = self.tab2.findChild(QWidget, "doc_button_2")
@@ -840,6 +841,7 @@ def __init__(self):
840841
self.doc_button.clicked.connect(self.openDocument)
841842
self.select_folder_button.clicked.connect(self.select_working_directory)
842843
self.fd_button.clicked.connect(self.select_fd)
844+
self.mask_button.clicked.connect(self.select_mask)
843845
self.ok_button2.clicked.connect(self.process_data2)
844846

845847
self.doc_button_2.clicked.connect(self.openDocument_2)
@@ -854,6 +856,7 @@ def __init__(self):
854856
self.directory = None
855857
self.in_fn = None
856858
self.NRT = None
859+
self.mask = None
857860
# Use NRT from the data store
858861
if central_data_store.NRT is not None:
859862
self.nrt_entry.setText(str(central_data_store.NRT))
@@ -910,6 +913,11 @@ def select_fd(self):
910913
if file_path:
911914
self.in_fn = file_path
912915
self.in_fn_entry.setText(file_path.split('/')[-1])
916+
def select_mask(self):
917+
file_path, _ = QFileDialog.getOpenFileName(self, 'Mask of Study Area')
918+
if file_path:
919+
self.mask = file_path
920+
self.mask_entry.setText(file_path.split('/')[-1])
913921

914922
def select_working_directory_2(self):
915923
data_folder_2 = QFileDialog.getExistingDirectory(self, "Working Directory")
@@ -943,8 +951,8 @@ def process_data2(self):
943951
QMessageBox.critical(self, "Error", "Please select the working directory!")
944952
return
945953

946-
if not self.in_fn:
947-
QMessageBox.critical(self, "Error", "Please select the input file!")
954+
if not self.in_fn or not self.mask:
955+
QMessageBox.critical(self, "Error", "Please select all input files!")
948956
return
949957

950958
NRT = self.nrt_entry.text()
@@ -1001,7 +1009,7 @@ def process_data2(self):
10011009

10021010
try:
10031011
self.vulnerability_map.set_working_directory(directory)
1004-
mask_arr = self.vulnerability_map.geometric_classification(self.in_fn, NRT, n_classes)
1012+
mask_arr = self.vulnerability_map.geometric_classification(self.in_fn, NRT, n_classes, self.mask)
10051013
self.vulnerability_map.array_to_image(self.in_fn, out_fn, mask_arr, gdal.GDT_Int16, -1)
10061014
self.vulnerability_map.replace_ref_system(self.in_fn, out_fn)
10071015

@@ -1553,6 +1561,7 @@ def __init__(self):
15531561
self.doc_button = self.tab1.findChild(QWidget, "doc_button")
15541562
self.select_folder_button = self.tab1.findChild(QWidget, "select_folder_button")
15551563
self.fd_button = self.tab1.findChild(QWidget, "fd_button")
1564+
self.mask_button = self.tab1.findChild(QWidget, "mask_button")
15561565
self.ok_button2 = self.tab1.findChild(QWidget, "ok_button2")
15571566

15581567
self.doc_button_2 = self.tab2.findChild(QWidget, "doc_button_2")
@@ -1565,6 +1574,7 @@ def __init__(self):
15651574
self.doc_button.clicked.connect(self.openDocument)
15661575
self.select_folder_button.clicked.connect(self.select_working_directory)
15671576
self.fd_button.clicked.connect(self.select_fd)
1577+
self.mask_button.clicked.connect(self.select_mask)
15681578
self.ok_button2.clicked.connect(self.process_data2)
15691579

15701580
self.doc_button_2.clicked.connect(self.openDocument_2)
@@ -1582,6 +1592,7 @@ def __init__(self):
15821592
if central_data_store.NRT is not None:
15831593
self.nrt_entry.setText(str(central_data_store.NRT))
15841594
self.n_classes = None
1595+
self.mask = None
15851596
self.out_fn = None
15861597
self.out_fn_entry.setPlaceholderText('e.g., Acre_Vulnerability_HRP.tif')
15871598

@@ -1628,7 +1639,11 @@ def select_fd(self):
16281639
if file_path:
16291640
self.in_fn = file_path
16301641
self.in_fn_entry.setText(file_path.split('/')[-1])
1631-
1642+
def select_mask(self):
1643+
file_path, _ = QFileDialog.getOpenFileName(self, 'Mask of Study Area')
1644+
if file_path:
1645+
self.mask = file_path
1646+
self.mask_entry.setText(file_path.split('/')[-1])
16321647
def select_working_directory_2(self):
16331648
data_folder_2 = QFileDialog.getExistingDirectory(self, "Working Directory")
16341649
data_folder_path_2 = Path(data_folder_2)
@@ -1661,8 +1676,8 @@ def process_data2(self):
16611676
QMessageBox.critical(self, "Error", "Please select the working directory!")
16621677
return
16631678

1664-
if not self.in_fn:
1665-
QMessageBox.critical(self, "Error", "Please select the input file!")
1679+
if not self.in_fn or not self.mask:
1680+
QMessageBox.critical(self, "Error", "Please select all input files!")
16661681
return
16671682

16681683
NRT = self.nrt_entry.text()
@@ -1719,7 +1734,7 @@ def process_data2(self):
17191734

17201735
try:
17211736
self.vulnerability_map.set_working_directory(directory)
1722-
mask_arr = self.vulnerability_map.geometric_classification(self.in_fn, NRT, n_classes)
1737+
mask_arr = self.vulnerability_map.geometric_classification(self.in_fn, NRT, n_classes, self.mask)
17231738
self.vulnerability_map.array_to_image(self.in_fn, out_fn, mask_arr, gdal.GDT_Int16, -1)
17241739
self.vulnerability_map.replace_ref_system(self.in_fn, out_fn)
17251740

@@ -1996,6 +2011,7 @@ def __init__(self):
19962011
self.doc_button = self.tab1.findChild(QWidget, "doc_button")
19972012
self.select_folder_button = self.tab1.findChild(QWidget, "select_folder_button")
19982013
self.fd_button = self.tab1.findChild(QWidget, "fd_button")
2014+
self.mask_button = self.tab1.findChild(QWidget, "mask_button")
19992015
self.ok_button2 = self.tab1.findChild(QWidget, "ok_button2")
20002016

20012017
self.doc_button_2 = self.tab2.findChild(QWidget, "doc_button_2")
@@ -2008,6 +2024,7 @@ def __init__(self):
20082024
self.doc_button.clicked.connect(self.openDocument)
20092025
self.select_folder_button.clicked.connect(self.select_working_directory)
20102026
self.fd_button.clicked.connect(self.select_fd)
2027+
self.mask_button.clicked.connect(self.select_mask)
20112028
self.ok_button2.clicked.connect(self.process_data2)
20122029

20132030
self.doc_button_2.clicked.connect(self.openDocument_2)
@@ -2025,6 +2042,7 @@ def __init__(self):
20252042
if central_data_store.NRT is not None:
20262043
self.nrt_entry.setText(str(central_data_store.NRT))
20272044
self.n_classes = None
2045+
self.mask = None
20282046
self.out_fn = None
20292047
self.out_fn_entry.setPlaceholderText('e.g., Acre_Vulnerability_VP.tif')
20302048

@@ -2071,6 +2089,11 @@ def select_fd(self):
20712089
if file_path:
20722090
self.in_fn = file_path
20732091
self.in_fn_entry.setText(file_path.split('/')[-1])
2092+
def select_mask(self):
2093+
file_path, _ = QFileDialog.getOpenFileName(self, 'Mask of Study Area')
2094+
if file_path:
2095+
self.mask = file_path
2096+
self.mask_entry.setText(file_path.split('/')[-1])
20742097

20752098
def select_working_directory_2(self):
20762099
data_folder_2 = QFileDialog.getExistingDirectory(self, "Working Directory")
@@ -2104,8 +2127,8 @@ def process_data2(self):
21042127
QMessageBox.critical(self, "Error", "Please select the working directory!")
21052128
return
21062129

2107-
if not self.in_fn:
2108-
QMessageBox.critical(self, "Error", "Please select the input file!")
2130+
if not self.in_fn or not self.mask:
2131+
QMessageBox.critical(self, "Error", "Please select all input files!")
21092132
return
21102133

21112134
NRT = self.nrt_entry.text()
@@ -2162,7 +2185,7 @@ def process_data2(self):
21622185

21632186
try:
21642187
self.vulnerability_map.set_working_directory(directory)
2165-
mask_arr = self.vulnerability_map.geometric_classification(self.in_fn, NRT, n_classes)
2188+
mask_arr = self.vulnerability_map.geometric_classification(self.in_fn, NRT, n_classes, self.mask)
21662189
self.vulnerability_map.array_to_image(self.in_fn, out_fn, mask_arr, gdal.GDT_Int16, -1)
21672190
self.vulnerability_map.replace_ref_system(self.in_fn, out_fn)
21682191

data/at_fit_cal_screen.ui

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<font>
8080
<family>AvenirNext LT Pro Cn</family>
8181
<pointsize>10</pointsize>
82-
<weight>7</weight>
82+
<weight>8</weight>
8383
<italic>false</italic>
8484
<bold>false</bold>
8585
</font>
@@ -116,7 +116,7 @@ border-radius:20px;
116116
<font>
117117
<family>AvenirNext LT Pro Cn</family>
118118
<pointsize>10</pointsize>
119-
<weight>7</weight>
119+
<weight>8</weight>
120120
<italic>false</italic>
121121
<bold>false</bold>
122122
</font>
@@ -318,7 +318,7 @@ color: rgb(125, 169, 172);
318318
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
319319
</property>
320320
<property name="text">
321-
<string>Map of Administrative Divisions</string>
321+
<string>Administrative Divisions image</string>
322322
</property>
323323
</widget>
324324
<widget class="QLabel" name="label_4">
@@ -334,7 +334,7 @@ color: rgb(125, 169, 172);
334334
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
335335
</property>
336336
<property name="text">
337-
<string>Vulnerability Map for the CAL (previous step)</string>
337+
<string>Vulnerability image for the CAL (previous step)</string>
338338
</property>
339339
</widget>
340340
<widget class="QLabel" name="label_6">
@@ -350,7 +350,7 @@ color: rgb(125, 169, 172);
350350
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
351351
</property>
352352
<property name="text">
353-
<string>Map of Deforestation in the CAL (binary map)</string>
353+
<string>Deforestation in the CAL</string>
354354
</property>
355355
</widget>
356356
<widget class="QLineEdit" name="municipality_entry">
@@ -513,7 +513,7 @@ color: rgb(125, 169, 172);
513513
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
514514
</property>
515515
<property name="text">
516-
<string>Name for the Modeling Region Map in the CAL</string>
516+
<string>Modeling Regions in the CAL</string>
517517
</property>
518518
</widget>
519519
<widget class="QLabel" name="label_10">
@@ -529,7 +529,7 @@ color: rgb(125, 169, 172);
529529
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
530530
</property>
531531
<property name="text">
532-
<string>Name for the Relative Frequency Table (.csv)</string>
532+
<string>Relative Frequency Table for the CAL</string>
533533
</property>
534534
</widget>
535535
<widget class="QLabel" name="label_9">
@@ -545,7 +545,7 @@ color: rgb(125, 169, 172);
545545
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
546546
</property>
547547
<property name="text">
548-
<string>Name for the Fitted Density Map in the CAL</string>
548+
<string>Fitted Density in the CAL</string>
549549
</property>
550550
</widget>
551551
<widget class="QLineEdit" name="image1_entry">

data/at_fit_hrp_screen.ui

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<font>
8080
<family>AvenirNext LT Pro Cn</family>
8181
<pointsize>10</pointsize>
82-
<weight>7</weight>
82+
<weight>8</weight>
8383
<italic>false</italic>
8484
<bold>false</bold>
8585
</font>
@@ -116,7 +116,7 @@ border-radius:20px;
116116
<font>
117117
<family>AvenirNext LT Pro Cn</family>
118118
<pointsize>10</pointsize>
119-
<weight>7</weight>
119+
<weight>8</weight>
120120
<italic>false</italic>
121121
<bold>false</bold>
122122
</font>
@@ -275,7 +275,7 @@ color: rgb(125, 169, 172);
275275
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
276276
</property>
277277
<property name="text">
278-
<string>Map of Administrative Divisions</string>
278+
<string>Administrative Divisions image</string>
279279
</property>
280280
</widget>
281281
<widget class="QLabel" name="label_4">
@@ -291,7 +291,7 @@ color: rgb(125, 169, 172);
291291
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
292292
</property>
293293
<property name="text">
294-
<string>Vulnerability Map for the HRP (previous step)</string>
294+
<string>Vulnerability image for the HRP (previous step)</string>
295295
</property>
296296
</widget>
297297
<widget class="QLabel" name="label_6">
@@ -307,7 +307,7 @@ color: rgb(125, 169, 172);
307307
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
308308
</property>
309309
<property name="text">
310-
<string>Map of Deforestation in the HRP (binary map)</string>
310+
<string>Deforestation in the HRP</string>
311311
</property>
312312
</widget>
313313
<widget class="QLineEdit" name="municipality_entry">
@@ -444,7 +444,7 @@ color: rgb(125, 169, 172);
444444
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
445445
</property>
446446
<property name="text">
447-
<string>Name for the Modeling Region Map in the HRP</string>
447+
<string>Modeling Regions in the HRP</string>
448448
</property>
449449
</widget>
450450
<widget class="QLabel" name="label_10">
@@ -460,7 +460,7 @@ color: rgb(125, 169, 172);
460460
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
461461
</property>
462462
<property name="text">
463-
<string>Name for the Relative Frequency Table (.csv)</string>
463+
<string>Relative Frequency Table for the HRP</string>
464464
</property>
465465
</widget>
466466
<widget class="QLabel" name="label_9">
@@ -476,7 +476,7 @@ color: rgb(125, 169, 172);
476476
<string notr="true">font: 10pt&quot;AvenirNext LT Pro Cn&quot;;</string>
477477
</property>
478478
<property name="text">
479-
<string>Name for the Fitted Density Map in the HRP</string>
479+
<string>Fitted Density in the HRP</string>
480480
</property>
481481
</widget>
482482
<widget class="QLineEdit" name="image1_entry">

0 commit comments

Comments
 (0)