Repository: dailyerosion/dep
Pull request #322: Omnibus
Author: login: akrherz
Created: 2025-03-06T17:15:17Z | Merged: 2025-03-06T17:19:39Z



Diff:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index d2fcca7d..aeeb85a9 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,6 @@
 repos:
   - repo: https://github.com/astral-sh/ruff-pre-commit
-    rev: "v0.9.6"
+    rev: "v0.9.9"
     hooks:
       - id: ruff
         args: [--fix, --exit-non-zero-on-fix]
diff --git a/scripts/gssurgo/1_extract_USSoils2021_dominantComponent.sql b/scripts/gssurgo/1_extract_USSoils2021_dominantComponent.sql
index 4f9b807e..876aacb1 100644
--- a/scripts/gssurgo/1_extract_USSoils2021_dominantComponent.sql
+++ b/scripts/gssurgo/1_extract_USSoils2021_dominantComponent.sql
@@ -13,7 +13,7 @@ USE US_Soils2
 IF OBJECT_ID('dbo.US_DomComponents') IS NOT NULL 
         DROP TABLE dbo.US_DomComponents
 
-set search_path=gssurgo24;
+set search_path=gssurgo25;
 SELECT mukey
       ,cokey
       ,compname
diff --git a/scripts/gssurgo/Calc1_DEP_chFrags_2020.sql b/scripts/gssurgo/Calc1_DEP_chFrags_2020.sql
index 3dfc20b1..3df63a68 100644
--- a/scripts/gssurgo/Calc1_DEP_chFrags_2020.sql
+++ b/scripts/gssurgo/Calc1_DEP_chFrags_2020.sql
@@ -21,7 +21,7 @@ USE DEPSoils2020
 IF OBJECT_ID('dbo.DEP_SoilFrags') IS NOT NULL 
         DROP TABLE dbo.DEP_SoilFrags
 
-set search_path=gssurgo24;
+set search_path=gssurgo25;
 SELECT hrz.chkey
       ,SUM(frg.fragvol_r) as FragTot
   INTO DEP_SoilFrags
diff --git a/scripts/gssurgo/Calc2_DEP_SurfaceTxt_2020.sql b/scripts/gssurgo/Calc2_DEP_SurfaceTxt_2020.sql
index 59f9f5ba..9c5fddbb 100644
--- a/scripts/gssurgo/Calc2_DEP_SurfaceTxt_2020.sql
+++ b/scripts/gssurgo/Calc2_DEP_SurfaceTxt_2020.sql
@@ -24,7 +24,7 @@ USE DEPSoils2020
 IF OBJECT_ID('dbo.DEP_SurfaceTexture') IS NOT NULL 
         DROP TABLE dbo.DEP_SurfaceTexture
 
-set search_path=gssurgo24;
+set search_path=gssurgo25;
 SELECT cokey
       ,compname
       ,comppct_r
diff --git a/scripts/gssurgo/Calc3_DEP_SoilFractions_2020.sql b/scripts/gssurgo/Calc3_DEP_SoilFractions_2020.sql
index 98edaece..5d100196 100644
--- a/scripts/gssurgo/Calc3_DEP_SoilFractions_2020.sql
+++ b/scripts/gssurgo/Calc3_DEP_SoilFractions_2020.sql
@@ -34,7 +34,7 @@ USE DEPSoils2020
 IF OBJECT_ID('dbo.DEP_SoilFractions') IS NOT NULL 
         DROP TABLE dbo.DEP_SoilFractions
 
-set search_path=gssurgo24;
+set search_path=gssurgo25;
 SELECT mukey
       , cokey
       , compname
diff --git a/scripts/gssurgo/Calc4_DEP_SoilParameters_2020.sql b/scripts/gssurgo/Calc4_DEP_SoilParameters_2020.sql
index 0c2ccb57..867b1d9f 100644
--- a/scripts/gssurgo/Calc4_DEP_SoilParameters_2020.sql
+++ b/scripts/gssurgo/Calc4_DEP_SoilParameters_2020.sql
@@ -33,7 +33,7 @@ USE DEPSoils2020
 
 IF OBJECT_ID('dbo.DEP_HrzCount') IS NOT NULL 
         DROP TABLE dbo.DEP_HrzCount
