Metadata-Version: 2.5
Name: jrsrp-s2ard
Version: 0.2.0
Summary: Converting Sentinel-2 L2A imagery into JRSRP ARD imagery
Author-email: rdenham <robert.denham@uq.edu.au>
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: numpy>=2.4.2
Requires-Dist: scipy>=1.17.0
Provides-Extra: cli
Requires-Dist: boto3>=1.42.40; extra == 'cli'
Requires-Dist: botocore>=1.42.40; extra == 'cli'
Requires-Dist: click>=8.3.1; extra == 'cli'
Requires-Dist: eo-history[rasterio]>=0.2.5; extra == 'cli'
Requires-Dist: planetary-computer>=1.0.0; extra == 'cli'
Requires-Dist: pystac>=1.14.3; extra == 'cli'
Requires-Dist: rasterio>=1.4.4; extra == 'cli'
Requires-Dist: requests>=2.32.0; extra == 'cli'
Requires-Dist: rio-cogeo>=7.0.1; extra == 'cli'
Requires-Dist: rss-da-stac>=0.1.0; extra == 'cli'
Description-Content-Type: text/markdown

![Pipeline Status](https://gitlab.com/jrsrp/sys/sentinel2/s2ard/badges/main/pipeline.svg)
![Security](https://gitlab.com/jrsrp/sys/sentinel2/s2ard/badges/main/pipeline.svg?job=secret_gatekeeper&key_text=secrets)
![Python](https://img.shields.io/badge/python-3.11%20%7C%203.12-blue)
![License](https://img.shields.io/badge/license-MIT-green)
[![Latest Release](https://img.shields.io/gitlab/v/tag/jrsrp/sys/sentinel2/s2ard?label=version&color=blue)](https://gitlab.com/jrsrp/sys/sentinel2/s2ard/-/tags)

# s2ard

A python project which will convert a Sentinel2 Level 2A image into a JRSRP Surface Reflectance
product with BRDF correction. This forms one of the JRSRP's analysis ready data (ARD) sets.
The approach uses code from
[`jrsrp-sen2brdf`](https://gitlab.com/jrsrp/sys/sentinel2/jrsrp-sen2brdf), which is
included in this package (`jrsrp_s2ard.sen2l2a_brdf`, from v1.0.2) as it is not available on PyPI.
See [Flood, N. (2020). Assessing BRDF effects in the Sentinel-2 Level 2A product in the Australian landscape. Joint Remote Sensing Research Program. ](https://figshare.com/articles/online_resource/Assessing_BRDF_effects_in_the_Sentinel-2_Level_2A_product_in_the_Australian_landscape/12820268)
for details.


## Installation

To use the `stac2ard` command, install the `cli` extra:

```sh
uv add "jrsrp-s2ard[cli]"
```

The core package, without the extra, only needs `numpy` and `scipy`. It provides the BRDF
adjustment itself (`jrsrp_s2ard.brdf`), for use by other packages:

```python
from jrsrp_s2ard import brdf

angles = brdf.read_angle_info("S2B_MSIL2A_....SAFE.zip")  # or an MTD_TL.xml file
gamma = brdf.calc_gamma(angles, "B04")  # on the 5km angle grid
bba = reflectance * brdf.upsample_gamma(gamma, reflectance.shape[1])
```

`brdf.gamma_window()` gives the same values one window at a time, for processing images in
blocks.


## Usage

Input is typically via a STAC item collection. An example is:


```sh
curl \
    https://earth-search.aws.element84.com/v1/collections/sentinel-2-c1-l2a/items/S2B_T53KLA_20250711T012135_L2A \
    -o eg.json
uv run stac2ard -c eg.json -b B04 -b B03 -b B02
```

This will produce the output files `cfmsre_t53kla_20250711_bbam3_B04.tif`,  `cfmsre_t53kla_20250711_bbam3_B03.tif`,
`cfmsre_t53kla_20250711_bbam3_B02.tif`.

See [documentation](https://jrsrp.gitlab.io/sys/sentinel2/s2ard) for more details.
