disdrodb.psd package

Contents

disdrodb.psd package#

Submodules#

disdrodb.psd.fitting module#

Routines for PSD fitting.

disdrodb.psd.fitting.apply_exponential_gs(Nt, ND_obs, V, D, dD, target, transformation, error_order)[source][source]#

Apply Grid Search for the ExponentialPSD distribution.

disdrodb.psd.fitting.apply_gamma_gs(Nt, ND_obs, V, D, dD, target, transformation, error_order)[source][source]#

Estimate GammaPSD model parameters using Grid Search.

disdrodb.psd.fitting.apply_lognormal_gs(Nt, ND_obs, V, D, dD, target, transformation, error_order)[source][source]#

Estimate LognormalPSD model parameters using Grid Search.

disdrodb.psd.fitting.apply_normalized_gamma_gs(Nw, D50, ND_obs, V, D, dD, target, transformation, error_order)[source][source]#

Estimate NormalizedGammaPSD model parameters using Grid Search.

disdrodb.psd.fitting.available_mom_methods(psd_model)[source][source]#

Implemented MOM methods for a given PSD model.

disdrodb.psd.fitting.available_optimization(psd_model)[source][source]#

Implemented fitting methods for a given PSD model.

disdrodb.psd.fitting.check_likelihood(likelihood)[source][source]#

Check valid likelihood argument.

disdrodb.psd.fitting.check_mom_methods(mom_methods, psd_model, allow_none=False)[source][source]#

Check valid mom_methods arguments.

disdrodb.psd.fitting.check_optimization(optimization)[source][source]#

Check valid optimization argument.

disdrodb.psd.fitting.check_optimization_kwargs(optimization_kwargs, optimization, psd_model)[source][source]#

Check valid optimization_kwargs.

disdrodb.psd.fitting.check_optimizer(optimizer)[source][source]#

Check valid optimizer argument.

disdrodb.psd.fitting.check_probability_method(probability_method)[source][source]#

Check valid probability_method argument.

disdrodb.psd.fitting.check_psd_model(psd_model, optimization)[source][source]#

Check valid psd_model argument.

disdrodb.psd.fitting.check_target(target)[source][source]#

Check valid target argument.

disdrodb.psd.fitting.check_transformation(transformation)[source][source]#

Check valid transformation argument.

disdrodb.psd.fitting.check_truncated_likelihood(truncated_likelihood)[source][source]#

Check valid truncated_likelihood argument.

disdrodb.psd.fitting.compute_gof_stats(obs, pred, dim='diameter_bin_center')[source][source]#

Compute various goodness-of-fit (GoF) statistics between obs and predicted values.

Parameters:
  • obs (xarray.DataArray) – Observations DataArray with at least dimension dim.

  • pred (xarray.DataArray) – Predictions DataArray with at least dimension dim.

  • dim (str) – DataArray dimension over which to compute GOF statistics. The default is DIAMETER_DIMENSION.

Returns:

ds – Dataset containing the computed GoF statistics.

Return type:

xarray.Dataset

disdrodb.psd.fitting.compute_negative_log_likelihood(params, bin_edges, counts, cdf_func, pdf_func, param_constraints=None, probability_method='cdf', likelihood='multinomial', truncated_likelihood=True)[source][source]#

General negative log-likelihood function for fitting distributions to binned data.

Parameters:
  • params (array-like) – Parameters of the distribution.

  • bin_edges (array-like) – Edges of the bins (length N+1).

  • counts (array-like) – obs counts in each bin (length N).

  • cdf_func (callable) – Cumulative distribution function of the distribution.

  • pdf_func (callable) – Probability density function of the distribution.

  • param_constraints (callable, optional) – Function that checks if parameters are valid.

  • probability_method (str, optional) – Method to compute expected probabilities, either ‘cdf’ or ‘pdf’. Default is ‘cdf’.

  • likelihood (str, optional) – Type of likelihood to compute, either ‘multinomial’ or ‘poisson’. Default is ‘multinomial’.

  • truncated_likelihood (bool, optional) – Whether to normalize the expected probabilities. Default is True.

  • nll (float) – Negative log-likelihood value.

Returns:

nll – The negative log-likelihood value.

Return type:

float

disdrodb.psd.fitting.estimate_exponential_parameters(counts, Lambda, bin_edges, probability_method='cdf', likelihood='multinomial', truncated_likelihood=True, output_dictionary=True, optimizer='Nelder-Mead')[source][source]#

Estimate the parameters of an exponential distribution given histogram data.

Parameters:
  • counts (array-like) – The counts for each bin in the histogram.

  • Lambda (float) – The initial guess of the scale parameter. scale = 1 / lambda correspond to the scale parameter of the scipy.stats.expon distribution. A good default value is 1.

  • bin_edges (array-like) – The edges of the bins.

  • probability_method (str, optional) – The method to compute probabilities, either "cdf" or "pdf". The default value is "cdf".

  • likelihood (str, optional) – The likelihood function to use, either "multinomial" or "poisson". The default value is "multinomial".

  • truncated_likelihood (bool, optional) – Whether to use truncated likelihood. The default value is True.

  • output_dictionary (bool, optional) – Whether to return the output as a dictionary. If False, returns a numpy array. The default value is True

  • optimizer (str, optional) – The optimization method to use. Default is "Nelder-Mead".

Returns:

The estimated parameters of the exponential distribution. If output_dictionary is True, returns a dictionary with keys N0 and Lambda. If output_dictionary is False, returns a numpy array with [N0, Lambda].

Return type:

dict or numpy.ndarray

Notes

The exponential distribution is defined as:

N(D) = N0 * exp(-Lambda * D) = Nt * Lambda * exp(-Lambda * D)

where Lambda = 1 / scale and N0 = Nt * Lambda.

References

disdrodb.psd.fitting.estimate_gamma_parameters(counts, mu, Lambda, bin_edges, probability_method='cdf', likelihood='multinomial', truncated_likelihood=True, output_dictionary=True, optimizer='Nelder-Mead')[source][source]#

