cratermaker.utils.montecarlo_utils.get_random_size#
- cratermaker.utils.montecarlo_utils.get_random_size(diameters, cdf, size=None, mu=None, rng=None, rng_seed=None, rng_state=None, **kwargs)[source]#
Sample diameters from a cumulative size-frequency distribution (SFD).
Given an array of diameters and optionally a cumulative distribution function (CDF), this function generates new diameter values that follow the specified distribution. The SFD is treated as a continuous function that interpolates between the provided diameters, which are assumed to represent a power-law distribution.
- Parameters:
diameters (array_like) – An array of diameters from which the SFD is constructed. Must be 1-dimensional.
cdf (array_like) – The cumulative distribution function corresponding to diameters. Must be the same size as diameters and must be monotonically increasing with decreasing diameter value.
size (int or tuple of ints, optional) – The number of samples to generate. If the shape is (m, n, k), then m * n * k samples are drawn. If size is None and mu is None then a single value is returned. Note: mu and size are mutually exclusive.
mu (int or tuple of ints, optional) – The expected number of samples to generate using a Poisson random number genertor. If the shape is (m, n, k), then m * n * k samples are drawn. Note: mu and size are mutually exclusive.
rng (numpy.random.Generator | None) – A numpy random number generator. If None, a new generator is created using the rng_seed if it is provided.
rng_seed (Any type allowed by the rng_seed argument of numpy.random.Generator, optional) – The rng_seed for the RNG. If None, a new RNG is created.
rng_state (dict, optional) – The state of the random number generator. If None, a new state is created.
**kwargs (Any) – Additional keyword arguments that are either ignored or passed to internal functions as needed.
- Returns:
ndarray of np.float64 – An array of sampled diameter values from the SFD.
Notes
The SFD is assumed to be a continuous distribution that follows a power-law between the provided discrete diameter values. Linear interpolation in log-space is used to sample new values between the known diameters. A small amount of random noise (of the order 1e-3 the diameter value) is added to the final diameter value to ensure that diameter values are unlikely to be identical, even when an input CDF could lead to identical diameter values.
Examples
>>> diameters = np.array([100.0, 56.0, 32.0, 18.0, 10.0]) >>> ncumul = np.array([1.0, 0.51, 0.21, 0.06, 0.01]) >>> sample_from_sfd(diameters, cdf=ncumul, size=4) array([14.80803668, 44.95292261, 29.80797715, 23.11082091])