cosmocore.settings module
Configuration management for cosmological analysis parameters.
This module provides the InputParams class for managing configuration parameters used in cosmological analysis workflows. It handles parameter validation, default settings, YAML file loading, and derived parameter computation for CMB analysis pipelines.
Classes
- InputParams
Parameter management class for cosmological analysis configuration.
Functions
- spec2idx
Convert field indices to spectrum index for compressed storage.
- idx2spec
Convert spectrum index back to field indices.
Notes
The module integrates with HEALPix for spherical harmonic analysis and supports YAML-based configuration files for parameter management. Key functionality includes: - Default parameter initialization - Configuration file loading and parsing - Automatic computation of derived parameters - Automatic field label expansion (e.g., “QU” -> [“Q”, “U”]) - Parameter validation and updates
- class cosmocore.settings.InputParams[source]
Bases:
objectParameter management class for cosmological analysis configuration.
This class handles all configuration parameters for cosmological analysis workflows, including HEALPix pixelization settings, field specifications, file paths, analysis options, and automatic computation of derived parameters.
- Parameters:
None – Initialized with default parameter values. Use update() method or read_parameter_file() to load custom configurations.
- labels
Field labels, e.g., [“T”, “E”, “B”] for temperature and polarization. Supports automatic expansion: “QU” -> [“Q”, “U”], “T1_T2” -> [“T1”, “T2”].
- physical_labels
Physical field labels for map data (defaults to same as labels). Supports automatic expansion: “TQU” -> [“T”, “Q”, “U”], “LOW_HIGH” -> [“LOW”, “HIGH”].
- covmatfile1, covmatfile2
Paths to noise covariance matrix files.
- Type:
- outinvcovmatfile1, outinvcovmatfile2
Paths for output inverse covariance matrices.
- Type:
- load_reduced
If True, read noise covariance matrices that have already been reduced to active pixels (via
read_covmat_reduced) instead of extracting the active-pixel sub-block from a full-sky covariance (viaread_covmat). Default is False.- Type:
- input_convention
Power spectrum convention of input files:
"Cl"(default) or"Dl". When set to"Dl", input spectra are converted from \(D_\ell = \ell(\ell+1) C_\ell / (2\pi)\) to \(C_\ell\) on read.- Type:
- output_convention
Power spectrum convention for QML output:
"Cl"(default) or"Dl". When set to"Dl", output spectra are converted from internal \(C_\ell\) to \(D_\ell\) before being returned.- Type:
- Derived Attributes
- ------------------
- cross_idxs
Indices for cross-correlation spectra.
- Type:
- auto_idxs
Indices for auto-correlation spectra.
- Type:
Examples
Create default parameters:
>>> params = InputParams() >>> print(params.nside, params.lmax) 16 64
Load from YAML file:
>>> params = InputParams.read_parameter_file('config.yaml')
Update specific parameters:
>>> params.update({'nside': 32, 'lmax': 128}) >>> print(params.npix) # Automatically recomputed 12288
Field label expansion:
>>> params.update({'physical_labels': ['QU']}) >>> print(params.physical_labels) # Expands to ['Q', 'U'] ['Q', 'U'] >>> params.update({'labels': ['T1_T2']}) >>> print(params.labels) # Expands to ['T1', 'T2'] ['T1', 'T2']
Notes
The class automatically computes derived parameters when base parameters are updated. This ensures consistency between related parameters like nside and npix, or labels and nfields.
Field Label Expansion: The class supports automatic expansion of concatenated field labels:
Single-character concatenation: “QU” -> [“Q”, “U”], “TEB” -> [“T”, “E”, “B”]
Underscore separation: “T1_T2” -> [“T1”, “T2”], “LOW_HIGH” -> [“LOW”, “HIGH”]
Mixed formats: [“T”, “QU”, “E1_E2”] -> [“T”, “Q”, “U”, “E1”, “E2”]
This expansion is applied automatically when updating ‘labels’ or ‘physical_labels’ parameters, providing backward compatibility while supporting flexible field specification formats.
- set_defaults()[source]
Set default values for all configuration parameters.
Notes
Establishes standard defaults suitable for CMB analysis: - HEALPix nside=16 for moderate resolution - Temperature and polarization fields [0, 2] spins - Standard CMB field labels [“T”, “E”, “B”] - Typical file paths for inputs and outputs - Reasonable beam and analysis parameters
- compute_derived()[source]
Compute derived parameters from base configuration.
Notes
Automatically calculates: - nfields from the length of labels - nspectra for auto and cross correlations - npix from HEALPix nside parameter - cross_idxs and auto_idxs arrays for spectrum indexing
This method is called automatically when parameters are updated to ensure consistency between related parameters.
- update(config_dict)[source]
Update parameters from a configuration dictionary.
- Parameters:
config_dict (dict) – Dictionary containing parameter names and values to update.
Notes
Updates any existing parameter attributes with values from the configuration dictionary. After updating, automatically recomputes derived parameters and sets physical_labels if not already defined.
Field expansion is applied to both ‘labels’ and ‘physical_labels’ if they contain concatenated field specifications like “QU” -> [“Q”, “U”]. Non-existent attributes are silently ignored.
- static read_parameter_file(yaml_file)[source]
Load parameters from a YAML configuration file.
- Parameters:
yaml_file (str) – Path to YAML file containing parameter configurations.
- Returns:
New InputParams instance with parameters loaded from file.
- Return type:
Notes
Creates a new InputParams instance, loads the YAML file, and updates the parameters with the file contents. Useful for loading standardized analysis configurations from file.
- __str__()[source]
Return string representation of all parameters.
- Returns:
Formatted string with all parameter names and values.
- Return type:
- __eq__(other)[source]
Check equality with another InputParams instance.
- Parameters:
other (object) – Object to compare with.
- Returns:
True if all parameter values are equal, False otherwise.
- Return type:
Notes
Compares all attributes for equality. Useful for testing and validation of parameter configurations.