Miscellaneous Utilities

These are miscellaneous utilities.

txpipe.utils.misc.hex_escape(s, replace_newlines=False)[source]

Replace non-printable characters in a string with hex-code equivalents so they can be printed or saved to a FITS file header. Newline characters will be replaced if replace_newlines is set to true

Based on: https://stackoverflow.com/a/13935582

Parameters:
  • s (str) – The initial string

  • replace_newlines (bool) – Whether to include newline characters in the replacement

Returns:

Same string with unprintable chars replaced with hex codes, e.g. the bell character becomes “”

Return type:

str

txpipe.utils.misc.rename_iterated(it, renames)[source]

Rename the items in dictionaries yielded by an interator.

In several places we load data from catalogs chunk by chunk, yielding a dictionary of data each time. This renames columns in each chunk.

Parameters:
  • it (iterator) – Must yield triplets of (any, any, data)

  • renames (dict) – dictionary of old names mapped to new names

txpipe.utils.misc.unique_list(seq)[source]

Find the unique elements in a list or other sequence while maintaining the order. (i.e., remove any duplicated elements but otherwise leave it the same)

Method from: https://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-whilst-preserving-order

Parameters:

seq (list or sequence) – Any input object that can be iterated

Returns:

L – a new list of the unique objects

Return type:

list

txpipe.utils.provenance.find_module_versions()[source]

Generate a dictionary of versions of all imported modules by looking for __version__ or version attributes on them.

txpipe.utils.provenance.get_caller_directory(grandparent=False)[source]

Find the directory where the code calling this module lives, or where the code calling that code lives if grandparent=True.

txpipe.utils.provenance.git_current_revision()[source]

Run git diff in the caller’s directory, and return stdout+stderr

txpipe.utils.provenance.git_diff()[source]

Run git diff in the caller’s directory, and return stdout+stderr

txpipe.utils.theory.fill_empty_sacc(sacc_data, ell_values=None, theta_values=None)[source]

Make a sacc object containing

txpipe.utils.theory.make_bias_parameters(bias_option, sacc_data, cosmo)[source]

Make a dictionary of bias parameters in the form required by the FireCrown LinearBiasSystematic class.

We allow any of: - a blank input (unit biases) - a dict, array, or comma-separated string (per-bin biases) - a float (biases following the growth rate)

In each case we force the bias to be flat within the tomographic bin by

Parameters:
  • b0 (float, str, dict, float array, or None) –

  • sacc_data (Sacc) –

  • cosmo (pyccl.Cosmology) –

Return type:

dict

txpipe.utils.theory.smooth_nz(nz)[source]

Smooth an n(z) by convolving with a Gassian of width 2 samples

Parameters:

nz (array) –

Return type:

array

txpipe.utils.theory.smooth_sacc_nz(sack)[source]

Smooth each n(z) in a sacc object, in-place.

Parameters:

sacc (Sacc) –

Return type:

None

txpipe.utils.theory.theory_3x2pt(cosmo, sacc_data, bias=None, smooth=False, ell_values=None, theta_values=None, theory_model='/home/docs/checkouts/readthedocs.org/user_builds/txpipe/checkouts/latest/txpipe/utils/theory_model.py')[source]

Use FireCrown to generate the theory predictions for the data in a sacc file.

If the supplied sacc data has only tracers and no data points then the output will be given data points at the ell or theta values supplued in the keyword options.

Linear galaxy bias parameters can optionally be provided as an array. If left as None they are set to unity.

Parameters:
  • cosmo (pyccl.Cosmology) – The cosmology at which to get the theory predictions

  • sacc_data (sacc.Sacc or str) – Sacc object or a path to one. If the file has only tracers and no data then ell_values or theta_values must be supplied.

  • bias (float, array, or None) – If a float b_0, use the scheme b = b_0 / D(<z>) for each bin. If an array, use the given value for each bin

  • ell_values (array, optional) – An array of ell’s to use if no data points are in the sacc file

  • theta_values (array, optional) – An array of theta’s to use if no data points are in the sacc file

Returns:

sacc_theory – A copy of the input sacc_data but with values replaced with theory predictions.

Return type:

sacc.Sacc