API Reference

This page provides detailed information about the galaxyGenius API.

Core Classes

Configuration

class galaxyGenius.config.Configuration(surveys: str | list[str] | None = None)[source]

Bases: object

The Configuration class handles all configuration settings for galaxyGenius, including:

  • Main configuration settings

  • Survey-specific configurations

  • Configuration validation and management

__init__(surveys: str | list[str] | None = None)[source]
init()[source]

Initialize configuration. Only use by init.py

add_survey(surveys: str | list[str] | None = None)[source]

Add surveys. Call get_config() to get the updated configs.

Parameters:

surveys (str or list[str] or None) – Survey names to add. If None, no surveys will be added.

remove_survey(surveys: str | list[str] | None = None)[source]

Remove surveys. Call get_config() to get the updated configs.

Parameters:

surveys (str or list[str] or None) – Survey names to remove. If None, no surveys will be removed.

save_config(conf: dict | None = None)[source]

Manually save the current configuration to the specified TOML files.

Parameters: conf (dict, optional): A dictionary containing configuration values.

get_config()[source]

Update and return the current configuration.

Returns:

The updated configuration dictionary.

Return type:

dict

check_config() int[source]

Check the configuration for any inconsistencies and issues.

Returns:

The number of issues found in the configuration.

Return type:

int

PreProcess

class galaxyGenius.preprocess.PreProcess(config: dict)[source]

Bases: object

The PreProcess class handles the preparation of data for SKIRT simulation:

  • Reading and processing subhalo data

  • Preparing particle data

  • Creating SKIRT input files

  • Managing simulation parameters

__init__(config: dict)[source]
get_subhalos() dict[source]

Retrieve subhalos from TNG snapshot or from requests.

Returns:

A dictionary containing subhaloIDs, SFRs.

Return type:

dict

subhalo(subhaloID: int)[source]

Specify one subhalo to be processed

Parameters:

subhaloID (int) – subhaloID of the subhalo to be processed

static _angular_momentum(coords, vels, masses)[source]

Calculates Total L with mass weighting.

get_default_params()[source]

Returns default parameters and their units for stars and gas (if includeDust is True).

Parameters:

None

Returns:

returns – Returns a tuple, where the first element is a dictionary of star parameters and their units, and the second element is a dictionary of gas parameters and their units (if includeDust is True). If includeDust is False, then the tuple contains only the star parameters and their units. The format of the dictionaries is {parameter: unit}.

Return type:

tuple

includeParams(starParams: list | dict | None = None, gasParams: list | dict | None = None, **kwargs)[source]

Adds parameters to the list of parameters to include in the data.

Parameters:
  • starParams (list or dict, optional) – List of parameters to include for stars. If a list is given, it should contain the parameter names as strings. If a dict is given, it should be in the format {parameter: unit}. In this case, the unit is not used to deduce the unit of the parameter but is directly used.

  • gasParams (list or dict, optional) – List of parameters to include for gas particles. If a list is given, it should contain the parameter names as strings. If a dict is given, it should be in the format {parameter: unit}. In this case, the unit is not used to deduce the unit of the parameter but is directly used.

  • **kwargs – Additional keyword arguments are not used.

Returns:

This function does not return anything.

Return type:

None

inputSubhaloParticleFile(subhaloParticleFile: str, subhaloInfo: dict, centerPosition: list | Quantity | None = None)[source]

Input subhalo particle file in h5 format.

Parameters:
  • subhaloParticleFile (str) – path to the subhalo particle file in h5 format.

  • subhaloInfo (dict) – dictionary containing information about the subhalo, required: SubhaloID, stellarMass, halfStellarMassRadius.

  • centerPosition (Union[list, u.Quantity, None], optional) – center position of the galaxy. If None, the particles are assumed to be in center coordinates.

createFile(paramNames, partType, saveFilename, function)[source]

Create a file containing the parameters of particles of a given type.

Parameters:
  • paramNames (list) – List of parameter names.

  • partType (str) – Type of particles.

  • saveFilename (str) – Path to save the file.

  • function (function) – Function used to process particles.

inputParticles(partType: str, particles: dict, subhaloInfo: dict, cosmology: Cosmology | None = None, centerPosition: list | Quantity | None = None)[source]
modify_configs(arguments: dict)[source]
inputs(data: dict)[source]
prepare(arguments: dict | None = None)[source]

DataGeneration

class galaxyGenius.generation.DataGeneration(config: dict)[source]

Bases: object

The DataGeneration class manages the SKIRT radiative transfer simulation process:

  • Running SKIRT simulations

  • Managing input/output files

  • Handling data cube generation

__init__(config: dict)[source]
runSKIRT(skirtPath: str | None = None)[source]

Run SKIRT radiative transfer simulation.

This method executes the SKIRT radiative transfer simulation using the configured parameters. It checks required files, runs SKIRT, saves the output data cube, and cleans up temporary files.

