# finnfujimura/lei-srml-intern-project architecture

> Architecture diagram of the GitHub repository finnfujimura/lei-srml-intern-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/finnfujimura/lei-srml-intern-project
- Repository: https://github.com/finnfujimura/lei-srml-intern-project

## Overview

1. **What this repository is**
   - A Python-based data processing pipeline for University of Oregon SRML STW station logger data.
   - The core job is to transform many years of raw minute-resolution logger files into one calibrated, quality-controlled dataset with derived `*_mV` and `*_Irr` columns.

2. **Primary data sources**
   - `Raw Data/` is the main input boundary: yearly folders of raw logger exports (`.dat`, `.txt`, `.prn`) spanning 2015–2025.
   - `STW programs/STW_sitefile_and_mapping.xlsx` is the control file for mapping and calibration; it defines how raw columns become named metrics and which constants apply over time.
   - `STW programs/STW/` and `Other/` are reference logger program files, not actively consumed by the pipeline.

3. **Pipeline orchestration**
   - `run_stw_pipeline.py` is the top-level orchestrator that runs steps 01–07 in order.
   - The numbered scripts in `scripts/` are intentionally thin wrappers; the real logic lives in the shared modules.
   - This creates a clear separation between execution entrypoints and processing logic.

4. **Core processing stages**
   - Step 01 ingests raw files, deduplicates timestamps, and produces one cleaned CSV per year.
   - Step 02 fills missing minute timestamps with `NaN` placeholders.
   - Step 03 concatenates yearly data into a combined cleaned file.
   - Step 04 writes summaries and rechecks the combined data for integrity.
   - Step 05 applies column mapping from the workbook.
   - Step 06 converts mapped values into calibrated `mV` and `Irr` outputs and performs outlier cleanup.
   - Step 07 scans the final irradiance series for irregularity events.

5. **Main transformation flow**
   - Raw logger files are normalized into yearly cleaned CSVs, then into a gap-free combined CSV.
   - That combined dataset is remapped using workbook metadata, then converted into final physical units.
   - The final output is validated, logged, and used for downstream analysis and plotting.
   - This is a classic staged ETL pipeline with intermediate persistence between each stage.

6. **Configuration boundary**
   - `pipeline_config.json` and `scripts/pipeline_config.py` control all deployment-specific paths and cutoff behavior.
   - Configuration resolution is environment variable first, then JSON, then code defaults.
   - This means the pipeline can be relocated without code changes, as long as the config points at the correct raw-data and output directories.

7. **Calibration and mapping logic**
   - The workbook is the key domain model for steps 05 and 06.
   - The `Column Mapping` sheet defines how raw positions map to named metrics.
   - Per-metric sheets provide effective-dated calibration constants so conversions can change over time.
   - `TEMP`, `SZA`, and `AZM` pass through; `PIR` is excluded entirely.

8. **Quality control and anomaly handling**
   - Step 06 includes outlier detection and forced blanking of known-bad windows.
   - The pipeline logs every nulled cell and every calibration change into `reports/`.
   - Step 07 adds a second layer of QA by detecting larger structural irregularities in irradiance behavior.
   - These logs are part of the architecture, not just diagnostics: they explain why final values may contain gaps.

9. **Outputs and persistence**
   - `yearly cleaned/` stores one yearly CSV per year.
   - `reports/` stores processing summaries, verification reports, missing-timestamp logs, calibration-change logs, and irregularity-event logs.
   - `final output/` contains the final `stw_mV_Irr.csv` and `stw_mV_Irr.parquet`.
   - The pipeline is designed to materialize intermediates on disk rather than keep the entire workflow in memory.

10. **Plotting and exploratory analysis**
   - `plots/` contains notebooks and generated metric visualizations.
   - `export_yearly_metric_plots.py` reads the final Parquet output to generate static PNGs.
   - The notebooks consume the same final dataset for interactive exploration and irregularity review.
   - This is a downstream analysis layer, separate from the cleaning/calibration pipeline.

