firecrown.metadata_functions

Two-point metadata functions module.

This module contains functions used to manipulate two-point metadata, including extracting metadata from a sacc file and creating new metadata objects.

Classes

TwoPointRealIndex

Intermediate object for reading SACC real-space two-point data.

TwoPointHarmonicIndex

Intermediate object for reading SACC harmonic-space two-point data.

Functions

make_measurement(value)

Create a Measurement object from a dictionary.

make_measurements(value)

Create a Measurement object from a dictionary.

make_measurement_dict(value)

Create a dictionary from a Measurement object.

make_measurements_dict(value)

Create a dictionary from a Measurement object.

make_correlation_space(value)

Create a CorrelationSpace object from a string.

extract_all_tracers_inferred_galaxy_zdists(sacc_data)

Extracts the two-point function metadata from a Sacc object.

extract_all_measured_types(sacc_data[, ...])

Extracts the two-point function metadata from a Sacc object.

extract_all_real_metadata_indices(sacc_data[, ...])

Extract all two-point function metadata from a sacc file.

extract_all_harmonic_metadata_indices(sacc_data[, ...])

Extracts the two-point function metadata from a sacc file.

extract_all_harmonic_metadata(sacc_data[, ...])

Extract the two-point function metadata and data from a sacc file.

extract_all_real_metadata(sacc_data[, ...])

Extract the two-point function metadata and data from a sacc file.

extract_all_photoz_bin_combinations(sacc_data[, ...])

Extracts the two-point function metadata from a sacc file.

extract_window_function(sacc_data, indices)

Extract ells and weights for a window function.

maybe_enforce_window(ells, indices, sacc_data)

Possibly enforce a window function on the given ells.

make_all_photoz_bin_combinations(inferred_galaxy_zdists)

Extract the two-point function metadata from a sacc file.

make_all_photoz_bin_combinations_with_cmb(...[, ...])

Create all galaxy combinations plus mdt.CMB-galaxy cross-correlations.

make_cmb_galaxy_combinations_only(inferred_galaxy_zdists)

Create only mdt.CMB-galaxy cross-correlations.

match_name_type(tracer1, tracer2, a, b[, ...])

Use the naming convention to assign the right measurement to each tracer.

make_two_point_xy(inferred_galaxy_zdists_dict, ...)

Build a mdt.TwoPointXY object from the inferred galaxy z distributions.

measurements_from_index(index)

Return the tracer names and measurements from a two-point index.

Package Contents

class firecrown.metadata_functions.TwoPointRealIndex

Bases: TypedDict

Inheritance diagram of firecrown.metadata_functions.TwoPointRealIndex

Intermediate object for reading SACC real-space two-point data.

Internal use only - not intended for direct user interaction.

data_type: str
tracer_names: firecrown.metadata_types.TracerNames
class firecrown.metadata_functions.TwoPointHarmonicIndex

Bases: TypedDict

Inheritance diagram of firecrown.metadata_functions.TwoPointHarmonicIndex

Intermediate object for reading SACC harmonic-space two-point data.

Internal use only - not intended for direct user interaction.

data_type: str
tracer_names: firecrown.metadata_types.TracerNames
firecrown.metadata_functions.make_measurement(value)

Create a Measurement object from a dictionary.

Parameters:

value (firecrown.metadata_types.Measurement | dict[str, Any])

Return type:

firecrown.metadata_types.Measurement

firecrown.metadata_functions.make_measurements(value)

Create a Measurement object from a dictionary.

Parameters:

value (set[firecrown.metadata_types.Measurement] | list[dict[str, Any]])

Return type:

set[firecrown.metadata_types.Measurement]

firecrown.metadata_functions.make_measurement_dict(value)

Create a dictionary from a Measurement object.

Parameters:

value (firecrown.metadata_types.Measurement) – the measurement to turn into a dictionary

Return type:

dict[str, str]

firecrown.metadata_functions.make_measurements_dict(value)

Create a dictionary from a Measurement object.

Parameters:

value (set[firecrown.metadata_types.Measurement]) – the measurement to turn into a dictionary

Return type:

list[dict[str, str]]

firecrown.metadata_functions.make_correlation_space(value)

Create a CorrelationSpace object from a string.

Parameters:

value (firecrown.metadata_types.TwoPointCorrelationSpace | str)

