roman_photoz
The roman_photoz package provides tools for processing catalogs
produced by the Roman Space Telescope Calibration Pipeline (romancal)
to estimate photometric redshift.
Overview
The Roman Space Telescope will produce large catalogs of astronomical objects. This package provides tools for processing these catalogs to estimate photometric redshifts using rail/LePhare. Key features include:
Processing Roman catalog data in ASDF format
Creating filter definitions based on Roman Space Telescope specifications
Generating simulated catalogs for development and testing
Estimating photometric redshifts using rail/LePhare
API Reference
- class roman_photoz.RomanCatalogHandler(catname: str = '', fit_colname: str = 'segment_{}_flux', fit_err_colname: str = 'segment_{}_flux_err')
Bases:
objectA class to handle Roman catalog operations including reading and formatting it in a suitable way for roman_photoz.
- format_catalog()
Format the catalog by appending necessary fields and columns.
- process()
Process the catalog by reading and formatting it.
- Returns:
The formatted catalog.
- Return type:
np.ndarray
- read_catalog()
Read the catalog file and convert it to a numpy structured array.
- class roman_photoz.RomanCatalogProcess(config_filename: dict | str = '', model_filename: str = 'roman_model.pkl')
Bases:
objectA class to process Roman catalog data using rail and lephare.
- data
Dictionary to store the processed data.
- Type:
dict
- flux_cols
List of flux columns.
- Type:
list
- flux_err_cols
List of flux error columns.
- Type:
list
- inform_stage
Informer stage for creating the library of SEDs.
- Type:
RailStage
- estimated
Estimator stage for finding the best fits from the library.
- Type:
RailStage
- model_filename
Name of the pickle model file.
- Type:
str
- create_estimator_stage()
Create the estimator stage to find the best fits from the library.
- create_informer_stage()
Create the informer stage to generate the library of SEDs with various parameters.
- get_data(input_filename, fit_colname: str = 'segment_{}_flux', fit_err_colname: str = 'segment_{}_flux_err') Table
Fetch the data from the input file.
- Parameters:
input_filename (str, optional) – Name of the input file.
- Returns:
The catalog data.
- Return type:
Table
- property informer_model_exists
Check if the informer model file exists.
- Returns:
True if the model file exists, False otherwise.
- Return type:
bool
- property informer_model_path
Get the path to the informer model file.
The path is determined by checking the INFORMER_MODEL_PATH environment variable first, falling back to LEPHAREWORK if not set.
- Returns:
The path to the informer model file.
- Return type:
str
- process(input_filename, output_filename: str = None, output_format: str = 'parquet', fit_colname: str = 'segment_{}_flux', fit_err_colname: str = 'segment_{}_flux_err')
Process the Roman catalog data.
- Parameters:
input_filename (str) – Name of the input file.
output_filename (str, optional) – Name of the output file.
output_format (str, optional) – Format to save the results. Supported formats are “parquet” (default) and “asdf.”
flux_type (str, optional) – The type of flux to use for fitting. Options are “psf” (default), “kron”, “segment”, or “aperture.”
- save_results(output_filename: str = None, output_format: str = 'parquet')
Save the results to the specified output file.
- Parameters:
output_filename (str, optional) – Name of the output file.
output_format (str, optional) – Format to save the results. Supported formats are “parquet” (default) and “asdf”.
- Raises:
ValueError – If there are no results to save.
- set_config_file(config_filename: dict | str = '')
Set the configuration file.
- Parameters:
config_filename (Union[dict, str], optional) – Path to the configuration file in JSON format or a configuration dictionary.
- update_input(input_filename)
- class roman_photoz.SimulatedCatalog(nobj: int = 1000, mag_noise: float = 0.1)
Bases:
objectA class to create a simulated catalog using the Roman telescope data.
- data
A dictionary to store the data.
- Type:
OrderedDict
- lephare_config
Configuration for LePhare.
- Type:
dict
- flux_cols
List of flux columns.
- Type:
list
- flux_err_cols
List of flux error columns.
- Type:
list
- inform_stage
Placeholder for inform stage.
- Type:
None
- estimated
Holds all the results from roman_photoz.
- Type:
None
- filter_lib
Placeholder for filter library.
- Type:
None
- simulated_data_filename
Filename for the simulated data.
- Type:
str
- simulated_data
Placeholder for simulated data.
- Type:
None
- abmag_to_njy(abmag)
- add_error(catalog, mag_noise: float = 0.1, seed: int = 42)
Add a Gaussian error to each magnitude column in the catalog.
For each magnitude column, this method adds: + a Gaussian noise with a mean equal to the original value and a standard deviation of mag_noise + an error column (<magnitude_column>_err) with values set to mag_noise.
- Parameters:
catalog (np.ndarray) – The catalog data.
mag_noise (float, optional) – The standard deviation of the Gaussian noise to be added to the observed magnitudes (default: 0.1).
seed (int, optional) – The seed for the random number generator.
- Returns:
The catalog data with error columns added.
- Return type:
np.ndarray
- add_ids(catalog)
Add an ID column to the catalog.
- Parameters:
catalog (np.ndarray) – The catalog data.
- Returns:
The catalog data with an ID column added.
- Return type:
np.ndarray
- create_column_names()
- create_filter_files()
Create filter files for the Roman telescope.
This method checks if the required filter files are present in the specified directory. If not, it generates them using the create_roman_filters module.
- Raises:
FileNotFoundError – If the filter files cannot be created or found.
- create_header(catalog_name: str)
Create the header for the catalog.
- Parameters:
catalog_name (str) – The name of the catalog file.
- Returns:
The list of column names for the catalog.
- Return type:
list
- create_simulated_data()
Generate simulated data using the LePhare configuration.
This method prepares the LePhare environment and generates simulated data for galaxies, stars, and quasars based on the provided configuration.
- Raises:
RuntimeError – If the LePhare preparation fails or the configuration is invalid.
- create_simulated_input_catalog(output_filename: str = 'roman_simulated_catalog.parquet', output_path: str = '')
Create a simulated input catalog from the simulated data.
- read the ROMAN_SIMULATED_MAGS.dat produced by LePhare’s
prepare method in create_simulated_input_catalog. The columns name are defined by LePhare.
format the columns name to match Roman catalog’s specifications
- create_simulated_roman_catalog(catalog)
Update the Roman catalog template with the simulated data.
- Parameters:
catalog (np.ndarray) – The catalog data to update the Roman catalog template with.
- is_folder_not_empty(folder_path: str, partial_text: str) bool
Check if a folder exists and contains files with the specified partial text.
- Parameters:
folder_path (str) – The path to the folder.
partial_text (str) – The partial text to look for in filenames.
- Returns:
True if the folder exists and contains files with the partial text, False otherwise.
- Return type:
bool
- pick_random_lines(num_lines: int)
Pick random lines from the data array.
- Parameters:
num_lines (int) – The number of random lines to pick.
- Returns:
An array containing the randomly picked lines.
- Return type:
np.ndarray
- process(output_path: str = '', output_filename: str = 'roman_simulated_catalog.parquet')
Run the process to create the simulated catalog.
- read_roman_template_catalog()
- roman_photoz.setup_logging(level=20)
Set up logging configuration for roman_photoz module