From f239d7f2d34727331557c49c62ef577ea9d8d236 Mon Sep 17 00:00:00 2001 From: chrishavlin Date: Fri, 7 Jul 2023 12:43:08 -0500 Subject: [PATCH] updating docs --- README.md | 4 ++-- docs/quickstart.rst | 37 ++++++++++++++++---------------- src/yt_napari/viewer.py | 47 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index e4daa23..e68b184 100644 --- a/README.md +++ b/README.md @@ -115,13 +115,13 @@ To load a different field or section, adjust the values and click "Load" again. ```json {"$schema": "https://raw.githubusercontent.com/data-exp-lab/yt-napari/main/src/yt_napari/schemas/yt-napari_0.0.1.json", "data": [{"filename": "IsolatedGalaxy/galaxy0030/galaxy0030", - "selections": [{ + "selections": {"regions": [{ "fields": [{"field_name": "Temperature", "field_type": "enzo", "take_log": true}, {"field_name": "Density", "field_type": "enzo", "take_log": true}], "left_edge": [460.0, 460.0, 460.0], "right_edge": [560.0, 560.0, 560.0], "resolution": [600, 600, 600] - }], + }]}, "edge_units": "kpc" }] } diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 8f75273..db7e0a3 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -32,22 +32,22 @@ jupyter notebook interaction right_edge = ds.domain_center + ds.arr([40, 40, 40], 'kpc') res = (600, 600, 600) - yt_scene.add_to_viewer(viewer, - ds, - ("enzo", "Temperature"), - left_edge = left_edge, - right_edge = right_edge, - resolution = res) + yt_scene.add_region(viewer, + ds, + ("enzo", "Temperature"), + left_edge = left_edge, + right_edge = right_edge, + resolution = res) - yt_scene.add_to_viewer(viewer, - ds, - ("enzo", "Density"), - left_edge = left_edge, - right_edge = right_edge, - resolution = res) + yt_scene.add_region(viewer, + ds, + ("enzo", "Density"), + left_edge = left_edge, + right_edge = right_edge, + resolution = res) -:code:`yt_scene.add_to_viewer` accepts any of the keyword arguments allowed by :code:`viewer.add_image`. +:code:`yt_scene.add_region` accepts any of the keyword arguments allowed by :code:`viewer.add_image`. See :meth:`yt_napari.viewer.Scene` for all available methods and the :doc:`example notebooks ` for further examples. @@ -60,16 +60,15 @@ loading a json file from the napari gui .. code-block:: json - {"$schema": "https://raw.githubusercontent.com/data-exp-lab/yt-napari/main/src/yt_napari/schemas/yt-napari_0.0.1.json", + {"$schema": "https://yt-napari.readthedocs.io/en/latest/_static/yt-napari_latest.json", "data": [{"filename": "IsolatedGalaxy/galaxy0030/galaxy0030", - "selections": [{ + "selections": {"regions": [{ "fields": [{"field_name": "Temperature", "field_type": "enzo", "take_log": true}, {"field_name": "Density", "field_type": "enzo", "take_log": true}], - "left_edge": [460.0, 460.0, 460.0], - "right_edge": [560.0, 560.0, 560.0], + "left_edge": {"value": [460.0, 460.0, 460.0], "unit": "kpc"}, + "right_edge": {"value": [560.0, 560.0, 560.0], "unit": "kpc"}, "resolution": [600, 600, 600] - }], - "edge_units": "kpc" + }]} }] } diff --git a/src/yt_napari/viewer.py b/src/yt_napari/viewer.py index 49c14b7..e4b614e 100644 --- a/src/yt_napari/viewer.py +++ b/src/yt_napari/viewer.py @@ -121,7 +121,7 @@ def add_region( **kwargs, ): """ - create a uniform sampling of ds and add it to the napari viewer + uniformly sample a region from a yt dataset and add it to a viewer Parameters ---------- @@ -242,6 +242,51 @@ def add_slice( link_to: Optional[Union[str, Layer]] = None, **kwargs, ): + """ + sample an orthogonal slice from a yt dataset and add it to a viewer + + Parameters + ---------- + viewer: napari.Viewer + the active napari viewer + ds + the yt dataset to sample + normal: str, int + the normal axis of the slice, either an axis name or number + field: Tuple[str, str] + the field tuple to sample e.g., ('enzo', 'Density') + center: unyt_array + the center of the slice (3D) + width: unyt_quantity + the width of the slice + height: unyt_quantity + the height of the slice + resolution: Tuple[int, int] + the sampling resolution in each dimension, e.g., (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. + periodic: Optional[bool] + use periodic bounds for the slice, default False + 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_slice(viewer, ds, "x", ("enzo", "Temperature")) + + """ if take_log is None: take_log = ds._get_field_info(field).take_log