clustertools.util.recipes module

Generic recipes for making key calculations

clustertools.util.recipes.binmaker(x, nbin=10, nsum=False, steptype='linear')[source]

Split an array into bins of equal width

Parameters:
xfloat

input array

nbinint

number of bins

nsumbool

return number of points in each bin (default: False)

steptypestr

linear or logarithmic steps (default: linear)

Returns:
x_lowerfloat

lower bin values

x_midfloat

mean value in each bin

x_upperfloat

upper bin values

x_hist

number of points in bin

if nsum==True:
x_sumfloat

sum of point values in each bin

clustertools.util.recipes.distance(x1, x2)[source]

Find distance between two points (made for use with numba)

Parameters:
x1float

3D position of first point of the form [x,y,z]

x2float

3D position of first point of the form [x,y,z]

Returns:
distancefloat

distance between the two points

clustertools.util.recipes.dx_function(x, nx=10, bintype='num', x_lower=None, x_mean=None, x_upper=None, plot=False, **kwargs)[source]

Find distribution function using nx bins

Parameters:
xfloat

input arrayå

nxint

number of bins (default : 10)

bintypestr

bin with equal number of stars per bin (num) or evenly in x (fix) (default: num)

x_lower,x_mean,x_upperfloat

preset lower limit, mean value, and upper limit bins

Returns:
x_meanfloat

mean value in each bin

x_histfloat

number of stars in each bin

dxfloat

number of stars in each bin divided by width of bin

alphafloat

power law slope fit to dx vs x_mean

ealphafloat

error in alpha

yalphafloat

y-intercept of fit to log(dx) vs lod(x_mean)

eyalphafloat

error in yalpha

clustertools.util.recipes.interpolate(r1, r2, x=None, y=None)[source]
Perform simple linear interpolation between two points in 2D
  • one of x or y must be defined

Parameters:
r1,r2float

x,y coordinates from which to interpolate

xfloat

x-value from which to interpolate y (default: None)

yfloat

y-value from which to interpolate x (default: None)

Returns:
valfloat

interpolated value

History
2019 - Written - Webb (UofT)
clustertools.util.recipes.mean_prof(x, y, nbin=10, bintype='num', steptype='linear', median=False, x_lower=None, x_mean=None, x_upper=None)[source]

Calculate mean profile of parameter y that depends on x

Parameters:
x,yfloat

coordinates from which to measure the mean profile

nbinint

number of bins

bintypestr

can be bins of fixed size (‘fix’) or equal number of stars (‘num’) (default: num)

steptypestr

for fixed size arrays, set step size to ‘linear’ or ‘log’

medianbool

find median instead of mean (Default: False)

x_lower,x_mean,x_upperfloat

preset lower limit, mean value, and upper limit bins

Returns:
x_binfloat

x values of mean profile

y_binfloat

y values of mean profile

y_sigfloat

dispersion about the mean profile

clustertools.util.recipes.minimum_distance(x)[source]

Find distance to each point’s nearest neighbour

Parameters:
xfloat (array)

3D position of each point of the form [x,y,z].Transpose

Returns:
min_distancefloat

distance to each points nearest neighbour

clustertools.util.recipes.nbinmaker(x, nbin=10, nsum=False)[source]

Split an array into bins with equal numbers of elements

Parameters:
xfloat

input array

nbinint

number of bins

nsumbool

return number of points in each bin (default: False)

Returns:
x_lowerfloat

lower bin values

x_midfloat

mean value in each bin

x_upperfloat

upper bin values

x_hist

number of points in bin

if nsum==True:
x_sumfloat

sum of point values in each bin

clustertools.util.recipes.power_law_distribution_function(n, alpha, xmin, xmax)[source]

Generate points from a power-law distribution function

Parameters:
nint

number of points

alphafloat

power-law slope of distribution function

xmin,xmaxfloat

minimum and maximum values of distribution

Returns:
xfloat

array of values drawn from distribution

clustertools.util.recipes.roaming_binmaker(x, nbin=10, ntot=20, nsum=False, steptype='linear')[source]

Split an array into bins of equal width with a roaming average

Parameters:
xfloat

input array

nbinint

number of bins to set bin width

ntotint

number of total bins

nsumbool

return number of points in each bin (default: False)

steptypestr

linear or logarithmic steps (default: linear)

Returns:
x_lowerfloat

lower bin values

x_midfloat

mean value in each bin

x_upperfloat

upper bin values

x_hist

number of points in bin

if nsum==True:
x_sumfloat

sum of point values in each bin

clustertools.util.recipes.roaming_nbinmaker(x, nbin=10, ntot=20, nsum=False)[source]

Split an array into bins with equal numbers of elements

Parameters:
xfloat

input array

nbinint

number of bins to set bin fraction

ntotint

number of total bins

nsumbool

return number of points in each bin (default: False)

Returns:
x_lowerfloat

lower bin values

x_midfloat

mean value in each bin

x_upperfloat

upper bin values

x_hist

number of points in bin

if nsum==True:
x_sumfloat

sum of point values in each bin

clustertools.util.recipes.smooth(x, y, dx, bintype='num', median=False)[source]

Smooth a profile

Parameters:
x,yfloat

coordinates from which to measure the mean profile

dxfloat

width of x smoothening bin

bintypestr

can be bins of fixed size (‘fix’) or equal number of stars (‘num’) (default: num)

steptypestr

for fixed size arrays, set step size to ‘linear’ or ‘log’

medianbool

find median instead of mean (Default: False)

Returns:
x_binfloat

x values of mean profile

y_binfloat

y values of mean profile

y_sigfloat

dispersion about the mean profile

Other Parameters:
dxfloat

width of smoothening bin

clustertools.util.recipes.tapered_dx_function(x, nx=10, bintype='num', x_lower=None, x_mean=None, x_upper=None, plot=False, **kwargs)[source]

Find distribution function using nx bins

Parameters:
xfloat

input arrayå

nxint

number of bins (default : 10)

bintypestr

bin with equal number of stars per bin (num) or evenly in x (fix) (default: num)

x_lower,x_mean,x_upperfloat

preset lower limit, mean value, and upper limit bins

Returns:
x_meanfloat

mean value in each bin

x_histfloat

number of stars in each bin

dxfloat

number of stars in each bin divided by width of bin

alphafloat

power law slope fit to dx vs x_mean

ealphafloat

error in alpha

yalphafloat

y-intercept of fit to log(dx) vs lod(x_mean)

eyalphafloat

error in yalpha

clustertools.util.recipes.x_hist(x, nx=10, bintype='num', bins=False, x_lower=None, x_mean=None, x_upper=None)[source]

Find histogram data using nx bins

Parameters:
xfloat

input arrayå

nxint

number of bins (default : 10)

bintypestr

bin with equal number of stars per bin (num) or evenly in x (fix) (default: num)

binsbool

return bins

x_lower,x_mean,x_upperfloat

preset lower limit, mean value, and upper limit bins

Returns:
if bins:

x_lower,x_mean,x_upper,x_hist

else:
x_meanfloat

mean value in each bin

x_histfloat

number of stars in each bin