Choosing a Sentinel-2 composite
S2_MED_PLANTING and S2_MED_HARVEST use latitude-based seasonal windows. The harvest example contains RGB, NIR, and a valid-pixel count:
s2med_harvest:B02- Blues2med_harvest:B03- Greens2med_harvest:B04- Reds2med_harvest:B08- NIRs2med_harvest:N_VALID_PIXELS- Number of valid observations used in the median
S2_MEDIANproduces one per-pixel RGB+NIR median over[start, end), labelled bystart.S2_MEDIAN_ALL_BANDSuses the same window and returns all 12 L2A reflectance bands.S2_CLOSEST_VALIDproduces one composite for an explicittarget_date, using the inclusive candidate window[start, end].S2_CLOSEST_VALID_BEFORE_AFTERproduces two closest-valid composites at the window endpoints.
target_date, plus a registered Mosaics version with these datasets. Set the client’s mosaics_version to that version when it is available. Backend API and billing workers must also support the new dataset names before these examples run.
Setup and Imports
Initializing the RasterFlow client
Selecting an Area of Interest (AOI)
We will use Haskell County, Kansas as our AOI. This is an agricultural region in the US Great Plains, ideal for demonstrating harvest-season imagery.Building the harvest season mosaic
This step builds a Sentinel-2 median composite mosaic for the harvest season only. The workflow will:- Query Sentinel-2 imagery for the AOI and date range
- Filter to harvest season dates based on latitude
- Apply cloud and quality filtering — excluding scenes with >= 75% cloud cover and masking pixels flagged as cloud, cloud shadow, cirrus, saturated/defective, or unclassified in the SCL band
- Compute a pixel-wise median composite across remaining valid observations
- Output the result as a Zarr store
Note: This step will take approximately 10-15 minutes to complete. If you want to skip this build_mosaics step, you can uncomment the next cell and start with a pre-generated mosaic.
(Optional) Build an optimized Zarr for visualization
RasterFlow writes its outputs as Zarr stores at native resolution. To explore them interactively on cloud.wherobots.com/map, you can build an optimized multiscale Zarr.build_zarr_multiscales adds downsampled overview levels (image pyramids) to the store so the map can stream coarse tiles when zoomed out and full-resolution pixels when zoomed in.
This step is optional and can take a few minutes for large outputs, so the code below is commented out by default — uncomment it to run it.
Visualizing outputs
You can visualize the Zarr outputs using cloud.wherobots.com/map.Building an all-bands median over a custom window
UseS2_MEDIAN_ALL_BANDS when you need a specific date window and bands beyond RGB+NIR. It returns B01, B02, B03, B04, B05, B06, B07, B08, B8A, B09, B11, and B12 at 10 m. B10 is absent from L2A.
This example creates one time step over UTC [2024-07-01, 2024-09-01), labelled 2024-07-01. It uses no seasonal heuristic. Cloud masking and per-pixel median calculation follow the harvest example above. Band names use the s2_median_all_bands prefix.
Building one closest-valid composite
S2_CLOSEST_VALID requires a reference date separate from the candidate window. This example searches UTC [2021-12-01, 2022-02-01] and produces one time step labelled 2022-01-01. The reference must fall within the window, and start must be earlier than end. Naive datetimes mean UTC; timezone-aware values normalize to UTC.
For each pixel, the compositor chooses the nearest SCL-valid observation among the selected scenes. Earlier acquisitions win equal-distance ties. Source dates may differ across pixels; the output label is the reference date. This method uses validity and date proximity, without ranking atmospheric quality. Its reflectance bands use the s2_closest_valid prefix.
Pass target_date only with S2_CLOSEST_VALID. Other datasets and mixed requests reject it. For two endpoint composites, use S2_CLOSEST_VALID_BEFORE_AFTER without target_date.
Next steps
- Compare with a planting-season median using
DatasetEnum.S2_MED_PLANTING. - Run the FTW model for field boundary detection in RasterFlow_FTW.ipynb.
- Use the mosaic for model inference.
bucket to a persistent storage prefix when you need to retain outputs. Temporary user storage expires after seven days.