Estimate the parameters of a gamma distribution given histogram data.

Parameters:
  • counts (array-like) – The counts for each bin in the histogram.

  • mu (float) – The initial guess of the shape parameter. a = mu + 1 correspond to the shape parameter of the scipy.stats.gamma distribution. A good default value is 0.

  • lambda (float) – The initial guess of the scale parameter. scale = 1 / lambda correspond to the scale parameter of the scipy.stats.gamma distribution. A good default value is 1.

  • bin_edges (array-like) – The edges of the bins.

  • probability_method (str, optional) – The method to compute probabilities, either "cdf" or "pdf". The default value is "cdf".

  • likelihood (str, optional) – The likelihood function to use, either "multinomial" or "poisson". The default value is "multinomial".

  • truncated_likelihood (bool, optional) – Whether to use truncated likelihood. The default value is True.

  • output_dictionary (bool, optional) – Whether to return the output as a dictionary. If False, returns a numpy array. The default value is True

  • optimizer (str, optional) – The optimization method to use. Default is "Nelder-Mead".

Returns:

The estimated parameters of the gamma distribution. If output_dictionary is True, returns a dictionary with keys N0, mu and Lambda. If output_dictionary is False, returns a numpy array with [N0, mu, Lambda].

Return type:

dict or numpy.ndarray

Notes

The gamma distribution is defined as:

N(D) = N0 * D**mu * exp(-Lambda*D)

where Lambda = 1/scale, and mu = a - 1 with a being the shape parameter of the gamma distribution. N0 is defined as N0 = Nt*Lambda**(mu+1)/gamma(mu+1).

References

disdrodb.psd.fitting.estimate_lognormal_parameters(counts, mu, sigma, bin_edges, probability_method='cdf', likelihood='multinomial', truncated_likelihood=True, output_dictionary=True, optimizer='Nelder-Mead')[source][source]#

Estimate the parameters of a lognormal distribution given histogram data.

Parameters:
  • counts (array-like) – The counts for each bin in the histogram.

  • mu (float) – The initial guess of the mean of the log of the distribution. A good default value is 0.

  • sigma (float) – The initial guess of the standard deviation of the log distribution. A good default value is 1.

  • bin_edges (array-like) – The edges of the bins.

  • probability_method (str, optional) – The method to compute probabilities, either "cdf" or "pdf". The default value is "cdf".

  • likelihood (str, optional) – The likelihood function to use, either "multinomial" or "poisson". The default value is "multinomial".

  • truncated_likelihood (bool, optional) – Whether to use truncated likelihood. The default value is True.

  • output_dictionary (bool, optional) – Whether to return the output as a dictionary. If False, returns a numpy array. The default value is True

  • optimizer (str, optional) – The optimization method to use. Default is "Nelder-Mead".

Returns:

The estimated parameters of the lognormal distribution. If output_dictionary is True, returns a dictionary with keys Nt, mu, and sigma. If output_dictionary is False,returns a numpy array with values [Nt, mu, sigma].

Return type:

dict or numpy.ndarray

Notes

The lognormal distribution is defined as: N(D) = Nt / (sqrt(2 * pi) * sigma * D) * exp(-(ln(D) - mu)**2 / (2 * sigma**2)) where Nt is the total number of counts, mu is the mean of the log of the distribution, and sigma is the standard deviation of the log of the distribution.

References

disdrodb.psd.fitting.estimate_model_parameters(ds, psd_model, optimization, optimization_kwargs=None)[source][source]#

Routine to estimate PSD model parameters.

disdrodb.psd.fitting.get_adjusted_nt(cdf, params, Nt, bin_edges)[source][source]#

Adjust Nt for the proportion of missing drops. See Johnson’s et al., 2013 Eqs. 3 and 4.

disdrodb.psd.fitting.get_expected_probabilities(params, cdf_func, pdf_func, bin_edges, probability_method, normalized=False)[source][source]#

Compute the expected probabilities for each bin given the distribution parameters.

Parameters:
  • params (array-like) – Parameters for the CDF or PDF function.

  • cdf_func (callable) – Cumulative distribution function (CDF) that takes bin edges and parameters as inputs.

  • pdf_func (callable) – Probability density function (PDF) that takes a value and parameters as inputs.

  • bin_edges (array-like) – Edges of the bins for which to compute the probabilities.

  • probability_method ({'cdf', 'pdf'}) – Method to compute the probabilities. If ‘cdf’, use the CDF to compute probabilities. If ‘pdf’, integrate the PDF over each bin range.

  • normalized (bool, optional) – If True, normalize the probabilities to sum to 1. Default is False.

Returns:

expected_probabilities – Array of expected probabilities for each bin.

Return type:

numpy.ndarray

Notes

  • If the ‘cdf’ method is used, the probabilities are computed as the difference in CDF values at the bin edges.

  • If the ‘pdf’ method is used, the probabilities are computed by integrating the PDF over each bin range.

  • Any zero or negative probabilities are replaced with a very small positive number (1e-10) to ensure optimization.

  • If normalized is True, the probabilities are normalized to sum to 1.

disdrodb.psd.fitting.get_exponential_parameters(ds, init_method=None, probability_method='cdf', likelihood='multinomial', truncated_likelihood=True, optimizer='Nelder-Mead')[source][source]#

Estimate the parameters of an exponential particle size distribution (PSD) from the given dataset.

Fitting this model is equivalent to fitting a GammaPSD model fixing mu to 0.

Parameters:
  • ds (xarray.Dataset) – Input dataset containing drop number concentration data and diameter information. It must include the following variables: - drop_number_concentration: The number concentration of drops. - diameter_bin_width”: The width of each diameter bin. - diameter_bin_lower: The lower bounds of the diameter bins. - diameter_bin_upper: The upper bounds of the diameter bins. - diameter_bin_center: The center values of the diameter bins.

  • probability_method (str, optional) – Method to compute probabilities. The default value is cdf.

  • likelihood (str, optional) – Likelihood function to use for fitting. The default value is multinomial.

  • truncated_likelihood (bool, optional) – Whether to use truncated likelihood. The default value is True.

  • optimizer (str, optional) – Optimization method to use. The default value is Nelder-Mead.

