Useful tools

Reading parameters

jjmodel.tools.read_parameters(path_to_file)[source]

Reads parameters from text file(s).

Parameters

path_to_file (string) -- Relative path to the parameter file(s). Main parameter file must have name 'parameters' and the second, optional parameter file, must be called 'sfrd_peaks_parameters'.

Returns

Names and values of all parameters given in the parameter file(s).

Return type

namedtuple

jjmodel.tools.resave_parameters(path_to_parameterfile, path_to_parameterfile_copy, p)[source]

Reads parameters from text file(s) and saves parameter file(s) to the output folder with only those parameters which are needed for this run (cleans parameter files from unnecessary input).

Parameters
  • path_to_parameterfile (string) -- Relative path to the parameter file(s).

  • path_to_parameterfile_copy (string) -- Destination where the file copies should be saved.

  • p (namedtuple) -- Set of model parameters from the parameter file.

Returns

None

Smoothing distributions

jjmodel.tools.gauss_weights(x, mean, sigma)[source]

Draws instances from the Gaussian PDF.

Parameters
  • x (array-like) -- Set of points, where probability density (PD) has to be calculated.

  • mean (scalar) -- Mean of the Gaussian distribution.

  • sigma (scalar) -- Standard deviation of the Gaussian distribution.

Returns

PD values at x, normalized to unity.

Return type

array-like

jjmodel.tools.convolve1d_gauss(array, dx_smooth, x_range)[source]

Smoothing a 1d-array with a Gaussian kernel.

Parameters
  • array (1d-array.) -- Initial array.

  • dx_smooth (scalar) -- Dispersion in x.

  • x_range (list) -- Min and max values along the array axes, [xmin,xmax].

Returns

New smoothed array of the same shape.

Return type

1d-array

jjmodel.tools.convolve2d_gauss(array, dxy_smooth, xy_range)[source]

Smoothing a 2d-array with a Gaussian kernel.

Parameters
  • array (2d-array.) -- Initial array.

  • dxy_smooth (list) -- Dispersions in x and y, [dx,dy].

  • xy_range (list[list]) -- Min and max values along the array axis, [[xmin,xmax],[ymin,ymax]].

Returns

New smoothed array of the same shape.

Return type

2d-array

jjmodel.tools.cumhist_smooth_savgol(y, m, n)[source]

Smoothes a normalized cumulative distribution of some quantity with the Savitzky-Golay filter.

Parameters
  • y (array-like) -- y-coordinates of the normalized cumulative distribution.

  • m (int) -- Parameter window_length of scipy.signal.savgol_filter.

  • n (int) -- Parameter polyorder of scipy.signal.savgol_filter.

Return y_sm

Smoothed y.

Return type

1d-array

Interpolation tools

class jjmodel.tools.ConvertAxes[source]

Interpolation methods.

get_closest(axis1_new, axis1_old, axis2_old)[source]

No interpolation is applied, the new axis1-values are replaced by the closest values from the old axis1-array and the corresponding old axis2-values are returned. This method is good when the resolution of the old axis1-array is much better than the resolution of the new axis1-array.

Parameters
  • axis1_new (array-like) -- New values along axis1.

  • axis1_old (array-like) -- Old values along axis1.

  • axis2_old (array-like) -- Old values along axis2.

Returns

New values along axis2 corresponding to the new axis1-values set.

Return type

1d-array

interpolate(axis1_new, axis1_old, axis2_old)[source]

Returns new axis2-values for a new set of axis1-values given the old (axis1,axis2). Uses linear interpolation.

Parameters
  • axis1_new (array-like) -- New values along axis1.

  • axis1_old (array-like) -- Old values along axis1.

  • axis2_old (array-like) -- Old values along axis2.

Returns

New values along axis2 corresponding to the new axis1-values set.

Return type

1d-array

jjmodel.tools.rebin_histogram(bin_edges, x_centers, counts)[source]

Uses existing histogram to create a new histogram for the different set of x-bins, such that the overall counts are conserved.

Parameters
  • bin_edges (array-like) -- Edges of the new x-bins.

  • x_centers (array-like) -- Centers of the old x-bins.

  • counts (array-like) -- Histogram counts corresponding to the old x-bin centers.

Returns

New counts corresponding to the new x-bins (len(bin_edges)-1).

Return type

1d-array

Retrieving status

class jjmodel.tools.Timer[source]

Class for measuring time intervals.

start()[source]

Creates an instance and checks the current time.

stop(moment)[source]

Returns time interval between the current and some previous moment. Output in fractions of hours, minutes and seconds.

Parameters

moment (float) -- Time record (in the format of output of time.time()).

Returns

Time interval in hms.

Return type

str

class jjmodel.tools.LogFiles(filename)[source]

Class for manipulations with text files. Includes methods for creating text files and adding lines to them. Used for writing log files.

__init__(filename)[source]

Creates an instance of the class.

Parameters

filename (str) -- Name of the file.

append(text)[source]

Opens the file, adds a line, closes the file.

Parameters

text (str) -- Text to be added to the file.

Returns

None.

write(text)[source]

Creates a file with filename (current directory), writes a line, closes the file.

Parameters

text (str) -- Text to be added to the file.

Returns

None.

Other

jjmodel.tools.reduce_table(tab, a)[source]

Calculates the surface number density of the mono-age subpopulations, thus, reduces the length of the 'stellar assemblies' table to the number of thin- or thick-disk, or halo subpopulations.

Parameters
  • tab (dict) -- Isochrone columns.

  • a (namedtuple) -- Collection of the fixed model parameters, useful quantities, and arrays.

Returns

Table with two columns: 't' and 'N', Galactic time (Gyr) and surface number densities (\(\mathrm{number \ pc^{-2}}\)).

Return type

astropy Table