SimFiles¶
-
class
simfiles._simfiles.
SimFiles
(snap_id, configfile=None, ncpu=2, share_mode=False, single_file=None)[source]¶ Provides a generic interface to simulation hdf5 files.
SimFiles is a dict with added features, notably __getattr__ and __setattr__, and automatic loading of data from simulation files based on a configuration file.
Parameters: - snap_id : index
An identifier for a specific simulation snapshot. The exact format is defined in the configuration for the simulation in question.
- configfile : str
Path to the configuration file to use (default: None).
- ncpu : int
Number of processors on which to run (default: 2).
- share_mode : bool
Setting ‘True’ disables the __delitem__ method (default: False) and suppresses warnings for repeated loading of the same keys.
- single_file : int
Specify to load from only a specific hdf5 file ‘piece’ of the snapshot. Assumes ‘pieces’ end in ‘.X.hdf5’ where X is an integer.
Returns: - out : SimFiles
A SimFiles object configured using the file provided.
Examples
The following example sets up a SimFiles instance, loads a few keys, and accesses the loaded data, for APOSTLE simulation data on the cavi system:
from simfiles import SimFiles from simfiles.configs.APOSTLE_cavi import __file__ as configfile import namedtuple snap_id = namedtuple('snap_id', ['res', 'phys', 'vol', 'snap']) mysnap = snap_id(res=3, phys='hydro', vol=1, snap=127) SF = SimFiles(mysnap, configfile=configfile) SF.load(keys=('m_s', 'xyz_s', 'vxyz_s')) # print mass and coordinates of one particle # both dict-like and attribute-like access are supported # this config file supports units via astropy.units print(SF.m_s[0], SF['xyz_s'][0])
-
clear
() → None. Remove all items from D.¶
-
copy
() → a shallow copy of D¶
-
fields
(keytype='all')[source]¶ Return a list of available keys, optionally for a specific keytype.
Parameters: - keytype : str
Specify which type of keys to include (default: ‘all’).
-
fromkeys
($type, iterable, value=None, /)¶ Create a new dictionary with keys from iterable and values set to value.
-
get
($self, key, default=None, /)¶ Return the value for key if key is in the dictionary, else default.
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
load
(keys=(), filetype=None, intervals=None, verbose=False)[source]¶ Load data for a set of keys.
Parameters: - keys : iterable
List of keys to load (default: tuple()).
- filetype : str
Advanced use only, override filetype defined in config file (default: None).
- intervals : iterable
List containing lists of 2-tuples, one for each key. Each 2-tuple represents an interval of indices from the underlying data table to load (default: None).
- verbose : bool
Setting ‘True’ prints messages upon loading each key (default: False).
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised
-
popitem
() → (k, v), remove and return some (key, value) pair as a¶ 2-tuple; but raise KeyError if D is empty.
-
setdefault
($self, key, default=None, /)¶ Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
-
update
([E, ]**F) → None. Update D from dict/iterable E and F.¶ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
-
values
() → an object providing a view on D's values¶