Returns:

Dataset containing the estimated expontial distribution parameters: - N0: Intercept parameter. - Lambda: Scale parameter. The resulting dataset will have an attribute disdrodb_psd_model set to ExponentialPSD.

Return type:

xarray.Dataset

Notes

The function uses xr.apply_ufunc to fit the exponential distribution parameters in parallel, leveraging Dask for parallel computation.

disdrodb.psd.fitting.get_exponential_parameters_M34(moment_3, moment_4)[source][source]#

Compute exponential distribution parameters following Testud 2001.

References

Testud, J., S. Oury, R. A. Black, P. Amayenc, and X. Dou, 2001: The Concept of “Normalized” Distribution to Describe Raindrop Spectra: A Tool for Cloud Physics and Cloud Remote Sensing. J. Appl. Meteor. Climatol., 40, 1118-1140, https://doi.org/10.1175/1520-0450(2001)040<1118:TCONDT>2.0.CO;2

disdrodb.psd.fitting.get_exponential_parameters_Zhang2008(moment_l, moment_m, l, m)[source][source]#

Calculate Exponential DSD parameters using the method of moments (MOM).

The choice of moments is given in the parameters.

Parameters:
  • moment_l (float) – First moment to use.

  • moment_l – Second moment to use.

  • l (float) – Moment order.

  • m (float) – Moment order,

References

[1] Zhang, et. al., 2008, Diagnosing the Intercept Parameter for Exponential Raindrop Size

Distribution Based on Video Disdrometer Observations: Model Development. J. Appl. Meteor. Climatol., https://doi.org/10.1175/2008JAMC1876.1

disdrodb.psd.fitting.get_exponential_parameters_gs(ds, target='ND', transformation='log', error_order=1)[source][source]#

Estimate the parameters of an Exponential distribution using Grid Search.

disdrodb.psd.fitting.get_gamma_parameters(ds, init_method=None, probability_method='cdf', likelihood='multinomial', truncated_likelihood=True, optimizer='Nelder-Mead')[source][source]#

Estimate gamma distribution parameters for drop size distribution (DSD) data.

Parameters:
  • ds (xarray.Dataset) –

    Input dataset containing drop size distribution data. It must include the following variables: - drop_number_concentration: The number concentration of drops. - diameter_bin_width”: The width of each diameter bin. - diameter_bin_lower: The lower bounds of the diameter bins. - diameter_bin_upper: The upper bounds of the diameter bins. - diameter_bin_center: The center values of the diameter bins. - The moments M0…M6 variables required to compute the initial parameters

    with the specified mom_method.

  • init_method (str or list) – The method(s) of moments used to initialize the gamma parameters. If None (or ‘None’), the scale parameter is set to 1 and mu to 0 (a=1).

  • probability_method (str, optional) – Method to compute probabilities. The default value is cdf.

  • likelihood (str, optional) – Likelihood function to use for fitting. The default value is multinomial.

  • truncated_likelihood (bool, optional) – Whether to use truncated likelihood. The default value is True.

  • optimizer (str, optional) – Optimization method to use. The default value is Nelder-Mead.

Returns:

Dataset containing the estimated gamma distribution parameters: - N0: Intercept parameter. - mu: Shape parameter. - Lambda: Scale parameter. The dataset will also have an attribute disdrodb_psd_model set to GammaPSD.

Return type:

xarray.Dataset

Notes

The function uses xr.apply_ufunc to fit the lognormal distribution parameters in parallel, leveraging Dask for parallel computation.

disdrodb.psd.fitting.get_gamma_parameters_M012(M0, M1, M2)[source][source]#

Compute gamma distribution parameters following Cao et al., 2009.

References

Cao, Q., and G. Zhang, 2009: Errors in Estimating Raindrop Size Distribution Parameters Employing Disdrometer and Simulated Raindrop Spectra. J. Appl. Meteor. Climatol., 48, 406-425, https://doi.org/10.1175/2008JAMC2026.1.

disdrodb.psd.fitting.get_gamma_parameters_M234(M2, M3, M4)[source][source]#

Compute gamma distribution parameters following Cao et al., 2009.

References

Cao, Q., and G. Zhang, 2009: Errors in Estimating Raindrop Size Distribution Parameters Employing Disdrometer and Simulated Raindrop Spectra. J. Appl. Meteor. Climatol., 48, 406-425, https://doi.org/10.1175/2008JAMC2026.1.

disdrodb.psd.fitting.get_gamma_parameters_M246(M2, M4, M6)[source][source]#

Compute gamma distribution parameters following Ulbrich 1998.

References

Ulbrich, C. W., and D. Atlas, 1998: Rainfall Microphysics and Radar Properties: Analysis Methods for Drop Size Spectra. J. Appl. Meteor. Climatol., 37, 912-923, https://doi.org/10.1175/1520-0450(1998)037<0912:RMARPA>2.0.CO;2

Cao, Q., and G. Zhang, 2009: Errors in Estimating Raindrop Size Distribution Parameters Employing Disdrometer and Simulated Raindrop Spectra. J. Appl. Meteor. Climatol., 48, 406-425, https://doi.org/10.1175/2008JAMC2026.1.

Thurai, M., Williams, C.R., Bringi, V.N., 2014: Examining the correlations between drop size distribution parameters using data from two side-by-side 2D-video disdrometers. Atmospheric Research, 144, 95-110, https://doi.org/10.1016/j.atmosres.2014.01.002.

disdrodb.psd.fitting.get_gamma_parameters_M346(M3, M4, M6)[source][source]#

Compute gamma distribution parameters following Kozu 1991.