firecrown.metadata_functions.extract_all_tracers_inferred_galaxy_zdists(sacc_data, include_maybe_types=False)

Extracts the two-point function metadata from a Sacc object.

The Sacc object contains a set of tracers (one-dimensional bins) and data points (measurements of the correlation between two tracers).

This function extracts the two-point function metadata from the Sacc object and returns it in a list.

Parameters:

sacc_data (sacc.Sacc)

Return type:

list[firecrown.metadata_types.InferredGalaxyZDist]

firecrown.metadata_functions.extract_all_measured_types(sacc_data, include_maybe_types=False)

Extracts the two-point function metadata from a Sacc object.

The Sacc object contains a set of tracers (one-dimensional bins) and data points (measurements of the correlation between two tracers).

This function extracts the two-point function metadata from the Sacc object and returns it in a list.

Parameters:
  • sacc_data (sacc.Sacc)

  • include_maybe_types (bool)

Return type:

dict[str, set[firecrown.metadata_types.Measurement]]

firecrown.metadata_functions.extract_all_real_metadata_indices(sacc_data, allowed_data_type=None)

Extract all two-point function metadata from a sacc file.

Extracts the two-point function measurement metadata for all measurements made in real space from a Sacc object.

Parameters:
  • sacc_data (sacc.Sacc)

  • allowed_data_type (None | list[str])

Return type:

list[firecrown.metadata_functions._type_defs.TwoPointRealIndex]

firecrown.metadata_functions.extract_all_harmonic_metadata_indices(sacc_data, allowed_data_type=None)

Extracts the two-point function metadata from a sacc file.

Parameters:
  • sacc_data (sacc.Sacc)

  • allowed_data_type (None | list[str])

Return type:

list[firecrown.metadata_functions._type_defs.TwoPointHarmonicIndex]

firecrown.metadata_functions.extract_all_harmonic_metadata(sacc_data, allowed_data_type=None, include_maybe_types=False)

Extract the two-point function metadata and data from a sacc file.

Parameters:
  • sacc_data (sacc.Sacc)

  • allowed_data_type (None | list[str])

Return type:

list[firecrown.metadata_types.TwoPointHarmonic]

firecrown.metadata_functions.extract_all_real_metadata(sacc_data, allowed_data_type=None, include_maybe_types=False)

Extract the two-point function metadata and data from a sacc file.

Parameters:
  • sacc_data (sacc.Sacc)

  • allowed_data_type (None | list[str])

Return type:

list[firecrown.metadata_types.TwoPointReal]

firecrown.metadata_functions.extract_all_photoz_bin_combinations(sacc_data, include_maybe_types=False)

Extracts the two-point function metadata from a sacc file.

Parameters:
  • sacc_data (sacc.Sacc)

  • include_maybe_types (bool)

Return type:

list[firecrown.metadata_types.TwoPointXY]

firecrown.metadata_functions.extract_window_function(sacc_data, indices)

Extract ells and weights for a window function.

Params sacc_data:

the Sacc object from which we read.

Params indices:

the indices of the data points in the Sacc object which are computed by the window function.

Returns:

the ells and weights of the window function that match the given indices from a sacc object, or a tuple of (None, None) if the indices represent the measured Cells directly.

Parameters:
  • sacc_data (sacc.Sacc)

  • indices (numpy.typing.NDArray[numpy.int64])

Return type:

tuple[None | numpy.typing.NDArray[numpy.int64], None | numpy.typing.NDArray[numpy.float64]]

firecrown.metadata_functions.maybe_enforce_window(ells, indices, sacc_data)

Possibly enforce a window function on the given ells.

Parameters:
  • ells (numpy.typing.NDArray) – The original ell values.

  • indices (numpy.typing.NDArray[numpy.int64]) – The indices of the data points in the SACC object.

  • sacc_data (sacc.Sacc) – The SACC object containing the data.

Returns:

A tuple containing the possibly replaced ells and the window weights.

Return type:

tuple[numpy.typing.NDArray[numpy.int64], None | numpy.typing.NDArray[numpy.float64], None | numpy.typing.NDArray]

firecrown.metadata_functions.make_all_photoz_bin_combinations(inferred_galaxy_zdists)

Extract the two-point function metadata from a sacc file.

Parameters:

