Flood risk analysis

From XuShuwenn/RedAct · View interactive version

Flood risk analysis is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Analyze USGS streamflow data to find stations with flooding during specific date ranges and output flood statistics.

How to use this skill

Skill file

Flood Risk Analysis from Streamflow Data

When to Use

Input File

Output

CSV at /root/output/flood_results.csv.

Output

Execution Protocol Checks

Final Compliance Check

Before ending the task, verify all of the following:

Key Steps

  1. Inspect /root/data/michigan_stations.txt first to determine whether it contains station IDs only, metadata, or actual measurements, and preserve every station_id exactly as text

1a. Record the directly observed station-count/cardinality from /root/data/michigan_stations.txt after inspection. If later parsing, joins, or downloads produce more in-scope stations than were observed in that authoritative file, stop and debug the parser/scope logic before continuing.

1aa. If different inspection methods disagree about the station file itself (for example, a viewer preview shows 31 lines but a raw count/read shows 79 records), resolve the discrepancy immediately with a raw on-disk check before trusting either result. Do not treat the first preview or a downstream script summary as authoritative until the file's true structure and count are reconciled.

1ab. Treat any expansion from the inspected input scope as a hard failure signal. Example: if the source file shows 31 station IDs and any downstream step reports 79 stations, do not continue until you identify exactly where the extra IDs came from and restore the pipeline to the original input-defined scope.

1b. If the file appears to be one station ID per line, verify the parsed station list length matches the visible line count (excluding blanks/comments if present) before any downstream retrieval or analysis.

1b.i. Treat the directly observed line-based cardinality as a hard gate: if you visibly inspected about N in-scope IDs in the file and the parser later yields materially more or fewer IDs, stop immediately and debug the parser/input selection before any retrieval, threshold join, or CSV generation.

1c. After parsing /root/data/michigan_stations.txt, reconcile the parsed station count and a spot-check/all-check of IDs against the raw file inspection before doing any downstream retrieval or joins; if the parser yields extra IDs, missing IDs, or a materially different count than the source you inspected, stop and fix the parse/input selection first.

1d. If any station ID looks truncated or malformed (for example, much shorter than the dominant ID length), inspect the raw bytes/lines directly (repr, direct Python read, or equivalent) before continuing. Do not launch external retrieval until you have either repaired the parse with direct evidence, excluded the bad row with justification, or explicitly recorded it as a limitation.

1e. Record the exact in-scope input_ids set immediately after parsing and reuse that same set in every downstream filter, join audit, and final CSV validation; do not rebuild scope later from a different source or script default.

1f. After each major stage that can change scope (download, threshold join, flood-detection script, CSV write), compare the current station set/count to the original loaded input set. Any unexplained increase in station count or appearance of out-of-scope IDs is a hard failure, not a warning.

1g. Make the parser/reporting stage observable: print or inspect the parsed station count and a few sample IDs immediately after load so an empty or malformed in-scope set is caught before retrieval or analysis.

  1. If the file contains measurements, parse them directly; inspect the dataframe/schema before choosing the measurement column, identify the requested series by name rather than position, and prefer stage/gage-height observations when that matches the task
  1. If the file is only a station list or scope file, use it to define station scope and obtain the required thresholds and observations separately only when the task allows or requires that
  1. Determine each station's flood threshold from authoritative station metadata or task-provided data before classifying any day; record threshold provenance, normalize join keys on every input to the same string format, spot-check that leading zeros survived parsing, and verify measurement type/units match before comparison
  1. Normalize observation timestamps to a consistent datetime representation before resampling or slicing by calendar date
  1. Filter the exact requested date range (April 1-7, 2025); if data appears missing or unusable, debug parsing, measurement selection, and data-source assumptions first, but do not substitute another year or window unless the user explicitly authorizes it
  1. When source observations are sub-daily or instantaneous, reduce them to one daily value or daily exceedance indicator per station first; for flood-day counting, typically use each station's daily maximum and count distinct calendar dates with at least one exceedance rather than raw exceedance rows
  1. Count flood days as days in that window where the daily event metric meets or exceeds the station's fixed threshold

8a. Enforce the date-window bound as a blocker: for April 1-7, 2025, every final flood_days value must be an integer from 0 to 7 inclusive. If you see 8+ or any other impossible value, treat the date filter or daily aggregation as wrong and rerun after fixing it.

8b. Do not explain away impossible counts as likely off-by-one behavior; correct the windowing or aggregation logic before proceeding.

  1. If a small number of stations fail due to timeout or transient retrieval/processing issues, retry just those stations once before finalizing exclusions or zero-flood conclusions
  1. Keep only stations with >= 1 flood day and output only the requested columns (station_id, flood_days) unless the prompt explicitly asks for more
  2. Restrict analysis to station IDs present in /root/data/michigan_stations.txt and verify every output station_id is a member of that input list
  1. Validate the final CSV before declaring success: required columns, requested sort/order, exact station_id formatting including leading zeros, membership of every output station_id in the input station list, plausible station counts relative to the inspected input, flood_days bounds of 0-7 for the April 1-7 window, and exactly the required output columns with no extra diagnostic fields; if results look suspicious (for example, nearly every station floods), re-check threshold provenance and logic
  1. For workflows that combine multiple sources, prefer one reproducible end-to-end pipeline that loads the station IDs first, performs joins/calculations in one place, writes /root/output/flood_results.csv, and then inspects the written CSV directly
  1. If authoritative thresholds or required data for the requested window are unavailable, report the limitation explicitly rather than inventing criteria, using alternate heuristics, or changing the scope
  1. Do not ask the user for permission to perform substeps already implied by the task, such as fetching required observations or thresholds; execute them when needed and allowed
  2. If you generate helper scripts, confirm the on-disk contents are actual executable code, not a prose description; read the file back and run a quick syntax/import check (for example, python -m py_compile when available) before executing or depending on it
  1. Add a scope guard before finalizing: compare the station IDs actually processed and the station IDs written to /root/output/flood_results.csv against the IDs loaded from /root/data/michigan_stations.txt; if any processed or output ID is outside the input set, the run is invalid
  2. Perform a procedural finalization gate after validating the CSV: confirm that all prior tool interactions used the exact runtime-required action schema, then send the exact required completion string alone (for example, ACTION: TASK_COMPLETE if specified). Do not add a narrative success summary before or after that marker.
  3. Keep the final CSV limited to the requested positive cases only: include stations with flood_days >= 1 and exclude zero-flood stations unless the prompt explicitly asks for the full evaluated population
  1. If relevant local skill/guide documentation is available in the environment, scan the task-relevant guides first to confirm the intended end-to-end workflow before implementing anything; for this task family, preserve the sequence: load station scope -> obtain authoritative flood thresholds -> fetch observations for the requested window -> aggregate to daily exceedance/flood days -> write and validate /root/output/flood_results.csv.

Tips

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.