pimf.sampling.sampling
Module Contents
Classes
A class to calculate and store properties of a sample, beyond just a list of masses. |
|
A class to calculate and store properties of several samples, beyond just a list of masses. |
Functions
Draw samples from the given imf until the target mass is reached within a user specified tolerance. |
|
Draw stars from the IMF using “optimal sampling”. (Which papers are best to cite here?) |
|
Data
API
- class pimf.sampling.sampling.IMFSample(masses, target_mass, stop_method)
A class to calculate and store properties of a sample, beyond just a list of masses.
Has the ability to store:
Quantity when the IMF has been sampled
The same Quantity when the IMF has been averaged over
The residual, defined as: (Qsampled - Qaveraged) / Qaveraged. for quantities like:
Number of Supernovae
Number of black holes
arbitrary quantities defined on a grid to be interpolated in mass, including ones that vary with time.
If you want to sample from the IMF several times, calculate the same quantities, and compare them, see also IMFSampleList.
Notes
The residual is defined as (Qsampled - Qaveraged) / Qaveraged, so a residual of 1 means the sampled value is twice that of the averaged, or 100%. A value close to 0 means they are similar, far away from 0 means different.
Initialization
- add_interpolated_quantity(mass_grid, quantity_grid, imf, name, interp_kwargs={}, imf_extrapolate=False, Mmin=None, Mmax=None)
- add_interpolated_quantity_time_dependant(mass_grid, quantity_grid, imf, name, interp_kwargs={}, imf_extrapolate=False, Mmin=None, Mmax=None)
- classmethod load(filename, i=None)
Load single sample from a hdf5 file containing either just that sample or the
ith sample of a list.Single sample corresponds to
i=None, ‘default’ but not yet implemented. Alternatively iffilenameis a sample list, i.e. saved withIMFSampleList.savespecifingiloads theith sample in.Parameters
filename : string Filename to read from. i : None or int, optional Indexes a list of samples to load just that one, by default None (loads from single file).
Raises
NotImplementedError
i=Nonecurrently not implemented as IMFSample doesn’t have a working save method. Use IMFSampleList (or contribute!) instead.
- class pimf.sampling.sampling.IMFSampleList(sample_list)
A class to calculate and store properties of several samples, beyond just a list of masses.
Has the ability to store:
Quantity when the IMF has been sampled
The same Quantity when the IMF has been averaged over
The residual, defined as: (Qsampled - Qaveraged) / Qaveraged. for quantities like:
Number of Supernovae
Number of black holes
arbitrary quantities defined on a grid to be interpolated in mass, including ones that vary with time.
If you want to sample from the IMF only once, see also IMFSample.
Notes
The residual is defined as (Qsampled - Qaveraged) / Qaveraged, so a residual of 1 means the sampled value is twice that of the averaged, or 100%. A value close to 0 means they are similar, far away from 0 means different.
Initialization
- add_interpolated_quantity(mass_grid, quantity_grid, imf, name, interp_kwargs={}, imf_extrapolate=False, Mmin=None, Mmax=None)
- add_interpolated_quantity_time_dependant(mass_grid, quantity_grid, imf, name, interp_kwargs={}, imf_extrapolate=False, Mmin=None, Mmax=None)
- pimf.sampling.sampling.draw_samples(imf, stop_method='below', target_mass=None, full_output=False, rescale=False, rng=rng)
Draw samples from the given imf until the target mass is reached within a user specified tolerance.
Parameters
imf : InitialMassFunction subclass The IMF to sample from. Needs to have
inverse_cdf()method implemented. stop_method : str from {“below” | “above” | “closest”}, optional The stopping criteria, see notes below for more information, by default “below” target_mass : int or float, optional The target mass to aim for, by default None. If None, use the total mass of the provided IMF. full_output : bool, optional Whether or not to return an IMFSample object (True) or just a numpy array of the sampled masses, by default False (only return mass array). rescale : bool, optional Whether or not to rescale each mass so the final total is the target mass exactly. mi -> mi * Mtarget / Mtotal. By default, False (don’t rescale). rng : instance on numpy random Generator, optional The instance of numpy Generator to use. This is how the user can provide their own seed/random number generation method. By default the result of calling numpy.random.default_rng().Returns
ndarray or IMFSample object An array of the masses drawn randomly from the IMF if full_output=False (default), or an IMFSample object representing the sample and additional information.
- pimf.sampling.sampling.optimal_sampling(imf, target_mass=None, Mmax=100, full_output=False)
Draw stars from the IMF using “optimal sampling”. (Which papers are best to cite here?)
Note that this differs from
~pimf.sampling.draw_samplesin that it is deterministic.WARNING This will mutate imf.
Parameters
imf : InitialMassFunction subclass The IMF to sample from. Needs to have
inverse_cdf()method implemented. target_mass : int or float, optional The target mass to aim for, by default None. If None, use the total mass of the provided IMF. full_output : bool, optional Whether or not to return an IMFSample object (True) or just a numpy array of the sampled masses, by default False (only return mass array).Returns
ndarray or IMFSample object An array of the masses drawn randomly from the IMF if full_output=False (default), or an IMFSample object representing the sample and additional information.