rubix.galaxy.input_handler package#
Submodules#
rubix.galaxy.input_handler.base module#
- class rubix.galaxy.input_handler.base.BaseHandler(logger_config: dict | Logger | None = None)[source]#
Bases:
ABCBase class for handling input data and converting it to Rubix format.
- Parameters:
logger_config (Optional[Union[dict, logging.Logger]]) – Optional logger configuration passed to the internal get_logger helper.
- rubix.galaxy.input_handler.base.create_rubix_galaxy(file_path: str, particle_data: dict, galaxy_data: dict, simulation_metadata: dict, units: dict, config: dict, logger: Logger) None[source]#
Create a Rubix file with the given data.
- Parameters:
file_path (str) – Path to save the Rubix file.
particle_data (dict) – Dictionary containing the particle data.
galaxy_data (dict) – Dictionary containing the galaxy data.
simulation_metadata (dict) – Dictionary containing the simulation metadata.
units (dict) – Dictionary containing the units.
config (dict) – Dictionary containing the configuration.
logger (logging.Logger) – Logger object to log messages.
- Returns:
None
rubix.galaxy.input_handler.factory module#
rubix.galaxy.input_handler.illustris module#
- class rubix.galaxy.input_handler.illustris.IllustrisHandler(path, logger=None)[source]#
Bases:
BaseHandlerThis class is used to handle the input data from the Illustris simulation. The data is stored in HDF5 files, which are read using the h5py library. The data is then converted to physical units using the values in the header of the file. The data is then stored in a dictionary, which can be accessed using the get_particle_data() method.
Module contents#
- class rubix.galaxy.input_handler.BaseHandler(logger_config: dict | Logger | None = None)[source]#
Bases:
ABCBase class for handling input data and converting it to Rubix format.
- Parameters:
logger_config (Optional[Union[dict, logging.Logger]]) – Optional logger configuration passed to the internal get_logger helper.
- class rubix.galaxy.input_handler.IllustrisAPI(api_key: str, particle_type: List[str] | None = None, simulation: str = 'TNG50-1', snapshot: int = 99, save_data_path: str = './api_data', logger: Logger | None = None)[source]#
Bases:
objectThis class is used to load data from the Illustris API.
It loads both subhalo data and particle data from a given simulation, snapshot, and subhalo ID.
Check the source for the API documentation for more information: https://www.tng-project.org/data/docs/api/
- URL#
Base URL of the Illustris API.
- Type:
str
- DEFAULT_FIELDS#
Default particle fields to download per particle type.
- Type:
dict[str, list[str]]
- Parameters:
api_key (str) – API key for authenticating with the Illustris API.
particle_type (Optional[List[str]], optional) – Particle categories to download (default: [“stars”, “gas”]).
simulation (str, optional) – Simulation to connect to (default: “TNG50-1”).
snapshot (int, optional) – Snapshot ID to query (default: 99).
save_data_path (str, optional) – Directory where downloaded data will be stored.
logger (Optional[logging.Logger], optional) – Logger instance for debug output.
- Raises:
ValueError – If the API key is missing.
- DEFAULT_FIELDS: dict[str, list[str]] = {'gas': ['Coordinates', 'Density', 'Masses', 'GFM_Metallicity', 'GFM_Metals', 'StarFormationRate', 'InternalEnergy', 'Velocities', 'ElectronAbundance'], 'stars': ['Coordinates', 'GFM_InitialMass', 'GFM_Metallicity', 'GFM_StellarFormationTime', 'Velocities']}#
- get_particle_data(id: int, particle_type: str, fields: str | List[str]) dict[str, Any][source]#
Download particle cutouts for a subhalo.
- Parameters:
id (int) – Subhalo ID to load.
particle_type (str) – Particle species to request.
fields (Union[str, List[str]]) – Data fields to include.
- Returns:
Downloaded particle data.
- Return type:
dict[str, Any]
- Raises:
ValueError – If the particle type, fields, or ID are invalid.
- get_subhalo(id: int) dict[str, Any][source]#
Get subhalo data for a given Illustris ID.
- Parameters:
id (int) – Subhalo ID to load.
- Returns:
Subhalo metadata.
- Return type:
dict[str, Any]
- Raises:
ValueError – If the provided ID is not an integer.
- load_galaxy(id: int, overwrite: bool = False, reuse: bool = False) dict[str, Any][source]#
Download subhalo and particle data for a galaxy.
The function fetches subhalo metadata and configured particle fields and stores everything in a local HDF5 file.
- Parameters:
id (int) – Subhalo ID to download.
overwrite (bool, optional) – Overwrite an existing file if True.
reuse (bool, optional) – Reuse an existing file instead of redownloading it.
- Returns:
Loaded galaxy data.
- Return type:
dict[str, Any]
- Raises:
ValueError – If the download is blocked by an existing file or an unsupported particle type is configured.
Example
>>> illustris_api = IllustrisAPI( ... api_key, ... simulation="TNG50-1", ... snapshot=99, ... particle_type=["stars", "gas"], ... ) >>> illustris_api.load_galaxy(id=0)
- rubix.galaxy.input_handler.get_input_handler(config: dict, logger: Logger | None = None) BaseHandler | MagicMock[source]#
Create a handler based on the config.
- Parameters:
config (dict) – Configuration for the handler.
logger (Optional[logging.Logger]) – Optional logger object.
- Returns:
Handler based on the config, or a MagicMock for tests.
- Return type:
- Raises:
ValueError – If the simulation type specified in the config is unsupported.