-set search_path=gssurgo24;
+set search_path=gssurgo25;
  SELECT dom.cokey
       , Count(F.chkey) as HrzCount
       
diff --git a/scripts/gssurgo/Calc5_subset_toMW_SoilParameters_2018.sql b/scripts/gssurgo/Calc5_subset_toMW_SoilParameters_2018.sql
index 4c8964d4..167d80f4 100644
--- a/scripts/gssurgo/Calc5_subset_toMW_SoilParameters_2018.sql
+++ b/scripts/gssurgo/Calc5_subset_toMW_SoilParameters_2018.sql
@@ -1,6 +1,6 @@
 USE DEP_Soils
 GO
-set search_path=gssurgo24;
+set search_path=gssurgo25;
 SELECT sp.mukey
       ,sp.cokey
       ,sp.compname
diff --git a/scripts/gssurgo/README.md b/scripts/gssurgo/README.md
index 3884b01d..2c7f5f72 100644
--- a/scripts/gssurgo/README.md
+++ b/scripts/gssurgo/README.md
@@ -18,15 +18,15 @@ discussion with DJ settled that this situation is isolated to wonky soils like
 Ran the following commands to ingest the needed layers into postgresql
 
 ```sql
-create schema gssurgo24;
-ALTER DATABASE idep SET search_path = public,gssurgo24;
+create schema gssurgo25;
+ALTER DATABASE idep SET search_path = public,gssurgo25;
 ```
 
 ```bash
-ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo24.component component -progress
-ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo24.mapunit mapunit -progress
-ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo24.chorizon chorizon -progress
-ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo24.chfrags chfrags -progress
-ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo24.chtexture  chtexture  -progress
-ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo24.chtexturegrp  chtexturegrp  -progress
+ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo25.component component -progress
+ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo25.mapunit mapunit -progress
+ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo25.chorizon chorizon -progress
+ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo25.chfrags chfrags -progress
+ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo25.chtexture  chtexture  -progress
+ogr2ogr -f "PostgreSQL" PG:"host=iemdb-idep.local dbname=idep" gSSURGO_CONUS.gdb -nln gssurgo25.chtexturegrp  chtexturegrp  -progress
 ```
diff --git a/scripts/gssurgo/calc6_insert_gssurgo.sql b/scripts/gssurgo/calc6_insert_gssurgo.sql
index 13ddc68d..0fe9eee3 100644
--- a/scripts/gssurgo/calc6_insert_gssurgo.sql
+++ b/scripts/gssurgo/calc6_insert_gssurgo.sql
@@ -2,8 +2,8 @@
 -- CHECK that this matches what happens in write_DEP2020_WEPPSoils.py
 
 INSERT into public.gssurgo(fiscal_year, mukey, label, kwfact, hydrogroup)
-SELECT 2024, mukey::int, compname, kwfact::real, hydrogroup
-FROM gssurgo24.DEP_SoilParameters
+SELECT 2025, mukey::int, compname, kwfact::real, hydrogroup
+FROM gssurgo25.DEP_SoilParameters
 WHERE HrzCount > 0 AND Albedo Is Not Null AND compname != 'Aquolls'
 AND KI Is Not Null AND KR Is Not Null AND TC Is Not Null
 AND KB Is Not Null;
@@ -11,8 +11,8 @@ AND KB Is Not Null;
 with data as (
     select mukey, clay, om, rank()
         OVER (PARTITION by mukey ORDER by depthto_mm ASC) from
-    gssurgo24.dep_soilfractions)
+    gssurgo25.dep_soilfractions)
 
 update public.gssurgo g SET
 plastic_limit = 14.22 + 0.005 * clay * clay + 3.63 * om - 0.048 * clay * om
