yt_napari.timeseries module

This module contains helper functions for working with timeseries data.

class yt_napari.timeseries.CoveringGrid(field: Tuple[str, str], left_edge: unyt_array | Tuple[ndarray, str] | None = None, right_edge: unyt_array | Tuple[ndarray, str] | None = None, level: int | None = 0, num_ghost_zones: int | None = 0, take_log: bool | None = None)

Bases: _RegionBase

sample_ds(ds)

sample a yt dataset with the selection object

class yt_napari.timeseries.Region(field: Tuple[str, str], left_edge: unyt_array | Tuple[ndarray, str] | None = None, right_edge: unyt_array | Tuple[ndarray, str] | None = None, resolution: Tuple[int, int, int] | None = (400, 400, 400), take_log: bool | None = None)

Bases: _RegionBase

A 3D rectangular selection through a domain.

Parameters:
  • field ((str, str)) – a yt field present in all timeseries to load.

  • left_edge (unyt_array or (ndarray, str)) – (optional) a 3-element unyt_array defining the left edge of the region, defaults to the domain left_edge of each active timestep.

  • right_edge (unyt_array or (ndarray, str)) – (optional) a 3-element unyt_array defining the right edge of the region, defaults to the domain right_edge of each active timestep.

  • resolution ((int, int, int)) – (optional) 3-element tuple defining the resolution to sample at. Default is (400, 400, 400).

  • take_log (bool) – (optional) If True, take the log10 of the sampled field. Defaults to the default behavior for the field in the dataset.

nd: int = 3
sample_ds(ds)

return a fixed resolution sample of a field in a yt dataset.

Parameters:

ds (yt dataset) – the yt dataset to sample

Examples

>>> import yt
>>> import numpy as np
>>> from yt_napari.timeseries import Region
>>> ds = yt.load_sample("IsolatedGalaxy")
>>> le = np.array([0.4, 0.4, 0.4], 'Mpc')
>>> re = np.array([0.6, 0.6, 0.6], 'Mpc')
>>> reg = Region(("enzo", "Density"), left_edge=le, right_edge=re)
>>> reg_data = reg.sample_ds(ds)

Notes

This is equivalent to ds.r[…,…,..][field], but is a useful abstraction for applying the same selection to a series of datasets.

class yt_napari.timeseries.Slice(field: Tuple[str, str], normal: str | int, center: unyt_array | Tuple[ndarray, str] | None = None, width: unyt_quantity | Tuple[float, str] | None = None, height: unyt_quantity | Tuple[float, str] | None = None, resolution: Tuple[int, int] | None = (400, 400), periodic: bool | None = False, take_log: bool | None = None)

Bases: _Selection

A 2D axis-normal slice through a domain.

Parameters:
  • field ((str, str)) – a yt field present in all timeseries to load.

  • normal (int or str) – the normal axis for slicing

  • center (unyt_array) – (optional) a 3-element unyt_array defining the slice center, defaults to the domain center of each active timestep.

  • width (unyt_quantity or (value, unit)) – (optional) the slice width, defaults to the domain width of each active timestep.

  • height (unyt_quantity or (value, unit)) – (optional) the slice height, defaults to the domain height of each active timestep.

  • resolution ((int, int)) – (optional) 2-element tuple defining the resolution to sample at. Default is (400, 400).

  • periodic (bool) – (optional, default is False) If True, treat domain as periodic

  • take_log (bool) – (optional) If True, take the log10 of the sampled field. Defaults to the default behavior for the field in the dataset.

nd: int = 2
sample_ds(ds)

return a fixed resolution slice of a field in a yt dataset.

Parameters:

ds (yt dataset) – the yt dataset to sample

Examples

>>> import yt
>>> from unyt import unyt_quantity
>>> from yt_napari.timeseries import Slice
>>> ds = yt.load_sample("IsolatedGalaxy")
>>> w = unyt_quantity(0.2, 'Mpc')
>>> slc = Slice(("enzo", "Density"), "x", width=w, height=w)
>>> slc_data = slc.sample_ds(ds)

Notes

This is equivalent to ds.slice(…).to_frb()[field], but is a useful abstraction for applying the same selection to a series of datasets.

yt_napari.timeseries.add_to_viewer(viewer: Viewer, selection: Slice | Region, file_dir: str | None = None, file_pattern: str | None = None, file_list: List[str] | None = None, file_range: Tuple[int, int, int] | None = None, load_as_stack: bool | None = False, use_dask: bool | None = False, return_delayed: bool | None = True, stack_scaling: float | None = 1.0, **kwargs)

Sample a timeseries and add to a napari viewer

Parameters:
  • viewer (napari.Viewer) – a napari Viewer instance

  • selection (Slice or Region) – the selection to apply to each matched dataset

  • file_dir (str) – (optional) a file directory to prepend to either the file_pattern or file_list argument.

  • file_pattern (str) – (optional) a file pattern to match, not used if file_list is set. One of file_pattern or file_list must be set.

  • file_list (str) – (optional) a list of files to use. One of file_list or file_pattern must be set.

  • file_range ((int, int, int)) – (optional) A range to limit matched files in the form (start, stop, step).

  • load_as_stack (bool) – (optional, default False) If True, the timeseries will be stacked to a single image array

  • use_dask (bool) – (optional, default False) If True, use dask to assemble the image array

  • return_delayed (bool) – (optional, default True) If True and if use_dask=True, then the image array will be a delayed array, resulting in lazy loading in napari. If False and if use_dask=True, then dask will distribute sampling tasks and assemble a final in-memory array.

  • stack_scaling (float) – (optional, default 1.0) Applies a scaling to the effective image array in the stacked (time) dimension if load_as_stack is True. If scale is provided as a separate parameter, then stack_scaling is only used if the len(scale) matches the dimensionality of the spatial selection.

  • **kwargs – any additional keyword arguments are passed to napari.Viewer().add_image()

Examples

>>> import napari
>>> from yt_napari.timeseries import Slice, add_to_viewer
>>> viewer = napari.Viewer()
>>> slc = Slice(("enzo", "Density"), "x")
>>> enzo_files = "enzo_tiny_cosmology/DD????/DD????"
>>> add_to_viewer(viewer, slc, file_pattern=enzo_files, file_range=(0,47, 5),
>>>                load_as_stack=True)