Python workflow for groundwater chemistry and water-level trend analysis.
project-root/
├── pyproject.toml
├── README.md
├── environment.yml
├── configs/
│ └── config.toml
├── input/
│ └── ...
└── src/
└── tta/
├── run_tta.py
├── config.py
├── utils.py
├── preprocessing/
│ ├── prepare_chromium_chemistry.py
│ ├── prepare_chemistry_data.py
│ ├── calculate_distance_00.py
│ ├── chemistry_import_01.py
│ ├── water_level_import_02.py
│ ├── water_level_trends_03.py
│ └── tobit_prep_04.py
├── model/
│ └── tobit_model_04.py
└── reporting/
└── generate_report_05.py
Create and activate the conda environment:
conda env create -f environment.yml
conda activate ttaInstall the package from the project root:
pip install -e .Edit the TOML file before running:
configs/config.toml
Run from the project root:
tta configs/config.tomlAlternative:
python -m tta.run_tta configs/config.tomlPaths in the TOML are expected to be relative to the project root.
Raw HEIS chemistry TXT files are listed directly in config.toml. Chemistry preparation runs automatically inside the workflow, with the mode controlled by chem_prep_mode:
[prep_chemistry]
raw_chemistry_files = [
"input/00_Data/Chemistry_Data/CY24/file1.txt",
"input/00_Data/Chemistry_Data/CY24/file2.txt",
]
chem_prep_mode = "chromium" # "chromium" | "single""chromium" mode — combines filtered total Chromium and Hexavalent Chromium into a single analyte stream. The full workflow runs once.
"single" mode — one or more analytes supplied as a list. The workflow runs end-to-end for each analyte in turn, producing a separate set of outputs per analyte:
chem_prep_mode = "single"
analyte = ["Nitrate"] # single analyte
analyte = ["Nitrate", "Uranium"] # multiple analytes — workflow loops over each
# filtered_keep_value = "Y" # optional FILTERED column restrictionOutputs are written to the configured output directory and run-version subfolder. Analyte-specific files include the analyte name as a slug (e.g. Nitrate, Hex_Filt_Chromium).
prepared_chemistry_<analyte>_<run_id>.parquet
Chem_TrendData_<analyte>_<run_id>.parquet
TTA_full_term_stats_<analyte>_<run_id>.csv
TTA_Results_<analyte>_<run_id>.csv
TobitRegression_WLlag_<OU>_<analyte>_<run_id>.pdf
WL_regression_<run_id>.pdf ← water-level only, produced once
tta.log
tta.log contains progress messages, warnings, errors, and detailed debug information from the run.
Main workflow entry point. It:
- reads the TOML configuration;
- creates the output directory;
- applies global well filters and optional
selected_wells; - runs Steps 00–03 once (analyte-independent);
- loops over each configured analyte, running Steps 01 and 04–05 per analyte;
- writes all outputs with the analyte name in the filename;
- writes progress and errors to
tta.log.
Calculates well distance to the river and distance to river-stage gauges. Runs once — results are shared across all analytes.
Imports and processes water-level data (Step 02), then estimates groundwater-level trends and river-stage lag times (Step 03). Both steps run once and are shared across all analytes.
Reads raw HEIS TXT files and prepares the chemistry dataset for one analyte. Runs in two phases:
- Raw data preparation — analyte selection and filtering via
prepare_chromium_chemistryorprepare_chemistry_datadepending onchem_prep_mode. The prepared dataset is written tooutput_diras a parquet. - Chemistry import — non-detect handling, REVIEWQ and collection-purpose filtering, daily averaging, and joining of river-stage, well metadata, and screen interval data.
Prepares chemistry data for censored regression by applying trend breaks, assigning trend terms, and handling no-river-stage wells. Fits Tobit models and writes TTA_full_term_stats_<analyte>_<run_id>.csv and TTA_Results_<analyte>_<run_id>.csv.
Generates OU-level PDF reports. The analyte name is used in plot axis labels (read directly from the chemistry data) and in the output PDF filename.