LoadSim#

class pyathena.LoadSim(basedir, savdir=None, load_method='xarray', units=<pyathena.util.units.Units object>, verbose=False)[source]#

Class to prepare Athena simulation data analysis. Read input parameters and find simulation output files.

Parameters
  • basedir (str) – Directory where simulation output files are stored.

  • savdir (str, optional) – Directory where pickles and figures are saved. Defaults to basedir.

  • load_method ({'xarray', 'pyathena_classic', 'yt'}, optional) – Load vtk/hdf5 snapshots using ‘xarray’, ‘pyathena_classic’, or ‘yt’. Defaults to ‘xarray’.

  • verbose (bool or str or int) – If True/False, set logging level to ‘INFO’/’WARNING’. Otherwise, one of valid logging levels (‘NOTSET’, ‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’) or their numerical values (0, 10, 20, 30, 40, 50). (see https://docs.python.org/3/library/logging.html#logging-levels)

basedir#

Directory where simulation output files are stored.

Type

str

savdir#

Directory where pickles and figures are saved.

Type

str

basename#

basename (last component) of basedir.

Type

str

load_method#

Load vtk/hdf5 snapshots using ‘xarray’, ‘pythena_classic’ (vtk only), or ‘yt’. Defaults to ‘xarray’.

Type

str

athena_variant#

[athena, athena++, athenak]

Type

str

problem_id#

Prefix for output files.

Type

str

domain#

Domain information such as box size and number of cells.

Type

dict

files#

Dictionary containing output file paths.

Type

dict

par#

Dictionary of dictionaries containing input parameters and configure options read from log file and output file names.

Type

dict

config_time#

Date and time when the athena code is configured.

Type

pandas.Timestamp

verbose#

If True/False, set logging level to ‘INFO’/’WARNING’. Otherwise, one of valid logging levels (‘NOTSET’, ‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’) or their numerical values (0, 10, 20, 30, 40, 50). (see https://docs.python.org/3/library/logging.html#logging-levels)

Type

bool or str or int

ds#

Class for reading vtk file

Type

AthenaDataSet or yt DataSet

nums#

vtk/hdf5 output numbers

Type

list of int

u#

Simulation unit

Type

Units object

dfi#

Derived field information

Type

dict

load_vtk() :

reads vtk file using pythena or yt and returns DataSet object

load_starpar_vtk() :

reads starpar vtk file and returns pandas DataFrame object

print_all_properties() :

prints all attributes and callable methods

Examples

>>> import pyathena as pa
>>> s = pa.LoadSim('/path/to/basedir', verbose=True)
class Decorators[source]#

Class containing a collection of decorators for prompt reading of analysis output, (reprocessed) hst, and zprof. Used in child classes.

create_tar(num=None, remove_original=False, kind='vtk')[source]#

Creating tarred vtk/rst from rearranged output

Parameters
  • num (int) – Snapshot number, e.g., /basedir/vtk/xxxx

  • remove_original (bool) – Remove original after tar it if True

  • kind (string) – vtk or rst

create_tar_all(remove_original=False, kind='vtk')[source]#

Move and tar all vtk/rst files from per-process id* directories.

Iterates over all snapshot numbers in nums_id0, calls move_to_tardir() to gather per-process files into numbered subdirectories, and then calls create_tar() to pack each subdirectory into a single .tar archive.

Parameters
  • remove_original (bool, optional) – If True, remove the source directory after archiving. Default is False.

  • kind ({'vtk', 'rst'}, optional) – File type to archive. Default is 'vtk'.

find_files(verbose=None)[source]#

Find output files under base directory and update the files attribute.

Parameters

verbose (bool or str or int) – If True/False, set logging level to ‘INFO’/’WARNING’. Otherwise, one of valid logging levels (‘NOTSET’, ‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’) or their numerical values (0, 10, 20, 30, 40, 50). (see https://docs.python.org/3/library/logging.html#logging-levels)

find_files_vtk2d()[source]#

Search for 2-D vtk slice files that were not found during initial setup.

Looks in both id* subdirectories and dedicated format subdirectories for files matching *.????.{fmt}.vtk. Found files are stored in self.files[fmt] and the corresponding snapshot numbers are set as self.nums_{fmt}.

load_hdf5(num=None, **kwargs)[source]#

Read an Athena++ or AthenaK HDF5 snapshot.

Dispatches to _load_hdf5_athenapp() or _load_hdf5_athenak() depending on athena_variant. See those methods for the full list of supported keyword arguments.

Parameters
  • num (int) – Snapshot number.

  • **kwargs – Additional arguments forwarded to the variant-specific loader.

Returns

ds – Loaded snapshot data.

Return type

xarray.Dataset or yt Dataset

load_parbin(num=None, iparbin=None, partag='par0', **kwargs)[source]#

Read Athena++ parbin file.

Parameters
  • num (int) – Snapshot number. e.g., /basedir/parbin/problem_id.out?.num.par?.parbin.

  • iparbin (int) – Read i-th file in the parbin file list. Overrides num if both are given.

  • partag (str) – Particle tag in the input file. Default value is ‘par0’

Returns

pds – Particle data

Return type

pandas.DataFrame

load_parhst(pid, **kwargs)[source]#

Read Athena++ individual particle history

Parameters

pid (int) – Particle id, e.g., /basedir/parhst/problem_id.pid.csv

Returns

phst – Individual particle history

Return type

pandas.DataFrame

load_partab(num=None, ipartab=None, partag='par0', **kwargs)[source]#

Read Athena++ partab file.

Parameters
  • num (int) – Snapshot number. e.g., /basedir/partab/problem_id.out?.num.par?.tab.

  • ipartab (int) – Read i-th file in the partab file list. Overrides num if both are given.

  • partag (str) – Particle tag in the input file. Default value is ‘par0’

Returns

pds – Particle data

Return type

pandas.DataFrame

load_pvtk(num=None, fidx=None, partag='par0', **kwargs)[source]#

Read AthenaK particle vtk file.

Parameters
  • num (int) – Snapshot number. e.g., /basedir/pvtk/problem_id.outvar.num.part.vtk.

  • fidx (int) – Read i-th file in the pvtk file list. Overrides num if both are given.

  • partag (str) – Particle tag in the input file. Default value is ‘par0’

Returns

pds – Particle data

Return type

dict

load_rst(num=None, irst=None, verbose=False)[source]#

Read an Athena restart file.

Parameters
  • num (int, optional) – Snapshot number.

  • irst (int, optional) – Read i-th file in the restart file list. Overrides num.

  • verbose (bool, optional) – Verbosity flag passed to the reader. Default is False.

Returns

rh – Restart file object.

Return type

RestartHandler

load_starpar_vtk(num=None, ivtk=None, force_override=False, verbose=False)[source]#

Function to read Athena starpar_vtk file using pythena and return DataFrame object.

Parameters
  • num (int) – Snapshot number, e.g., /basedir/starpar/problem_id.xxxx.starpar.vtk

  • ivtk (int) – Read i-th file in the vtk file list. Overrides num if both are given.

  • force_override (bool) – Flag to force read of starpar_vtk file even when pickle exists

load_vtk(num=None, ivtk=None, id0=True, load_method=None)[source]#

Function to read Athena vtk file using pythena or yt and return DataSet object.

Parameters
  • num (int) – Snapshot number, e.g., /basedir/vtk/problem_id.xxxx.vtk

  • ivtk (int) – Read i-th file in the vtk file list. Overrides num if both are given.

  • id0 (bool) – Read vtk file in /basedir/id0. Default value is True.

  • load_method (str) – ‘xarray’, ‘pyathena_classic’ or ‘yt’

make_movie(fname_glob=None, fname_out=None, fps_in=10, fps_out=10, force_override=False, display=False)[source]#

Create an mp4 movie from a sequence of PNG snapshots.

Wraps make_movie(). By default, looks for PNG files under <basedir>/snapshots/ and writes the movie to /tigress/<user>/movies/<basename>.mp4.

Parameters
  • fname_glob (str, optional) – Glob pattern matching the input PNG files, e.g. '/path/to/snapshots/*.png'. Defaults to <basedir>/snapshots/*.png.

  • fname_out (str, optional) – Output movie file path (must end in .mp4). Defaults to /tigress/<user>/movies/<basename>.mp4.

  • fps_in (int, optional) – Frame rate of the input images. Default is 10.

  • fps_out (int, optional) – Frame rate of the output movie. Default is 10.

  • force_override (bool, optional) – If True, re-create the movie even if the output file already exists. Default is False.

  • display (bool, optional) – If True, display the movie after creation (notebook use). Default is False.

move_to_tardir(num=None, kind='vtk')[source]#

Move vtk files from id* to vtk/XXXX

Parameters

num (int) – Snapshot number, e.g., /basedir/vtk/xxxx

print_all_properties()[source]#

Print all attributes and callable methods

class pyathena.LoadSimAll(models, load_sim_class=<class 'pyathena.load_sim.LoadSim'>)[source]#

Class to manage a collection of simulations.

Provides a convenient interface for loading and switching between multiple LoadSim instances (or subclasses) identified by short model names.

Parameters
  • models (dict) – Mapping of model name (str) to basedir path (str). Non-existent base directories are skipped with a warning.

  • load_sim_class (type, optional) – LoadSim or a subclass to instantiate for each model. Default is LoadSim.

models#

Model names whose base directories exist.

Type

list of str

basedirs#

Mapping of model name to base directory path.

Type

dict

simdict#

Cache of already-loaded LoadSim instances keyed by model name.

Type

dict

model#

Name of the currently active model (set by set_model()).

Type

str

sim#

LoadSim instance for the currently active model.

Type

LoadSim

Examples

>>> import pyathena as pa
>>> models = {'run1': '/path/to/run1', 'run2': '/path/to/run2'}
>>> sa = pa.LoadSimAll(models)
>>> s = sa.set_model('run1', verbose=True)
set_model(model, savdir=None, load_method='xarray', load_sim_class=None, units=<pyathena.util.units.Units object>, verbose=False)[source]#

Load (or retrieve from cache) a simulation and set it as active.

On first call for a given model, instantiates a new LoadSim and caches it in simdict. Subsequent calls for the same model return the cached instance without re-reading the output directory.

Parameters
  • model (str) – Model name — must be a key in basedirs.

  • savdir (str, optional) – Directory for pickles and figures. Defaults to basedir.

  • load_method ({'xarray', 'pyathena_classic', 'yt'}, optional) – Method for reading vtk/hdf5 snapshots. Default is 'xarray'.

  • load_sim_class (type, optional) – Override the class used to create the LoadSim instance. Defaults to self.load_sim_class.

  • units (Units, optional) – Unit system for the simulation.

  • verbose (bool or str or int, optional) – Verbosity level. Default is False.

Returns

sim – Loaded simulation object, also stored as self.sim.

Return type

LoadSim