-from data d where d.rank = 1 and d.mukey::int = g.mukey and g.fiscal_year = 2024;
+from data d where d.rank = 1 and d.mukey::int = g.mukey and g.fiscal_year = 2025;
diff --git a/scripts/gssurgo/write_DEP2020_WEPPSoils.py b/scripts/gssurgo/write_DEP2020_WEPPSoils.py
index 13639821..a34bf4bc 100644
--- a/scripts/gssurgo/write_DEP2020_WEPPSoils.py
+++ b/scripts/gssurgo/write_DEP2020_WEPPSoils.py
@@ -33,7 +33,7 @@
 def main():
     """Main loop."""
     #
-    outPath = "/i/0/sol_input_fy2024"
+    outPath = "/i/0/sol_input_fy2025"
 
     # SQL Server connect
     cxn = get_dbconn("idep")
@@ -41,7 +41,7 @@ def main():
     Pcursor = cxn.cursor()
     Pcursor.execute(
         """Select mukey, compname, Albedo, Texture, HrzCount, KI, KR, TC, KB
-        From gssurgo24.DEP_SoilParameters
+        From gssurgo25.DEP_SoilParameters
         Where HrzCount > 0 AND Albedo Is Not Null AND compname != 'Aquolls'
         AND KI Is Not Null AND KR Is Not Null AND TC Is Not Null
         AND KB Is Not Null
@@ -65,7 +65,7 @@ def main():
             outf.write("#\n")
             outf.write("# DEP SOL\n")
             outf.write(f"# daryl {utc():%Y-%m-%dT%H:%M:%SZ}\n")
-            outf.write("# Source: US gSSURGO CONUS FY2024\n")
+            outf.write("# Source: US gSSURGO CONUS FY2025\n")
             outf.write("#\n")
             outf.write(f"SSURGO MUKEY: {row[0]}\n")
             outf.write("1 1\n")
@@ -76,7 +76,7 @@ def main():
             HrzCursor.execute(
                 """
                 SELECT DepthTo_mm, Sand, Clay, OM, CEC7, FragTot
-                FROM gssurgo24.DEP_SoilFractions
+                FROM gssurgo25.DEP_SoilFractions
                 WHERE mukey = %s ORDER by DepthTo_mm
                 """,
                 (row[0],),
diff --git a/scripts/import/flowpath_importer.py b/scripts/import/flowpath_importer.py
index b43e5c0c..133582e9 100644
--- a/scripts/import/flowpath_importer.py
+++ b/scripts/import/flowpath_importer.py
@@ -39,13 +39,14 @@
     "MAX_POINTS_OFE": 97,
     "CONSTANT_LANDUSE": None,
     "CONSTANT_MANAGEMENT": None,
+    "TRUNC_GRIDORDER_AT": 4,
+    "CLIMATE_SCENARIO": 0,
 }
 
 YEARS = 2025 - 2007 + 1
 SOILFY = 2024
 ROTATION_FIELD = "CropRotatn_CY_2023"  # Tied to ACPF
 SOILCOL = f"SOL_FY_{SOILFY}"
-TRUNC_GRIDORDER_AT = 4
 GENLU_CODES = {}
 PROCESSING_COUNTS = {
     "flowpaths_found": 0,
@@ -55,7 +56,7 @@
     "flowpaths_toosteep": 0,
     "flowpaths_toomanydupes": 0,
     "flowpaths_invalidgeom": 0,
-    "flowpaths_lenzero_reset": 0,
+    "flowpaths_not_start_len_zero": 0,
     "flowpaths_inconsistent_gridorder": 0,
     "flowpaths_deleted": 0,
     "flowpath_ofes_deleted": 0,
@@ -336,12 +337,12 @@ def insert_ofe(cursor, gdf, db_fid, ofe, ofe_starts):
     )
 
 
-def get_cli_fname_and_id(cursor, lon, lat, scenario) -> tuple[str, int]:
+def get_cli_fname_and_id(cursor, lon, lat) -> tuple[str, int]:
     """Get database entry or add one."""
-    clifn = get_cli_fname(lon, lat, scenario)
+    clifn = get_cli_fname(lon, lat, KNOBS["CLIMATE_SCENARIO"])
     cursor.execute(
         "select id from climate_files where scenario = %s and filepath = %s",
-        (scenario, clifn),
+        (KNOBS["CLIMATE_SCENARIO"], clifn),
     )
     if cursor.rowcount == 0:
         # Danger, we are doing lame things from the database on my laptop to
@@ -352,7 +353,7 @@ def get_cli_fname_and_id(cursor, lon, lat, scenario) -> tuple[str, int]:
         cursor.execute(
             "INSERT into climate_files(id, scenario, filepath, geom) "
             "values (%s, %s, %s, ST_Point(%s, %s, 4326))",
-            (cli_id, scenario, clifn, lon, lat),
+            (cli_id, KNOBS["CLIMATE_SCENARIO"], clifn, lon, lat),
         )
     else:
         cli_id = cursor.fetchone()[0]
@@ -368,7 +369,7 @@ def process_flowpath(
     # to bottom, rename columns to simplify further code.
     df = df.sort_values("len", ascending=True)
     if df.iloc[0]["len"] > 0:
-        PROCESSING_COUNTS["flowpaths_lenzero_reset"] += 1
+        PROCESSING_COUNTS["flowpaths_not_start_len_zero"] += 1
         df["len"] = df["len"] - df.iloc[0]["len"]
     # remove duplicate points due to a bkgelder sampling issue whereby some
     # points exist in two fields
@@ -383,7 +384,7 @@ def process_flowpath(
         return
 
     # Truncate at grid order
-    df = df[df["gorder"] <= TRUNC_GRIDORDER_AT]
+    df = df[df["gorder"] <= KNOBS["TRUNC_GRIDORDER_AT"]]
 
     if len(df.index) < 3:
         PROCESSING_COUNTS["flowpaths_tooshort"] += 1
@@ -431,7 +432,7 @@ def process_flowpath(
         df.iloc[0].geometry.x,
         df.iloc[0].geometry.y,
     )
-    clifn, clifn_id = get_cli_fname_and_id(cursor, lon, lat, scenario)
+    clifn, clifn_id = get_cli_fname_and_id(cursor, lon, lat)
     cursor.execute(
         """
         UPDATE flowpaths SET geom = %s, irrigated = %s,
@@ -578,6 +579,7 @@ def scan_file_attributes(fns: list):
 @click.option("--constant-landuse", "cl", type=str, default=None)
 @click.option("--constant-management", "cm", type=str, default=None)
 @click.option("--skipscan", is_flag=True)
+@click.option("--gorder", type=int, default=4, help="Truncate at grid order")
 def main(
     scenario,
     datadir,
@@ -585,11 +587,13 @@ def main(
     cl: Optional[str],
     cm: Optional[str],
     skipscan: bool,
+    gorder: int,
 ):
     """Our main function, the starting point for code execution"""
     KNOBS["MAX_POINTS_OFE"] = mpe
     KNOBS["CONSTANT_LANDUSE"] = cl
     KNOBS["CONSTANT_MANAGEMENT"] = cm
+    KNOBS["TRUNC_GRIDORDER_AT"] = gorder
     pgconn = get_dbconn("idep")
     cursor = pgconn.cursor()
     load_genlu_codes(cursor)
diff --git a/scripts/util/delete_huc12.py b/scripts/util/delete_huc12.py
index f5400dfa..3d1a6e99 100644
--- a/scripts/util/delete_huc12.py
+++ b/scripts/util/delete_huc12.py
@@ -2,58 +2,48 @@
 
 import glob
 import os
-import sys
 
-from pyiem.util import get_dbconn
+import click
+from pyiem.database import get_sqlalchemy_conn, sql_helper
 
 
-def do_delete(huc12, scenario):
+def do_delete(conn, huc12, scenario):
     """Delete all things."""
-    pgconn = get_dbconn("idep")
-    cursor = pgconn.cursor()
-
-    # Remove any flowpath points, ofes
-    for table in [
-        "ofes",
-    ]:
-        cursor.execute(
-            f"""
-        delete from flowpath_{table} pts using flowpaths f where
-        pts.flowpath = f.fid and f.huc_12 = %s and f.scenario = %s
-        """,
-            (huc12, scenario),
-        )
-        print(f"removed {cursor.rowcount} flowpath_{table}")
-
-    # Remove any flowpaths
-    cursor.execute(
-        """
-    DELETE from flowpaths where huc_12 = %s and scenario = %s
-    """,
-        (huc12, scenario),
+    params = {"huc12": huc12, "scenario": scenario}
+    res = conn.execute(
+        sql_helper("""
+    delete from flowpath_ofes pts using flowpaths f where
+    pts.flowpath = f.fid and f.huc_12 = :huc12 and f.scenario = :scenario
+    """),
+        params,
     )
-    print(f"removed {cursor.rowcount} flowpaths")
+    print(f"removed {res.rowcount} flowpath_ofes")
 
-    # remove any results
-    cursor.execute(
-        """
-    DELETE from results_by_huc12 where huc_12 = %s and scenario = %s
-    """,
-        (huc12, scenario),
+    res = conn.execute(
+        sql_helper("""
+    delete from field_operations o using fields f where
+    o.field_id = f.field_id and f.huc12 = :huc12 and f.scenario = :scenario
+    """),
+        params,
     )
-    print(f"removed {cursor.rowcount} results_by_huc12")
+    print(f"removed {res.rowcount} field_operations")
 
-    # remove the huc12 from the baseline table
-    cursor.execute(
-        """
-        DELETE from huc12 where huc_12 = %s and scenario = %s
-    """,
-        (huc12, scenario),
-    )
-    print(f"removed {cursor.rowcount} rows from huc12")
+    for table in ["flowpaths", "results_by_huc12", "huc12", "fields"]:
+        hcol = "huc_12" if table != "fields" else "huc12"
+        res = conn.execute(
+            sql_helper(
+                """
+        DELETE from {table} where {hcol} = :huc12 and scenario = :scenario
+        """,
+                table=table,
+                hcol=hcol,
+            ),
+            params,
+        )
+        print(f"removed {res.rowcount} from {table}")
 
     # Remove some files
-    for prefix in ["env", "error", "man", "prj", "run", "slp", "sol", "wb"]:
+    for prefix in "env error man prj run slp sol wb".split():
         dirname = f"/i/{scenario}/{prefix}/{huc12[:8]}/{huc12[8:]}"
         if not os.path.isdir(dirname):
             continue
@@ -67,16 +57,16 @@ def do_delete(huc12, scenario):
         # Try to remove the huc8 folder
         os.rmdir(f"/i/{scenario}/{prefix}/{huc12[:8]}")
 
-    cursor.close()
-    pgconn.commit()
-
 
-def main(argv):
+@click.command()
+@click.option("--huc12", required=True, help="HUC12 to delete")
+@click.option("--scenario", required=True, help="Scenario", type=int)
+def main(huc12: str, scenario: int):
     """Go Main Go"""
-    huc12 = argv[1]
-    scenario = int(argv[2])
-    do_delete(huc12, scenario)
+    with get_sqlalchemy_conn("idep") as conn:
+        do_delete(conn, huc12, scenario)
+        conn.commit()
 
 
 if __name__ == "__main__":
-    main(sys.argv)
+    main()


Reviews:
user: login: gemini-code-assist[bot]
body: Hello @akrherz, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

## Summary of Changes
This pull request appears to be an omnibus update, primarily focused on updating the gSSURGO (Gridded Soil Survey Geographic Database) data ingestion scripts and updating the ruff pre-commit hook. The gSSURGO updates involve switching from the `gssurgo24` schema to `gssurgo25`, reflecting a likely update to the data source for the year 2025. The `flowpath_importer.py` script is also updated to reflect the new data and add some additional knobs.

### Highlights
* **gSSURGO Data Update**: The scripts under `scripts/gssurgo/` have been updated to use the `gssurgo25` schema instead of `gssurgo24`, indicating a data refresh for the year 2025.
* **Pre-commit Hook Update**: The `.pre-commit-config.yaml` file has been updated to use a newer version of the `ruff` pre-commit hook (`v0.9.9` from `v0.9.6`).
* **Flowpath Importer Updates**: The `flowpath_importer.py` script has been updated to include a `CLIMATE_SCENARIO` knob and a `TRUNC_GRIDORDER_AT` knob, as well as some changes to how flowpaths are processed.
* **HUC12 Deletion Script**: The `delete_huc12.py` script has been refactored to use sqlalchemy and click.

### Changelog
<details>
<summary>Click here to see the changelog</summary>

* **.pre-commit-config.yaml**
  * Updated the `ruff` pre-commit hook version from `v0.9.6` to `v0.9.9`.
* **scripts/gssurgo/1_extract_USSoils2021_dominantComponent.sql**
  * Changed `set search_path` from `gssurgo24` to `gssurgo25`.
* **scripts/gssurgo/Calc1_DEP_chFrags_2020.sql**
  * Changed `set search_path` from `gssurgo24` to `gssurgo25`.
* **scripts/gssurgo/Calc2_DEP_SurfaceTxt_2020.sql**
  * Changed `set search_path` from `gssurgo24` to `gssurgo25`.
* **scripts/gssurgo/Calc3_DEP_SoilFractions_2020.sql**
  * Changed `set search_path` from `gssurgo24` to `gssurgo25`.
* **scripts/gssurgo/Calc4_DEP_SoilParameters_2020.sql**
  * Changed `set search_path` from `gssurgo24` to `gssurgo25`.
* **scripts/gssurgo/Calc5_subset_toMW_SoilParameters_2018.sql**
  * Changed `set search_path` from `gssurgo24` to `gssurgo25`.
* **scripts/gssurgo/README.md**
  * Updated the `create schema` and `ALTER DATABASE` commands to use `gssurgo25` instead of `gssurgo24`.
  * Updated the `ogr2ogr` commands to use `gssurgo25` instead of `gssurgo24`.
* **scripts/gssurgo/calc6_insert_gssurgo.sql**
  * Changed the `INSERT` statement to use `2025` as the `fiscal_year` and `gssurgo25.DEP_SoilParameters` as the source table.
  * Changed the `update` statement to use `gssurgo25.dep_soilfractions` as the source table and `2025` as the `fiscal_year`.
* **scripts/gssurgo/write_DEP2020_WEPPSoils.py**
  * Changed `outPath` to `/i/0/sol_input_fy2025`.
  * Changed the `SELECT` statement to use `gssurgo25.DEP_SoilParameters` as the source table.
  * Updated the file header comment to indicate `US gSSURGO CONUS FY2025` as the source.
  * Changed the `SELECT` statement to use `gssurgo25.DEP_SoilFractions` as the source table.
* **scripts/import/flowpath_importer.py**
  * Added `TRUNC_GRIDORDER_AT` and `CLIMATE_SCENARIO` to the `KNOBS` dictionary.
  * Renamed `flowpaths_lenzero_reset` to `flowpaths_not_start_len_zero`.
  * Modified `get_cli_fname_and_id` to use `KNOBS["CLIMATE_SCENARIO"]` instead of a passed-in `scenario` argument.
  * Modified the `INSERT` statement in `get_cli_fname_and_id` to use `KNOBS["CLIMATE_SCENARIO"]` instead of a passed-in `scenario` argument.
  * Updated the conditional check for resetting flowpath length to increment `flowpaths_not_start_len_zero`.
  * Modified the truncation of grid order to use `KNOBS["TRUNC_GRIDORDER_AT"]`.
  * Modified `process_flowpath` to use `get_cli_fname_and_id` without the scenario, and pass the lon/lat directly.
  * Added `gorder` option to the `main` function and set `KNOBS["TRUNC_GRIDORDER_AT"]` accordingly.
* **scripts/util/delete_huc12.py**
  * Refactored to use sqlalchemy and click.
  * Removed cursor and pgconn objects.
  * Modified queries to use sql_helper and named parameters.
  * Consolidated table deletion into a loop.
  * Modified main function to use click and sqlalchemy.

</details>


<details>

<summary><b>Using Gemini Code Assist</b></summary>
<br>

The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.

<b>Invoking Gemini</b>

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands.

Feature | Command | Description
--- | --- | ---
Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments.
Help | `/gemini help` | Displays a list of available commands.

<b>Customization</b>

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/review-github-code).

<b>Limitations & Feedback</b>

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments to provide feedback.

</details>

<b>You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the [Gemini Code Assist IDE Extension](https://cloud.google.com/products/gemini/code-assist).</b>


[^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/review-github-code). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).

---

**Did you know?**

The Natural Resources Conservation Service (NRCS) is the agency responsible for maintaining and updating the gSSURGO database.

state: COMMENTED
author_association: NONE
submitted_at: 2025-03-06T17:15:30Z
user: login: gemini-code-assist[bot]
body: ## Code Review
This pull request updates the gSSURGO data processing scripts and imports flowpath data for a new fiscal year (FY2025). The changes involve updating schema names, file paths, and database queries to reflect the new data year. The pull request also includes updates to the flowpath importer script to handle climate scenarios and grid order truncation. Overall, the changes seem well-organized and necessary for updating the data processing pipeline.

### Summary of Findings
* **Inconsistent Fiscal Year Updates**: While most scripts are updated to reflect the FY2025 data, the `SOILFY` variable in `scripts/import/flowpath_importer.py` remains set to 2024. This inconsistency could lead to errors or unexpected behavior during data processing.
* **Hardcoded Climate Scenario**: The `CLIMATE_SCENARIO` knob is hardcoded to 0 in `scripts/import/flowpath_importer.py`. This limits the flexibility of the script and may require future modifications to support different climate scenarios.
* **Magic Number in Plastic Limit Calculation**: The plastic limit calculation in `scripts/gssurgo/calc6_insert_gssurgo.sql` uses the magic number `14.22`. It would be beneficial to provide context or a comment explaining the origin or significance of this value.

### Merge Readiness
The pull request is not quite ready for merging. The inconsistent fiscal year update in `scripts/import/flowpath_importer.py` and the hardcoded climate scenario should be addressed before merging. The magic number in the plastic limit calculation should also be clarified. I am unable to approve this pull request, and recommend that others review and approve this code before merging. Addressing the high severity issues is crucial for ensuring the correctness and maintainability of the code.
state: CHANGES_REQUESTED
author_association: NONE
submitted_at: 2025-03-06T17:15:47Z

Review comments:
diff_hunk: @@ -39,13 +39,14 @@
     "MAX_POINTS_OFE": 97,
     "CONSTANT_LANDUSE": None,
     "CONSTANT_MANAGEMENT": None,
+    "TRUNC_GRIDORDER_AT": 4,
+    "CLIMATE_SCENARIO": 0,
 }
 
 YEARS = 2025 - 2007 + 1
 SOILFY = 2024
path: scripts/import/flowpath_importer.py
user: login: gemini-code-assist[bot]
body: ![high](https://img.shields.io/badge/priority-high-orange)

The `SOILFY` variable is still set to 2024. Should this be updated to 2025 to align with the other changes in this pull request?

```suggestion
SOILFY = 2025
```
created_at: 2025-03-06T17:15:47Z
author_association: NONE
diff_hunk: @@ -2,17 +2,17 @@
 -- CHECK that this matches what happens in write_DEP2020_WEPPSoils.py
 
 INSERT into public.gssurgo(fiscal_year, mukey, label, kwfact, hydrogroup)
-SELECT 2024, mukey::int, compname, kwfact::real, hydrogroup
-FROM gssurgo24.DEP_SoilParameters
+SELECT 2025, mukey::int, compname, kwfact::real, hydrogroup
+FROM gssurgo25.DEP_SoilParameters
 WHERE HrzCount > 0 AND Albedo Is Not Null AND compname != 'Aquolls'
 AND KI Is Not Null AND KR Is Not Null AND TC Is Not Null
 AND KB Is Not Null;
 
 with data as (
     select mukey, clay, om, rank()
         OVER (PARTITION by mukey ORDER by depthto_mm ASC) from
-    gssurgo24.dep_soilfractions)
+    gssurgo25.dep_soilfractions)
 
 update public.gssurgo g SET
 plastic_limit = 14.22 + 0.005 * clay * clay + 3.63 * om - 0.048 * clay * om
path: scripts/gssurgo/calc6_insert_gssurgo.sql
user: login: gemini-code-assist[bot]
body: ![medium](https://img.shields.io/badge/priority-medium-yellow)

The value `14.22` is a magic number. Consider adding a comment explaining where this value comes from or what it represents.

```sql
plastic_limit = 14.22 + 0.005 * clay * clay + 3.63 * om - 0.048 * clay * om -- 14.22 is constant derived from [source]
```
created_at: 2025-03-06T17:15:47Z
author_association: NONE
diff_hunk: @@ -39,13 +39,14 @@
     "MAX_POINTS_OFE": 97,
     "CONSTANT_LANDUSE": None,
     "CONSTANT_MANAGEMENT": None,
+    "TRUNC_GRIDORDER_AT": 4,
+    "CLIMATE_SCENARIO": 0,
path: scripts/import/flowpath_importer.py
user: login: gemini-code-assist[bot]
body: ![medium](https://img.shields.io/badge/priority-medium-yellow)

The `CLIMATE_SCENARIO` is hardcoded to 0. Consider making this configurable via a command-line argument or environment variable to allow for different climate scenarios to be used without modifying the code.

```suggestion
    "CLIMATE_SCENARIO": 0, # Consider making this configurable
```
created_at: 2025-03-06T17:15:47Z
author_association: NONE

PR comments:
user: login: deepsource-io[bot]
created_at: 2025-03-06T17:15:41Z
body: <div><p>Here's the code health analysis summary for commits <code>03a0d7a..22f899e</code>. <a href="https://app.deepsource.com/gh/dailyerosion/dep/run/520616ed-9fee-4a14-952a-3d8b03496320/">View details on DeepSource</a>&nbsp;↗.</p><h3>Analysis Summary</h3><table><thead><tr><th>Analyzer</th><th>Status</th><th>Summary</th><th>Link</th></tr></thead><tbody><tr><td><img src="https://static.deepsource.com/analyzer_logos/javascript.svg" alt="DeepSource JavaScript Logo" width="16px" height="16px"/><strong>JavaScript</strong></td><td><span>✅&nbsp;</span><span>Success</span></td><td></td><td><a href="https://app.deepsource.com/gh/dailyerosion/dep/run/520616ed-9fee-4a14-952a-3d8b03496320/javascript/">View Check</a>&nbsp;↗</td></tr><tr><td><img src="https://static.deepsource.com/analyzer_logos/python.svg" alt="DeepSource Python Logo" width="16px" height="16px"/><strong>Python</strong></td><td><span>✅&nbsp;</span><span>Success</span></td><td></td><td><a href="https://app.deepsource.com/gh/dailyerosion/dep/run/520616ed-9fee-4a14-952a-3d8b03496320/python/">View Check</a>&nbsp;↗</td></tr></tbody></table><hr/><blockquote><div>💡 If you’re a repository administrator, you can configure the quality gates from the <a href="https://app.deepsource.com/gh/dailyerosion/dep/settings/reporting">settings</a>.</div></blockquote></div>

author_association: NONE
user: login: codecov[bot]
created_at: 2025-03-06T17:19:40Z
body: ## [Codecov](https://app.codecov.io/gh/dailyerosion/dep/pull/322?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dailyerosion) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 96.39%. Comparing base [(`03a0d7a`)](https://app.codecov.io/gh/dailyerosion/dep/commit/03a0d7a54d6fecc7d90c56d0d8bfa0c3c61a281b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dailyerosion) to head [(`22f899e`)](https://app.codecov.io/gh/dailyerosion/dep/commit/22f899e71bc3126b88a8c3e94d56787d8fda19e5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dailyerosion).
> Report is 6 commits behind head on main.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #322   +/-   ##
=======================================
  Coverage   96.39%   96.39%           
=======================================
  Files          10       10           
  Lines         472      472           
=======================================
  Hits          455      455           
  Misses         17       17           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/dailyerosion/dep/pull/322?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dailyerosion).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dailyerosion).

<details><summary>🚀 New features to boost your workflow: </summary>

- ❄ [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
author_association: NONE