rubix.galaxy.input_handler package#
Submodules#
rubix.galaxy.input_handler.base module#
- class rubix.galaxy.input_handler.base.BaseHandler(logger_config=None)[source]#
Bases:
ABC
Base class for handling input data and converting it to Rubix format.
- Parameters:
config (dict) – Configuration for the BaseHandler.
_logger (logging.Logger) – Logger object to log messages.
- 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)[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:
BaseHandler
This 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=None)[source]#
Bases:
ABC
Base class for handling input data and converting it to Rubix format.
- Parameters:
config (dict) – Configuration for the BaseHandler.
_logger (logging.Logger) – Logger object to log messages.
- class rubix.galaxy.input_handler.IllustrisAPI(api_key, particle_type: list = ['stars', 'gas'], simulation='TNG50-1', snapshot=99, save_data_path='./api_data', logger=None)[source]#
Bases:
object
This 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/
- DEFAULT_FIELDS = {'gas': ['Coordinates', 'Density', 'Masses', 'GFM_Metallicity', 'StarFormationRate', 'InternalEnergy', 'Velocities', 'ElectronAbundance'], 'stars': ['Coordinates', 'GFM_InitialMass', 'GFM_Metallicity', 'GFM_StellarFormationTime', 'Velocities']}#
- get_particle_data(id: int, particle_type, fields: str | List[str])[source]#
Get particle data from the Illustris API.
Returns the particle data for the given subhalo ID.
- Parameters:
id (int) – Subhalo ID to load.
fields (str or list) – Fields to load. If a string, the fields should be comma-separated.
- Returns:
Dictionary containing the particle data in the given fields (data).
- get_subhalo(id)[source]#
Get subhalo data from the Illustris API.
Returns the subhalo data for the given subhalo ID.
- Parameters:
id (int) – Subhalo ID to load.
- Returns:
The subhalo data as a dictionary (r).
- load_galaxy(id: int, overwrite: bool = False, reuse: bool = False)[source]#
Download Galaxy Data from the Illustris API.
This function downloads both the subhalo data and the particle data for stars and gas particles, for the fields specified in DEFAULT_FIELDS. It saves the data in a HDF5 file.
- Parameters:
id (int) – The ID of the subhalo to download.
overwrite (bool) – Whether to overwrite the file if it already exists. Default is False.
reuse (bool) – Whether to reuse the file if it already exists. Default is False.
- Returns:
The galaxy data as dictionary.
Example
>>> illustris_api = IllustrisAPI(api_key, simulation="TNG50-1", snapshot=99, particle_type=["stars", "gas"]) >>> data = illustris_api.load_galaxy(id=0, verbose=True)
- rubix.galaxy.input_handler.get_input_handler(config: dict, logger=None) BaseHandler [source]#
Creates a handler based on the config
- Parameters:
config (dict) – Configuration for the handler
logger (Logger) – Logger object
- Returns:
BaseHandler based on the config