skyan1002's picture
v1.0 manifest covering all 806 testbeds; docs/CLI corrected; mirror Zenodo qc/ and code/pipeline/; DOI 10.5281/zenodo.22100899
80ca811 verified
Raw History Blame Contribute Delete
3.84 kB
#!/bin/sh
# ffbench - minimal CLI for the TORRENT CONUS flash-flood benchmark (curl required; jq optional).
# Usage: ffbench {query|download|get|bundle|help} [flags]
# query list catalog rows (record_type=record) matching the filters
# download fetch artifact files matching the filters; --kind picks one file type
# get fetch every file of one testbed: ffbench get FF_2025_07_TX_ep002__08165500
# bundle fetch a curated bundle: ffbench bundle {primary21|strict175}
# Docs: DOWNLOAD.md / AGENTS.md. Archive of record: doi.org/10.5281/zenodo.22118051
set -eu
BASE="${FFBENCH_BASE:-https://huggingface.co/datasets/skyan1002/flash-flood-benchmark-data/resolve/main}"
CACHE="${FFBENCH_CACHE:-${TMPDIR:-/tmp}/ffbench_manifest.jsonl}"
have_jq() { command -v jq >/dev/null 2>&1; }
get_manifest() { [ -f "$CACHE" ] || curl -sL "$BASE/manifest.jsonl" -o "$CACHE"; }
LEVEL=l3; STATE=""; START=""; END=""; STRICT=""; DEDUP=""; PRIMARY=""; RPMIN=""
KIND="all"; OUT="./ffbench_out"; CMD="${1:-help}"; [ $# -gt 0 ] && shift || true; ARG=""
while [ $# -gt 0 ]; do case "$1" in
--level) LEVEL=$2; shift 2;; --state) STATE=$2; shift 2;; --start) START=$2; shift 2;;
--end) END=$2; shift 2;; --strict) STRICT=1; shift;;
--dedup|--selected) DEDUP=1; shift;; --primary) PRIMARY=1; shift;;
--rp-min) RPMIN=$2; shift 2;; --kind) KIND=$2; shift 2;; --out) OUT=$2; shift 2;;
-*) echo "unknown flag $1" >&2; exit 2;; *) ARG=$1; shift;; esac; done
build_filter() {
f=".level==\"$(echo "$LEVEL"|tr a-z A-Z)\""
[ -n "$STATE" ] && f="$f and .primary_state_abbrev==\"$STATE\""
[ -n "$START" ] && f="$f and .begin_date>=\"$START\""
[ -n "$END" ] && f="$f and .begin_date<=\"$END\""
[ -n "$STRICT" ] && f="$f and .is_strict_flash_flood==true"
[ -n "$DEDUP" ] && f="$f and (.dedup_selected==true or .selected==true)"
[ -n "$PRIMARY" ] && f="$f and .primary_benchmark==true"
[ -n "$RPMIN" ] && f="$f and .lp3_return_period_yr>=$RPMIN"
echo "$f"
}
case "$CMD" in
query)
get_manifest; have_jq || { echo "query needs jq" >&2; exit 3; }
jq -c "select(.record_type==\"record\" and $(build_filter)) | {testbed_id,ff_episode_id,gage_id,primary_state_abbrev,begin_date,lp3_return_period_yr,flash_flood_class,package_class}" "$CACHE";;
download)
get_manifest; have_jq || { echo "download needs jq" >&2; exit 3; }
mkdir -p "$OUT"
kf='true'; [ "$KIND" != all ] && kf=".artifact_kind==\"$KIND\""
jq -r "select(.record_type==\"artifact\" and $(build_filter) and $kf).resolve_url" "$CACHE" \
| while read -r u; do (cd "$OUT" && curl -L -C - -O "$u"); done;;
get)
[ -n "$ARG" ] || { echo "get needs TESTBED_ID (e.g. FF_2025_07_TX_ep002__08165500)" >&2; exit 2; }
get_manifest; mkdir -p "$OUT"
if have_jq; then urls=$(jq -r "select(.testbed_id==\"$ARG\" and .record_type==\"artifact\").resolve_url" "$CACHE");
else
# the JSONL is emitted with a space after each colon; ' ?' tolerates either form
urls=$(grep -E "\"testbed_id\": ?\"$ARG\"" "$CACHE" | grep -E '"record_type": ?"artifact"' \
| grep -oE '"resolve_url": ?"[^"]*"' | sed 's/.*"resolve_url": *"//; s/"$//'); fi
[ -n "$urls" ] || { echo "no artifacts for testbed_id=$ARG" >&2; exit 4; }
echo "$urls" | while read -r u; do [ -n "$u" ] && (cd "$OUT" && curl -L -C - -O "$u"); done;;
bundle)
case "$ARG" in primary21) z=testbeds_primary21.zip;; strict175) z=testbeds_strict175.zip;;
*) echo "bundle: primary21|strict175" >&2; exit 2;; esac
curl -L -C - -O "$BASE/bundles/$z";;
help|*)
sed -n '2,8p' "$0"
echo "flags: --level l1|l2|l3 --state XX --start YYYY-MM-DD --end YYYY-MM-DD"
echo " --strict --dedup|--selected --primary --rp-min N --out DIR"
echo " --kind streamflow|watershed|hwms_inside|summary|mrms_basin_mean|package_zip|bundle|all";;
esac