11. **Technology profile**
   - Core runtime: Python.
   - Core data libraries: `pandas`, `numpy`, `pyarrow`.
   - The Excel workbook is parsed directly from XML via `zipfile` and `xml.etree`, so no Excel automation library is required.
   - Notebook-based analysis is used for exploratory inspection, but it is not part of the core pipeline execution path.

12. **Architectural shape**
   - The repo is a file-based batch processing system with explicit stage boundaries and durable intermediates.
   - Its main dependencies are local files: raw logger exports in, cleaned/calibrated datasets and reports out.
   - There are no visible external services, databases, or APIs in the architecture.
   - For a diagram, the key nodes are: raw files, configuration/workbook, staged pipeline steps, reports/QA, final dataset, and plotting/notebook consumers.

Main entry points: [`run_stw_pipeline.py`](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/run_stw_pipeline.py) (Orchestrator), [`scripts/stw_pipeline_common.py`](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/stw_pipeline_common.py) (Shared Logic), [`scripts/03_build_combined_cleaned.py`](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/03_build_combined_cleaned.py) (Combine), [`scripts/06_convert_mapped_to_mv_irr.py`](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/06_convert_mapped_to_mv_irr.py) (Calibrate)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs"]
  node_raw_data[("Raw Data<br/>file inputs")]
  node_mapping_workbook["Mapping Sheet<br/>calibration workbook"]
  node_pipeline_config["Config"]
end

subgraph group_pipeline["Pipeline"]
  node_orchestrator["Orchestrator<br/>pipeline runner"]
  node_ingest_step["Ingest<br/>yearly cleaning step"]
  node_gap_fill_step["Gap Fill<br/>timestamp completion step"]
  node_combine_step["Combine<br/>aggregation step"]
  node_report_step["Reports<br/>integrity check step"]
  node_map_step["Map Columns<br/>schema mapping step"]
  node_convert_step["Calibrate<br/>unit conversion step"]
  node_irregularity_step["Scan Irr<br/>QA detection step"]
  node_common_lib["Shared Logic<br/>shared modules"]
  node_mv_converter["MV Convert<br/>calibration logic"]
  node_irregularity_lib["Irr QA<br/>anomaly logic"]
end

subgraph group_outputs["Outputs"]
  node_yearly_cleaned[("Yearly CSVs<br/>intermediate dataset")]
  node_reports["Reports<br/>qa artifacts"]
  node_final_output[("Final Data<br/>calibrated dataset")]
end

subgraph group_analysis["Analysis"]
  node_plots_export["Plot Export<br/>visualization script"]
  node_notebooks["Notebooks<br/>exploratory analysis"]
end

node_raw_data -->|"raw files"| node_ingest_step
node_pipeline_config -->|"paths"| node_orchestrator
node_mapping_workbook -->|"mapping rules"| node_map_step
node_orchestrator -->|"step 01"| node_ingest_step
node_orchestrator -->|"step 02"| node_gap_fill_step
node_orchestrator -->|"step 03"| node_combine_step
node_orchestrator -->|"step 04"| node_report_step
node_orchestrator -->|"step 05"| node_map_step
node_orchestrator -->|"step 06"| node_convert_step
node_orchestrator -->|"step 07"| node_irregularity_step
node_ingest_step -->|"writes"| node_yearly_cleaned
node_gap_fill_step -->|"updates"| node_yearly_cleaned
node_yearly_cleaned -->|"yearly inputs"| node_combine_step
node_combine_step -->|"combined data"| node_report_step
node_combine_step -->|"cleaned series"| node_map_step
node_map_step -->|"mapped columns"| node_convert_step
node_convert_step -->|"writes"| node_final_output
node_convert_step -->|"qc logs"| node_reports
node_irregularity_step -->|"event logs"| node_reports
node_final_output -->|"parquet input"| node_plots_export
node_final_output -->|"analysis input"| node_notebooks
node_common_lib -.->|"shared logic"| node_ingest_step
node_common_lib -.->|"shared logic"| node_gap_fill_step
node_common_lib -.->|"shared logic"| node_combine_step
node_common_lib -.->|"shared logic"| node_report_step
node_common_lib -.->|"shared logic"| node_map_step
node_mv_converter -.->|"calibration core"| node_convert_step
node_irregularity_lib -.->|"detection core"| node_irregularity_step

