Skip to content

Commit 6cf3215

Browse files
authored
Merge pull request #63 from ar-siddiqui/feature/ornl-algorithm
Add ESA ORNL algorithm
2 parents bf3ffeb + 556882a commit 6cf3215

23 files changed

Lines changed: 98 additions & 101 deletions

curve_number_generator/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
-------------------
99
begin : 2020-06-06
1010
copyright : (C) 2021 by Abdul Raheem Siddiqui
11-
email : mailto:ars.work.ce@gmail.com
11+
email : mailto:ar-siddiqui@outlook.com
1212
***************************************************************************/
1313
1414
/***************************************************************************

curve_number_generator/curve_number_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-------------------
1010
begin : 2022-07-22
1111
copyright : (C) 2022 by Abdul Raheem Siddiqui
12-
email : mailto:ars.work.ce@gmail.com
12+
email : mailto:ar-siddiqui@outlook.com
1313
***************************************************************************/
1414
1515
/***************************************************************************

curve_number_generator/metadata.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
name=Curve Number Generator
77
qgisMinimumVersion=3.18
88
description=Curve Number Generator plugin has multiple algorithms to generate the curve number layer for any area of interest using different datasets.
9-
version=2.2.0
9+
version=2.2.1
1010
author=Abdul Raheem Siddiqui
11-
email=ars.work.ce@gmail.com
11+
email=ar-siddiqui@outlook.com
1212

1313
about=Curve Number Generator plugin has multiple algorithms to generate the curve number layer for any area of interest using different datasets.
1414

@@ -21,7 +21,10 @@ repository=https://github.com/ar-siddiqui/curve_number_generator
2121

2222
hasProcessingProvider=yes
2323
# Uncomment the following line and add your changelog:
24-
changelog= Version 2.2.0 - 2024-04-16
24+
changelog=Version 2.2.1 - 2024-07-21
25+
- Add a new global algorithm utilizing ESA Land Cover and ORNL HSG datasets
26+
- Deprecate ESA and ISRIL aglorithm
27+
Version 2.2.0 - 2024-04-16
2528
- Add a new global algorithm utilizing ESA and ISRIC datasets
2629
Version 2.1.3 - 2023-10-17
2730
- Change NLCD Land Cover and Impervious layer to 2021 dataset
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
from .conus_nlcd_ssurgo.conus_nlcd_ssurgo import ConusNlcdSsurgo
22
from .custom.custom import Custom
3-
4-
from .global_esa_isric.global_esa_isric import GlobalEsaIsric
3+
from .global_esa_ornl.global_esa_ornl import GlobalEsaORNL

curve_number_generator/processing/algorithms/conus_nlcd_ssurgo/conus_nlcd_ssurgo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-------------------
1010
begin : 2022-07-22
1111
copyright : (C) 2022 by Abdul Raheem Siddiqui
12-
email : ars.work.ce@gmail.com
12+
email : ar-siddiqui@outlook.com
1313
***************************************************************************/
1414
1515
/***************************************************************************
@@ -487,7 +487,7 @@ def shortHelpString(self):
487487
<p>SSURGO Extended Soil Dataset </p>
488488
<h3>Curve Number</h3>
489489
<p>Generated Curve Number layer based on Land Cover and HSG values.</p>
490-
<br><p align="right">Algorithm author: Abdul Raheem Siddiqui</p><p align="right">Help author: Abdul Raheem Siddiqui</p><p align="right">Algorithm version: {PLUGIN_VERSION}</p><p align="right">Contact email: ars.work.ce@gmail.com</p><p>Disclaimer: The curve numbers generated with this algorithm are high level estimates and should be reviewed in detail before being used for detailed modeling or construction projects.</p></body></html>"""
490+
<br><p align="right">Algorithm author: Abdul Raheem Siddiqui</p><p align="right">Help author: Abdul Raheem Siddiqui</p><p align="right">Algorithm version: {PLUGIN_VERSION}</p><p align="right">Contact email: ar-siddiqui@outlook.com</p><p>Disclaimer: The curve numbers generated with this algorithm are high level estimates and should be reviewed in detail before being used for detailed modeling or construction projects.</p></body></html>"""
491491
)
492492

493493
def createInstance(self):

curve_number_generator/processing/algorithms/custom/custom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-------------------
1010
begin : 2022-07-22
1111
copyright : (C) 2022 by Abdul Raheem Siddiqui
12-
email : mailto:ars.work.ce@gmail.com
12+
email : mailto:ar-siddiqui@outlook.com
1313
***************************************************************************/
1414
1515
/***************************************************************************
@@ -226,7 +226,7 @@ def shortHelpString(self):
226226
<h2>Outputs</h2>
227227
<h3>Curve Number</h3>
228228
<p>Generated Curve Number Layer based on Land Cover and Soils.</p>
229-
<br><p align="right">Algorithm author: Abdul Raheem Siddiqui</p><p align="right">Help author: Abdul Raheem Siddiqui</p><p align="right">Algorithm version: {PLUGIN_VERSION}</p><p align="right">Contact email: ars.work.ce@gmail.com</p></body></html>"""
229+
<br><p align="right">Algorithm author: Abdul Raheem Siddiqui</p><p align="right">Help author: Abdul Raheem Siddiqui</p><p align="right">Algorithm version: {PLUGIN_VERSION}</p><p align="right">Contact email: ar-siddiqui@outlook.com</p></body></html>"""
230230
)
231231

232232
def createInstance(self):

curve_number_generator/processing/algorithms/global_esa_isric/esa_land_cover.qml renamed to curve_number_generator/processing/algorithms/global_esa_ornl/esa_land_cover.qml

File renamed without changes.

curve_number_generator/processing/algorithms/global_esa_isric/esa_worldcover_2021.vrt renamed to curve_number_generator/processing/algorithms/global_esa_ornl/esa_worldcover_2021.vrt

File renamed without changes.

curve_number_generator/processing/algorithms/global_esa_isric/global_esa_isric.py renamed to curve_number_generator/processing/algorithms/global_esa_ornl/global_esa_ornl.py

Lines changed: 58 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
This plugin generates a Curve Number layer for the given Area of Interest within the contiguous United States. It can also download Soil, Land Cover, and Impervious Surface datasets for the same area.
88
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
99
-------------------
10-
begin : 2022-07-22
11-
copyright : (C) 2022 by Abdul Raheem Siddiqui
12-
email : ars.work.ce@gmail.com
10+
begin : 2024-07-07
11+
copyright : (C) 2024 by Abdul Raheem Siddiqui
12+
email : ar-siddiqui@outlook.com
1313
***************************************************************************/
1414
1515
/***************************************************************************
@@ -38,13 +38,15 @@
3838
)
3939
from qgis.PyQt.QtGui import QIcon
4040

41-
from curve_number_generator.processing.config import GLOBAL_ESA_ISRIC, PLUGIN_VERSION
41+
from curve_number_generator.processing.config import GLOBAL_ESA_ORNL, PLUGIN_VERSION
4242
from curve_number_generator.processing.curve_number_generator_algorithm import (
4343
CurveNumberGeneratorAlgorithm,
4444
)
4545
from curve_number_generator.processing.tools.curve_numper import CurveNumber
4646
from curve_number_generator.processing.tools.utils import (
4747
createDefaultLookup,
48+
createRequestBBOXDim,
49+
downloadFile,
4850
gdalPolygonize,
4951
gdalWarp,
5052
generate_cn_exprs,
@@ -66,7 +68,7 @@
6668
__revision__ = "$Format:%H$"
6769

6870

69-
class GlobalEsaIsric(CurveNumberGeneratorAlgorithm):
71+
class GlobalEsaORNL(CurveNumberGeneratorAlgorithm):
7072
# Constants used to refer to parameters and outputs. They will be
7173
# used when calling the algorithm from another algorithm, or when
7274
# calling from the QGIS console.
@@ -79,7 +81,7 @@ def initAlgorithm(self, config=None):
7981
self.hc = ["Poor", "Fair", "Good"]
8082
self.arc = ["I", "II", "III"]
8183
self.lc_pixel_size = 0.000083333333333
82-
self.soils_pixel_size = 0.0026
84+
self.soils_pixel_size = 0.00208333
8385

8486
self.addParameter(
8587
QgsProcessingParameterVectorLayer(
@@ -133,7 +135,7 @@ def initAlgorithm(self, config=None):
133135
self.addParameter(
134136
QgsProcessingParameterRasterDestination(
135137
"Soils",
136-
"ISRIC Derived HSG",
138+
"HSG",
137139
optional=True,
138140
createByDefault=False,
139141
defaultValue=None,
@@ -161,7 +163,7 @@ def initAlgorithm(self, config=None):
161163
def processAlgorithm(self, parameters, context, model_feedback):
162164
# Use a multi-step feedback, so that individual child algorithm progress reports are adjusted for the
163165
# overall progress through the model
164-
feedback = QgsProcessingMultiStepFeedback(6, model_feedback)
166+
feedback = QgsProcessingMultiStepFeedback(7, model_feedback)
165167
results = {}
166168
outputs = {}
167169

@@ -184,12 +186,13 @@ def processAlgorithm(self, parameters, context, model_feedback):
184186
extent[2] + 2 * self.lc_pixel_size,
185187
extent[3] + 2 * self.lc_pixel_size,
186188
)
187-
extent_isric = (
189+
extent_ornl = (
188190
extent[0] - 2 * self.soils_pixel_size,
189191
extent[1] - 2 * self.soils_pixel_size,
190192
extent[2] + 2 * self.soils_pixel_size,
191193
extent[3] + 2 * self.soils_pixel_size,
192194
)
195+
bbox_dim_soil = createRequestBBOXDim(extent_ornl, self.soils_pixel_size)
193196

194197
step = 1
195198
feedback.setCurrentStep(step)
@@ -250,67 +253,51 @@ def processAlgorithm(self, parameters, context, model_feedback):
250253
]
251254
):
252255

256+
if parameters.get("Soils", None):
257+
try:
258+
parameters["Soils"].destinationName = "HSG"
259+
except AttributeError:
260+
pass
261+
262+
soils_output = parameters["Soils"]
263+
else:
264+
soils_output = QgsProcessing.TEMPORARY_OUTPUT
265+
266+
outputs["DownloadedSoils"] = downloadFile(
267+
GLOBAL_ESA_ORNL["ORNL_HYSOG"].format(
268+
bbox_dim_soil[0],
269+
bbox_dim_soil[1],
270+
",".join([str(item) for item in extent_ornl]),
271+
),
272+
"https://webmap.ornl.gov/ogcbroker/wcs",
273+
"Error getting Hydorologic Soil Group data from 'https://webmap.ornl.gov/'. Most probably because either their server is down or there is a certification issue.\nThis should be temporary. Try again later.\n",
274+
context=context,
275+
feedback=feedback,
276+
)
277+
253278
alg_params = {
254-
"DATA_TYPE": 0,
255-
"EXTRA": "",
256-
"INPUT": GLOBAL_ESA_ISRIC["ISRIC_CLAY"],
279+
"INPUT": outputs["DownloadedSoils"],
280+
"TARGET_CRS": None,
257281
"NODATA": None,
282+
"COPY_SUBDATASETS": False,
258283
"OPTIONS": "",
259-
"PROJWIN": f"{extent_isric[0]},{extent_isric[2]},{extent_isric[1]},{extent_isric[3]} [EPSG:4326]",
260-
"OUTPUT": QgsProcessing.TEMPORARY_OUTPUT,
284+
"EXTRA": "",
285+
"DATA_TYPE": 0,
286+
"OUTPUT": soils_output,
261287
}
262-
outputs["IsricClay"] = processing.run(
263-
"gdal:cliprasterbyextent",
264-
alg_params,
265-
context=context,
266-
feedback=feedback,
267-
is_child_algorithm=True,
268-
)["OUTPUT"]
269288

270289
step += 1
271290
feedback.setCurrentStep(step)
272291
if feedback.isCanceled():
273292
return {}
274293

275-
# reproject to 4326
276-
# the original CRS of of ISRIC raster is probalamtic and raster is disappearing in QGIS in that CRS
277-
outputs["IsricClay4326"] = gdalWarp(
278-
outputs["IsricClay"],
279-
QgsCoordinateReferenceSystem("EPSG:4326"),
294+
outputs["Soils"] = processing.run(
295+
"gdal:translate",
296+
alg_params,
280297
context=context,
281298
feedback=feedback,
282-
)
283-
284-
step += 1
285-
feedback.setCurrentStep(step)
286-
if feedback.isCanceled():
287-
return {}
288-
289-
input_dict = {
290-
"input_a": outputs["IsricClay4326"],
291-
"band_a": 1,
292-
}
293-
exprs = "((A== 0) * 0) + ((A >= 1) * (A <= 100) * 1) + ((A >= 100) * (A <= 200) * 2) + ((A > 200) *(A <= 400) * 3) + ((A > 400) * 4)"
294-
295-
if parameters.get("Soils", None):
296-
try:
297-
parameters["Soils"].destinationName = "ISRIC Derived HSG"
298-
except AttributeError:
299-
pass
300-
301-
soils_output = parameters["Soils"]
302-
else:
303-
soils_output = QgsProcessing.TEMPORARY_OUTPUT
304-
305-
outputs["Soils"] = perform_raster_math(
306-
exprs,
307-
input_dict,
308-
context,
309-
feedback,
310-
output=soils_output,
311-
no_data=255,
312-
out_data_type=0,
313-
)
299+
is_child_algorithm=True,
300+
)["OUTPUT"]
314301

315302
step += 1
316303
feedback.setCurrentStep(step)
@@ -414,14 +401,14 @@ def name(self):
414401
lowercase alphanumeric characters only and no spaces or other
415402
formatting characters.
416403
"""
417-
return "globalesaisric"
404+
return "globalesaornl"
418405

419406
def displayName(self):
420407
"""
421408
Returns the translated algorithm name, which should be used for any
422409
user-visible display of the algorithm name.
423410
"""
424-
return self.tr("Curve Number Generator (Global) (ESA & ISRIC)")
411+
return self.tr("Curve Number Generator (Global) (ESA & ORNL)")
425412

426413
def icon(self):
427414
icon = QIcon(os.path.join(cmd_folder, "icon.png"))
@@ -438,33 +425,34 @@ def shortHelpString(self):
438425
msg
439426
+ f"""<html><body>
440427
<h2>Algorithm description</h2>
441-
<p>This algorithm generates a Curve Number layer for the given Area of Interest. It can also generate Hydrologic Soil Groups (HSG) raster from ISRIC clay dataset and download ESA Land Cover raster for the same area.
428+
<p>This algorithm generates a Curve Number layer for the given Area of Interest. It can also generate Hydrologic Soil Groups (HSG) raster from ORNL Hydrologic Soil Group dataset (HYSOGs250m) and download ESA Land Cover 2021 raster for the same area.
442429
443-
For areas where the ISRIC dataset has no data such as urban areas, HSG D is assumed.</p>
430+
For areas where the ORNL dataset has no data such as permanent water bodies, HSG D is assumed.</p>
444431
<h2>Input parameters</h2>
445432
<h3>Area of Interest</h3>
446-
<p>Polygon layer representing an area of interest</p>
433+
<p>Polygon layer representing an area of interest.</p>
447434
<h3>Lookup Table [optional</h3>
448-
<p>Optional Table to relate ESA Land Cover Value and HSG Value to a particular curve number. By default the algorithm uses pre defined tables. The table must have two columns 'grid_code' and 'cn'. grid_code is a concatenation of ESA Land Cover code and Hydrologic Soil Group. <a href="https://raw.githubusercontent.com/ar-siddiqui/curve_number_generator/v{PLUGIN_VERSION}/curve_number_generator/processing/algorithms/global_esa_isric/lookups/default_lookup_f_ii.csv">Template csv file to create custom table</a>.</p>
435+
<p>Optional Table to relate ESA Land Cover Value and HSG Value to a particular curve number. By default the algorithm uses pre defined tables. The table must have two columns 'grid_code' and 'cn'. grid_code is a concatenation of ESA Land Cover code and Hydrologic Soil Group. <a href="https://raw.githubusercontent.com/ar-siddiqui/curve_number_generator/v{PLUGIN_VERSION}/curve_number_generator/processing/algorithms/global_esa_ornl/lookups/default_lookup_f_ii.csv">Template csv file to create custom table</a>.</p>
449436
<h3>Hydrologic Condition [Ignored when custom lookup table is provided]</h3>
450437
<p> Hydrologic condition is a parameter that represents combinations of factors that affect infiltration and runof. It can be Poor, Fair, or Good. (see <a href="https://directives.sc.egov.usda.gov/17758.wba">Table 9-1</a> for further description).
451438
452439
If unsure, use the default fair hydrologic conidtion which is the most common case in hydrologic studies.
453440
<h3>Antecedent Runoff Condition [Ignored when custom lookup table is provided]</h3>
454441
<p> Antecedent Runoff Condition (ARC) is the relative wetness or dryness index for the soil. I for dry, II for average, and III for wet conditions. (see <a href="https://directives.sc.egov.usda.gov/17752.wba">Table 10-1</a> for further understanding)</p>
442+
443+
If unsure, use the default ARC II which is the most common case in hydrologic studies.
455444
<h2>Outputs</h2>
456445
<h3>ESA World Cover</h3>
457446
<p>ESA Land Cover 2021 raster.</p>
458-
<h3>ISRIC Derived HSG</h3>
459-
<p>Hydrologic Soil Groups raster derived from the ISRIC clay dataset.
460-
461-
Note: In dense urban areas, ISRIC soil raster has nodata cells, which are also reflected in the derived HSG raster.</p>
447+
<h3>HSG</h3>
448+
<p>ORNL Hydrologic Soil Groups (HYSOGs250m).</p>
462449
<h3>Curve Number</h3>
463450
<p>Generated Curve Number layer based on Land Cover and HSG values.</p>
464451
<h3>Curve Number (Vectorized)</h3>
465452
<p>Vector form of the generated Curve Number layer.</p>
466-
<br><p align="right">Algorithm author: Abdullah Azzam</p><p align="right">Help author: Abdullah Azzam</p><p align="right">Algorithm version: {PLUGIN_VERSION}</p><p align="right">Contact email: ars.work.ce@gmail.com</p><p>Disclaimer: The curve numbers generated with this algorithm are high level estimates and should be reviewed in detail before being used for detailed modeling or construction projects.</p></body></html>"""
453+
<br>
454+
<p align="right">Algorithm science author: Abdullah Azzam</p><p align="right">Code author: Abdul Raheem Siddiqui</p><p align="right">Help author: Abdullah Azzam</p><p align="right">Algorithm version: {PLUGIN_VERSION}</p><p align="right">Contact email: ar-siddiqui@outlook.com</p><p>Disclaimer: The curve numbers generated with this algorithm are high level estimates and should be reviewed in detail before being used for detailed modeling or construction projects.</p></body></html>"""
467455
)
468456

469457
def createInstance(self):
470-
return GlobalEsaIsric()
458+
return GlobalEsaORNL()

curve_number_generator/processing/algorithms/global_esa_isric/icon.png renamed to curve_number_generator/processing/algorithms/global_esa_ornl/icon.png

File renamed without changes.

0 commit comments

Comments
 (0)