Reading GRMHD Output Files¶
There are two levels of interface for reading GRMHD files in pyharm. The more common is the higher-level pyharm.fluid_dump.FluidDump class, but for more control one can opt to use the pyharm.io module.
This page has the documentation for creating & using FluidDump objects, but to get anything from them you will want to see Keys.
FluidDump Objects¶
-
class
pyharm.fluid_dump.FluidDump(fname, tag='', ghost_zones=False, grid_cache=True, cache_conn=False, units=None, add_grid=True, params=None)¶ Read and cache data from a fluid dump file in any supported format, and allow accessing various derived properties directly.
-
__getitem__(key)¶ Get any of a number of different things from the backing dump file, or from a cached version. The full list of keys is covered in depth in the documentation at Keys.
Also allows slicing FluidDump objects to get just a section, and read/operate on just that section thereafter. This supports only a small subset of slicing operations: you must pass a tuple of three elements, all of which must either be integers or slice objects (not None). Due to overloading, it is thus impossible to allow requesting lists of variables at once. I have no idea why you’d want that. Just, don’t.
-
__init__(fname, tag='', ghost_zones=False, grid_cache=True, cache_conn=False, units=None, add_grid=True, params=None)¶ Attach the fluid dump file ‘fname’ and make its contents accessible like a dictionary. For a list of some variables and properties accessible this way, see the README.
Fluid dumps can be sliced like arrays! That is,
dump[i,j,k]['var_name']will read or compute'var_name'only for the particular index in question, and similarly for slices of any size (e.g., 2D slices for plots). This is tremendously useful, so remember to slice first to save time if efficiency is important. Note, though, that slicing preserves the dimensionality – that is,dump[i,j,k][var].shapewill be (1,1,1). Being able to assume every dump has three dimensions makes a lot of internal logic easier. If you need 2D arrays, just usenp.squeeze, or the internal functionsflatten_xzandflatten_xy, which return common 2D slices or averages.Also, note that slicing does not support strides, and that slices may be views rather than copies – if you’re going to modify array contents yourself within a slice (for some reason…), it may affect the global array. Generally this will just behave how you want, but it can be confusing if you’re really digging around. If you have the memory, you can use
copy.copyorcopy.deepcopyto be certain.Parameters: - fname – file name or path to dump
- tag – any string, usually long name of dump/model for plotting
- ghost_zones – Load ghost zones when reading from a dump file
- grid_cache – Cache geometry values in the grid file. These are not yet automatically added, so keep this True unless plotting a very simple variable
- cache_conn – Cache the connection coefficients at zone centers. Default off as memory-intensive and rarely needed
- units – a ‘Units’ object representing a physical scale for the dump (density M_unit and BH mass MBH)
- add_grid – Whether to construct a Grid object at all. Only used for copy construction.
- params – dictionary of parameters. Only used for copy construction.
-
__weakref__¶ list of weak references to the object (if defined)
-
set_units(MBH, M_unit)¶ Associate a scale & units with this dump, for calculating scale-dependent quantities in CGS. :param MBH: Black hole mass in solar masses :param M_unit: Density unit in grams, as fit by imaging with e.g.
ipoleNote this function will not change anything – rather it adds a dict ‘units’ and a number of keys: ‘M_unit’, ‘RHO_unit’, ‘T_unit’, etc. See
units.pyfor definitions.
-