# yotkadata/uhi_detector architecture

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

- Interactive diagram: https://gitdiagram.com/yotkadata/uhi_detector
- Repository: https://github.com/yotkadata/uhi_detector

## Overview

#### 1. Purpose and Runtime Entry Point
This is a Python 3.10 urban-heat-island analysis project. It combines Landsat-derived geospatial layers—NDVI, emissivity, and land-surface temperature (LST)—with deep-learning roof/building segmentation. The interactive delivery surface is a Streamlit application launched from `app.py`, with page logic in `app/landsat_maps.py` and `app/segmentation.py`.

#### 2. Streamlit Presentation and Interaction Layer
`app.py` is the application entry point and coordinates the Streamlit UI. The application exposes project visualization and live segmentation workflows; styling is local rather than a separate frontend build.
- `app.py`
- `app/landsat_maps.py`
- `app/segmentation.py`
- `app/style.css`

#### 3. Segmentation Inference Pipeline
The roof/building-footprint workflow accepts high-resolution satellite or orthophoto imagery, runs a pretrained U-Net segmentation model with a ResNet-34 or ResNet-50 encoder, and produces mask predictions. Tiled inference and postprocessing/blending are separated, allowing images larger than model patch dimensions to be processed without hard seams.
- `src/predict.py`
- `src/predict_orthophotos.py`
- `src/smooth_tiled_predictions.py`
- `data/models/landcover_25_epochs_resnet50_backbone_batch16_freeze_iou_0.86.hdf5`

The model runtime depends on TensorFlow/Keras through `segmentation_models`; `SM_FRAMEWORK=tf.keras` must be set before startup.

#### 4. Training and Dataset Preparation Boundary
Model development is an offline pipeline, not part of normal app execution. Source imagery and labels are prepared into patches, then the U-Net is trained/evaluated in notebooks. This boundary is represented by persisted `.hdf5` model artifacts consumed by prediction code.
- `src/prepare_data.py`
- `notebooks/segmentation_step_1_data_preparation.ipynb`
- `notebooks/segmentation_step_2_model.ipynb`

#### 5. Landsat Raster-Derivation Pipeline
A separate geospatial-processing path derives environmental layers from Landsat bands: NDVI and emissivity use red/NIR inputs; LST additionally uses thermal band 10. Raster creation, LST-specific preparation, and visualization are modularized. Generated layer metadata/color bounds are stored as JSON and used by the mapping/presentation workflow.
- `src/create_rasters.py`
- `src/prepare_lst_layer.py`
- `src/plot.py`
- `data/raster_files/LC09_L1TP_179032_20230217_20230310_02_T1_lst_repr_colored_bounds.json`

#### 6. Spatial Data and Map Boundaries
GeoJSON area boundaries provide geographic context for city/map views, while raster data and segmentation imagery enter through file-based local workflows. OpenStreetMap building footprints are an external data source mentioned by the project, distinct from model-generated footprints.
- `data/geojson/berlin.geojson`
- `data/geojson/berlin-wedding.geojson`
- `src/utils.py`

GDAL is a material system dependency for geospatial raster IO and transformations.

#### 7. Batch and Example Prediction Paths
In addition to interactive inference, folder-oriented scripts support batch processing. The repository ships sample GeoTIFF inputs and an output-oriented example directory, making the prediction pipeline reproducible without acquiring new imagery.
- `src/predict_from_folder.py`
- `data/predict/examples/source/`
- `data/predict/examples/prediction/`

