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’

Methods

cut(*[, verbose])

cut all data & supporting files, writing results to new path based on self.new_snapname.

cut_idl_file()

cut idl_file, writing results to self.newpath(self.bcalc.idlfile).

cut_kind(kind)

cut data for this kind, writing results to self.kind2newpath[kind].

cut_meshfile()

cut meshfile, writing results to self.newpath(self.bcalc.meshfile).

help()

print docstring of self...

init_aux_kind()

vars stored in snapname_NNN.aux file.

init_convenience()

initialize convenience tuples.

init_helium_kind()

vars stored in snapname.helium_NNN.snap file.

init_hion_kind()

vars stored in snapname.hion_NNN.snap file.

init_kinds()

initialize all kinds in self, filling in all the details for self's storage dicts.

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.

init_storage()

initialize storage dicts.

kind2filebase(kind)

returns file basename for this kind.

new_file_paths()

list of abspaths to all new files which self.cut() will create.

newpath(oldpath)

return newpath from oldpath.

slices_tuple()

returns tuple of slices to apply to array with (x, y, z) as first 3 dims.

snappath(filename)

returns os.path.join(self.snapdir, filename)

_check_output_files_dont_exist()

ensure that all output files do not exist yet.

_data_array_shape_after_cut()

returns shape each data array will be after cutting (using self.slices).

_idl_file_path()

path to idl file for self.snap.

_init_kind_vars_path(kind, vars, path)

updates self with corresponding kind, vars, and path.

_new_idl_file_path()

abspath to new idl file.

_new_meshfile_path()

abspath to new meshfile.

_repr_contents()

contents for repr(self), as list of strings

Attributes

KIND2FILEBASE

KINDS

NNN

(str) the NNN part of the snapname_NNN.idl filename.

aux_todo

list of all vars in 'aux' not yet handled by this VarPathsManager instance.

calc

gets self._calc(), or just self._calc if not self._calc_is_weakref.

params

alias to self.snap.params

slices

self.bcalc.slices, but ensuring all are slice objects and have trivial step (1 or None).

snap

gets self._snap(), or just self._snap if not self._snap_is_weakref.

snapdir

alias to self.calc.snapdir

snapname

alias to self.params['snapname']

property NNN

(str) the NNN part of the snapname_NNN.idl filename.

_check_output_files_dont_exist()

ensure that all output files do not exist yet.

_data_array_shape_after_cut()

returns shape each data array will be after cutting (using self.slices).

_idl_file_path()

path to idl file for self.snap. Equivalent: self.bcalc.snap_filepath(self.snap).

_init_kind_vars_path(kind, vars, path)

updates self with corresponding kind, vars, and path.

_new_idl_file_path()

abspath to new idl file. Equivalent: self.newpath(self.bcalc.snap_filepath(self.snap)).

_new_meshfile_path()

abspath to new meshfile. Equivalent: self.newpath(self.bcalc.meshfile).

_repr_contents()

contents for repr(self), as list of strings

property aux_todo

list of all vars in ‘aux’ not yet handled by this VarPathsManager instance.

Presently, this means the list of all vars containing ‘xy’, ‘yz’, or ‘xz’.
property calc

gets self._calc(), or just self._calc if not self._calc_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_aux_kind()

vars stored in snapname_NNN.aux file.

init_convenience()

initialize convenience tuples.

init_helium_kind()

vars stored in snapname.helium_NNN.snap file.

init_hion_kind()

vars stored in snapname.hion_NNN.snap file.

init_kinds()

initialize all kinds in self, filling in all the details for self’s storage dicts.

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.

init_storage()

initialize storage dicts.

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.calc.snapdir

property snapname

alias to self.params[‘snapname’]

snappath(filename)

returns os.path.join(self.snapdir, filename)