# jarojuan96/hs_tool architecture

> Architecture diagram of the GitHub repository jarojuan96/hs_tool, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jarojuan96/hs_tool
- Repository: https://github.com/jarojuan96/hs_tool

## Overview

#### Purpose and execution

HS_tool is an interactive Python workflow that converts hyperspectral L1 radiance scenes into L2 gas-enhancement maps and L4 plume emission estimates. The likely orchestration entry point is `scripts/main.py`; it requires GUI-backed user decisions for masking, plume selection, and source localization.

#### Mission ingestion and scene normalization

Mission-specific readers ingest L1 products from EnMAP, EMIT, Gaofen-5A, PRISMA, and AVIRIS-NG, producing the radiance, spectral, and spatial metadata consumed by shared processing.
- `scripts/EnMAP_reader.py`
- `scripts/EMIT_reader.py`
- `scripts/AVIRIS_NG_reader.py`

Additional mission adapters are `scripts/GF_reader.py` and `scripts/PRISMA_reader.py`. ENVI-oriented input/output handling is centralized in `scripts/envi_files.py`.

#### Retrieval configuration and physical inputs

Shared variables and paths, including LUT/default-atmosphere locations, are defined in `scripts/variable_definition.py`. Matched-filter absorption signatures are derived from gas-specific NetCDF lookup tables under `lut_nc/`, using the default atmospheric profile `RFM_midlatitude_summer.dat`.

The LUT boundary encapsulates precomputed spectroscopy/radiative-transfer inputs rather than invoking HITRAN, ARTS, or LibRadtran at runtime. Supported retrieval gases include CH4, CO2, H2O, C2H4, C2H2, CO, N2O, and NH3.

#### L1-to-L2 retrieval pipeline

`main.py` coordinates scene reuse/reprocessing, interactive radiance screening, and retrieval execution. `scripts/radiance_masking.py` presents quicklooks and applies user-approved lower/upper radiance masks for water, clouds, shadows, or invalid radiance. `scripts/Retrieval_methods.py` implements the matched-filter retrieval stage, while `scripts/RT_functions.py` supports radiative-transfer/spectral calculations.

The output boundary is an L2 concentration-enhancement raster in ppm·m, stored in ENVI format.

#### Spatial handling and plume delineation

After retrieval, the workflow displays radiance alongside the gas map and requires an operator to confirm detection, zoom to a plume subset, choose one emission-source pixel, and digitize plume extent. Georeferencing and geospatial export are handled by:
- `scripts/georreferencing.py`
- `scripts/hs_tool4_deltaxgas.py`

Georeferenced retrievals and plume masks/bands are emitted as TIFFs.

#### Wind and IME quantification

L4 quantification applies the IME approach to the operator-delineated plume. `scripts/wind_v2.py` obtains or reuses wind information from GEOS-FP; `scripts/quant_func_v2.py` calculates emission-related values. Quantification is principally intended for CH4, NH3, C2H4, CO, and C2H2, with documented simplified wind assumptions for AVIRIS-NG and CO2 and EMIT-specific effective-wind handling for some gases.

#### Persistence and runtime dependencies

L2 products are reusable: existing retrievals can bypass the retrieval path and enter plume quantification. Result serialization is managed by `scripts/store_results.py`, which writes L4-related values to CSV. The runtime is Python with scientific/geospatial and hyperspectral dependencies, notably GDAL, georasters, and spectral; graphical backend behavior is operationally important because interaction is integral to control flow.

