This page documents the public function and class library for the IRATE format tool package. These modules can be used by other programs or users to simplify various processing tasks relating to the IRATE format. The following modules are present:
General tools of use with the IRATE format, such as creating standard sections or quickly extracting particles. Note that these functions should be imported directly from the irate namespace.
Code for testing if a file obeys the IRATE format and tools for extending this process (see Custom Validators/Extending the IRATE Format)
These modules all contain functions used by the Command Line Scripts and Conversion Tools to convert files in other formats from or to IRATE. This documentation is provided to allow other programs to easily script such conversions without using the command line tools.
Not that the base irate module contains most of the irate.core functionality, as well as __version__, which contains a string with the version of the IRATE tools, and formatversion, which contains an integer specifying the format version.
The irate.core module contains the core utilities used by IRATE. These include a variety of convinience functions for working with IRATE format files. While they are technically part of the irate.core module, they are all also included in the base irate namespace, so the best way to import these is to do:
from irate import create_irate
rather than importing from irate.core.
Creates or updates a cosmology section of an IRATE file.
This function creates an IRATE file or opens it if it already exists, and either adds the given cosmology-related values to it, checks that they match with what’s in the existing file, or updates the cosmology with the given values.
Parameters: |
|
---|---|
Raises: |
|
Adds or updates a cosmology from the name of a standard cosmology.
The cname parameter gives the name of the cosmology to be used from the list below, while all other parameters are the same as for the add_cosmology() function.
‘WMAP7’
LCDM Cosmological parameters for the 7-year WMAP data (Komatsu et al. 2011). For details, see http://lambda.gsfc.nasa.gov/product/map/dr4/params/lcdm_sz_lens_wmap7.cfm
‘WMAP5’
LCDM Cosmological parameters for the 5-year WMAP data (Komatsu et al. 2009). For details, see http://lambda.gsfc.nasa.gov/product/map/dr3/params/lcdm_sz_lens_wmap7.cfm
‘WMAP3’
LCDM Cosmological parameters for the 3-year WMAP data (Spergel et al. 2007). For details, see http://lambda.gsfc.nasa.gov/product/map/dr2/params/lcdm_sz_lens_wmap7.cfm
‘WMAP1’
LCDM Cosmological parameters for the 1-year WMAP data. For details, see Spergel et al. 2003.
Convinience function to determine the number of particles of each type in an IRATE format file.
Parameters: | |
---|---|
Returns: | a 3-namedtuple (ndark,nstar,ngas) |
Convinience function to determine the number of entries in an IRATE halo catalog file.
Parameters: | |
---|---|
Returns: | an integer with the total number of halos |
A Convinience function to create an IRATE format file data as numpy arrays. This will overwrite a currently existing file.
Parameters: |
|
---|---|
Returns: | The h5py.File of the newly-created file (still open). |
Raises: |
|
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: |
|
---|---|
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. |
Splits a single IRATE file into separate files for each dataset.
Parameters: |
|
---|---|
Returns: | A list of filenames that were created with the base name as the first. |
Combine all external file that are part of a master IRATE file into a single monolithic file.
Note
This function can be driven from the command line via the irategather script. See Command Line Scripts and Conversion Tools for details.
Parameters: |
|
---|---|
Returns: | (outfilename,filelist) where outfilename is the name of the output file, and filelist is a list of all the files gathered together to create this file. |
Gets a metadata value from an IRATE file dataset.
Parameters: | |
---|---|
Returns: | The value of the metadata requested, or None if the metadata with the requested name does not exist. |
Raises TypeError: | |
If the dataset is not a dataset |
Sets a metadata value for an IRATE file dataset.
Parameters: |
---|
Note
Any other datasets with the same as this one below this group in the heirarchy will be assigned the same units (unless that dataset overrides them itself).
Raises: |
|
---|
Note
A MetadataHiddenWarning will be issued as a warning if the metadata for this dataset has already been set somewhere lower down in the heirarchy than the requested group. The result of this is that this function will not alter the resulting units for the dataset because it will be overshadowed by the metadata setting further down. (see warnings for an explanation of warnings)
Gets the units for a dataset in an IRATE file.
Because units are typically expressed in factors of the hubble constant and may or may not be comoving or otherwise varying with scale factor, two additional factors are needed beyond the raw unit conversion. To use these together, the appropriate factor to multiple the dataset by to get to physical units for an assumed hubble parameter h and scale factor a is: tocgs`*h^`hubbleexponent`*a^`scalefactorexponent . Hence, for example, comoving Mpc/h would have tocgs =3.0857e24 , hubbleexponent =-1, and scalefactorexponent =1 .
Parameters: | dataset – A Dataset object in an IRATE file |
---|---|
Returns: | name,tocgs,hubbleexponent,scalefactorexponent. name is the name of the unit for this dataset, tocgs is a factor to multiply the dataset by to get cgs units, hubleexponent is the exponent of the reduced hubble parameter (h=H0/100) for this unit, and scalefactorexponent is the exponent describing how this unit varies with the scale factor. Alternatively, if no unit is found, None is returned. |
Note
I f you are not working with a file where you know for sure what the units are, is important to check whether or not the unit is None, because the IRATE format does not require units for all datasets, as some quantities are dimensionless. The easiest way to do this is:
res = get_units(mydataset)
if res is None:
... do something if it is unitless ...
else:
nm,tocgs,hexp,sfexp = res
... do something with the units ...
Raises TypeError: | |
---|---|
If dataset is not a dataset |
Sets the units of a dataset to the provided values.
Because units are typically expressed in factors of the hubble constant and may or may not be comoving or otherwise varying with scale factor, two additional factors are needed beyond the raw unit conversion. To use these together, the appropriate factor to multiple the dataset by to get to physical units for an assumed hubble parameter h and scale factor a is: tocgs`*h^`hubbleexponent`*a^`scalefactorexponent . Hence, for example, comoving Mpc/h would have tocgs =3.0857e24 , hubbleexponent =-1, and scalefactorexponent =1 .
Parameters: |
|
---|---|
Raises TypeError: | |
If an input is not the correct type |
Retrieves the factor to multiply by the dataset to convert to physical CGS units at a given scale factor and hubble constant.
Parameters: |
|
---|---|
Raises: |
|
The irate.validate module contains classes and functions for testing if a file conforms to the IRATE specification. It also contains tools for easily extending the validator to allow 3rd parties to provide validator modules for their formats.
See Custom Validators/Extending the IRATE Format for more details on how to write custom extensions to the IRATE format.
This exception is raised if a file is loaded that does not conform to the IRATE Format.
Validates the root level of an IRATE file.
The base class for classes that are intended to validate IRATE format files.
To implement a validator, a subclass must override validate(), which will be valled to validate a Group. If not, an object of the subclass will not be able to be created, as this is an abstract class. See the Validator.validate docstring for the correct way to report format errors when they are encountered.
A subclass should also define a groupname attribute at the class level - that name will be used to identify groups that are to be assigned to that validator.
Check the units on a dataset
Parameters: | |
---|---|
Returns: | True if the unit check succeeded, False if it failed because the name of the units does not match unitname, or None if it failed because no units are present. |
Note
If the dataset provided is not a dataset, this method will call invalid() with a message indicating that this occured.
Subclasses should override this - it is called to validate a particular h5py.Group that is matched to this validator.
If a problem is encountered, the validator should call Validator.invalid() with a message describing the problem. If a dataset on the validated group should have units, the check_units() method should be called on the dataset to check for units (or a specific unit name, if desired)
After this method finishes, all subgroups will also be validated - to skip validation for some subgroups, set the skipsubgroups attribute of this object to either a list of names to skip, or True to not validate any subgroups.
Thus, a simple example might be:
def validate(self,grp):
if 'somegroup' not in grp:
self.invalid('somegroup missing!')
self.skipsubgroups = ['ignorethisgroupname']
self.check_units(grp['datasetwunits'])
self.check_units(grp['distance'],'kpc')
Sets the active list of validators to those for the requested type.
Parameters: |
|
---|---|
Raises KeyError: | |
If tname is not a validator type name. |
Adds a set of validator classes as a type.
Parameters: |
|
---|---|
Raises TypeError: | |
If something in validators is not a Validator subclass. |
Identifies and returns the directory that stores custom validators.
Returns: | The directory where validator files are supposed to live |
---|---|
Raises OSError: | If no suitable directory can be found. |
Locates the appropriate validator based on the given group name.
Parameters: | groupname – The name of the group to match against a Validator groupname. |
---|---|
Returns: | The class matched to the provided group name or False if the search failed. |
Returns a list of all the validator types available, or all the validator classes associated with a given validator type.
Parameters: | tname – If None, returns a list of validator types, or if a validator type, returns a list of Validator subclasses for that type. |
---|---|
Returns: | A list of types if tname is None or a list of Validator subclasses |
Raises KeyError: | |
If tname is not a validator type name. |
Registers a Validator class for use by the find_validator() function.
Parameters: |
|
---|
Removes a set of type validators. :param tname: The name of the type to have its validators removed.
Raises KeyError: | |
---|---|
If tname is not a validator type name. |
Tests whether or not the file conforms to the IRATE format.
Parameters: |
|
---|---|
Returns: | A list of errors encountered (or an empty list if valid). |
Raises IRATEFormatError: | |
If any part of the file does not conform to the standard and immediatefail is True. |
Reads an AHF_halos file, then collimates it such that a list of column headers and a list of arrays, each of which corresponds to a column. All entries in the columns will be in the same order–i.e. the ith entry in column x corresponds to the same halo as the ith entry in column y.
Parameters: |
|
---|---|
Returns: | An array that contains the number of bins used for each halo in the radial profiles file, for the purpose of reading the .AHF_profiles file. |
Reads an AHF .parameter file and adds it to an existing IRATE file as attributes to the /CatalogHeader/AHF group.
Parameters: |
|
---|
Read a .AHF_particles file and save an array with all the particles in it in order, along with a list of the number of particles in each halo to an IRATE file. If there’s a particle identifier, the array is Nx2 with the identifier in the second column.
Parameters: |
|
---|
Read an ASCII .AHF_profiles file, collimate it, and return a list of data and a list of column headers. The list of data is a list over columns, then each halo has it’s own list within the columns.
Parameters: |
|
---|
The HDF5 v 1.8 method of reading and writing particles should allow me to use a lot less memory by periodically writing to the file (since v 1.8 allows for appending to datasets). Note that this will probably be slower than the 1.6 method, at least for small files, but if memory is a problem, this is probably the way to go.
Warning
THIS DOESN’T WORK RIGHT NOW. I can’t get the appending to work, so if you desperately want to use this function, you’ll have to fix it. In fact, I should probably just delete it, but I always hate doing that Furthermore, since it isn’t working, it hasn’t been updated to work adhere to the new IRATE format, so this function absolutely does NOT work.
Parameters: |
|
---|
Transforms Gadget type 3 (HDF5) snapshots into a format that meets the IRATE specifications. This will automatically check for Makefile enabled blocks.
Parameters: |
|
---|
# refers to the same names as Gadget2:
Reads a GADGET type 2 snapshot file block by block (e.g. coordinate block for gas particles), writes the block to an IRATE formate HDF5 file, and then deletes that block from memory. If a given block identifier isn’t recognized, one of two things will happen: either the script will figure out which particles that data belongs to and add it automatically with the dataset named according to the label used, or if it’s not obvious what particles the data belongs to, the user will be given the option to skip it or to exit entirely.
Parameters: |
|
---|
# refers to the same names as Gadget2:
Reads a GADGET format file block by block (e.g. coordinate block for gas particles), writes the block to an IRATE formate HDF5 file, and then deletes that block from memory.
Parameters: |
|
---|
# refers to the same names as Gadget2:
Converts a single snapshot in an IRATE format file into a SnapFormat = 1 Gadget binary file. If there are groups with “Star” in the name, they’re assumed to contain star particles and will be placed in Gadget group 4; likewise, if there are groups with “Gas” in the name, their particles will be placed in Gadget group 0. All other particles will be placed in Gadget group 5.
Parameters: |
|
---|
Warning
Currently unused in the IRATE suite, and definitely not maintained either. Use at your own risk.
Parameters: |
|
---|
Writes the already read data from EnBiD to an existing IRATE file under the Analysis group.
Parameters: |
|
---|
Warning
This function hasn’t been maintained and updated to the new format yet, so it’s not yet ready for use.
Parameters: | fname – The binary file to read. |
---|
Warning
This function hasn’t been maintained and updated to the new format yet, so it’s not yet ready for use.
Reads a Rockstar ASCII file and collimates it, then saves the data in an IRATE format file (creating one if it doesn’t exist).
Parameters: |
|
---|
load_tipsy_binary(fn, verbose=True, unitconv=True, compression=None, printiters=100000)
Load a Tipsy binary file using the tipsyapi tools.
Parameters: |
|
---|---|
Returns: | A dictionary with ‘dark’,’star’, and ‘gas’ entries that are dictionaries of strings to arrays that match the IRATE format. |
tipsy_to_hdf5(tipsyfn, hdfn=None, verbose=True, unitconv=True, compression=None, printiters=100000)
Converts a tipsy file to an equivalent HDF5 file.
Parameters: |
|
---|
Other arguments are the same as load_tipsy_binary().
Returns: | The h5py.File object (not closed). |
---|