yt_napari package

Subpackages

Submodules

yt_napari.viewer module

class yt_napari.viewer.Scene(reference_layer: Optional[yt_napari._model_ingestor.ReferenceLayer] = None)

Bases: object

add_to_viewer(viewer: napari.viewer.Viewer, ds, field: Tuple[str, str], resolution: Optional[Tuple[int, int, int]] = None, left_edge: Optional[unyt.array.unyt_array] = None, right_edge: Optional[unyt.array.unyt_array] = None, take_log: Optional[bool] = None, colormap: Optional[str] = None, link_to: Optional[Union[str, napari.layers.base.base.Layer]] = None, **kwargs)

create a uniform sampling of ds and add it to the napari viewer

Parameters
  • viewer (napari.Viewer) – the active napari viewer

  • ds – the yt dataset to sample

  • field (Tuple[str, str]) – the field tuple to sample e.g., (‘enzo’, ‘Density’)

  • left_edge (unyt_array) – the left edge of the bounding box

  • right_edge (unyt_array) – the right edge of the bounding box

  • resolution (Tuple[int, int, int]) – the sampling resolution in each dimension, e.g., (400, 400, 400)

  • take_log (Optional[bool]) – if True, will take the log of the extracted data. Defaults to the default behavior for the field set by ds.

  • colormap (Optional[str]) – the color map to use, default is “viridis”

  • link_to (Optional[Union[str, Layer]]) – specify a layer to which the new layer should link

  • **kwargs – any keyword argument accepted by Viewer.add_image()

Examples

>>> import napari
>>> import yt
>>> from yt_napari.viewer import Scene
>>> viewer = napari.Viewer()
>>> ds = yt.load_sample("IsolatedGalaxy")
>>> yt_scene = Scene()
>>> yt_scene.add_to_viewer(viewer, ds, ("enzo", "Temperature"))
get_data_range(layers: List[Union[str, napari.layers.base.base.Layer]], layer_list: Optional[napari.components.layerlist.LayerList] = None, check_linked: Optional[bool] = True) Tuple[float, float]

retrieve the extrema across layers

Parameters
  • layers (List[Union[str, Tuple]]) – a list of the layers to normalize across

  • layer_list (Optional[LayerList]) – the LayerList from an active napari Viewer. Required if you are providing layers by layer name only

  • check_linked (Optional[bool]) – if True (default), will also check for linked layers even if they are not explicitly included in layers.

Returns

length-2 tuple with the min and max values across layers.

Return type

Tuple(float, float)

Examples

>>> import napari
>>> import yt
>>> from yt_napari.viewer import Scene
>>> viewer = napari.Viewer()
>>> ds = yt.load_sample("IsolatedGalaxy")
>>> yt_scene = Scene()
>>> yt_scene.add_to_viewer(viewer, ds, ("enzo", "Temperature"))
>>> yt_scene.get_data_range(viewer.layers)
(3.2446250040130398, 5.003147905498429)
normalize_color_limits(layers: List[Union[str, napari.layers.base.base.Layer]], layer_list: Optional[napari.components.layerlist.LayerList] = None, check_linked: Optional[bool] = True)

normalize the color limits (the contrast_limits) across layers.

Parameters
  • layers (List[Union[str, Tuple]]) – a list of the layers to normalize across

  • layer_list (Optional[LayerList]) – the LayerList from an active napari Viewer. Required if you are providing layers by layer name only

  • check_linked (Optional[bool]) – if True (default), will also check for linked layers even if they are not explicitly included in layers.

Notes

This method does not affect the linked state of any layers.

Examples

The following adds two layers and then normalizes the color scale between the two:

>>> import napari
>>> import yt
>>> from yt_napari.viewer import Scene
>>> viewer = napari.Viewer()
>>> ds = yt.load_sample("IsolatedGalaxy")
>>> yt_scene = Scene()
>>> le = ds.domain_center - ds.arr([10, 10, 10], 'kpc')
>>> re = ds.domain_center + ds.arr([10, 10, 10], 'kpc')
>>> yt_scene.add_to_viewer(viewer,
>>>                        ds,
>>>                        ("enzo", "Density"),
>>>                        left_edge = le,
>>>                        right_edge = re,
>>>                        resolution=(600, 600, 600),
>>>                        name="Density_1")
>>> le = ds.domain_center + ds.arr([10, 10, 10], 'kpc')
>>> re = le + ds.arr([20, 20, 20], 'kpc')
>>> yt_scene.add_to_viewer(viewer,
>>>                        ds,
>>>                        ("enzo", "Density"),
>>>                        left_edge = le,
>>>                        right_edge = re,
>>>                        resolution=(300, 300, 300),
>>>                        name="Density_2")
>>> yt_scene.normalize_color_limits(["Density_2", "Density_1"], viewer.layers)
set_across_layers(layers: List[Union[str, napari.layers.base.base.Layer]], attribute: str, value: Any, layer_list: Optional[napari.components.layerlist.LayerList] = None)

set the value of an attribute for all the provided layers

Parameters
  • layers – a list of napari Layer objects or string names of layers.

  • attribute – the layer attribute to set

  • value – the value of the attribute to set

  • layer_list – the active napari LayerList. required if providing layers by name.

Notes

Any existing layers that are linked to the provided layers will also be updated.

Module contents