Main entry points: [`scripts/Retrieval_methods.py`](https://github.com/jarojuan96/hs_tool/blob/main/scripts/Retrieval_methods.py) (Matched-filter retrieval), [`scripts/main.py`](https://github.com/jarojuan96/hs_tool/blob/main/scripts/main.py) (Interactive orchestrator), [`scripts/radiance_masking.py`](https://github.com/jarojuan96/hs_tool/blob/main/scripts/radiance_masking.py) (Radiance masking), [`scripts/quant_func_v2.py`](https://github.com/jarojuan96/hs_tool/blob/main/scripts/quant_func_v2.py) (IME emission estimate)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Mission ingestion"]
  node_mission_readers["Mission readers<br/>sensor adapters"]
  node_enmap_reader["EnMAP reader<br/>[EnMAP_reader.py]"]
  node_emit_reader["EMIT reader<br/>[EMIT_reader.py]"]
  node_aviris_reader["AVIRIS-NG reader"]
  node_envi["ENVI I/O<br/>raster I/O<br/>[envi_files.py]"]
end

subgraph group_retrieval["L2 retrieval"]
  node_main["Interactive orchestrator<br/>Python entry point<br/>[main.py]"]
  node_variables["Retrieval settings<br/>shared definitions"]
  node_lut[("Gas LUTs<br/>NetCDF spectroscopy")]
  node_atmosphere["Default atmosphere<br/>profile"]
  node_masking["Radiance masking<br/>interactive screening"]
  node_matched_filter["Matched-filter retrieval<br/>L1→L2 retrieval"]
  node_rt["Spectral calculations<br/>radiative transfer<br/>[RT_functions.py]"]
  node_l2[("L2 enhancement raster<br/>ENVI output")]
end

subgraph group_plume["Plume workflow"]
  node_plume_ui["Plume delineation<br/>operator interaction"]
  node_georef["Georeferencing export<br/>geospatial export<br/>[georreferencing.py]"]
end

subgraph group_quant["L4 quantification"]
  node_wind["GEOS-FP wind<br/>wind input<br/>[wind_v2.py]"]
  node_ime["IME emission estimate<br/>L4 quantification<br/>[quant_func_v2.py]"]
  node_results["L4 results CSV<br/>result serialization<br/>[store_results.py]"]
end

node_enmap_reader --> node_mission_readers
node_emit_reader --> node_mission_readers
node_aviris_reader --> node_mission_readers
node_mission_readers -->|"normalized scene I/O"| node_envi
node_main -->|"selects reader"| node_mission_readers
node_main -->|"interactive screening"| node_masking
node_envi -->|"radiance scene"| node_masking
node_masking -->|"approved radiance"| node_matched_filter
node_variables -->|"retrieval settings"| node_matched_filter
node_lut -->|"gas signature"| node_matched_filter
node_atmosphere -->|"profile"| node_rt
node_rt -->|"spectral support"| node_matched_filter
node_matched_filter -->|"ppm·m raster"| node_l2
node_main -.->|"reuse existing"| node_l2
node_l2 -->|"gas map"| node_plume_ui
node_plume_ui -->|"plume mask and source"| node_georef
node_georef -->|"georeferenced plume"| node_ime
node_wind -->|"wind input"| node_ime
node_ime -->|"L4 values"| node_results

click node_main "https://github.com/jarojuan96/hs_tool/blob/main/scripts/main.py"
click node_enmap_reader "https://github.com/jarojuan96/hs_tool/blob/main/scripts/EnMAP_reader.py"
click node_emit_reader "https://github.com/jarojuan96/hs_tool/blob/main/scripts/EMIT_reader.py"
click node_aviris_reader "https://github.com/jarojuan96/hs_tool/blob/main/scripts/AVIRIS_NG_reader.py"
click node_envi "https://github.com/jarojuan96/hs_tool/blob/main/scripts/envi_files.py"
click node_variables "https://github.com/jarojuan96/hs_tool/blob/main/scripts/variable_definition.py"
click node_atmosphere "https://github.com/jarojuan96/hs_tool/blob/main/RFM_midlatitude_summer.dat"
click node_masking "https://github.com/jarojuan96/hs_tool/blob/main/scripts/radiance_masking.py"
click node_matched_filter "https://github.com/jarojuan96/hs_tool/blob/main/scripts/Retrieval_methods.py"
click node_rt "https://github.com/jarojuan96/hs_tool/blob/main/scripts/RT_functions.py"
click node_plume_ui "https://github.com/jarojuan96/hs_tool/blob/main/scripts/hs_tool4_deltaxgas.py"
click node_georef "https://github.com/jarojuan96/hs_tool/blob/main/scripts/georreferencing.py"
click node_wind "https://github.com/jarojuan96/hs_tool/blob/main/scripts/wind_v2.py"
click node_ime "https://github.com/jarojuan96/hs_tool/blob/main/scripts/quant_func_v2.py"
click node_results "https://github.com/jarojuan96/hs_tool/blob/main/scripts/store_results.py"

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_mission_readers,node_enmap_reader,node_emit_reader,node_aviris_reader,node_envi toneBlue
class node_main,node_variables,node_lut,node_atmosphere,node_masking,node_matched_filter,node_rt,node_l2 toneAmber
class node_plume_ui,node_georef toneMint
class node_wind,node_ime,node_results toneRose
```

## Components

### Mission ingestion

- **Mission readers**: sensor adapters · Normalize EnMAP, EMIT, AVIRIS-NG, Gaofen-5A, and PRISMA L1 scenes.
- [EnMAP reader](https://github.com/jarojuan96/hs_tool/blob/main/scripts/EnMAP_reader.py): reader · `scripts/EnMAP_reader.py`
- [EMIT reader](https://github.com/jarojuan96/hs_tool/blob/main/scripts/EMIT_reader.py): reader · `scripts/EMIT_reader.py`
- [AVIRIS-NG reader](https://github.com/jarojuan96/hs_tool/blob/main/scripts/AVIRIS_NG_reader.py): reader · `scripts/AVIRIS_NG_reader.py`
- [ENVI I/O](https://github.com/jarojuan96/hs_tool/blob/main/scripts/envi_files.py): raster I/O · Centralizes ENVI-oriented input and output. · `scripts/envi_files.py`

### L2 retrieval

- [Interactive orchestrator](https://github.com/jarojuan96/hs_tool/blob/main/scripts/main.py): Python entry point · Coordinates reusable L2 products and operator-driven workflow. · `scripts/main.py`
- [Retrieval settings](https://github.com/jarojuan96/hs_tool/blob/main/scripts/variable_definition.py): shared definitions · Defines shared variables and LUT/default-atmosphere locations. · `scripts/variable_definition.py`
- **Gas LUTs**: NetCDF spectroscopy · Precomputed absorption and radiative-transfer inputs.
- [Default atmosphere](https://github.com/jarojuan96/hs_tool/blob/main/RFM_midlatitude_summer.dat): profile · `RFM_midlatitude_summer.dat`
- [Radiance masking](https://github.com/jarojuan96/hs_tool/blob/main/scripts/radiance_masking.py): interactive screening · Operator approves masks for water, clouds, shadows, and invalid radiance. · `scripts/radiance_masking.py`
- [Matched-filter retrieval](https://github.com/jarojuan96/hs_tool/blob/main/scripts/Retrieval_methods.py): L1→L2 retrieval · Produces concentration enhancement from radiance and gas signatures. · `scripts/Retrieval_methods.py`
- [Spectral calculations](https://github.com/jarojuan96/hs_tool/blob/main/scripts/RT_functions.py): radiative transfer · `scripts/RT_functions.py`
- **L2 enhancement raster**: ENVI output · Reusable concentration-enhancement product in ppm·m.

### Plume workflow

- [Plume delineation](https://github.com/jarojuan96/hs_tool/blob/main/scripts/hs_tool4_deltaxgas.py): operator interaction · Confirms detection, selects source pixel, and digitizes plume extent. · `scripts/hs_tool4_deltaxgas.py`
- [Georeferencing export](https://github.com/jarojuan96/hs_tool/blob/main/scripts/georreferencing.py): geospatial export · Emits georeferenced retrievals and plume masks as TIFFs. · `scripts/georreferencing.py`

### L4 quantification

- [GEOS-FP wind](https://github.com/jarojuan96/hs_tool/blob/main/scripts/wind_v2.py): wind input · Obtains or reuses wind information. · `scripts/wind_v2.py`
- [IME emission estimate](https://github.com/jarojuan96/hs_tool/blob/main/scripts/quant_func_v2.py): L4 quantification · Calculates plume emission-related values from IME and wind. · `scripts/quant_func_v2.py`
- [L4 results CSV](https://github.com/jarojuan96/hs_tool/blob/main/scripts/store_results.py): result serialization · `scripts/store_results.py`

## Connections

- EnMAP reader → Mission readers
- EMIT reader → Mission readers
- AVIRIS-NG reader → Mission readers
- Mission readers → ENVI I/O: normalized scene I/O
- Interactive orchestrator → Mission readers: selects reader
- Interactive orchestrator → Radiance masking: interactive screening
- ENVI I/O → Radiance masking: radiance scene
- Radiance masking → Matched-filter retrieval: approved radiance
- Retrieval settings → Matched-filter retrieval: retrieval settings
- Gas LUTs → Matched-filter retrieval: gas signature
- Default atmosphere → Spectral calculations: profile
- Spectral calculations → Matched-filter retrieval: spectral support
- Matched-filter retrieval → L2 enhancement raster: ppm·m raster
- Interactive orchestrator → L2 enhancement raster: reuse existing
- L2 enhancement raster → Plume delineation: gas map
- Plume delineation → Georeferencing export: plume mask and source
- Georeferencing export → IME emission estimate: georeferenced plume
- GEOS-FP wind → IME emission estimate: wind input
- IME emission estimate → L4 results CSV: L4 values
