disdrodb.l1 package#

Submodules#

disdrodb.l1.classification module#

DISDRODB hydrometeor classification and QC module.

disdrodb.l1.classification.classify_raw_spectrum(ds, ds_env, sample_interval, sensor_name, temperature=None, rain_temperature_lower_limit=-5, snow_temperature_upper_limit=5)[source][source]#

Run precipitation and hydrometeor type classification.

disdrodb.l1.classification.define_graupel_mask(spectrum, ds_env, minimum_diameter=0.5, maximum_diameter=5, minimum_density=50, maximum_density=600)[source][source]#

Define graupel mask.

disdrodb.l1.classification.define_hail_mask(spectrum, ds_env, minimum_diameter=5)[source][source]#

Define hail mask.

disdrodb.l1.classification.define_qc_margin_fallers(spectrum, fall_velocity_upper, above_velocity_fraction=None, above_velocity_tolerance=2)[source][source]#

Define QC mask for margin fallers and splashing.

disdrodb.l1.classification.define_qc_rain_strong_wind_mask(spectrum)[source][source]#

Define QC mask for strong wind artefacts in heavy rainfall.

Based on Katia Friedrich et al. 2013.

disdrodb.l1.classification.define_qc_temperature(temperature, sample_interval, threshold_minutes=360)[source][source]#

Define segment-based QC rule for temperature.

Return a qc array with 1 when temperature is constant for over threshold_minutes. Return a qc of 2 if temperature is not available.

disdrodb.l1.classification.get_temperature(ds)[source][source]#

Retrieve temperature variable from L0C product.

disdrodb.l1.classification.map_precip_flag_to_precipitation_type(precip_flag)[source][source]#

Map OCEANRAIN precip_flag to DISDRODB precipitation_type.

disdrodb.l1.classification.qc_spikes_isolated_precip(hydrometeor_type, sample_interval)[source][source]#

Identify isolated precipitation spikes based on hydrometeor classification.

This quality control (QC) routine flags short, isolated precipitation detections (spikes) that are not supported by neighboring precipitating timesteps within a defined time window. The test helps remove spurious single-sample precipitation detections caused by instrument noise or transient misclassification.

The algorithm:
  1. Identifies potential precipitation timesteps where hydrometeor_type>= 1.

  2. Computes time differences between consecutive potential precipitation samples.

  3. Flags a timestep as a spike when both the previous and next precipitation detections are separated by more than the configured time window.

  4. Skips the QC test entirely if the temporal resolution exceeds 2 minutes.

Parameters:
  • hydrometeor_type (xarray.DataArray) – Hydrometeor type classification array with a time coordinate. Precipitation presence is defined where hydrometeor_type>= 1.

  • sample_interval (float or int) – Nominal sampling interval of the dataset in seconds. If sample_interval >= 120 (2 minutes), the QC test is skipped.

Returns:

flag_spikes

Binary QC flag array (same dimensions as input) with:
  • 0 : no spike detected

  • 1 : isolated precipitation spike

Return type:

xarray.DataArray of int

Notes

  • The time window is currently fixed to ±60 seconds for typical 1-minute sampling intervals but can be adapted to scale with sample_interval.

  • Designed to work with irregular time coordinates; relies on actual timestamp differences instead of fixed rolling windows.

  • For datasets with coarse sampling (> 2 minutes), the function returns a zero-valued flag (QC not applied).

disdrodb.l1.processing module#

Core functions for DISDRODB L1 production.

disdrodb.l1.processing.generate_l1(ds, **kwargs)[source][source]#

Generate DISDRODB L1 Dataset from DISDRODB L0C Dataset.

Parameters:

ds (xarray.Dataset) – DISDRODB L0C dataset.

Returns:

DISDRODB L1 dataset.

Return type:

xarray.Dataset

disdrodb.l1.resampling module#

Utilities for temporal resampling.

disdrodb.l1.resampling.add_sample_interval(ds, sample_interval)[source][source]#

Add a sample_interval coordinate to the dataset.

Parameters:
  • ds (xarray.Dataset) – The input dataset to which the sample_interval coordinate will be added.

  • sample_interval (int or float) – The dataset sample interval in seconds.

Returns:

The dataset with the added sample interval coordinate.

Return type:

xarray.Dataset

Notes

The function adds a new coordinate named ‘sample_interval’ to the dataset and updates the ‘measurement_interval’ attribute.

disdrodb.l1.resampling.define_window_size(sample_interval, accumulation_interval)[source][source]#

Calculate the rolling window size based on sampling and accumulation intervals.

Parameters:
  • sampling_interval (int) – The sampling interval in seconds.

  • accumulation_interval (int) – The desired accumulation interval in seconds.

Returns:

The calculated window size as the number of sampling intervals required to cover the accumulation interval.

Return type:

int

Raises:

ValueError – If the accumulation interval is not a multiple of the sampling interval.

Examples

>>> define_window_size(60, 300)
5
>>> define_window_size(120, 600)
5
disdrodb.l1.resampling.resample_dataset(ds, sample_interval, temporal_resolution)[source][source]#

Resample the dataset to a specified accumulation interval.

The output timesteps correspond to the starts of the periods over which the resampling operation has been performed !

Parameters:
  • ds (xarray.Dataset) – The input dataset to be resampled.

  • sample_interval (int) – The sample interval (in seconds) of the input dataset.

  • temporal_resolution (str) – The desired temporal resolution for resampling. It should be a string representing the accumulation interval, e.g., “5MIN” for 5 minutes, “1H” for 1 hour, “30S” for 30 seconds, etc. Prefixed with “ROLL” for rolling resampling, e.g., “ROLL5MIN”.

Returns:

The resampled dataset with updated attributes.

Return type:

xarray.Dataset

Notes

  • The function regularizes the dataset (infill possible missing timesteps) before performing the resampling operation.

  • Variables are categorized into those to be averaged, accumulated, minimized, and maximized.

  • Custom processing for quality flags and handling of NaNs is defined.

  • The function updates the dataset attributes and the sample_interval coordinate.

Module contents#

DISDRODB L1 module.

disdrodb.l1.generate_l1(ds, **kwargs)[source][source]#

Generate DISDRODB L1 Dataset from DISDRODB L0C Dataset.

Parameters:

ds (xarray.Dataset) – DISDRODB L0C dataset.

Returns:

DISDRODB L1 dataset.

Return type:

xarray.Dataset