Main entry points: [`src/predict.py`](https://github.com/yotkadata/uhi_detector/blob/main/src/predict.py) (Interactive inference), [`app.py`](https://github.com/yotkadata/uhi_detector/blob/main/app.py) (App entry point), [`src/predict_from_folder.py`](https://github.com/yotkadata/uhi_detector/blob/main/src/predict_from_folder.py) (Folder batch prediction), [`app/landsat_maps.py`](https://github.com/yotkadata/uhi_detector/blob/main/app/landsat_maps.py) (Landsat maps page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Streamlit app"]
  node_app["App entry point<br/>Streamlit runtime<br/>[app.py]"]
  node_maps_page["Landsat maps page<br/>Streamlit page<br/>[landsat_maps.py]"]
  node_seg_page["Segmentation page<br/>Streamlit page<br/>[segmentation.py]"]
  node_style["Local styling<br/>CSS<br/>[style.css]"]
end

subgraph group_seg["Segmentation"]
  node_predict["Interactive inference<br/>prediction runtime<br/>[predict.py]"]
  node_orthophoto_predict["Orthophoto inference<br/>prediction runtime"]
  node_tiled_blending["Tiled prediction blending<br/>postprocessing"]
  node_model[("Pretrained U-Net model<br/>HDF5 model artifact")]
  node_batch_predict["Folder batch prediction<br/>batch script"]
  node_example_source["Example GeoTIFF inputs<br/>sample imagery"]
  node_example_output["Example predictions<br/>output directory"]
end

subgraph group_geo["Landsat mapping"]
  node_create_rasters["Raster derivation<br/>geospatial processing<br/>[create_rasters.py]"]
  node_prepare_lst["LST preparation<br/>geospatial processing"]
  node_plot["Raster visualization<br/>mapping utility<br/>[plot.py]"]
  node_layer_metadata["Layer color bounds<br/>raster metadata"]
  node_boundaries["Berlin area boundaries<br/>GeoJSON<br/>[berlin.geojson]"]
  node_spatial_utils["Spatial utilities<br/>geospatial utility<br/>[utils.py]"]
end

subgraph group_offline["Offline model development"]
  node_prepare_data["Patch preparation<br/>dataset preparation<br/>[prepare_data.py]"]
  node_data_notebook["Data preparation notebook"]
  node_training_notebook["U-Net training notebook"]
end

node_app -->|"serves"| node_maps_page
node_app -->|"serves"| node_seg_page
node_app -->|"uses"| node_style
node_seg_page -->|"runs"| node_predict
node_predict -->|"processes imagery via"| node_orthophoto_predict
node_orthophoto_predict -->|"blends tiles with"| node_tiled_blending
node_predict -->|"loads"| node_model
node_batch_predict -->|"reads"| node_example_source
node_batch_predict -->|"uses"| node_predict
node_batch_predict -->|"writes"| node_example_output
node_prepare_data -.->|"implemented in"| node_data_notebook
node_data_notebook -->|"prepared patches feed"| node_training_notebook
node_training_notebook -->|"produces"| node_model
node_create_rasters -->|"feeds raster inputs to"| node_prepare_lst
node_prepare_lst -->|"generates display bounds"| node_layer_metadata
node_plot -->|"uses"| node_layer_metadata
node_maps_page -->|"renders layers through"| node_plot
node_maps_page -->|"uses map context"| node_boundaries
node_spatial_utils -->|"reads"| node_boundaries

click node_app "https://github.com/yotkadata/uhi_detector/blob/main/app.py"
click node_maps_page "https://github.com/yotkadata/uhi_detector/blob/main/app/landsat_maps.py"
click node_seg_page "https://github.com/yotkadata/uhi_detector/blob/main/app/segmentation.py"
click node_style "https://github.com/yotkadata/uhi_detector/blob/main/app/style.css"
click node_predict "https://github.com/yotkadata/uhi_detector/blob/main/src/predict.py"
click node_orthophoto_predict "https://github.com/yotkadata/uhi_detector/blob/main/src/predict_orthophotos.py"
click node_tiled_blending "https://github.com/yotkadata/uhi_detector/blob/main/src/smooth_tiled_predictions.py"
click node_model "https://github.com/yotkadata/uhi_detector/blob/main/data/models/landcover_25_epochs_resnet50_backbone_batch16_freeze_iou_0.86.hdf5"
click node_batch_predict "https://github.com/yotkadata/uhi_detector/blob/main/src/predict_from_folder.py"
click node_prepare_data "https://github.com/yotkadata/uhi_detector/blob/main/src/prepare_data.py"
click node_data_notebook "https://github.com/yotkadata/uhi_detector/blob/main/notebooks/segmentation_step_1_data_preparation.ipynb"
click node_training_notebook "https://github.com/yotkadata/uhi_detector/blob/main/notebooks/segmentation_step_2_model.ipynb"
click node_create_rasters "https://github.com/yotkadata/uhi_detector/blob/main/src/create_rasters.py"
click node_prepare_lst "https://github.com/yotkadata/uhi_detector/blob/main/src/prepare_lst_layer.py"
click node_plot "https://github.com/yotkadata/uhi_detector/blob/main/src/plot.py"
click node_layer_metadata "https://github.com/yotkadata/uhi_detector/blob/main/data/raster_files/LC09_L1TP_179032_20230217_20230310_02_T1_lst_repr_colored_bounds.json"
click node_boundaries "https://github.com/yotkadata/uhi_detector/blob/main/data/geojson/berlin.geojson"
click node_spatial_utils "https://github.com/yotkadata/uhi_detector/blob/main/src/utils.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_app,node_maps_page,node_seg_page,node_style toneBlue
class node_predict,node_orthophoto_predict,node_tiled_blending,node_model,node_batch_predict,node_example_source,node_example_output toneAmber
class node_create_rasters,node_prepare_lst,node_plot,node_layer_metadata,node_boundaries,node_spatial_utils toneMint
class node_prepare_data,node_data_notebook,node_training_notebook toneRose
```

## Components

### Streamlit app

- [App entry point](https://github.com/yotkadata/uhi_detector/blob/main/app.py): Streamlit runtime · Coordinates map and segmentation workflows. · `app.py`
- [Landsat maps page](https://github.com/yotkadata/uhi_detector/blob/main/app/landsat_maps.py): Streamlit page · `app/landsat_maps.py`
- [Segmentation page](https://github.com/yotkadata/uhi_detector/blob/main/app/segmentation.py): Streamlit page · `app/segmentation.py`
- [Local styling](https://github.com/yotkadata/uhi_detector/blob/main/app/style.css): CSS · `app/style.css`

### Segmentation

- [Interactive inference](https://github.com/yotkadata/uhi_detector/blob/main/src/predict.py): prediction runtime · Loads the pretrained U-Net and produces masks. · `src/predict.py`
- [Orthophoto inference](https://github.com/yotkadata/uhi_detector/blob/main/src/predict_orthophotos.py): prediction runtime · Processes high-resolution imagery. · `src/predict_orthophotos.py`
- [Tiled prediction blending](https://github.com/yotkadata/uhi_detector/blob/main/src/smooth_tiled_predictions.py): postprocessing · Combines tile predictions without hard seams. · `src/smooth_tiled_predictions.py`
- [Pretrained U-Net model](https://github.com/yotkadata/uhi_detector/blob/main/data/models/landcover_25_epochs_resnet50_backbone_batch16_freeze_iou_0.86.hdf5): HDF5 model artifact · ResNet-50 land-cover segmentation weights. · `data/models/landcover_25_epochs_resnet50_backbone_batch16_freeze_iou_0.86.hdf5`
- [Folder batch prediction](https://github.com/yotkadata/uhi_detector/blob/main/src/predict_from_folder.py): batch script · `src/predict_from_folder.py`
- **Example GeoTIFF inputs**: sample imagery
- **Example predictions**: output directory

### Landsat mapping

- [Raster derivation](https://github.com/yotkadata/uhi_detector/blob/main/src/create_rasters.py): geospatial processing · Derives NDVI and emissivity from Landsat bands. · `src/create_rasters.py`
- [LST preparation](https://github.com/yotkadata/uhi_detector/blob/main/src/prepare_lst_layer.py): geospatial processing · Uses thermal band 10 for land-surface temperature. · `src/prepare_lst_layer.py`
- [Raster visualization](https://github.com/yotkadata/uhi_detector/blob/main/src/plot.py): mapping utility · `src/plot.py`
- [Layer color bounds](https://github.com/yotkadata/uhi_detector/blob/main/data/raster_files/LC09_L1TP_179032_20230217_20230310_02_T1_lst_repr_colored_bounds.json): raster metadata · Generated layer display metadata. · `data/raster_files/LC09_L1TP_179032_20230217_20230310_02_T1_lst_repr_colored_bounds.json`
- [Berlin area boundaries](https://github.com/yotkadata/uhi_detector/blob/main/data/geojson/berlin.geojson): GeoJSON · City and Wedding geographic context. · `data/geojson/berlin.geojson`
- [Spatial utilities](https://github.com/yotkadata/uhi_detector/blob/main/src/utils.py): geospatial utility · Handles local spatial data workflows. · `src/utils.py`

### Offline model development

- [Patch preparation](https://github.com/yotkadata/uhi_detector/blob/main/src/prepare_data.py): dataset preparation · Prepares source imagery and labels into training patches. · `src/prepare_data.py`
- [Data preparation notebook](https://github.com/yotkadata/uhi_detector/blob/main/notebooks/segmentation_step_1_data_preparation.ipynb): notebook · `notebooks/segmentation_step_1_data_preparation.ipynb`
- [U-Net training notebook](https://github.com/yotkadata/uhi_detector/blob/main/notebooks/segmentation_step_2_model.ipynb): notebook · Trains and evaluates the segmentation model. · `notebooks/segmentation_step_2_model.ipynb`

## Connections

- App entry point → Landsat maps page: serves
- App entry point → Segmentation page: serves
- App entry point → Local styling: uses
- Segmentation page → Interactive inference: runs
- Interactive inference → Orthophoto inference: processes imagery via
- Orthophoto inference → Tiled prediction blending: blends tiles with
- Interactive inference → Pretrained U-Net model: loads
- Folder batch prediction → Example GeoTIFF inputs: reads
- Folder batch prediction → Interactive inference: uses
- Folder batch prediction → Example predictions: writes
- Patch preparation → Data preparation notebook: implemented in
- Data preparation notebook → U-Net training notebook: prepared patches feed
- U-Net training notebook → Pretrained U-Net model: produces
- Raster derivation → LST preparation: feeds raster inputs to
- LST preparation → Layer color bounds: generates display bounds
- Raster visualization → Layer color bounds: uses
- Landsat maps page → Raster visualization: renders layers through
- Landsat maps page → Berlin area boundaries: uses map context
- Spatial utilities → Berlin area boundaries: reads