click node_raw_data "https://github.com/finnfujimura/lei-srml-intern-project/tree/main/Raw Data"
click node_mapping_workbook "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/STW programs/STW_sitefile_and_mapping.xlsx"
click node_pipeline_config "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/pipeline_config.json"
click node_orchestrator "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/run_stw_pipeline.py"
click node_ingest_step "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/01_ingest_raw_to_yearly_cleaned.py"
click node_gap_fill_step "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/02_fill_yearly_gaps.py"
click node_combine_step "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/03_build_combined_cleaned.py"
click node_report_step "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/04_write_reports_and_recheck.py"
click node_map_step "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/05_map_combined_columns.py"
click node_convert_step "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/06_convert_mapped_to_mv_irr.py"
click node_irregularity_step "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/07_detect_irr_irregularity_events.py"
click node_common_lib "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/stw_pipeline_common.py"
click node_mv_converter "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/convert_stw_mapped_to_mv.py"
click node_irregularity_lib "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/stw_irr_irregularity_events.py"
click node_plots_export "https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/export_yearly_metric_plots.py"
click node_notebooks "https://github.com/finnfujimura/lei-srml-intern-project/tree/main/plots"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_raw_data,node_mapping_workbook,node_pipeline_config toneBlue
class node_orchestrator,node_ingest_step,node_gap_fill_step,node_combine_step,node_report_step,node_map_step,node_convert_step,node_irregularity_step,node_common_lib,node_mv_converter,node_irregularity_lib toneAmber
class node_yearly_cleaned,node_reports,node_final_output toneMint
class node_plots_export,node_notebooks toneRose
```

## Components

### Inputs

Raw logger exports and control metadata

- [Raw Data](https://github.com/finnfujimura/lei-srml-intern-project/tree/HEAD/Raw%20Data): file inputs · Yearly logger exports spanning many seasons and formats · `Raw Data`
- [Mapping Sheet](https://github.com/finnfujimura/lei-srml-intern-project/blob/HEAD/STW%20programs/STW_sitefile_and_mapping.xlsx): calibration workbook · Control workbook for column mapping and effective-dated constants · `STW programs/STW_sitefile_and_mapping.xlsx`
- [Config](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/pipeline_config.json): deployment config · Path and cutoff configuration resolved from environment, JSON, and defaults · `pipeline_config.json`

### Pipeline

Staged ETL processing and orchestration

- [Orchestrator](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/run_stw_pipeline.py): pipeline runner · Top-level driver that executes steps 01 through 07 in order · `run_stw_pipeline.py`
- [Ingest](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/01_ingest_raw_to_yearly_cleaned.py): yearly cleaning step · Reads raw files, normalizes records, and writes one cleaned CSV per year · `scripts/01_ingest_raw_to_yearly_cleaned.py`
- [Gap Fill](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/02_fill_yearly_gaps.py): timestamp completion step · Adds missing minute timestamps as NaN placeholders · `scripts/02_fill_yearly_gaps.py`
- [Combine](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/03_build_combined_cleaned.py): aggregation step · Concatenates yearly cleaned data into a combined dataset · `scripts/03_build_combined_cleaned.py`
- [Reports](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/04_write_reports_and_recheck.py): integrity check step · Writes summaries and rechecks combined data for consistency · `scripts/04_write_reports_and_recheck.py`
- [Map Columns](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/05_map_combined_columns.py): schema mapping step · Applies workbook-driven column naming and pass-through rules · `scripts/05_map_combined_columns.py`
- [Calibrate](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/06_convert_mapped_to_mv_irr.py): unit conversion step · Converts mapped values to mV and Irr, including outlier cleanup · `scripts/06_convert_mapped_to_mv_irr.py`
- [Scan Irr](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/07_detect_irr_irregularity_events.py): QA detection step · Detects irregularity events in the final irradiance series · `scripts/07_detect_irr_irregularity_events.py`
- [Shared Logic](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/stw_pipeline_common.py): shared modules · Reusable pipeline utilities and domain logic shared by thin wrappers · `scripts/stw_pipeline_common.py`
- [MV Convert](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/convert_stw_mapped_to_mv.py): calibration logic · Workbook-driven mapping and calibration routines used by unit conversion · `scripts/convert_stw_mapped_to_mv.py`
- [Irr QA](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/stw_irr_irregularity_events.py): anomaly logic · Irradiance irregularity detection routines · `scripts/stw_irr_irregularity_events.py`

### Outputs

Persisted cleaned, calibrated, and QA artifacts

- **Yearly CSVs**: intermediate dataset · One cleaned and gap-filled CSV per year
- **Reports**: qa artifacts · Processing summaries, verification logs, missing-timestamp logs, calibration changes, and irregularity events
- **Final Data**: calibrated dataset · Final calibrated mV and Irr dataset in CSV and Parquet form

### Analysis

Plotting and notebook-based review

- [Plot Export](https://github.com/finnfujimura/lei-srml-intern-project/blob/main/scripts/export_yearly_metric_plots.py): visualization script · Generates static metric plots from the final Parquet output · `scripts/export_yearly_metric_plots.py`
- [Notebooks](https://github.com/finnfujimura/lei-srml-intern-project/tree/main/plots): exploratory analysis · Interactive notebooks for metric exploration and irregularity review · `plots`

## Connections

- Raw Data → Ingest: raw files · Yearly logger exports are the ingestion boundary
- Config → Orchestrator: paths · Configuration determines run-time locations and cutoffs
- Mapping Sheet → Map Columns: mapping rules · Workbook sheets supply column mapping and calibration constants
- Orchestrator → Ingest: step 01 · Runs the first stage
- Orchestrator → Gap Fill: step 02 · Runs the second stage
- Orchestrator → Combine: step 03 · Runs the third stage
- Orchestrator → Reports: step 04 · Runs the reporting and integrity stage
- Orchestrator → Map Columns: step 05 · Runs workbook-based remapping
- Orchestrator → Calibrate: step 06 · Runs calibration and conversion
- Orchestrator → Scan Irr: step 07 · Runs final irradiance QA
- Ingest → Yearly CSVs: writes · Produces one cleaned file per year
- Gap Fill → Yearly CSVs: updates · Fills minute gaps before combination
- Yearly CSVs → Combine: yearly inputs · Cleaned yearly files are concatenated
- Combine → Reports: combined data · Integrity checks operate on the merged dataset
- Combine → Map Columns: cleaned series · Mapped columns are derived from the combined file
- Map Columns → Calibrate: mapped columns · Mapped values are converted into physical units
- Calibrate → Final Data: writes · Final CSV and Parquet are materialized on disk
- Calibrate → Reports: qc logs · Nulling and calibration changes are recorded
- Scan Irr → Reports: event logs · Irregularity findings are persisted for review
- Final Data → Plot Export: parquet input · Static plot generation reads the final dataset
- Final Data → Notebooks: analysis input · Notebooks explore the final calibrated dataset
- Shared Logic → Ingest: shared logic · Thin wrappers delegate to shared modules
- Shared Logic → Gap Fill: shared logic · Thin wrappers delegate to shared modules
- Shared Logic → Combine: shared logic · Thin wrappers delegate to shared modules
- Shared Logic → Reports: shared logic · Thin wrappers delegate to shared modules
- Shared Logic → Map Columns: shared logic · Thin wrappers delegate to shared modules
- MV Convert → Calibrate: calibration core · Conversion step uses the reusable mapping/calibration implementation
- Irr QA → Scan Irr: detection core · QA step uses the reusable irregularity detection implementation
