spacing_functions module¶
Module containing the spacing functions for the binarycpython package. Very under-populated at the moment, but more are likely to come soon
- Tasks:
TODO: add more spacing functions to this module.
- binarycpython.utils.spacing_functions.const(min_bound, max_bound, steps)[source]¶
Samples a range linearly. Uses numpy linspace.
- Parameters
min_bound (
Union
[int
,float
]) – lower bound of rangemax_bound (
Union
[int
,float
]) – upper bound of rangesteps (
int
) – number of segments between min_bound and max_bound
- Return type
list
- Returns
np.linspace(min_bound, max_bound, steps+1)
- binarycpython.utils.spacing_functions.const_dt(self, dt=1000.0, dlogt=0.1, mmin=0.07, mmax=100.0, nres=1000, logspacing=False, tmin=3.0, tmax=None, mindm=None, maxdm=((0.07, 1.0, 0.1), (1.0, 300.0, 1.0)), fsample=1.0, factor=1.0, logmasses=False, log10masses=False, showlist=False, showtable=False)[source]¶
const_dt returns a list of masses spaced at a constant age difference
- Parameters
dt – the time difference between the masses (1000.0 Myr, used when logspacing==False)
dlogt – the delta log10(time) difference between masses (0.1 dex, used when logspacing==True)
mmin – the minimum mass to be considered in the stellar lifetime interpolation table (0.07 Msun)
mmax – the maximum mass to be considered in the stellar lifetime interpolation table (100.0 Msun)
nres – the resolution of the stellar lifetime interpolation table (100)
logspacing – whether to use log-spaced time, in which case dt is actually d(log10(t))
tmin – the minimum time to consider (Myr, default 3.0 Myr)
tmax – the maximum time to consider (Myr, default None which means we use the grid option ‘max_evolution_time’)
mindm – a tuple of tuples containing a mass range and minimum mass spacing in that range. The default is ((0.07,1.0,0.1),(1.0,300.0,1.0)) allocated a minimum dm of 0.1Msun in the mass range 0.07 to 1.0 Msun and 1.0Msun in the range 1.0 to 300.0 Msun. Anything you set overrides this. Note, if you use only one tuple, you must set it with a trailing comma, thus, e.g. ((0.07,1.0,0.1),). (default None)
maxdm – a list of tuples similar to mindm but specifying a maximum mass spacing. In the case of maxdm, if the third option in each tuple is negative it is treated as a log step (its absolute value is used as the step). (default None)
fsample – a global sampling (Shannon-like) factor (<1) to improve resolution (default 1.0, set to smaller to improve resolution)
factor – all masses generated are multiplied by this after generation
showtable – if True, the mass list and times are shown to stdout after generation
showlist – if True, show the mass list once generated
logmasses – if True, the masses are logged with math.log()
log10masses – if True, the masses are logged with math.log10()
- Returns
Array of masses.
Example: # these are lines set as options to Population.add_grid_value(…)
# linear time bins of 1Gyr samplerfunc=”const_dt(self,dt=1000,nres=100,mmin=0.07,mmax=2.0,showtable=True)”
# logarithmic spacing in time, generally suitable for Galactic # chemical evolution yield grids. samplerfunc=”const_dt(self,dlogt=0.1,nres=100,mmin=0.07,mmax=80.0,maxdm=((0.07,1.0,0.1),(1.0,10.0,1.0),(10.0,80.0,2.0)),showtable=True,logspacing=True,fsample=1.0/4.0)”
- binarycpython.utils.spacing_functions.const_ranges(ranges)[source]¶
Samples a series of ranges linearly.
- Parameters
ranges – a tuple of tuples passed to the const() spacing function.
- Return type
list
- Returns
numpy array of masses
Example
The following allocates 10 stars between 0.1 and 0.65, 20 stars between 0.65 and 0.85, and 10 stars between 0.85 and 10.0 Msun.
- samplerfunc=”const_ranges((({},{},{}),({},{},{}),({},{},{})))”.format(
0.1,0.65,10, 0.65,0.85,20, 0.85,10.0,10
),
- binarycpython.utils.spacing_functions.gaussian_zoom(min_bound, max_bound, zoom_mean, zoom_dispersion, zoom_magnitude, steps)[source]¶
Samples such that a region is zoomed in according to a 1-Gaussian function
- Parameters
min_bound (
Union
[int
,float
]) – lower bound of rangemax_bound (
Union
[int
,float
]) – upper bound of rangezoom_mean (
Union
[int
,float
]) – mean of the Gaussian zoom locationzoom_dispersion (
Union
[int
,float
]) – dispersion of the Gaussianzoom_magnitude (
Union
[int
,float
]) – depth of the Gaussian (should be 0<= zoom_magntiude <1)steps (
int
) – number of segments between min_bound and max_bound assuming a linear step this is what you’d normally call “resolution”
- Return type
list
- Returns
Numpy array of sample values
- binarycpython.utils.spacing_functions.peak_normalized_gaussian_func(x, mean, sigma)[source]¶
Function to evaluate a Gaussian at a given point, note that the normalization is such that the peak is always 1.0, not that the integral is 1.0
- Parameters
x (
Union
[int
,float
]) – location at which to evaluate the distributionmean (
Union
[int
,float
]) – mean of the Gaussiansigma (
Union
[int
,float
]) – standard deviation of the Gaussian
- Return type
Union
[int
,float
]- Returns
value of the Gaussian at x