PlasmaCalcs.hookups.bifrost.bifrost_io_tools.BifrostDataCutter

class PlasmaCalcs.hookups.bifrost.bifrost_io_tools.BifrostDataCutter(snap, bcalc, *, new_snapname=UNSET)

Bases: BifrostVarPathsManager

interface for creating new data files cut from existing data files.
“cut” refers to indexing by simple slices, with trivial step (1 or None),
e.g. slice x by slice(500, 1000). But not by slice(500, 1000, 10).
(NEVER overwrites existing files; if any result files already exist, crash.)
self.kind2path = {kind: path}
self.kind2vars = {kind: [list of readable vars]}
self.var2kind = {var: kind}
self.var2path = {var: path}
self.path2kind = {path: kind}
self.path2vars = {path: [list of readable vars]}
self.var2index = {var: index of var in its path’s list of vars}
self.kind2newpath = {kind: newpath}
self.path2newpath = {original path: newpath}
self.newpath2path = {newpath: original path}
self.kinds: tuple of kinds with any vars in self.
self.vars: tuple of all vars in self.
self.paths: tuple of all paths with any vars in self.
self.newpaths: tuple of all newpaths with any vars in self.
kinds are: ‘snap’, ‘aux’, ‘hion’, ‘helium’, ‘ooe’.
if kind has no vars, do not include it in results.

snap: BifrostSnap bcalc: BifrostCalculator new_snapname: str or UNSET

new snapname to use for the cutted data files. UNSET –> ‘{self.snapname}_cut’
__init__(snap, bcalc, *, new_snapname=UNSET)

Methods

__init__(snap, bcalc, *[, new_snapname])

cut(*[, verbose])

cut_idl_file()

cut_kind(kind)

cut_meshfile()

help()

init_all()

init_aux_kind()

init_helium_kind()

init_hion_kind()

init_new_paths()

init_ooe_kind()

init_snap_kind()

kind2filebase(kind)

new_file_paths()

newpath(oldpath)

slices_tuple()

snappath(filename)

Attributes

KIND2FILEBASE

KINDS

NNN

bcalc

params

slices

snap

snapdir

snapname

property NNN
(str) the NNN part of the snapname_NNN.idl filename.
property bcalc
gets self._bcalc(), or just self._bcalc if not self._bcalc_is_weakref.
cut(*, verbose=True)
cut all data & supporting files, writing results to new path based on self.new_snapname.
(never edits any existing files, only makes new ones.)
returns list of all new file paths (i.e. self.new_file_paths())
verbose: bool
whether to print progress updates during cutting.
cut_idl_file()
cut idl_file, writing results to self.newpath(self.bcalc.idlfile).
the idlfile is the snapname_NNN.idl file; see self.bcalc.snap_filepath().
amount to cut is determined by self.bcalc.slices.
“cutting the idlfile” means replacing the relevant parameters in the idlfile:
‘mx’, ‘my’, ‘mz’ –> new sizes after cutting
‘snapname’ –> new snapname
‘meshfile’ –> new meshfile name
cut_kind(kind)
cut data for this kind, writing results to self.kind2newpath[kind].
see self.kinds for options.
returns self.kind2newpath[kind], which is an abspath to the new path.
(NEVER overwrites existing data; if the newpath exists already, crash.)
amount to cut is determined by self.bcalc.slices.
size of arrays within memmap data files is determined by bcalc.data_array_shape.
cut_meshfile()
cut meshfile, writing results to self.newpath(self.bcalc.meshfile).
amount to cut is determined by self.bcalc.slices.
“cutting the meshfile” means apply slice_bifrost_meshfile()
help()
print docstring of self…
init_all()
init all KINDS in self.
init_aux_kind()
vars stored in snapname_NNN.aux file.
init_helium_kind()
vars stored in snapname.helium_NNN.snap file.
init_hion_kind()
vars stored in snapname.hion_NNN.snap file.
init_new_paths()
initialize self.kind2newpath, path2newpath and newpath2path
init_ooe_kind()
out of equilibrium vars.
init_snap_kind()
vars stored in snapname_NNN.snap file.
kind2filebase(kind)
returns file basename for this kind.

Equivalent: self.KIND2FILEBASE[kind].format(snapname=self.snapname, NNN=self.NNN)

new_file_paths()
list of abspaths to all new files which self.cut() will create.
These are self.newpaths, and the new path for the meshfile & idl file.
newpath(oldpath)
return newpath from oldpath. (both are abspaths.)
newpath = oldpath, but replace self.bcalc.snapname (within oldpath basename) by new_snapname
crash if newpath == oldpath.
property params
alias to self.snap.params
property slices
self.bcalc.slices, but ensuring all are slice objects and have trivial step (1 or None).
Also ensures at least 1 nontrivial slice exists (i.e. not empty and not all slice(None).)
slices_tuple()
returns tuple of slices to apply to array with (x, y, z) as first 3 dims.
determined by self.slices.get(x, slice(None)) for x in ‘x’, ‘y’, ‘z’.
property snap
gets self._snap(), or just self._snap if not self._snap_is_weakref.
property snapdir
alias to self.bcalc.snapdir
property snapname
alias to self.params[‘snapname’]
snappath(filename)
returns os.path.join(self.snapdir, filename)