Processing#
easysnowdata.processing#
Pure processing functions (design contract §2.6): xarray in, xarray out, no I/O.
masks— Sentinel-2 SCL and HLS Fmask masks, nodata maskingoptical— baseline harmonization, scale/offset, spectral indices, RGB composites and stretchessar— dB conversion, border-noise removal, slope/aspect and the local incidence anglesnow— snow-product class tables, binary snow and the SNODAS flat-file readerwateryear— vectorized water-year helperscategorical— CF flag attributes for categorical products (the contract’s replacement forclass_infodicts)contract— the output contract (§2.5): CRS via both accessors, dim names, nodata policy, provenance attrs
Attach |
|
Mask obj to NaN where Fmask flags are set ( |
|
Turn a MODIS/VIIRS snow-cover band into a 0/1 snow mask. |
|
Mask obj to NaN where the SCL class is in remove ( |
|
Day of the water year, 1-indexed (1 October = 1 in the northern hemisphere). |
|
|
|
Decode a PlanetScope UDM2 mask into named variables. |
|
Enhanced Vegetation Index |
|
Boolean mask that is |
|
Read CF flag attributes into a DataFrame with |
|
The aerosol level 0–3 encoded in Fmask bits 6–7. |
|
The value (0/1) of bit in each Fmask pixel. |
|
Boolean mask that is |
|
Convert the legacy |
|
Undo the post-2022-01-25 Sentinel-2 L2A offset so all dates share one baseline. |
|
|
|
Local incidence angle from a DEM and the ellipsoidal incidence angle. |
|
Radar look azimuth in degrees from the platform heading. |
|
Replace the nodata value with NaN (converting integers to float). |
|
Normalized Difference Built-up Index as used here: |
|
Normalized Difference Snow Index |
|
Normalized Difference Vegetation Index |
|
Normalized Difference Water Index (McFeeters) |
|
CF attributes for an NDSI byte: percentages plus the sentinel meanings. |
|
|
|
Parse a NOHRSC |
|
Mask falsely low backscatter (border noise) in linear-power data. |
|
Stack three bands into a |
|
Apply |
|
Boolean mask that is |
|
Attach CF flag attributes to a categorical DataArray. |
|
Slope and aspect of a projected DEM, by central differences. |
|
Contrast Limited Adaptive Histogram Equalization per band (scikit-image). |
|
Percentile contrast stretch per band, clipped to 0–1. |
|
The value (0/1) of one UDM1 bit ( |
|
The water year of each time as an integer (calendar year the WY ends in for the north). |
|
The first day of the water year containing each time (same container type as the input). |
easysnowdata.processing.categorical#
CF flag attributes for categorical products.
The design contract (§2.5) forbids Python objects in .attrs: a categorical
variable carries flag_values (list of ints), flag_meanings (one
space-separated string, blanks inside a meaning become underscores) and
flag_colors (space-separated hex strings). These helpers write and read
that form; easysnowdata.plotting turns it into colormaps and legends.
Normalise a class name to a CF |
easysnowdata.processing.contract#
Output-contract helpers (design contract §2.5), shared by every theme loader.
Pure functions: they rename dimensions, write the CRS with both the rio
and odc accessors, mask nodata the way the contract prescribes
(categorical keeps the sentinel with rio.nodata set; continuous is
NaN-masked with encoded_nodata preserved) and stamp the standard
provenance attributes (source, source_url, product_id,
data_citation, license, easysnowdata_version). No I/O.
Rename spatial dims to the contract: |
|
Write crs so that both |
|
NaN-mask a continuous variable and keep the encoded nodata value. |
|
Keep the source sentinel and record it as |
|
The standard provenance attrs for a catalog product loaded via source. |
|
Apply the catalog |
|
Bring a loaded object onto the output contract. |
easysnowdata.processing.masks#
Quality masks: Sentinel-2 SCL classes, HLS Fmask bits, nodata.
easysnowdata.processing.optical#
Optical processing: Sentinel-2 baseline harmonization, scale/offset, spectral indices, RGB composites and contrast stretches. Pure functions.
easysnowdata.processing.sar#
SAR backscatter helpers: dB conversion and Sentinel-1 border-noise removal.
easysnowdata.processing.snow#
Snow-product processing: class tables, binary snow, SNODAS headers.
Pure functions (design contract §2.6). The class tables are the MODIS and VIIRS sentinel values that share a byte with the NDSI percentage, so they are what turns a raw granule into something a user can threshold.
Put the upstream 256/265 fill values back to 255 and return uint8. |
|
Group a SNODAS day's tar into |
|
Build a georeferenced DataArray from one SNODAS |
easysnowdata.processing.wateryear#
Vectorized water-year helpers.
This is the single copy of these functions (§12 Q16): the scalar
utils.datetime_to_WY/datetime_to_DOWY that used to be applied with
pd.Index.map and the global_snow_networks utils/utils.py
implementations are both reconciled here. The names wy_start/wy_end
from that repo are water_year_bounds(), wy_date_range is
water_year_range(), wy_length is water_year_length() and
add_wy_coords is add_water_year_coords(); all of them also take a
hemisphere, which the originals did not.
A northern-hemisphere water year starts 1 October and is named for the
calendar year in which it ends (WY 2021 = 2020-10-01 … 2021-09-30); a
southern-hemisphere one starts 1 April and is named for the year it starts.
For aggregation prefer the pandas anchored offsets:
ds.resample(time="YS-OCT").max(). Day-of-water-year has no pandas
primitive, hence day_of_water_year() and add_water_year_coords().
First and last day of water year year. |
|
Daily |
|
Number of days in water year year — 366 when 29 February falls inside it. |