References

Kozu, T., and K. Nakamura, 1991: Rainfall Parameter Estimation from Dual-Radar Measurements Combining Reflectivity Profile and Path-integrated Attenuation. J. Atmos. Oceanic Technol., 8, 259-270, https://doi.org/10.1175/1520-0426(1991)008<0259:RPEFDR>2.0.CO;2

Tokay, A., and D. A. Short, 1996: Evidence from Tropical Raindrop Spectra of the Origin of Rain from Stratiform versus Convective Clouds. J. Appl. Meteor. Climatol., 35, 355-371, https://doi.org/10.1175/1520-0450(1996)035<0355:EFTRSO>2.0.CO;2

Cao, Q., and G. Zhang, 2009: Errors in Estimating Raindrop Size Distribution Parameters Employing Disdrometer and Simulated Raindrop Spectra. J. Appl. Meteor. Climatol., 48, 406-425, https://doi.org/10.1175/2008JAMC2026.1.

disdrodb.psd.fitting.get_gamma_parameters_M456(M4, M5, M6)[source][source]#

Compute gamma distribution parameters following Cao et al., 2009.

References

Cao, Q., and G. Zhang, 2009: Errors in Estimating Raindrop Size Distribution Parameters Employing Disdrometer and Simulated Raindrop Spectra. J. Appl. Meteor. Climatol., 48, 406-425, https://doi.org/10.1175/2008JAMC2026.1.

disdrodb.psd.fitting.get_gamma_parameters_gs(ds, target='ND', transformation='log', error_order=1)[source][source]#

Compute Grid Search to identify mu and Lambda Gamma distribution parameters.

disdrodb.psd.fitting.get_gamma_parameters_johnson2014(ds, method='Nelder-Mead')[source][source]#

Deprecated model. See Gamma Model with truncated_likelihood and ‘pdf’.

disdrodb.psd.fitting.get_gs_parameters(ds, psd_model, target='ND', transformation='log', error_order=1)[source][source]#

Retrieve PSD model parameters using Grid Search.

disdrodb.psd.fitting.get_lognormal_parameters(ds, init_method=None, probability_method='cdf', likelihood='multinomial', truncated_likelihood=True, optimizer='Nelder-Mead')[source][source]#

Estimate lognormal distribution parameters for drop size distribution (DSD) data.

Parameters:
  • ds (xarray.Dataset) –

  • variables (Input dataset containing drop size distribution data. It must include the following) –

  • drop_number_concentration (-) –

  • diameter_bin_width" (-) –

  • diameter_bin_lower (-) –

  • diameter_bin_upper (-) –

  • diameter_bin_center (-) –

  • probability_method (str, optional) – Method to compute probabilities. The default value is cdf.

  • likelihood (str, optional) – Likelihood function to use for fitting. The default value is multinomial.

  • truncated_likelihood (bool, optional) – Whether to use truncated likelihood. The default value is True.

  • optimizer (str, optional) – Optimization method to use. The default value is Nelder-Mead.

Returns:

Dataset containing the estimated lognormal distribution parameters: - Nt: Total number concentration. - mu: Mean of the lognormal distribution. - sigma: Standard deviation of the lognormal distribution. The resulting dataset will have an attribute disdrodb_psd_model set to LognormalPSD.

Return type:

xarray.Dataset

Notes

The function uses xr.apply_ufunc to fit the lognormal distribution parameters in parallel, leveraging Dask for parallel computation.

disdrodb.psd.fitting.get_lognormal_parameters_M346(M3, M4, M6)[source][source]#

Compute lognormal distribution parameters following Kozu1991.

References

Kozu, T., and K. Nakamura, 1991: Rainfall Parameter Estimation from Dual-Radar Measurements Combining Reflectivity Profile and Path-integrated Attenuation. J. Atmos. Oceanic Technol., 8, 259-270, https://doi.org/10.1175/1520-0426(1991)008<0259:RPEFDR>2.0.CO;2

disdrodb.psd.fitting.get_lognormal_parameters_gs(ds, target='ND', transformation='log', error_order=1)[source][source]#

Compute Grid Search to identify mu and sigma lognormal distribution parameters.

disdrodb.psd.fitting.get_ml_parameters(ds, psd_model, init_method=None, probability_method='cdf', likelihood='multinomial', truncated_likelihood=True, optimizer='Nelder-Mead')[source][source]#

Estimate model parameters for a given distribution using Maximum Likelihood.

Parameters:

ds (xarray.Dataset) – Input dataset containing drop number concentration data and diameter information. It must include the following variables: - drop_number_concentration: The number concentration of drops. - diameter_bin_width”: The width of each diameter bin. - diameter_bin_lower: The lower bounds of the diameter bins. - diameter_bin_upper: The upper bounds of the diameter bins. - diameter_bin_center: The center values of the diameter bins.

psd_modelstr

The PSD model to fit. See available_psd_models().

init_method: str or list

The method(s) of moments used to initialize the PSD model parameters. Multiple methods can be specified. See available_mom_methods(psd_model).

probability_methodstr, optional

Method to compute probabilities. The default value is cdf.

likelihoodstr, optional

Likelihood function to use for fitting. The default value is multinomial.

truncated_likelihoodbool, optional

Whether to use Truncated Maximum Likelihood (TML). The default value is True.

optimizerstr, optional

Optimization method to use. The default value is Nelder-Mead.

Returns:

The dataset containing the estimated parameters.

Return type:

xarray.Dataset

disdrodb.psd.fitting.get_mom_parameters(ds: Dataset, psd_model: str, mom_methods=None) Dataset[source][source]#

Compute PSD model parameters using various method-of-moments (MOM) approaches.

The method is specified by the mom_methods abbreviations, e.g. ‘M012’, ‘M234’, ‘M246’.

Parameters:
  • ds (xarray.Dataset) – An xarray Dataset with the required moments M0…M6 as data variables.

  • mom_methods (str or list (optional)) – See valid values with disdrodb.psd.available_mom_methods(psd_model) If None (the default), compute model parameters with all available MOM methods.