Parameters:

skirtPath (str, optional) – Path to SKIRT executable. If None, assumes ‘skirt’ is in PATH.

Returns:

0 if successful, exits with error otherwise.

Return type:

int

PostProcess

class galaxyGenius.postprocess.PostProcess(subhaloID: int)[source]

Bases: object

The PostProcess class handles the post-processing of simulation results:

  • Processing data cubes

  • Generating bandpass images

  • Creating SEDs

  • Visualizing results

__init__(subhaloID: int)[source]
static integrate_bandpass(img, tran, wave)[source]
runPostprocess(showImages: bool = False)[source]

This method performs the post-processing of the mock observations for the specified subhalo.

Parameters:

showImages (bool, optional) – If True, displays the generated images, and can only work in Jupyter environment.

Utility Functions

Utility functions for various operations including:

  • Data conversion and manipulation

  • File handling

  • Mathematical operations

  • Visualization helpers

class galaxyGenius.utils.Units(cosmology=None, snapRedshift=None, reinitialize=False)[source]

Bases: object

__init__(cosmology=None, snapRedshift=None, reinitialize=False)[source]
get_cosmology()[source]
get_snapRedshift()[source]
unit_convention()[source]
explain()[source]

Default unit conventions are used by TNG simulation:

  • distance: ckpc / h

  • density: (10**10 * Msun) / (ckpc / h)^3

  • mass: 10**10 * Msun

  • sfr: Msun / yr

  • velocity: km * sqrt(a) / s

  • potential: (km / s)^2 / a

  • temperature: K

  • energy: (km / s)^2

comoving quantities can be converted to physical ones by multiplying for the appropriate power of the scale factor a. For instance, to convert a length in physical units it is sufficient to multiply it by a, volumes need a factor a^3, densities a^-3 and so on.

When using other simulations, the unit convention can be re-defined.

galaxyGenius.utils.setup_logging(log_file='galaxygenius.log', log_level=20, force_reconfigure=False)[source]

Set up logging configuration that can be used across multiple modules

Parameters:
  • log_file (default: 'galaxygenius.log') – Path to the log file

  • log_level (default: 20) – Logging level (default: logging.INFO)

  • force_reconfigure (default: False) – If True, forces reconfiguration even if handlers exist. Use this after moving log files to update file handlers.

galaxyGenius.utils.galaxygenius_data_dir()[source]
galaxyGenius.utils.u2temp(u_energy: float | Quantity, x_e: float) float[source]

u_energy: InternelEnergy x_e: ElectronAbundance

return: T: temperatrure in K

Return type:

float

galaxyGenius.utils.convert_to_rgb(bandpassImage: ndarray | list, idx: list = [2, 3, 5]) ndarray[source]

Convert the bandpass image to RGB image

Parameters:
  • bandpassImage (Union[ndarray, list]) – bandpass image

  • idx (list, default: [2, 3, 5]) – index of the bandpass image used to create the RGB image

Returns:

RGB image

Return type:

rgb

galaxyGenius.utils.split(string: str, castType: type | None = None) list[source]

Split the string into a list

Parameters:
  • string (str) – string to be split

  • castType (Optional[type], default: None) – type of the elements in the list

Returns:

list of the split string

Return type:

splits

galaxyGenius.utils.get_wavelength_scale(filename: str) float[source]

Get the wavelength scale of the filter

Parameters:

filename (str) – filename of the filter

Returns:

wavelength scale of the filter

Return type:

wavelength_scale

galaxyGenius.utils.get_wavelength_unit(filename: str) Unit[source]
Return type:

Unit

galaxyGenius.utils.calc_pivot(dataDir: str, survey: str, filter: str) float[source]

Calculate the pivot wavelength of the filter

Parameters:
  • dataDir (str) – directory of the data

  • survey (str) – survey name

  • filter (str) – filter name

Returns:

pivot wavelength of the filter

Return type:

pivot

galaxyGenius.utils.copyfile(src: str, tar: str)[source]
galaxyGenius.utils.extend(values: int | float | list | Quantity, nums: int) list[source]

Extend the values to list with size consistent with nums

Parameters:
  • values (Union[int, float, list, Quantity]) – values to be extended

  • nums (int) – number of values to be extended

Returns:

extended values

Return type:

values

galaxyGenius.utils.custom_serialier(obj)[source]

Custom serializer for json dump

Parameters:

obj – object to be serialized

Returns:

serialized object

Return type:

obj

galaxyGenius.utils.check_exist_and_assign_unit(conf, key, unit)[source]
galaxyGenius.utils.handle_array(key, conf, unit)[source]
galaxyGenius.utils.assign_unit(conf)[source]
galaxyGenius.utils.to_quantity_list(value)[source]
galaxyGenius.utils.read_properties(workingDir: str) dict[source]
Return type:

dict

galaxyGenius.utils.read_config(directory: str) dict[source]
Return type:

dict