binmod1d packageο
Submodulesο
binmod1d.analytical_solutions moduleο
These are analytical solutions to the SCE, SBE, and SCE-SBE steady-state solution following Scott (1964) and Feingold et al. (1988). For more information, see:
Scott, W. T.: Analytical studies of cloud droplet coalesence I, J. Atmos. Sci., 25, 54β65, https://doi.org/10.1175/1520- 0469(1968)025<0054:ASOCDC>2.0.CO;2, 1968.
Feingold, G., Tzivion, S., and Levin, Z.: Evolution of raindrop spectra. Part I: Solution to the Stochastic Collection/Breakup equation using the method of moments, J. Atmos. Sci., 45, 3387β3399, https://doi.org/10.1175/1520-0469(1988)045<3387:EORSPI>2.0.CO;2, 1988.
- binmod1d.analytical_solutions.Feingold_dists(xbins, t, nu, E, B, gam, kernel_type='SBE')ο
Calculates Feingoldβs analytical number distribution function solution to the SBE/SCE-SBE steady-state solution for Constant kernel.
- Parameters:
xbins (TYPE) β DESCRIPTION.
t (TYPE) β DESCRIPTION.
nu (TYPE) β DESCRIPTION.
E (TYPE) β DESCRIPTION.
B (TYPE) β DESCRIPTION.
gam (TYPE) β DESCRIPTION.
kernel_type (TYPE, optional) β DESCRIPTION. The default is βSBEβ.
- Returns:
npbins β DESCRIPTION.
- Return type:
TYPE
- binmod1d.analytical_solutions.Feingold_moments(r, t, nu, B, gam, kernel_type='SBE')ο
Calculate moments for Feingoldβs analytical solutions to the SBE/SCE-SBE Steady state solution for Constant kernel.
- Parameters:
r (TYPE) β DESCRIPTION.
t (TYPE) β DESCRIPTION.
nu (TYPE) β DESCRIPTION.
B (TYPE) β DESCRIPTION.
gam (TYPE) β DESCRIPTION.
kernel_type (TYPE, optional) β DESCRIPTION. The default is βSBEβ.
- Returns:
M_rt β DESCRIPTION.
- Return type:
TYPE
- binmod1d.analytical_solutions.Scott_dists(xbins, Eagg, nu, t, kernel_type='Golovin', max_k=100)ο
Calculates Scottβs analytical number distribution function solution to the SCE for Golovin, Product, and Constant kernels.
- Parameters:
xbins (TYPE) β DESCRIPTION.
Eagg (TYPE) β DESCRIPTION.
nu (TYPE) β DESCRIPTION.
t (TYPE) β DESCRIPTION.
kernel_type (TYPE, optional) β DESCRIPTION. The default is βGolovinβ.
max_k (TYPE, optional) β DESCRIPTION. The default is 100.
- Returns:
npbins β DESCRIPTION.
- Return type:
TYPE
- binmod1d.analytical_solutions.Scott_moments(r, t, nu, E, B, kernel_type='Golovin')ο
Calculate moments for Scottβs analytical solutions to the SCE for Golovin, Product, and Constant kernels.
- Parameters:
r (TYPE) β DESCRIPTION.
t (TYPE) β DESCRIPTION.
nu (TYPE) β DESCRIPTION.
E (TYPE) β DESCRIPTION.
B (TYPE) β DESCRIPTION.
kernel_type (TYPE, optional) β DESCRIPTION. The default is βGolovinβ.
- Returns:
M_rt β DESCRIPTION.
- Return type:
TYPE
binmod1d.bin_integrals moduleο
Created on Wed Sep 24 08:17:50 2025
@author: edwin.dunnavan
- binmod1d.bin_integrals.GAU_int(n, mu, sig2, x1, x2)ο
Integrates x^n * Normal(mu, sigma^2) from x1 to x2. Uses a 3rd-order central moment expansion that is EXACT for integer moments (n=0, 1, 2, 3) and highly accurate for fractional moments.
- binmod1d.bin_integrals.In_int(n, c, x1, x2)ο
- binmod1d.bin_integrals.LGN_int(n, mu, sig2, x1, x2)ο
High-Precision Log-Normal integral. Handles both Left Tail (z < -26) and Right Tail (z > 26) using erfcx scaling. Calculates Integral(x^n * PDF(x) dx) from x1 to x2.
- binmod1d.bin_integrals.Pn(n, x1, x2)ο
- binmod1d.bin_integrals.breakup_1mom_kernel(M_gain, M_loss, dMb_kernel, i_idx, j_idx, h_idx, k_limit_idx, indb, Ebr)ο
2-moment breakup calculations using numba
- binmod1d.bin_integrals.breakup_kernel(M_gain, N_gain, M_loss, dMb_kernel, dNb_kernel, Ebr, p_idx, i_idx, j_idx, h_idx, k_limit_idx, indb)ο
2-moment breakup calculations using numba
- binmod1d.bin_integrals.calculate_rates(Hlen, bins, region_inds, x_bottom_edge, x_top_edge, y_left_edge, y_right_edge, kr, ir, jr, x11, x21, ak1, ck1, x12, x22, ak2, ck2, PK, kmin, kmid, dMb_gain_frac, dNb_gain_frac, w, L, breakup=False)ο
Description: Calcualates Wang et al. (2007) integrals using numpy functions.
# kr = Height index (batch,) # ir = collectee index (batch,) # jr = collector index (batch,)
Vectorized Integration Regions: cond_1 : All rectangular bin-pair interactions used cond_2 : k bin: Lower triangle region. Just clips BR corner.
Triangle = ((xi1,xj1),(xi1,y_left_edge),(xi2,xj1))
- cond_3k bin: Lower triangle region. Just clips UL corner.
Triangle = ((xi1,xj1),(xi1,xj2),(x_bottom_edge,xj1))
- cond_2bk+1 bins: Upper triangle region. Just clips BR corner.
Triangle = ((xi1,xj1),(x_top_edge,xj2),(xi2,xj2))
- cond_3bk+1 bin: Upper triangle region. Just clips UL corner.
Triangle = ((xi1,xj2),(xi2,xj2),(xi2,y_right_edge)
cond_4 : Full Rectangular source region based on self collection: ii == jj β> ii+sbin or jj+sbin cond_5 : k bin: Top/Bottom clip: Rectangle on left, triangle on right
Rectangle = ((xi1,xj1),(xi1,xj2),(x_top_edge,xj2),(x_top_edge,xj1)) Triangle = ((x_top_edge,xj1),(x_top_edge,xj2),(x_bottom_edge,xj1))
- cond_6k bin: Left/Right clip: Rectangle on bottom, triangle on top
Rectangle = ((xi1,xj1),(xi1,y_right_edge),(xi2,y_right_edge),(xi2,xj1)) Triangle = ((xi1,y_right_edge),(xi1,y_left_edge),(xi2,y_right_edge))
- cond_7k+1 bin: Triangle in top right corner
Triangle = ((x_top_edge,xj2),(xi2,xj2),(xi2,y_right_edge))
- cond_8k bin: Triangle in lower left corner
Triangle = ((xi1,xj1),(xi1,y_left_edge),(x_bottom_edge,xj1))
cond_9: k bin: Rectangle collection within k bin. All Mass/Number goes into kbin cond_10: k+1 bin: Rectangle collection within k+1 bin. All Mass/Number goes into kbin
- binmod1d.bin_integrals.calculate_regions_batch(Hlen, bins, kr, ir, jr, x11, x21, ak1, ck1, x12, x22, ak2, ck2, PK, region_inds, x_bottom_edge, x_top_edge, y_left_edge, y_right_edge, w, L)ο
Vectorized Integration Regions: cond_1 : All rectangular bin-pair interactions used cond_2 : k bin: Lower triangle region. Just clips BR corner.
Triangle = ((xi1,xj1),(xi1,y_left_edge),(xi2,xj1))
- cond_3k bin: Lower triangle region. Just clips UL corner.
Triangle = ((xi1,xj1),(xi1,xj2),(x_bottom_edge,xj1))
- cond_2bk+1 bins: Upper triangle region. Just clips BR corner.
Triangle = ((xi1,xj1),(x_top_edge,xj2),(xi2,xj2))
- cond_3bk+1 bin: Upper triangle region. Just clips UL corner.
Triangle = ((xi1,xj2),(xi2,xj2),(xi2,y_right_edge)
cond_4 : Full Rectangular source region based on self collection: ii == jj β> ii+sbin or jj+sbin cond_5 : k bin: Top/Bottom clip: Rectangle on left, triangle on right
Rectangle = ((xi1,xj1),(xi1,xj2),(x_top_edge,xj2),(x_top_edge,xj1)) Triangle = ((x_top_edge,xj1),(x_top_edge,xj2),(x_bottom_edge,xj1))
- cond_6k bin: Left/Right clip: Rectangle on bottom, triangle on top
Rectangle = ((xi1,xj1),(xi1,y_right_edge),(xi2,y_right_edge),(xi2,xj1)) Triangle = ((xi1,y_right_edge),(xi1,y_left_edge),(xi2,y_right_edge))
- cond_7k+1 bin: Triangle in top right corner
Triangle = ((x_top_edge,xj2),(xi2,xj2),(xi2,y_right_edge))
- cond_8k bin: Triangle in lower left corner
Triangle = ((xi1,xj1),(xi1,y_left_edge),(x_bottom_edge,xj1))
cond_9: k bin: Rectangle collection within k bin. All Mass/Number goes into kbin cond_10: k+1 bin: Rectangle collection within k+1 bin. All Mass/Number goes into kbin
- binmod1d.bin_integrals.combined_coeffs_array(f, ax, cx, ay, cy)ο
Returns C00,C10,C01,C20,C11,C02,C21,C12 such that: P(x,y) = sum Cij * x^i y^j
- binmod1d.bin_integrals.combined_coeffs_tensor(f, params)ο
Expands: (a + bx + cy + dxy) * (aki1*x + cki1) * (aki2*y + cki2) f: (4, pnum, 1, bins, bins) | aki, cki: (pnum, H, bins, 1) or (pnum, H, 1, bins)
- binmod1d.bin_integrals.gam_int(n, mu, Dm, x1, x2)ο
- binmod1d.bin_integrals.init_rk(rk_order)ο
- Parameters:
rk_order (int) β Runge-Kutta order.
- Returns:
RK β Dictionary of Runge-Kutta Butcher table parameters.
- Return type:
dict
- binmod1d.bin_integrals.kernel_1mom(M_loss, M_gain, Eagg, Ebr, rate, h_idx, s1_idx, s2_idx, i_idx, j_idx, p_idx, dMi, dMj, k0_map, k1_map, dMg, dMb_kernel, indc, indb)ο
1 moment Numba kernel calculations
- binmod1d.bin_integrals.loss_kernel_numba(dN_out, dMi_out, dMj_out, C, x1, x2, y1, y2)ο
2-moment loss term numba calculation
- binmod1d.bin_integrals.moments(r, aki, cki, x1, x2)ο
- binmod1d.bin_integrals.rect_gain_integrals(C, x1, x2, y1, y2)ο
Tensor-based rectangular integration for N rectangles. Calculates Int(P), Int(xP), Int(yP), and Int((x+y)P).
- binmod1d.bin_integrals.rect_integrals(C00, C10, C01, C20, C11, C02, C21, C12, C22, x1, x2, y1, y2)ο
Tensor-based rectangular integration for N rectangles. Calculates Int(P), Int(xP), Int(yP), and Int((x+y)P).
- binmod1d.bin_integrals.setup_regions(bins, kr, ir, jr, x11, x21, x12, x22, xk_min)ο
- binmod1d.bin_integrals.source_integrals(C, x1, x2, y1, y2)ο
Tensor-based rectangular integration for N rectangles. Calculates Int(P), Int(xP), Int(yP), and Int((x+y)P).
- binmod1d.bin_integrals.transfer_1mom_bins(Hlen, bins, kr, ir, jr, n12, dMi_loss, dMj_loss, dM_loss, dM_gain, kmin, kmid, dMb_gain_frac, breakup)ο
- binmod1d.bin_integrals.transfer_bins(Hlen, bins, kr, ir, jr, kmin, kmid, dMi_loss, dMj_loss, dM_loss, dM_gain, dNi_loss, dN_gain, dMb_gain_frac, dNb_gain_frac, breakup=False)ο
Performs bin transfer of mass and number
- binmod1d.bin_integrals.tri_gain_integrals(C, xt1, yt1, xt2, yt2, xt3, yt3, w, L)ο
Direct contraction of a (3, 3, N) coefficient tensor. i: x-power (0,1,2), j: y-power (0,1,2), n: triangle index
- binmod1d.bin_integrals.tri_kernel_numba(dN_out, dM_out, C, x1, y1, x2, y2, x3, y3, w, L)ο
2-moment triangular gain region calculations using numba
- binmod1d.bin_integrals.vectorized_1mom(cki, params, dMi, dMj, dMg, kmin, kmid, dMb_kernel, indc, indb, dnum, Hlen, bins)ο
Numba-optimized 1-moment gain and loss bin integral calculations
- binmod1d.bin_integrals.vectorized_2mom(params, w, L, dMb_kernel, dNb_kernel, indc, indb, dnum, Hlen, bins)ο
Numba-optimized 2-moment gain and loss bin integral calculations
binmod1d.collection_kernels moduleο
Created on Wed Sep 24 08:16:15 2025
@author: edwin.dunnavan
- binmod1d.collection_kernels.CKE(di1d, dj1d, vi1d, vj1d)ο
Collisional Kinetic Energy as defined by Low and List and others.
- Parameters:
di1d (array (bins,)) β i bin midpoint diameter.
dj1d (array (,bins)) β j bin midpoint diameter.
vi1d (array (bins,)) β i bin midpoint fall speed.
vj1d (array (,bins)) β i bin midpoint diameter.
- Returns:
CKE values broadcasted for each i,j bin combination.
- Return type:
array (bins,bins)
- binmod1d.collection_kernels.Constant_kernel(xi, xj)ο
Constant kernel
- Parameters:
xi (array (bins,)) β Bin mass edges for i distribution
xj (array (,bins)) β Bin mass edges for j distribution
- Returns:
Constant kernel evaluated at bin edge combination.
- Return type:
array (bins,bins)
- binmod1d.collection_kernels.Golovin_kernel(xi, xj)ο
Golovin (summation) kernel
- Parameters:
xi (array (bins,)) β Bin mass edges for i distribution
xj (array (,bins)) β Bin mass edges for j distribution
- Returns:
Golovin (summation) kernel evaluated at bin edge combination.
- Return type:
array (bins,bins)
- binmod1d.collection_kernels.Prod_kernel(xi, xj)ο
Product kernel
- Parameters:
xi (array (bins,)) β Bin mass edges for i distribution
xj (array (,bins)) β Bin mass edges for j distribution
- Returns:
Product kernel evaluated at bin edge combination.
- Return type:
array (bins,bins)
- binmod1d.collection_kernels.Straub_params(di1d, dj1d, vi1d, vj1d)ο
Straub et al. (2010) fragment distribution parameters
- Parameters:
di1d (array (bins,)) β i bin midpoint diameter.
dj1d (array (,bins)) β j bin midpoint diameter.
vi1d (array (bins,)) β i bin midpoint fall speed.
vj1d (array (,bins)) β i bin midpoint diameter.
- Returns:
Straub_dict β Dictionary of Straubβs parameters for lognormal, two Gaussians, and dirac distributions.
- Return type:
dict
- binmod1d.collection_kernels.Weber_number(di1d, dj1d, vi1d, vj1d)ο
Weber number as defined by Low and List and others.
- Parameters:
di1d (array (bins,)) β i bin midpoint diameter.
dj1d (array (,bins)) β j bin midpoint diameter.
vi1d (array (bins,)) β i bin midpoint fall speed.
vj1d (array (,bins)) β i bin midpoint diameter.
- Returns:
We values broadcasted for each i,j bin combination.
- Return type:
array (bins,bins)
- binmod1d.collection_kernels.hall_kernel(di, dj, vi, vj, Ai, Aj)ο
Hall (1980) collection kernel.
- Parameters:
di (array (bins,)) β Bin diameter edges for i distribution
dj (array (,bins)) β Bin diameter edges for j distribution
vti (array (bins,)) β Bin fall speed edges for i distribution
vtj (array (,bins)) β Bin fall speed edges for j distribution
Ai (array (bins,)) β Bin collection surface area for i distribution
Aj (array (,bins)) β Bin collection surface area for j distribution
- Returns:
Kxy β Collection kernel evaluated at bin edges
- Return type:
array (bins,bins)
- binmod1d.collection_kernels.hydro_kernel(vtx, vty, Ax, Ay)ο
Hydrodynamic kernel
- Parameters:
vtx (array (bins,)) β Bin fall speed edges for i distribution
vty (array (,bins)) β Bin fall speed edges for j distribution
Ax (array (bins,)) β Bin collection surface area for i distribution
Ay (array (,bins)) β Bin collection surface area for j distribution
- Returns:
Kxy β Hydrodynamic collection kernel evaluated at bin edges
- Return type:
array (bins,bins)
- binmod1d.collection_kernels.long_kernel(di, dj, vi, vj, Ai, Aj)ο
Long (1974) kernel as formulated by Simmel et al. (2000)
- Parameters:
di (array (bins,)) β Bin diameter edges for i distribution
dj (array (,bins)) β Bin diameter edges for j distribution
vti (array (bins,)) β Bin fall speed edges for i distribution
vtj (array (,bins)) β Bin fall speed edges for j distribution
Ai (array (bins,)) β Bin collection surface area for i distribution
Aj (array (,bins)) β Bin collection surface area for j distribution
- Returns:
Kxy β Collection kernel evaluated at bin edges
- Return type:
array (bins,bins)
- binmod1d.collection_kernels.straub_efficiency(di, dj, vi, vj, Ai, Aj)ο
Calculates Coalescence Efficiency (E_coal) based on Straub et al. (2010). Equation: Ec = exp(-1.15 * We)
Note: The parameterization is based on CGS units. We must ensure the Weber number calculation uses consistent units.
ALSO, BinMod1D currently does not handle non-constant Es parameterizations! Future versions will incorporate this.
- Parameters:
di (array (bins,)) β Bin diameter edges for i distribution
dj (array (,bins)) β Bin diameter edges for j distribution
vti (array (bins,)) β Bin fall speed edges for i distribution
vtj (array (,bins)) β Bin fall speed edges for j distribution
Ai (array (bins,)) β Bin collection surface area for i distribution
Aj (array (,bins)) β Bin collection surface area for j distribution
- Returns:
Kxy β Collection kernel evaluated at bin edges
- Return type:
array (bins,bins)
binmod1d.distribution moduleο
Created on Wed Sep 24 08:35:18 2025
@author: edwin.dunnavan
- binmod1d.distribution.angular_moments(sigma)ο
Calculates angular moments from Ryzhkov et al. (2011)
- Parameters:
sigma (TYPE) β DESCRIPTION.
- Returns:
angs β DESCRIPTION.
- Return type:
TYPE
- binmod1d.distribution.dielectric_ice(lamda, TK)ο
- binmod1d.distribution.dielectric_water(t, eps_0, t0=273.15, wave=110.0)ο
Calculate dielectric constant for fresh water at temperature T based on Ray (1972).
- Input:
Temperature [K]
- Output:
Dielectric constant
- class binmod1d.distribution.dist(sbin=4, bins=80, D1=0.01, dist_var='mass', kernel='Hydro', habit_dict=None, ptype='rain', Tc=10.0, x0=None, mom_num=2)ο
Bases:
objectA class for initializing a spectral bin distribution
- bin_analytical_dist(func_nD, var='size')ο
Populates bins using user-defined analytical functions. func_N: A lambda returning number concentration (dN/dD or dN/dm) func_M: (Optional) A lambda returning mass concentration var: βdiameterβ or βmassβ indicating what the lambda expects.
- bin_direct_dist(edges, Nbins, Mbins=None, var='size')ο
Conservatively regrids discrete user arrays onto the modelβs native grid.
Parameters:ο
- edgesarray
Array of length (K+1) defining the userβs bin boundaries.
- Nbinsarray
Array of length K defining the absolute total number in each user bin.
- Mbinsarray (Optional)
Array of length K defining the absolute total mass in each user bin.
- varstr
βdiameterβ or βmassβ, indicating what physical property edges represents.
- bin_empirical_counts(user_edges, user_N, user_M=None)ο
Conservatively regrids external binned data to the modelβs native grid. user_edges: Array of length (N+1) defining the userβs bin boundaries. user_N: Array of length N defining total number in each bin.
- bin_empirical_dist(user_edges, user_nD)ο
Conservatively regrids external PSD data (density n(D)) to the modelβs grid.
Parameters:ο
- user_edgesarray
Array of length (K+1) defining the userβs bin boundaries (diameter). Must be in the same units as the modelβs internal self.d1 / self.d2
- user_nDarray
Array of length K defining the number density n(D). Assumed to be piecewise-constant across the bin.
- bin_gamma_dist(Nt0=1.0, Mt0=1.0, mbar=None, mu0=3, Dm0=2, normalize=False)ο
Description: Set up bins and integrals if using only mass moment
- diagnose()ο
Function for diagnosing uniform distribution function following Wang et al. (2008)
- diagnose_1mom()ο
Function for diagnosing uniform distribution function
- init_dist(sbin, bins, D1, kernel='Hydro', habit_dict=None, ptype='rain', Tc=10.0, dist_var='mass', x0=None, mom_num=2)ο
- Parameters:
sbin (int) β Spectral bin mass grid resolution. The default is 4.
bins (int) β Number of bins used for each distribution. The default is 80
D1 (float, optional) β Left-hand edge of first bin in mm if dist_var=βsizeβ. The default is 0.01.
kernel (str, optional) β
- Name of collection kernel used. Option must be either:
kernel=βGolovinβ kernel=βProductβ kernel=βConstantβ kernel=βHydroβ (Hydrodynamic kernel) kernel=βLongβ (see Long (1974)) kernel=βHallβ (see Hall (1980)) The default is βHydroβ.
habit_dict (dict, optional) β Dictionary with habit parameters. If None, then dictionary will default to βrainβ (see habits.py). The default is None.
ptype (str, optional) β
Type of precipitation. Either, ptype = βrainβ
or
ptype = βsnowβ The default is βrainβ.
Tc (float, optional) β Assumed mean temperature of layer in degrees Celsius. Currently only used for dielectric constant calculation but eventually will be used for collection kernels and potentially other microphysical processes. The default is 10..
dist_var (str, optional) β The independent variable chosen for specifying initial distribution function. dist_var = βsizeβ (if particle size distribution n(D)) dist_var = βmassβ (if particle mass distribution n(m)) The default is βmassβ.
x0 (float, optional) β Left-hand edge of first bin in g if dist_var=βmassβ. If None, then defaults to 0.01.
mom_num (int, optional) β Number of bin moments used to specify subgrid linear distribution (either mom_num=2 or mom_num=1). The default is 2.
- moments(r)ο
Integrates to find arbitrary moments of subgrid distribution Mn = Int x^n *[n(x)=ak*x+ck]*dx
- plot(log_switch=True, x_axis='mass', ax=None)ο
Plots number and mass distributions for distribution object.
- Parameters:
log_switch (Bool, optional) β Whether distribution scaling is log or linear. The default is True.
x_axis (string, optional) β Whether x axis is βmassβ or βsizeβ. The default is βmassβ.
ax (matplotlib.pyplot axes() object, optional) β Plots number/mass distributions in existing pyplot axes. The default is None.
- Returns:
fig (matplotlib figure object)
ax (matplotlib axes object)
- radar_bins()ο
Calculate radar variables for each bin of distribution.
- binmod1d.distribution.extended_brandes(d)ο
Brandes et al. (2002): https://doi.org/10.1175/1520-0450(2002)041<0674:EIREWA>2.0.CO;2 their equation 2
Modified Brandes AR fit function: - Unity (1.0) at d=0 - Matches original poly between ~0.3743 and 10 - Levels off to 0.4 for d > 10
- binmod1d.distribution.rain_terminal_velocity(d_mm)ο
Calculates terminal velocity (m/s) from diameter (mm) using a Weibull-like fit to the Gunn & Kinzer (1949) measurements according to Equation 5 from Best (1950).
- binmod1d.distribution.spheroid_factors(ar)ο
Calculates spheroid factors for Rayleigh scattering calculations.
- Parameters:
ar (TYPE) β DESCRIPTION.
- Returns:
La (TYPE) β DESCRIPTION.
Lc (TYPE) β DESCRIPTION.
- binmod1d.distribution.update_1mom(Mbins, dxi)ο
Updates 1 moment distribution uniform subgrid parameters.
- Parameters:
Mbins (TYPE) β DESCRIPTION.
dxi (TYPE) β DESCRIPTION.
- Returns:
DESCRIPTION.
- Return type:
TYPE
- binmod1d.distribution.update_2mom(Mbins, Nbins, rhobins, bound_low, bound_high, dx, xi1, xi2)ο
Google Gemini enhanced version of 2 moment subgrid linear distribution diagnosis from Mbins and Nbins. Needed to bug fix. (see original commented).
- Parameters:
Mbins (TYPE) β DESCRIPTION.
Nbins (TYPE) β DESCRIPTION.
rhobins (TYPE) β DESCRIPTION.
bound_low (TYPE) β DESCRIPTION.
bound_high (TYPE) β DESCRIPTION.
dx (TYPE) β DESCRIPTION.
xi1 (TYPE) β DESCRIPTION.
xi2 (TYPE) β DESCRIPTION.
- Returns:
aki (TYPE) β DESCRIPTION.
cki (TYPE) β DESCRIPTION.
x1i (TYPE) β DESCRIPTION.
x2i (TYPE) β DESCRIPTION.
binmod1d.habits moduleο
Created on Tue Oct 7 09:06:50 2025
@author: edwin.dunnavan
- binmod1d.habits.fragments(dist='exp', **kwargs)ο
This function can be used to generate example fragment distribution functions that spectral_1d() can use based on the desired dist input parameter string. The format of each output dictionary has the same structure. For example, the lognormal fragment distribution has the following default dictionary:
- {βdistβ: βLGNβ,
βvarβ: βsizeβ, βDf_medβ: 0.25, βDf_modeβ: 0.2, βcdf_boundsβ: (0.5, 0.95), βd_startβ: np.float64(0.25), βd_endβ: np.float64(0.5437328654539426), βfuncβ: <function binmod1d.habits.fragments.<locals>.<lambda>(n, c, pi, pj)>}
Here, βdistβ is the name of the distribution, βvarβ is whether the fragment distribution is defined in terms of mass (βmassβ) or size (βsizeβ), βDf_medβ and βDf_modeβ are the lognormal distribution parameters, cdf_bounds are the requested percentile bounds of the lognormal distribution where the distribution will become active. The d_start and d_end parameters correspond to the 50% and 95% percentiles where d<d_start will not be active d_start<d<d_end will ramp from 0 to Eb and d>d_end will have Eb. The lambda function βfuncβ is the output conditional fragment distribution BIN-WISE MOMENT FUNCTION:
(mass) int_xi1^xi2 m^n P(m|x,y) dm
or
(size) int_d1^d2 d_m^n P(d_m|d_x,d_y) dd_m
that Interaction() will use. Users who want to create their own fragment distributions simply need to structure their lambda function as follows:
where c corresponds to the fragment distribution (i.e., dists[indb]) whereas pi and pj correspond to the i and j distributions (i.e., dists[d1_indices] and dists[d2_indices]).
Note, for marginal distributions which use a static (yet truncated) distribution (as with the examples shown here), pi and pj do not need to be used in the lambda function but still need to be inputs. For conditional fragment distributions of the form p(m|x,y), users can use the pi and pj object inputs to structure the conditional nature of the multivariate distribution function. For example, if the conditional distribution depends upon the i and j bin midpoint fall speeds, then the lambda function structure might be something like:
func = lambda n, c, pi, pj: dist_int(n,c.d1,c.d2,pi.vt,pj.vt).
- Parameters:
dist (str, optional) β Name of default distribution. The default is βexpβ.
**kwargs (dict) β Extra parameters.
- Returns:
fragments β Dictionary of fragment parameters and lambda function.
- Return type:
dict
- binmod1d.habits.habits()ο
Sample habit dictionary parameters that can be used in βhabit_paramsβ input for spectral_1d class.
- Returns:
habits β Dictionary of habit parameters.
- Return type:
Dict
- binmod1d.habits.straub_wrapper(n, c, pi, pj, cdf_bounds=None, state=None)ο
Evaluates the full 4-part Straub distribution efficiently in 4D.
binmod1d.interaction moduleο
Created on Thu Oct 2 11:31:38 2025
@author: edwin.dunnavan
- class binmod1d.interaction.BroadcastNode4D(dist_list, indices, target_axes)ο
Bases:
objectWraps an array of distributions. Intercepts property requests, stacks them across the pnum axis, and broadcasts them into 4D space: (pnum, fragment_bins, i_bins, j_bins).
- class binmod1d.interaction.Interaction(dists, Hlen, cc_dest, br_dest, Eagg, Ecb, Ebr, frag_dict=None, kernel='Golovin', mom_num=2, gpu=False)ο
Bases:
objectInteraction class initializes Interaction objects that contain arrays in the form (Ndists x M x N) which specifies the interactions among all Ndists distributions.
- calc_smootherstep(d_array, d_start, d_end)ο
Calculates the quintic smootherstep function over an array. Mathematically guarantees 1st and 2nd derivatives are zero at the boundaries.
- Parameters:
d_array (np.ndarray) β Array of diameters to evaluate.
d_start (float) β Diameter where efficiency starts to rise above 0.
d_end (float) β Diameter where efficiency reaches 1.0.
- Returns:
Scale factors from 0.0 to 1.0 matching the shape of d_array.
- Return type:
np.ndarray
- create_kernels(dists)ο
Creates collection kernel bilinear coefficients for requested kernel type.
- Parameters:
dists (TYPE) β DESCRIPTION.
- Returns:
DESCRIPTION.
- Return type:
TYPE
- get_dynamic_params()ο
Synchronizes moving grid edges and evolving distributions into a single parameter dictionary.
- get_dynamic_params_1mom()ο
Flattens everything into 1D vectors. This removes all 3D/4D indexing from the Numba kernel.
- interact_1mom(dt)ο
Interaction kernel calculation for 1 moment scheme.
- interact_2mom(dt)ο
Interaction kernel calculation for 2 moment scheme.
- setup_1mom()ο
Sets up 1 moment calculations
- setup_fragments()ο
Sets up conditional fragment distribution based on self.kernel.
- update_1mom_subgrid()ο
Updates 1 moment subgrid uniform distribution parameters from Mbins
- update_2mom_subgrid()ο
Updates 2 moment subgrid linear distribution from Mbins and Nbins
binmod1d.plotting_functions moduleο
Created on Mon Oct 13 10:50:41 2025
@author: edwin.dunnavan
- binmod1d.plotting_functions.get_cm_cmaps()ο
Generate colormap lists of NWS colormaps from cmweather python package
- Returns:
NWS_REF_COLORS (List) β NWS Ref colormap list.
THEODORE16_COLORS (List) β THEODORE16 colormap list.
NWS_CC_COLORS (TYPE) β NWS CC colormap list.
RRATE11_COLORS (TYPE) β RRATE11 colormap list.
- binmod1d.plotting_functions.get_cmap_vars(varname)ο
- Parameters:
varname (str) β Variable name.
- Returns:
cmap (matplotlib.color colorbar) β colorbar handle.
levels (array or list) β Array or list of levels for contours.
levels_ticks (array or list) β Array or list of ticks for levels.
clabel (str) β Colorbar label.
labelpad (int) β matplotlib colorbar labelpad parameter.
fontsize (int) β fontsize for colorbar title.
slabel (str) β Shorthand label for colorbar.
binmod1d.radar moduleο
Created on Thu Jan 29 08:23:48 2026
@author: edwin.dunnavan
- binmod1d.radar.angular_moments(sigma)ο
Calculate angular moments following Ryzhkov et al. (2011)
- Parameters:
sigma (float) β Axisymmteric Gaussian angle standard deviation (generally between 0 and 40 deg) from Ryzhkov et al. (2011).
- Returns:
angs β Angular moments in order: [Ang1,Ang2,Ang3,Ang4,Ang5,Ang6,Ang7].
- Return type:
array
- binmod1d.radar.dielectric_ice(lamda, TK)ο
Ray (1972) dielectric constant calculation for ice.
- Parameters:
lamda (froat) β Radar wavelength in mm.
TK (float) β Air temperature in Kelvin.
- Returns:
ei β Dielectric constant of ice for wavelength and temperature.
- Return type:
complex
- binmod1d.radar.dielectric_water(t, eps_0, t0=273.15, wave=110.0)ο
Calculate dielectric constant for fresh water at temperature T based on Ray (1972).
- Parameters:
t (float) β Air temperature in Kelvins.
eps_0 (Dielectric constant for liquid water at 0 C.) β DESCRIPTION.
t0 (float, optional) β 0 degrees Celsisus in Kelvins. The default is 273.15.
wave (float, optional) β Radar wavelength in mm. The default is 110..
- Returns:
ew β Dielectric constant for liquid water at temperature and radar wavlength.
- Return type:
complex
- binmod1d.radar.spheroid_factors(ar)ο
Calculate spheroid factors
- Parameters:
ar (array) β Particle aspect ratios.
- Returns:
La (array) β Geometric shape factor along a axis.
Lc (array) β Geometric shape factor along c axis
binmod1d.spectral_model moduleο
Created on Thu Sep 4 11:51:00 2025
- @author: Edwin L. Dunnavan, RSII Cooperative Institute for Severe and High-Impact
Weather Research and Operations (CIWRO)
Description:
This code can be used to generate model objects representing collision-coalescence and collisional breakup based on the Wang et al. (2007) source-based solution to the Kinetic Collection Equation (KCE).
Version 1.0.10
- binmod1d.spectral_model.get_kwargs(kwargs)ο
Get kwargs for figure, axis, and plot.
- binmod1d.spectral_model.latex_check()ο
Verifies that all executables required by Matplotlibβs usetex engine are in the system PATH.
- class binmod1d.spectral_model.spectral_1d(sbin=2, bins=60, dt=1, tmax=800.0, output_freq=1, dz=10.0, ztop=0.0, zbot=0.0, D1=0.1, x0=0.05, Ecol=1.0, Es=1.0, Eb=0.0, moments=2, dist_var='size', kernel='Hydro', frag_dist='LGN', habit_params='rain', ptype='rain', Tc=10.0, boundary=None, cc_dest=1, br_dest=1, radar=False, wavl=110.0, rk_order=1, adv_order=1, gpu=False, load=None, progress=True, **kwargs)ο
Bases:
object- calc_micro()ο
Calculate microphysical variables
- calc_moments(r, moments=2)ο
Calculates bin-wise moments using subgrid distributions.
- Parameters:
r (int) β Moment order.
moments (int, optional) β Whether 2-moment or 1-moment subgrid distribution. The default is 2.
- Returns:
Bin-wise moments.
- Return type:
float array
- calc_radar()ο
Calculates radar variables from Mbins and Nbins.
- clean_up()ο
Method for cleaning up spectral_1d object after model runs.
- diagnose_subgrid()ο
Diagnoses 2-moment and 1-moment subgrid distribution parameters.
- get_sed_rate_2mom_only(M_curr, N_curr)ο
Calculates pure sedimentation rate (dM/dt, dN/dt) for 2-moment. Does NOT apply boundary clamping (allows flux to flow).
- get_sed_rate_only(M_curr)ο
Calculates pure sedimentation rate (dM/dt). Does NOT apply boundary clamping (allows flux to flow).
- get_steady_rate_1mom(M_curr)ο
Helper function to calculate derivatives for the Steady State RK scheme. Updates the kernel state and returns the rate of change.
- get_steady_rates(M_curr, N_curr)ο
Helper function to calculate derivatives for the Steady State RK scheme. Equivalent to βadvance_2momβ but for the steady-state loop.
- load_case(filename)ο
Loads netcdf file variables and attributes into spectral_1d object.
- Parameters:
filename (str) β Filename of netcdf file.
- plot_dists(tind=-1, hind=-1, x_axis='mass', xscale='log', yscale='linear', distscale='log', normbin=False, scott_solution=False, feingold_solution=False, plot_habits=False, plot_init=True, ax=None, **kwargs)ο
- Parameters:
tind (int, optional) β Time index for plotting moments if steady-state or full 1D model run. The default is -1.
hind (int, optional) β Height index for plotting moments if steady-state or full 1D model run. The default is -1 (i.e., bottom level).
x_axis (str, optional) β x axis variable. Either βsizeβ or βmassβ. The default is βmassβ.
xscale (TYPE, optional) β Whether to plot x axis with linear (βlinearβ) or log (βlogβ) scaling. The default is βlogβ.
yscale (str, optional) β Whether to plot y axis with linear (βlinearβ) or log (βlogβ) scaling. The default is βlinearβ.
distscale (str, optional) β Whether to plot distribution functions in a log-scaled way (e.g., dN/dlog(m)). The default is βlogβ.
normbin (bool, optional) β Normalize number (mass) distribution function by total number (mass). The default is False.
scott_solution (bool, optional) β Plots Scott (1968) analytical solutions for Golovin, Product, or Constant kernels. The default is False.
feingold_solution (bool, optional) β Whether to plot Feingold et al. (1988) analytical solutions to SBE or SCE/SBE steady-state. The default is False.
plot_habits (bool, optional) β Plots individual habit variables. The default is False.
plot_init (bool, optional) β Whether to plot initial distribution functions. The default is True.
ax (array of objects, optional) β Array of Matplotlib pyplot axes objects for each subplot. If None, then create new figure and axes. The default is None.
**kwargs (dict) β Keyword arguments to be passed into axes and/or plots.
- Returns:
fig (object) β Matplotlib pyplot figure object.
ax (objects) β Numpy array of Matplotlib pyplot axes objects.
- plot_dists_height(tind=-1, dz=1.0, plot_habits=False, **kwargs)ο
Plots number distribution function at various height levels. Note, only works for steady-state or full 1D time/height modes.
- Parameters:
tind (int, optional) β Time index for plotting moments if steady-state or full 1D model run. The default is -1.
dz (float, optional) β Height difference (in km) between each subplot (starting with topmost height level, ztop). The default is 1..
plot_habits (bool, optional) β Plots individual habit variables. The default is False.
**kwargs (dict) β Keyword arguments to be passed into axes and/or plots.
- Returns:
fig (object) β Matplotlib pyplot figure object.
ax (objects) β Numpy array of Matplotlib pyplot axes objects.
- plot_init(x_axis='mass', xscale='log', yscale='linear', distscale='log', normbin=False, plot_habits=False, **kwargs)ο
- Parameters:
x_axis (str, optional) β x axis variable. Either βsizeβ or βmassβ. The default is βmassβ.
xscale (TYPE, optional) β Whether to plot x axis with linear (βlinearβ) or log (βlogβ) scaling. The default is βlogβ.
yscale (str, optional) β Whether to plot y axis with linear (βlinearβ) or log (βlogβ) scaling. The default is βlinearβ.
distscale (str, optional) β Whether to plot distribution functions in a log-scaled way (e.g., dN/dlog(m)). The default is βlogβ.
normbin (bool, optional) β Normalize number (mass) distribution function by total number (mass). The default is False.
plot_habits (bool, optional) β Plots individual habit variables. The default is False.
**kwargs (dict) β Keyword arguments to be passed into axes and/or plots.
- Returns:
fig (object) β Matplotlib pyplot figure object.
ax (objects) β Numpy array of Matplotlib pyplot axes objects.
- plot_moments_radar(ax=None, tind=-1, plot_habits=False, **kwargs)ο
Plots timeseries or height profiles of bulk microphysical parameters and radar parameters from spectral_1d model run.
- Parameters:
ax (object, optional) β Matplotlib pyplot axes object. If none, then create new figure and axes. The default is None.
tind (int, optional) β Time index for plotting moments if steady-state or full 1D model run. The default is -1.
plot_habits (bool, optional) β Plots individual habit variables. The default is False.
**kwargs (dict) β Keyword arguments to be passed into axes and/or plots.
- Returns:
fig (object) β Matplotlib pyplot figure object.
ax (objects) β Numpy array of Matplotlib pyplot axes objects.
- plot_time_height(var='Z', ax=None, **kwargs)ο
Plots time/height profile of microphysical or radar variables from full 1D column model spectral_1d run.
- Parameters:
var (TYPE, optional) β DESCRIPTION. The default is βZβ.
- Returns:
fig (object) β Matplotlib pyplot figure object.
ax (objects) β Matplotlib pyplot axes object.
- run()ο
Runs bin model for user-prescribed parameters.
- run_full_1mom(pbar=None)ο
Run full 1D bin model using Adaptive Sub-stepping RK4. Matches original BC logic and optimizes CFL calculation.
- run_full_2mom(pbar=None)ο
Run full 1D bin model (2-Moment) using Adaptive Sub-stepping RK4.
Physics: Calculated ONCE over full dt (Linearized Source).
Transport: Calculated iteratively using update_2mom_subgrid (Accuracy).
Stability: Adaptive sub-stepping handles CFL and Depletion (M & N).
- run_steady_state_1mom(pbar=None)ο
Run steady-state bin model (1-Moment) using Explicit Runge-Kutta integration. Uses ADAPTIVE SUB-STEPPING based on βFraction of Residence Timeβ.
- run_steady_state_2mom(pbar=None)ο
Run steady-state bin model using Explicit Runge-Kutta integration. Uses ADAPTIVE SUB-STEPPING based on βFraction of Residence Timeβ.
- setup_case(sbin=4, bins=160, D1=0.001, x0=0.01, dist_var='mass', kernel='Golovin', Ecol=1.53, Es=0.001, Eb=0.0, moments=2, ztop=3000.0, zbot=0.0, zout=None, tout=None, tmax=800.0, output_freq=1, dt=10.0, dz=10.0, frag_dist='exp', habit_dict=None, ptype='rain', Tc=10.0, radar=False, wavl=110.0, boundary=None, cc_dest=1, br_dest=1, rk_order=1, adv_order=1, gpu=False, progress=True, **kwargs)ο
Setβs up BinMod1D model for solving the SCE/SBE equation for user-prescribed parameters.
- Parameters:
sbin (int) β Spectral bin mass grid resolution. The default is 4.
bins (int) β Number of bins used for each distribution. The default is 56.
D1 (float, optional) β Minimum equivolume diameter bin size in mm when the βdist_varβ parameter is βsizeβ. The default is 0.25.
x0 (float, optional) β Minimum bin mass in grams when the βdist_varβ parameter is βmassβ.. The default is 0.05.
dist_var (str, optional) β Whether to use mass or size to specify initial gamma distribution. The default is βmassβ.
kernel (str, optional) β Type of collision kernel in collection_kernels.py to use for coalescence/breakup. The default is βGolovinβ.
Ecol (float, optional) β Collision efficiency. The default is 1.0.
Es (float, optional) β Sticking efficiency. The default is 1.0.
Eb (float, optional) β Breakup efficiency. The default is 0..
moments (int, optional) β Number of moments to use for spectral bin model (either 1 (mass) or 2 (mass and number)). The default is 2.
ztop (float, optional) β Top height of steady-state/1D model domain in meters. The default is 0..
zbot (float, optional) β Bottom height of steady-state/1D model domain in meters. The default is 0..
tmax (float, optional) β Maximum time in seconds the model is run. The default is 800.
output_freq (int, optional) β Frequency in time with which the Full 1D column model is output. The default is 60..
dt (float, optional) β Model time step in seconds. The default is 1.
dz (float, optional) β Height grid spacing in meters. The default is 10..
frag_dist (str, optional) β Type of fragment distribution. The default is βexpβ.
habit_params (list, optional) β List of distribution parameters for each category (total distribution number determined by len(habit_lists)). elements of list can be either strings where each string defines a default habit type from the habits() function in the habits module or a dictionary with the necessary parameters. The default is [βrainβ].
ptype (str, optional) β Whether particles are rain or snow. NOTE: currently not considering mixed phase or mixture of rain/show. The default is βrainβ.
Tc (float, optional) β Layer-averaged temperature in degrees Celsius. Used in radar calculations. The default is 10..
boundary (Nonetype or str, optional) β
- Upper boundary conditions for full 1D model: None = fallout mode for 1D model
βfixedβ = fixed upper boundary condition. The default is None.
cc_dest (int, optional) β Distribution destination of coalesced particles. Index (1 = first distribution) corresponds to the distribution in habit_list. The default is 1.
br_dest (int, optional) β Distribution destination of breakup (fragment) particles. Index (1 = first distribution) corresponds to the distribution in habit_list. DESCRIPTION. The default is 1.
radar (bool, optional) β Whether to calculate radar variables for each bin. The default is False.
wavl (float, optional) β Radar wavelength in mm.
rk_order (int, optional) β Runge-Kutta time stepping order. The default is 1.
adv_order (int, optional) β Upwind advection scheme order (CURRENTLY NOT IMPLMENTED YET). The default is 1.
gpu (bool, optional) β Whether to use GPU (if available) (CURRENTLY NOT IMPLEMENTED YET). The default is False.
load (str, optional) β If loading spectral_1d() object from netcdf file, this is the path string to the netcdf file. None means no loading. The default is None.
progress (bool, optional) β If using a progressbar when using run() method. The default is None.
**kwargs (TYPE) β DESCRIPTION.
- setup_habits(habit_params, psd_params=None)ο
Setβs up habits based on habit_params list.
- Parameters:
habit_params (list or str or dict) β Habit parameters for each desired distribution.
psd_params (dict, optional) β PSD parameters. The default is None.
- setup_radar()ο
- write_netcdf(filename, save_radar=False)ο
Writes netcdf file for spectral_1d object.
- Parameters:
filename (str) β Path and filename of netcdf file.
save_radar (bool, optional) β Whether to save total radar variables to netcdf file. The default is False.