Returns:

A Dataset containing mu, Lambda, and N0 variables. If multiple mom_methods are specified, the dataset has the dimension mom_method.

Return type:

xarray.Dataset

disdrodb.psd.fitting.get_normalized_gamma_parameters_gs(ds, target='ND', transformation='log', error_order=1)[source][source]#

Estimate $mu$ of a Normalized Gamma distribution using Grid Search.

The D50 and Nw parameters of the Normalized Gamma distribution are derived empirically from the obs DSD. $mu$ is derived by minimizing the errors between the obs DSD and modelled Normalized Gamma distribution.

Parameters:
  • Nd (array_like) – A drop size distribution

  • D50 (optional, float) – Median drop diameter in mm. If none is given, it will be estimated.

  • Nw (optional, float) – Normalized Intercept Parameter. If none is given, it will be estimated.

  • order (optional, float) – Order to which square the error when computing the sum of errors. Order = 2 is equivalent to minimize the mean squared error (MSE) (L2 norm). The default is 2. Order = 1 is equivalent to minimize the mean absolute error (MAE) (L1 norm). Higher orders typically stretch higher the gamma distribution.

Returns:

ds_params – Dataset containing the estimated Normalized Gamma distribution parameters.

Return type:

xarray.Dataset

disdrodb.psd.models module#

Definition of PSD models.

The class implementation is inspired by pytmatrix.psd and pyradsim.psd modules and adapted to allow efficient vectorized computations with xarray.

Source code: - jleinonen/pytmatrix - wolfidan/pyradsim

class disdrodb.psd.models.BinnedPSD(bin_edges, bin_psd, interp_method='step_left')[source][source]#

Bases: PSD

Binned Particle Size Distribution (PSD).

This class represents a binned particle size distribution (PSD) that computes PSD values based on provided bin edges and corresponding PSD values. The PSD is evaluated via interpolation using one of several available methods.

Parameters:
  • bin_edges (array_like) – A sequence of n+1 bin edge values defining the bins. The edges must be monotonically increasing.

  • bin_psd (array_like) – A sequence of n PSD values corresponding to the intervals defined by bin_edges.

  • interp_method ({'step_left', 'step_right', 'linear', 'pchip'}, optional) – The interpolation method used to compute the PSD values. The default is ‘step_left’.

  • D (For any input diameter (or diameters)) –

    • If D lies outside the range (bin_edges[0], bin_edges[-1]), the PSD value is set to 0.

    • The interpolation function is defined internally based on the chosen method.

    • PSD values are clipped to ensure they are non-negative.

Examples

>>> import numpy as np
>>> bin_edges = [0.0, 1.0, 2.0, 3.0, 4.0]
>>> bin_psd = [10.0, 20.0, 30.0, 0.0]
>>> D = np.linspace(0, 3.5, 100)
>>>
>>> # Using linear interpolation
>>> psd_linear = BinnedPSD(bin_edges, bin_psd, interp_method="linear")
>>> psd_values = psd_linear(D)
>>>
>>> # Values for D outside (bin_edges[0], bin_edges[-1]) are set to 0
class disdrodb.psd.models.ExponentialPSD(N0=1.0, Lambda=1.0)[source][source]#

Bases: XarrayPSD

Exponential particle size distribution (PSD).

Callable class to provide an exponential PSD with the given parameters. The attributes can also be given as arguments to the constructor.

The PSD form is: N(D) = N0 * exp(-Lambda*D)

N0#
Type:

the intercept parameter.

Lambda#
Type:

the inverse scale parameter

Args (call):

D: the particle diameter in millimeter.

Returns (call):

The PSD value for the given diameter.

static formula(D, N0, Lambda)[source][source]#

Calculates the Exponential PSD values.

static from_parameters(parameters)[source][source]#

Initialize ExponentialPSD from a dictionary or xr.Dataset.

Args:

parameters (dict or xr.Dataset): Parameters to initialize the class.

Returns:

ExponentialPSD

Return type:

An instance of ExponentialPSD initialized with the parameters.

property name[source]#

Return name of the PSD.

parameters_summary()[source][source]#

Return a string with the parameter summary.

static required_parameters()[source][source]#

Return the required parameters of the PSD.

class disdrodb.psd.models.GammaPSD(N0=1.0, mu=0.0, Lambda=1.0)[source][source]#

Bases: ExponentialPSD

Gamma particle size distribution (PSD).

Callable class to provide an gamma PSD with the given parameters. The attributes can also be given as arguments to the constructor.

The PSD form is: N(D) = N0 * D**mu * exp(-Lambda*D)

N0#
Type:

the intercept parameter [mm**(-1-mu) m**-3] (scale parameter)

Lambda#
Type:

the inverse scale parameter [mm-1] (slope parameter)

mu#
Type:

the shape parameter [-]

Args (call):

D: the particle diameter in millimeter.

Returns (call):

The PSD value for the given diameter.

References

Ulbrich, C. W., 1985: The Effects of Drop Size Distribution Truncation on Rainfall Integral Parameters and Empirical Relations. J. Appl. Meteor. Climatol., 24, 580-590, https://doi.org/10.1175/1520-0450(1985)024<0580:TEODSD>2.0.CO;2

static formula(D, N0, Lambda, mu)[source][source]#

Calculates the Gamma PSD values.

static from_parameters(parameters)[source][source]#

Initialize GammaPSD from a dictionary or xr.Dataset.

Args:

parameters (dict or xr.Dataset): Parameters to initialize the class.

Returns:

GammaPSD

Return type:

An instance of GammaPSD initialized with the parameters.

property name[source]#

Return name of the PSD.

parameters_summary()[source][source]#

Return a string with the parameter summary.

static required_parameters()[source][source]#

Return the required parameters of the PSD.

class disdrodb.psd.models.LognormalPSD(Nt=1.0, mu=0.0, sigma=1.0)[source][source]#

