How finnfujimura/lei-srml-intern-project works
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 Orchestrator · stw_pipeline_common.py Shared Logic · 03_build_combined_cleaned.py Combine · 06_convert_mapped_to_mv_irr.py Calibrate
Components 19
Inputs
Raw logger exports and control metadata
- Raw Data · Yearly logger exports spanning many seasons and formats
Raw Data - Mapping Sheet · Control workbook for column mapping and effective-dated constants
STW programs/STW_sitefile_and_mapping.xlsx - Config · Path and cutoff configuration resolved from environment, JSON, and defaults
pipeline_config.json
Pipeline
Staged ETL processing and orchestration
- Orchestrator · Top-level driver that executes steps 01 through 07 in order
run_stw_pipeline.py - Ingest · Reads raw files, normalizes records, and writes one cleaned CSV per year
scripts/01_ingest_raw_to_yearly_cleaned.py - Gap Fill · Adds missing minute timestamps as NaN placeholders
scripts/02_fill_yearly_gaps.py - Combine · Concatenates yearly cleaned data into a combined dataset
scripts/03_build_combined_cleaned.py - Reports · Writes summaries and rechecks combined data for consistency
scripts/04_write_reports_and_recheck.py - Map Columns · Applies workbook-driven column naming and pass-through rules
scripts/05_map_combined_columns.py - Calibrate · Converts mapped values to mV and Irr, including outlier cleanup
scripts/06_convert_mapped_to_mv_irr.py - Scan Irr · Detects irregularity events in the final irradiance series
scripts/07_detect_irr_irregularity_events.py - Shared Logic · Reusable pipeline utilities and domain logic shared by thin wrappers
scripts/stw_pipeline_common.py - MV Convert · Workbook-driven mapping and calibration routines used by unit conversion
scripts/convert_stw_mapped_to_mv.py - Irr QA · Irradiance irregularity detection routines
scripts/stw_irr_irregularity_events.py
Outputs
Persisted cleaned, calibrated, and QA artifacts
- Yearly CSVs · One cleaned and gap-filled CSV per year
- Reports · Processing summaries, verification logs, missing-timestamp logs, calibration changes, and irregularity events
- Final Data · Final calibrated mV and Irr dataset in CSV and Parquet form
Analysis
Plotting and notebook-based review
- Plot Export · Generates static metric plots from the final Parquet output
scripts/export_yearly_metric_plots.py - Notebooks · Interactive notebooks for metric exploration and irregularity review
plots
Connections 28
- 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