Create Simulated Catalog
This module provides functionality to create a simulated catalog using data from the Roman Space Telescope. It leverages the LePhare photometric redshift estimation tool and other utilities to generate simulated data, process it, and save it in a structured format.
Module API
- class roman_photoz.create_simulated_catalog.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.create_simulated_catalog.main()
Command-Line Usage
The module can also be executed as a standalone script to create a simulated catalog. It provides command-line arguments for specifying the output path and filename.
Arguments
--output_path(str) Path to save the output catalog (default:LEPHAREWORK).--output_filename(str) Filename for the output catalog (default:roman_simulated_catalog.asdf).
Example
python -m roman_photoz.create_simulated_catalog --output_path=/path/to/output/ --output_filename=simulated_catalog.asdf
Usage Examples
The following example demonstrates how to programmatically create a simulated catalog:
from roman_photoz.create_simulated_catalog import CreateSimulatedCatalog
# Initialize the catalog creator with default parameters
creator = CreateSimulatedCatalog()
# Create a simulated catalog with 100 sources
catalog = creator.create_catalog(n_sources=100)
# Save the catalog to a file
creator.save_catalog(
catalog,
output_path="/path/to/output/",
output_filename="simulated_catalog.asdf"
)
print(f"Simulated catalog with {len(catalog)} sources created successfully")