Bases: XarrayPSD

Lognormal drop size distribution (DSD).

Callable class to provide a lognormal PSD with the given parameters.

The PSD form is:

N(D) = Nt/(sqrt(2*pi)*sigma*D)) * exp(-(ln(D)-mu)**2 / (2*sigma**2))

# g = sigma # theta = 0

Nt#
g#
theta#
mu#
sigma#
static formula(D, Nt, mu, sigma)[source][source]#

Calculates the Lognormal PSD values.

static from_parameters(parameters)[source][source]#

Initialize LognormalPSD from a dictionary or xr.Dataset.

Args:

parameters (dict or xr.Dataset): Parameters to initialize the class.

Returns:

LognormalPSD

Return type:

An instance of LognormalPSD initialized with the parameters.

property name[source]#

Return name of the PSD.

parameters_summary()[source][source]#

Return a string with the parameter summary.

static required_parameters()[source][source]#

Return the required parameters of the PSD.

class disdrodb.psd.models.NormalizedGammaPSD(Nw=1.0, D50=1.0, mu=0.0)[source][source]#

Bases: XarrayPSD

Normalized gamma particle size distribution (PSD).

Callable class to provide a normalized gamma PSD with the given parameters. The attributes can also be given as arguments to the constructor.

The PSD form is:

N(D) = Nw * f(mu) * (D/D50)**mu * exp(-(mu+3.67)*D/D50) f(mu) = 6/(3.67**4) * (mu+3.67)**(mu+4)/Gamma(mu+4)

An alternative formulation as function of Dm: # Testud (2001), Bringi (2001), Williams et al., 2014, Dolan 2018 # –> Normalized with respect to liquid water content (mass) –> Nx=D3/Dm4 N(D) = Nw * f1(mu) * (D/Dm)**mu * exp(-(mu+4)*D/Dm) # Nw * f(D; Dm, mu) f1(mu) = 6/(4**4) * (mu+4)**(mu+4)/Gamma(mu+4)

Note: gamma(4) = 6

An alternative formulation as function of Dm: # Tokay et al., 2010 # Illingworth et al., 2002 (see eq10 to derive full formulation!) # –> Normalized with respect to total concentration –> Nx = #/Dm N(D) = Nt* * f2(mu) * (D/Dm)**mu * exp(-(mu+4)*D/Dm) f2(mu) = (mu+4)**(mu+1)/Gamma(mu+1)

D50#
Type:

the median volume diameter.

Nw#
Type:

the intercept parameter.

mu#
Type:

the shape parameter.

Args (call):

D: the particle diameter in millimeter.

Returns (call):

The PSD value for the given diameter.

References

Willis, P. T., 1984: Functional Fits to Some Observed Drop Size Distributions and Parameterization of Rain. J. Atmos. Sci., 41, 1648-1661, https://doi.org/10.1175/1520-0469(1984)041<1648:FFTSOD>2.0.CO;2

Testud, J., S. Oury, R. A. Black, P. Amayenc, and X. Dou, 2001: The Concept of “Normalized” Distribution to Describe Raindrop Spectra: A Tool for Cloud Physics and Cloud Remote Sensing. J. Appl. Meteor. Climatol., 40, 1118-1140, https://doi.org/10.1175/1520-0450(2001)040<1118:TCONDT>2.0.CO;2

Illingworth, A. J., and T. M. Blackman, 2002: The Need to Represent Raindrop Size Spectra as Normalized Gamma Distributions for the Interpretation of Polarization Radar Observations. J. Appl. Meteor. Climatol., 41, 286-297, https://doi.org/10.1175/1520-0450(2002)041<0286:TNTRRS>2.0.CO;2

Bringi, V. N., G. Huang, V. Chandrasekar, and E. Gorgucci, 2002: A Methodology for Estimating the Parameters of a Gamma Raindrop Size Distribution Model from Polarimetric Radar Data: Application to a Squall-Line Event from the TRMM/Brazil Campaign. J. Atmos. Oceanic Technol., 19, 633-645, https://doi.org/10.1175/1520-0426(2002)019<0633:AMFETP>2.0.CO;2

Bringi, V. N., V. Chandrasekar, J. Hubbert, E. Gorgucci, W. L. Randeu, and M. Schoenhuber, 2003: Raindrop Size Distribution in Different Climatic Regimes from Disdrometer and Dual-Polarized Radar Analysis. J. Atmos. Sci., 60, 354-365, https://doi.org/10.1175/1520-0469(2003)060<0354:RSDIDC>2.0.CO;2

Tokay, A., and P. G. Bashor, 2010: An Experimental Study of Small-Scale Variability of Raindrop Size Distribution. J. Appl. Meteor. Climatol., 49, 2348-2365, https://doi.org/10.1175/2010JAMC2269.1

static formula(D, Nw, D50, mu)[source][source]#

Calculates the NormalizedGamma PSD values.

static from_parameters(parameters)[source][source]#

Initialize NormalizedGammaPSD from a dictionary or xr.Dataset.

Args:

parameters (dict or xr.Dataset): Parameters to initialize the class.

Returns:

NormalizedGammaPSD

Return type:

An instance of NormalizedGammaPSD initialized with the parameters.

property name[source]#

Return the PSD name.

parameters_summary()[source][source]#

Return a string with the parameter summary.

static required_parameters()[source][source]#

Return the required parameters of the PSD.

class disdrodb.psd.models.PSD[source][source]#

Bases: object

Dummy.

class disdrodb.psd.models.XarrayPSD[source][source]#

Bases: PSD

PSD class template allowing vectorized computations with xarray.

We currently inherit from pytmatrix PSD to allow scattering simulations: –> ltelab/pytmatrix-lte

has_scalar_parameters()[source][source]#

Check if the PSD object contains only a single set of parameters.

has_xarray_parameters()[source][source]#

Check if the PSD object contains at least one xarray parameter.

