Reference Guide and Tools API

The IRATE library includes convinience functions for working with IRATE format files. The functions documented below are present in the irate namespace, so the typical way to import is:

from irate import validate_irate

rather than importing from irate.core.

Reference For IRATE core library

exception irate.core.IRATEFormatError

This exception is raised if a file is loaded that does not conform to the IRATE Format.

exception irate.core.StrictIRATEFormatError

This exception is raised if a file is loaded that does not conform to the strict IRATE Format.

irate.core.create_irate(fn, dark, star, gas, headername, headerdict=None, compression=None)

A Convinience function to create an IRATE format file data as numpy arrays. This will overwrite a currently existing file.

Parameters:
  • fn (str) – The file name to use for the new file
  • dark – The data for the dark matter particles. Should be a dict with keys ‘Position’, ‘Velocity’, ‘Mass’, (and possibly others) mapping to numpy.ndarray arrays. Alternatively, it can be a structured array (i.e. dtype with names and formats) with the names of the dtype giving the names of the resulting datasets.
  • star – The data for the star particles. See dark for format.
  • gas – The data for the gas particles. See dark for format.
  • headername (str) – The group name to use for the header entry or None to create no header.
  • headerdict – A dictionary mapping strings to attribute values. These will be used for the attributes of the header entry. If None, an attribute will be added to indicate header content is missing.
  • compression – The type of compression to use for the datasets. Can be any of the compression that h5py supports on your system (‘gzip’,’lzf’, or ‘szip’) or None to do no compression.
Returns:

The h5py.File of the newly-created file (still open).

Raises:
  • IRATEFormatError – If any of the data arrays are missing the necessary fields.
  • ValueError – If the input data is invalid.
irate.core.get_all_particles(fn, ptype, dataname, subsample=None, validate=True)

Convinience function to build an array with all the particles of a requested type or types (i.e. all subgroups, if present, will be visited).

Parameters:
  • fn (str) – The filename of an IRATE formatted file or a h5py.File object.
  • ptype (str) – The particle type: ‘Dark’,’Star’, ‘Gas’, a sequence of a mix of those three, or None for all particles of all types.
  • dataname (str) – The dataset name to extract (e.g. ‘Position’, ‘Mass’)
  • subsample (int) – Gives the stride of the data - e.g. each array will be spliced to only return every subsample data point. If None, all the data will be returned.
  • validate (bool) – If True, the file will be validate as IRATE format. If ‘strict’, strict validation will be used. Otherwise no validation will be performed.
Returns:

A 3-tuple (data,grpidx,grpmap) where data is the data arrays, grpidx is an int array with the same first dimension as data, and grpmap is a dictionary mapping the values in grpidx to group names.

Raises ValueError:
 

If a group does not have the requested dataname.

irate.core.get_irate_catalog_halo_nums(fn, validate=True)

Convinience function to determine the number of entries in an IRATE halo catalog file.

Parameters:
  • fn (str) – The filename of an IRATE halo catalog file or a h5py.File object.
  • validate (bool) – If True, the file will be validate as IRATE halo catalog format.
Returns:

an integer with the total number of halos

irate.core.get_irate_particle_nums(fn, validate=True)

Convinience function to determine the number of particles of each type in an IRATE format file.

Parameters:
  • fn (str) – The filename of an IRATE formatted file or a h5py.File object.
  • validate (bool) – If True, the file will be validate as IRATE format. If ‘strict’, strict validation will be used. Otherwise no validation will be performed.
Returns:

a 3-namedtuple (ndark,nstar,ngas)

irate.core.validate_catalog(file)

Ensures the supplied file conforms to the IRATE halo catalog format. If it does not, an exception will be raised.

Parameters:

file – The file name or h5py.File object to be validated.

Raises:
  • IOError – If the file does not exist or is not an HDF5 file.
  • IRATEFormatError – If the file is a valid HDF5 file, but does not conform to the IRATE halo catalog format. The exception message will describe the problem.
irate.core.validate_irate(file, strict=True)

Ensures the supplied file conforms to the IRATE format. If it does not, an exception will be raised.

Parameters:
  • file – The file name or h5py.File object to be validated.
  • strict (bool) – If True, does the addition checks for strict compliance (i.e. no additional elements at the root level beyond those in IRATE).
Raises:
  • IOError – If the file does not exist or is not an HDF5 file.
  • IRATEFormatError – If the file is a valid HDF5 file, but does not conform to the IRATE format. The exception message will describe the problem.
  • StrictIRATEFormatError – If the file is a valid HDF5 file, but does not conform to the strict IRATE format. These will only be raised if strict is True.

Table Of Contents

Previous topic

Command Line Scripts and Conversion Tools

This Page