SubsamplingInfo

class PlasmaCalcs.dimensions.subsampling.SubsamplingInfo(json, *, meta=UNSET, _json_indent=4, _init_appliers=True)

Bases: object

information about subsampling

json: dict of subsampling info: {

‘forall’: { # optional; if not provided use vals from byvars.
‘snaps’: [mode, info], # optional, can provide here or in byvars but not both.
‘array_dims’: [list of array dim names in order], # provide here or in byvars but not both.
},
‘byvars’: [ # optional; if not provided do snaps slicing only
{
‘snaps’: [mode, info], # optional, can provide here or in forall but not both.
‘array_dims’: [list of array dim names in order], # provide here or in forall but not both.
‘exact’: { # optional
var1: [mode1, info1],
var2: [mode2, info2], # optional
…,
},
‘regex’: { # optional
re_var3: [mode3, info3],
…,
},
},
…, # optionally can provide more dicts like above
]
}
where:
snaps = how to subsample snapshots (use dim=’snap’ for these). Example:
‘snaps’: [‘slice’, {‘snap’: [start, stop, step]}]
exact = dict of exact names; subsampling for var with this name
regex = dict of regex patterns; subsampling for var if re.fullmatch(pattern, var)
mode = mode for subsampling. e.g. ‘slice’
info = info for subsampling, format depends on mode.
e.g. for ‘slice’, info = dict of {dim: [start, stop, step]}.
Note: if multiple matches for any var, always use the earliest one;
i.e. earliest dict in list, and always exact match before regex match.
meta: dict, None, or UNSET
metadata about the subsampling info. Must be in json format, if provided.
None –> no metadata
UNSET –> use code_snapshot_info() to get metadata when this object is created.
_json_indent: int
number of spaces to indent when saving json file.
_init_appliers: bool
whether to self.init_appliers() during __init__.
Usually should be True, but if debugging might want to use False.

Methods

get_applier(var, *[, missing_ok])

returns a SubsamplingMode instance appropriate for var based on self.

get_var_info(var[, default])

returns the (mode, info, array_dims, None_or_snaps_mode_and_info) for var within self.

has_byvars_snaps()

return True if 'snaps' in any byvars, else False.

has_forall_snaps()

returns True if 'snaps' in 'forall', else False.

implied_from(json_or_filename_or_info, **kw_cls)

return cls object from json, filename, or SubsamplingInfo object.

init_appliers()

initialize all subsampling appliers for this SubsamplingInfo object.

init_checks()

do some sanity checks about this SubsamplingInfo object.

init_meta()

initialize self.meta.

load([file_or_dir])

load based on subsampling_info.txt.

register_applier_mode(cls_applier_to_register)

register cls_applier_to_register as a known applier mode for subsampling.

save([dir])

saves subsampling info.

update_meta(d)

self.meta.update(d).

Attributes

MODES

get_applier(var, *, missing_ok=True)

returns a SubsamplingMode instance appropriate for var based on self.

Assumes self.init_appliers() was run and is up-to-date.
var: str
variable name to get applier for, or string ‘snaps’.
‘snaps’ –> get ‘snaps’ applier from forall, else crash.
else –> get first match from byvars.
missing_ok: bool
When var has no match in self:
if missing_ok: return SubsamplingIdentity instance.
otherwise: raise SubsamplingNotFoundError.
get_var_info(var, default=UNSET)

returns the (mode, info, array_dims, None_or_snaps_mode_and_info) for var within self.

default: UNSET or any object

if var not found, return default if provided, else raise SubsamplingNotFoundError
has_byvars_snaps()

return True if ‘snaps’ in any byvars, else False.

has_forall_snaps()

returns True if ‘snaps’ in ‘forall’, else False.

classmethod implied_from(json_or_filename_or_info, **kw_cls)

return cls object from json, filename, or SubsamplingInfo object.

init_appliers()

initialize all subsampling appliers for this SubsamplingInfo object.

init_checks()

do some sanity checks about this SubsamplingInfo object.

Raise SubsamplingFormatError if any checks fail.
Here, checks:
- uniqueness of var keys: expect to not have exact same var key appear in multiple places.
- snaps can appear in forall or byvars, but not both.
- array_dims can appear in forall or byvars, but not both.
- array_dims must be provided (possibly via forall) for any byvars dict with at least 1 var.
init_meta()

initialize self.meta. None remains None. UNSET becomes code_snapshot_info().

classmethod load(file_or_dir=None, **kw_cls)

load based on subsampling_info.txt.

file_or_dir: None or str

where to load from.
None –> load from current directory
directory –> load from ‘subsampling_info.txt’ here,
or from ‘subsampling_info/subsampling_info.txt’ here.
file –> load from this file.
static register_applier_mode(cls_applier_to_register, mode=None)

register cls_applier_to_register as a known applier mode for subsampling.

save(dir='.')

saves subsampling info. Return SubsamplingInfoPathManager instance with relevant paths.

Crashes if this would overwrite any existing files.
dir: str
save to ‘subsampling_info/subsampling_info.txt’ within this directory,
or to ‘subsampling_info.txt’ within this dir if dir basename == ‘subsampling_info’.
Also saves ‘subsampling_meta.txt’ if relevant, at same level as subsampling_info.txt.
subsampling_path_manager_cls

alias of SubsamplingInfoPathManager

update_meta(d)

self.meta.update(d). If self.meta is None, keep it as None.