isel(**kwargs)[source][source]#

Subset the parameters by index using xarray.isel.

If the PSD has xarray parameters, returns a new PSD with subset parameters. Otherwise raises an error.

sel(**kwargs)[source][source]#

Subset the parameters by label using xarray.sel.

If the PSD has xarray parameters, returns a new PSD with subset parameters. Otherwise raises an error.

disdrodb.psd.models.available_psd_models()[source][source]#

Return a list of available PSD models.

disdrodb.psd.models.check_diameter_inputs(D)[source][source]#

Check valid diameter input.

disdrodb.psd.models.check_input_parameters(parameters)[source][source]#

Check valid input parameters.

disdrodb.psd.models.check_psd_model(psd_model)[source][source]#

Check validity of a PSD model.

disdrodb.psd.models.create_psd(psd_model, parameters)[source][source]#

Define a PSD from a dictionary or xr.Dataset of parameters.

disdrodb.psd.models.define_interpolator(bin_edges, bin_values, interp_method)[source][source]#

Returns an interpolation function that takes one argument D.

Parameters:
  • (str) (interp_method) –

  • (array-like) (bin_values) –

  • (array-like)

Returns:

A function f(D) that returns the interpolated values.

Return type:

callable

disdrodb.psd.models.get_exponential_moment(N0, Lambda, moment)[source][source]#

Compute exponential distribution moments.

disdrodb.psd.models.get_gamma_moment_v1(N0, mu, Lambda, moment)[source][source]#

Compute gamma distribution moments.

References

Kozu, T., and K. Nakamura, 1991: Rainfall Parameter Estimation from Dual-Radar Measurements Combining Reflectivity Profile and Path-integrated Attenuation. J. Atmos. Oceanic Technol., 8, 259-270, https://doi.org/10.1175/1520-0426(1991)008<0259:RPEFDR>2.0.CO;2

disdrodb.psd.models.get_gamma_moment_v2(Nt, mu, Lambda, moment)[source][source]#

Compute gamma distribution moments.

References

Kozu, T., and K. Nakamura, 1991: Rainfall Parameter Estimation from Dual-Radar Measurements Combining Reflectivity Profile and Path-integrated Attenuation. J. Atmos. Oceanic Technol., 8, 259-270, https://doi.org/10.1175/1520-0426(1991)008<0259:RPEFDR>2.0.CO;2

disdrodb.psd.models.get_lognormal_moment(Nt, sigma, mu, moment)[source][source]#

Compute lognormal distribution moments.

References

Kozu, T., and K. Nakamura, 1991: Rainfall Parameter Estimation from Dual-Radar Measurements Combining Reflectivity Profile and Path-integrated Attenuation. J. Atmos. Oceanic Technol., 8, 259-270, https://doi.org/10.1175/1520-0426(1991)008<0259:RPEFDR>2.0.CO;2

disdrodb.psd.models.get_psd_model(psd_model)[source][source]#

Retrieve the PSD Class.

disdrodb.psd.models.get_psd_model_formula(psd_model)[source][source]#

Retrieve the PSD formula.

disdrodb.psd.models.get_required_parameters(psd_model)[source][source]#

Retrieve the list of parameters required by a PSD model.

disdrodb.psd.models.is_scalar(value)[source][source]#

Determines if the input value is a scalar.

Module contents#

Implement PSD model and fitting routines.

class disdrodb.psd.ExponentialPSD(N0=1.0, Lambda=1.0)[source][source]#

Bases: XarrayPSD

Exponential particle size distribution (PSD).

Callable class to provide an exponential PSD with the given parameters. The attributes can also be given as arguments to the constructor.

The PSD form is: N(D) = N0 * exp(-Lambda*D)

N0#
Type:

the intercept parameter.

Lambda#
Type:

the inverse scale parameter

Args (call):

D: the particle diameter in millimeter.

Returns (call):

The PSD value for the given diameter.

static formula(D, N0, Lambda)[source][source]#

Calculates the Exponential PSD values.

static from_parameters(parameters)[source][source]#

Initialize ExponentialPSD from a dictionary or xr.Dataset.

Args:

parameters (dict or xr.Dataset): Parameters to initialize the class.

Returns:

ExponentialPSD

Return type:

An instance of ExponentialPSD initialized with the parameters.

property name[source]#

Return name of the PSD.

parameters_summary()[source][source]#

Return a string with the parameter summary.

static required_parameters()[source][source]#

Return the required parameters of the PSD.

class disdrodb.psd.GammaPSD(N0=1.0, mu=0.0, Lambda=1.0)[source][source]#

Bases: ExponentialPSD

Gamma particle size distribution (PSD).

Callable class to provide an gamma PSD with the given parameters. The attributes can also be given as arguments to the constructor.

The PSD form is: N(D) = N0 * D**mu * exp(-Lambda*D)

N0#
Type:

the intercept parameter [mm**(-1-mu) m**-3] (scale parameter)

Lambda#
Type:

the inverse scale parameter [mm-1] (slope parameter)

mu#
Type:

the shape parameter [-]

Args (call):

D: the particle diameter in millimeter.

Returns (call):

The PSD value for the given diameter.

References

Ulbrich, C. W., 1985: The Effects of Drop Size Distribution Truncation on Rainfall Integral Parameters and Empirical Relations. J. Appl. Meteor. Climatol., 24, 580-590, https://doi.org/10.1175/1520-0450(1985)024<0580:TEODSD>2.0.CO;2

static formula(D, N0, Lambda, mu)[source][source]#

Calculates the Gamma PSD values.

static from_parameters(parameters)[source][source]#

Initialize GammaPSD from a dictionary or xr.Dataset.

Args:

parameters (dict or xr.Dataset): Parameters to initialize the class.

Returns:

GammaPSD

Return type:

An instance of GammaPSD initialized with the parameters.

property name[source]#

Return name of the PSD.

parameters_summary()[source][source]#

Return a string with the parameter summary.