inferred_galaxy_zdists (list[firecrown.metadata_types.InferredGalaxyZDist])

Return type:

list[firecrown.metadata_types.TwoPointXY]

firecrown.metadata_functions.make_all_photoz_bin_combinations_with_cmb(inferred_galaxy_zdists, cmb_tracer_name='cmb_convergence', include_cmb_auto=False)

Create all galaxy combinations plus mdt.CMB-galaxy cross-correlations.

Parameters:
  • inferred_galaxy_zdists (list[firecrown.metadata_types.InferredGalaxyZDist]) – List of galaxy redshift bins

  • cmb_tracer_name (str) – Name of the mdt.CMB tracer

  • include_cmb_auto (bool) – Whether to include mdt.CMB auto-correlation (default: False)

Returns:

List of all XY combinations including mdt.CMB-galaxy crosses

Return type:

list[firecrown.metadata_types.TwoPointXY]

firecrown.metadata_functions.make_cmb_galaxy_combinations_only(inferred_galaxy_zdists, cmb_tracer_name='cmb_convergence')

Create only mdt.CMB-galaxy cross-correlations.

Parameters:
Returns:

List of mdt.CMB-galaxy cross-correlation XY combinations only

Return type:

list[firecrown.metadata_types.TwoPointXY]

firecrown.metadata_functions.match_name_type(tracer1, tracer2, a, b, require_convention=False)

Use the naming convention to assign the right measurement to each tracer.

Given two tracer names and two measurements, this function inspects the tracer names against the lens, source, and CMB naming conventions to determine the correct pairing of names and measurements. The returned names and measurements may be reordered relative to the inputs so that the lens (or CMB) tracer always comes first. The function also returns a boolean indicating whether we are able to apply the naming convention to verify that the right type is associated with the right tracer name.

If the function is able to determine that the tracer names and the measurement types are not compatible, then an exception is raised.

If the tracer names follow the convention but the measurement types are not consistent with those name, then an exception is raised.

If the tracer names follow the convention and the measurement types are consistent with those names and the association is not ambiguous, the boolean value is True and the names and measurements are returned in the order consistent with the convention.

If none of the above applies, and if require_convention is False,, then the boolean value is False and the names and measurements are returned in the original order.

If none of the above applies and if require_convention is True, then if the tracer names match the same convention, then the returned boolean value is False, and we return the tracer names and measurements in the original order.

Otherwise, an exception is raised.

Parameters:
  • tracer1 (str) – the name of the first tracer.

  • tracer2 (str) – the name of the second tracer.

  • a (firecrown.metadata_types.Measurement) – the measurement associated with tracer1.

  • b (firecrown.metadata_types.Measurement) – the measurement associated with tracer2.

  • require_convetion – if True, raise a ValueError when the tracer names do not match any recognised naming convention.

  • require_convention (bool)

Returns:

a tuple of (matched, tracer_name1, measurement1, tracer_name2, measurement2), where the names and measurements have been reordered to satisfy the naming convention when necessary, and matched indicates that an unambiguous association between names and measurement types has been made.

Return type:

tuple[bool, str, firecrown.metadata_types.Measurement, str, firecrown.metadata_types.Measurement]

firecrown.metadata_functions.make_two_point_xy(inferred_galaxy_zdists_dict, tracer_names, data_type)

Build a mdt.TwoPointXY object from the inferred galaxy z distributions.

The mdt.TwoPointXY object is built from the inferred galaxy z distributions, the data type, and the tracer names.

Parameters:
Returns:

a mdt.TwoPointXY object.

Return type:

firecrown.metadata_types.TwoPointXY

firecrown.metadata_functions.measurements_from_index(index)

Return the tracer names and measurements from a two-point index.

The tracer names and measurements are extracted from the index using the naming convention enforced by match_name_type(). The names and measurements are reordered to satisfy the convention when necessary.

Parameters:

index (firecrown.metadata_functions._type_defs.TwoPointRealIndex | firecrown.metadata_functions._type_defs.TwoPointHarmonicIndex) – a two-point index containing tracer names and a data type.

Returns:

a tuple of (tracer_name1, measurement1, tracer_name2, measurement2).

Return type:

tuple[str, firecrown.metadata_types.Measurement, str, firecrown.metadata_types.Measurement]