Metadata-Version: 2.4
Name: hls-burn
Version: 0.1.0
Summary: Burn scar mapping from pre/post-fire HLS (Harmonized Landsat Sentinel-2) scenes
License-Expression: MIT
Project-URL: U-Net model, https://huggingface.co/hughbertlongshanks/unet-burn-hls
Keywords: wildfire,burn scar,dNBR,HLS,Landsat,Sentinel-2,remote sensing,segmentation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: GIS
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=2.5
Requires-Dist: scipy>=1.18
Requires-Dist: pandas>=3.0
Requires-Dist: xarray>=2026.9
Requires-Dist: rioxarray>=0.19
Requires-Dist: rasterio>=1.5
Requires-Dist: geopandas>=1.1
Requires-Dist: shapely>=2.1
Requires-Dist: pyproj>=3.7
Requires-Dist: pyogrio>=0.13
Requires-Dist: opencv-python-headless>=5.0
Requires-Dist: odc-stac>=0.5
Requires-Dist: odc-geo>=0.5
Requires-Dist: pystac>=1.16
Requires-Dist: pystac-client>=0.9
Requires-Dist: planetary-computer>=1.0
Requires-Dist: requests>=2.34
Requires-Dist: PyYAML>=6.0
Requires-Dist: matplotlib>=3.11
Requires-Dist: xgboost>=3.2
Provides-Extra: deep
Requires-Dist: torch>=2.13; extra == "deep"
Requires-Dist: segmentation-models-pytorch>=0.5; extra == "deep"
Requires-Dist: huggingface-hub>=1.29; extra == "deep"
Requires-Dist: safetensors>=0.8; extra == "deep"
Provides-Extra: map
Requires-Dist: ipyleaflet>=0.20; extra == "map"
Requires-Dist: ipywidgets>=8.1; extra == "map"
Requires-Dist: xyzservices>=2026.9; extra == "map"
Requires-Dist: folium>=0.20; extra == "map"
Requires-Dist: pillow>=12.3; extra == "map"
Provides-Extra: sklearn
Requires-Dist: scikit-learn>=1.9; extra == "sklearn"
Provides-Extra: all
Requires-Dist: hls-burn[deep,map,sklearn]; extra == "all"
Dynamic: license-file

# hls-burn

Map burn scars from a pre-fire and a post-fire scene of NASA's Harmonized Landsat
Sentinel-2 (HLS, 30 m). Scenes are searched and read from Microsoft Planetary Computer,
so all you need is an area and the fire's dates.

There are three segmenters, and they all work the same way: `segment()` gives a class
raster, `polygonize()` gives a GeoDataFrame.

| segmenter | method | classes |
|---|---|---|
| `ThresholdSegmenter` | thresholds on a burn index (dNBR by default) | USGS-style severity, or your own bins |
| `SklearnSegmenter` | bundled XGBoost model on burn indices, trained on ~1,000 US fires | burned / unburned |
| `DeepSegmenter` | 24M-param [U-Net](https://huggingface.co/hughbertlongshanks/unet-burn-hls), trained on ~6,000 US pre/post pairs | burned / unburned |

## Install

```bash
pip install hls-burn              # threshold + XGBoost
pip install "hls-burn[deep]"      # + U-Net (PyTorch)
pip install "hls-burn[map]"       # + polygon editor for notebooks
pip install "hls-burn[all]"
```

Python 3.11+.

## Usage

The steps below follow `examples.ipynb`, which maps a February 2026 fire near Lake
Okeechobee.

### Get scenes

```python
import shapely
from hls_burn.data.fire_data import HLSFireData

fire = HLSFireData()
fire.get_clearest_hls_scenes_pre_post(
    search_area=shapely.Point(-80.88, 27.11).buffer(0.1),  # lon/lat; a shapely geom or WKT
    start_date="2026-02-12",
    end_date="2026-02-15",
    pre_offset_days=30,   # search this far before start_date for a clear scene
    post_offset_days=30,  # and this far after end_date
)
fire.show_scenes()                               # true colour
fire.show_scenes(bands=("swir2", "nir", "red"))  # false colour: burns show up red
```

If either scene is mostly cloud, shadow or snow you get a warning.

### Burn index

```python
fire.calc_dnbr()
fire.plot_computed_index(vmin=0, vmax=0.5)
```

There are other indices too. Some of them need a perimeter or an unburned reference
area.

### Threshold segmentation

```python
from hls_burn.segmenters.classical_segmenter import ThresholdSegmenter

seg = ThresholdSegmenter(index="dnbr")  # default bins: 6 USGS-style severity classes
seg.segment(fire)
seg.plot_segmentation()

seg.bins = (0.1,)                       # binary: dNBR > 0.1 is burned
seg.segment(fire)
seg.export_raster("mask.tif", crs=5070)
```

You'll usually have to tune the thresholds for each fire. The pretrained models don't
need that.

### Pretrained models

```python
from hls_burn.segmenters.scikit_segmenter import SklearnSegmenter
from hls_burn.segmenters.deep_segmenter import DeepSegmenter   # needs [deep]

xgb = SklearnSegmenter()          # bundled model; or pass your own scikit-learn estimator
xgb.segment(fire)

unet = DeepSegmenter(cutoff=0.6)  # probability threshold
unet.segment(fire)
unet.plot_segmentation()
```

Unusable pixels (cloud, nodata) come back as 255.

### Polygons

```python
gdf = unet.polygonize()                 # one row per connected patch
gdf.explore(tiles="Esri.WorldImagery")  # it's a plain GeoDataFrame
unet.export_polygons("burned.fgb", crs=5070)
```

The polygons are also stored on the segmenter, and every call replaces them.

### Edit polygons in a notebook (`[map]`)

```python
unet.edit_polygons(fire=fire, window="post")                  # false colour by default
unet.edit_polygons(fire=fire, bands=("red", "green", "blue"))
```

This opens a map with the scene under the polygons. You can move vertices, reshape
polygons or delete them, then call `export_polygons()` when you're done.

## Model Performance 
The library currently ships with access to two pretrained models as shown above.

The XGBoost model performs better than un tuned threshholding in 
most cases and has an IOU of ~70%. It tends to fail in scenes where having a lot of context would be beneficial.
e.g. fields. It's reliance on computed features (dnbr, rbr, etc...) 
also limit it. A good model, and cheap to run.

The UNET was trained on multi temporal image pairs.
(3 best pairs within ~90-120 days pre/post and all thier valid permutations)
It tends to perform very well and was measured with a ~90% IOU
on held out fires. it was only trained on fires greater than 250 acres.

Both models used refined WFIGS permiters. by taking a rough final perimeter and 
refining it using dnbr we can more readily isolate the positve burn signal and reduce unburned island noise inherent in field perimeters.

## License

MIT