static required_parameters()[source][source]#

Return the required parameters of the PSD.

class disdrodb.psd.LognormalPSD(Nt=1.0, mu=0.0, sigma=1.0)[source][source]#

Bases: XarrayPSD

Lognormal drop size distribution (DSD).

Callable class to provide a lognormal PSD with the given parameters.

The PSD form is:

N(D) = Nt/(sqrt(2*pi)*sigma*D)) * exp(-(ln(D)-mu)**2 / (2*sigma**2))

# g = sigma # theta = 0

Nt#
g#
theta#
mu#
sigma#
static formula(D, Nt, mu, sigma)[source][source]#

Calculates the Lognormal PSD values.

static from_parameters(parameters)[source][source]#

Initialize LognormalPSD from a dictionary or xr.Dataset.

Args:

parameters (dict or xr.Dataset): Parameters to initialize the class.

Returns:

LognormalPSD

Return type:

An instance of LognormalPSD initialized with the parameters.

property name[source]#

Return name of the PSD.

parameters_summary()[source][source]#

Return a string with the parameter summary.

static required_parameters()[source][source]#

Return the required parameters of the PSD.

class disdrodb.psd.NormalizedGammaPSD(Nw=1.0, D50=1.0, mu=0.0)[source][source]#

Bases: XarrayPSD

Normalized gamma particle size distribution (PSD).

Callable class to provide a normalized gamma PSD with the given parameters. The attributes can also be given as arguments to the constructor.

The PSD form is:

N(D) = Nw * f(mu) * (D/D50)**mu * exp(-(mu+3.67)*D/D50) f(mu) = 6/(3.67**4) * (mu+3.67)**(mu+4)/Gamma(mu+4)

An alternative formulation as function of Dm: # Testud (2001), Bringi (2001), Williams et al., 2014, Dolan 2018 # –> Normalized with respect to liquid water content (mass) –> Nx=D3/Dm4 N(D) = Nw * f1(mu) * (D/Dm)**mu * exp(-(mu+4)*D/Dm) # Nw * f(D; Dm, mu) f1(mu) = 6/(4**4) * (mu+4)**(mu+4)/Gamma(mu+4)

Note: gamma(4) = 6

An alternative formulation as function of Dm: # Tokay et al., 2010 # Illingworth et al., 2002 (see eq10 to derive full formulation!) # –> Normalized with respect to total concentration –> Nx = #/Dm N(D) = Nt* * f2(mu) * (D/Dm)**mu * exp(-(mu+4)*D/Dm) f2(mu) = (mu+4)**(mu+1)/Gamma(mu+1)

D50#
Type:

the median volume diameter.

Nw#
Type:

the intercept parameter.

mu#
Type:

the shape parameter.

Args (call):

D: the particle diameter in millimeter.

Returns (call):

The PSD value for the given diameter.

References

Willis, P. T., 1984: Functional Fits to Some Observed Drop Size Distributions and Parameterization of Rain. J. Atmos. Sci., 41, 1648-1661, https://doi.org/10.1175/1520-0469(1984)041<1648:FFTSOD>2.0.CO;2

Testud, J., S. Oury, R. A. Black, P. Amayenc, and X. Dou, 2001: The Concept of “Normalized” Distribution to Describe Raindrop Spectra: A Tool for Cloud Physics and Cloud Remote Sensing. J. Appl. Meteor. Climatol., 40, 1118-1140, https://doi.org/10.1175/1520-0450(2001)040<1118:TCONDT>2.0.CO;2

Illingworth, A. J., and T. M. Blackman, 2002: The Need to Represent Raindrop Size Spectra as Normalized Gamma Distributions for the Interpretation of Polarization Radar Observations. J. Appl. Meteor. Climatol., 41, 286-297, https://doi.org/10.1175/1520-0450(2002)041<0286:TNTRRS>2.0.CO;2

Bringi, V. N., G. Huang, V. Chandrasekar, and E. Gorgucci, 2002: A Methodology for Estimating the Parameters of a Gamma Raindrop Size Distribution Model from Polarimetric Radar Data: Application to a Squall-Line Event from the TRMM/Brazil Campaign. J. Atmos. Oceanic Technol., 19, 633-645, https://doi.org/10.1175/1520-0426(2002)019<0633:AMFETP>2.0.CO;2

Bringi, V. N., V. Chandrasekar, J. Hubbert, E. Gorgucci, W. L. Randeu, and M. Schoenhuber, 2003: Raindrop Size Distribution in Different Climatic Regimes from Disdrometer and Dual-Polarized Radar Analysis. J. Atmos. Sci., 60, 354-365, https://doi.org/10.1175/1520-0469(2003)060<0354:RSDIDC>2.0.CO;2

Tokay, A., and P. G. Bashor, 2010: An Experimental Study of Small-Scale Variability of Raindrop Size Distribution. J. Appl. Meteor. Climatol., 49, 2348-2365, https://doi.org/10.1175/2010JAMC2269.1

static formula(D, Nw, D50, mu)[source][source]#

Calculates the NormalizedGamma PSD values.

static from_parameters(parameters)[source][source]#

Initialize NormalizedGammaPSD from a dictionary or xr.Dataset.

Args:

parameters (dict or xr.Dataset): Parameters to initialize the class.

Returns:

NormalizedGammaPSD

Return type:

An instance of NormalizedGammaPSD initialized with the parameters.

property name[source]#

Return the PSD name.

parameters_summary()[source][source]#

Return a string with the parameter summary.

static required_parameters()[source][source]#

Return the required parameters of the PSD.

disdrodb.psd.available_psd_models()[source][source]#

Return a list of available PSD models.

disdrodb.psd.create_psd(psd_model, parameters)[source][source]#

Define a PSD from a dictionary or xr.Dataset of parameters.

disdrodb.psd.estimate_model_parameters(ds, psd_model, optimization, optimization_kwargs=None)[source][source]#

Routine to estimate PSD model parameters.