Skip to main content

A napari plugin for loading data from yt

Project description

yt-napari

License PyPI Python Version tests codecov napari hub Documentation Status

A napari plugin for loading data from yt.

This readme provides a brief overview including:

  1. Installation
  2. Quick Start
  3. Contributing

Full documentation is available at yt-napari.readthedocs.io.

Installation

1. (optional) install yt and napari

If you skip this step, the installation in the following section will only install the minimal package requirements for yt or napari, in which case you will likely need to manually install some packages. So if you are new to either package, or if you are installing in a clean environment, it may be simpler to install these packages first.

For napari,

pip install napari[all]

will install napari with the default Qt backend (see here for how to choose between PyQt5 or PySide2).

For yt, you will need yt>=4.0.1 and any of the optional dependencies for your particular workflow. If you know that you'll need more than the base yt install, you can install the full suite of dependent packages with

pip install yt[full]

See the yt documentation for more information. If you're not sure which packages you'll need but don't want the full yt installation, you can proceed to the next step and then install any packages as needed (you will receive error messages when a required package is missing).

2. install yt-napari

You can install the yt-napari plugin with:

pip install yt-napari

If you are missing either yt or napari (or they need to be updated), the above installation will fetch and run a minimal installation for both.

To install the latest development version of the plugin instead, use:

pip install git+https://github.com/data-exp-lab/yt-napari.git

Quick Start

After installation, there are three modes of using yt-napari:

  1. jupyter notebook interaction (jump down)
  2. loading a json file from the napari gui (jump down)
  3. napari widget plugins (jump down)

jupyter notebook interaction

yt-napari provides a helper class, yt_napari.viewer.Scene that assists in properly aligning new yt selections in the napari viewer when working in a Jupyter notebook.

import napari
import yt
from yt_napari.viewer import Scene
from napari.utils import nbscreenshot

viewer = napari.Viewer()
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
yt_scene = Scene()

left_edge = ds.domain_center - ds.arr([40, 40, 40], 'kpc')
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_to_viewer(viewer,
                       ds,
                       ("enzo", "Density"),
                       left_edge = left_edge,
                       right_edge = right_edge,
                       resolution = res)

nbscreenshot(viewer)

Loading a subset of a yt dataset in napari from a Jupyter notebook

yt_scene.add_to_viewer accepts any of the keyword arguments allowed by viewer.add_image. See the full documentation (!!!NEED LINK!!!) for more examples, including additional helper methods for linking layer appearance.

loading a selection from a yt dataset interactively

yt-napari provides a two ways to sample a yt dataset and load in an image layer into a Napari viewer: the yt Reader plugin and json file specification.

using the yt Reader plugin

To use the yt Reader plugin, click on Plugins -> yt-napari: yt Reader. Select a file, specify a field type and field, set the region to sample and then simply click "Load":

Loading a subset of a yt dataset from the napari viewer

To load a different field or section, adjust the values and click "Load" again.

using a json file and schema

yt-napari also provides the ability to load json that contain specifications for loading a file. Properly formatted files can be loaded from the napari GUI as you would load any image file (File->Open). The json file describes the selection process for a dataset as described by a json-schema. The following json file results in similar layers as the above examples:

{"$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": [{
                            "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"
         }]
}

To help in filling out a json file, it is recommended that you use an editor capable of parsing a json schema and displaying hints. For example, in vscode, you will see field suggestions after specifying the yt-napari schema:

interactive json completion for yt-napari

See the full documentation at yt-napari.readthedocs.io for a complete specification.

Contributing

Contributions are very welcome! Development follows a fork and pull request workflow. To get started, you'll need a development installation and a testing environment.

development environment

To start developing, fork the repository and clone your fork to get a local copy. You can then install in development mode with

pip install -e .

tests and style checks

Both bug fixes and new features will need to pass the existing test suite and style checks. While both will be run automatically when you submit a pull request, it is helpful to run the test suites locally and run style checks throughout development. For testing, you can use tox.

pip install tox

And then from the top level of the yt-napari directory, run

tox .

Tox will then run a series of tests in isolated environments. In addition to checking the terminal output for test results, the tox run will generate a test coverage report: a coverage.xml file and a htmlcov folder -- to view the results, open htmlcov/index.html in a browser.

For style checks, you can use pre-commit to run checks as you develop. To set up pre-commit:

pip install pre-commit
pre-commit install

after which, every time you run git commit, some automatic style adjustments and checks will run. The same style checks will run when you submit a pull request, but it's often easier to catch them early.

building documentation locally

Documentation can be built using sphinx in two steps. First, update the api mapping with

sphinx-apidoc -f -o docs/source src/yt_napari/

This will update the rst files in docs/source/ with the latest docstrings in yt_napari. Next, build the html documentation with

make html

updating the pydantic models and schema

Updates to the pydantic models should be accompanied by updates to the json schema. There are a number of utilities to help automate the management of schema.

The schema versioning follows a major.minor.micro versioning pattern and yt-napari schema are stored in src/yt_napari/schemas/. When changing the model, you can store a new schema from a python shell with:

from yt_napari._data_model import _store_schema
_store_schema()

And the current version of the primary pydantic model, yt_napari._data_model.InputModel, will be exported to a new json schema file. By default, the micro version number will be incremented. To increment the major or minor version number, you can supply any of the keyword arguments described in the write_new_schema method of the yt_napari.schemas._mananager.Manager class.

After updating or adding a new schema, the docs also need to be updated. To do that, run

python repo_utilities/update_schema_docs.py
make clean && make html

License

Distributed under the terms of the BSD-3 license, "yt-napari" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.


This napari plugin was generated with Cookiecutter using @napari's cookiecutter-napari-plugin template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yt_napari-0.0.1.tar.gz (34.9 kB view hashes)

Uploaded Source

Built Distribution

yt_napari-0.0.1-py3-none-any.whl (32.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page