pyvista / pyvista-xarray

xarray DataArray accessors for PyVista
Apache License 2.0
100 stars 7 forks source link

Add binder link and notebook example #24

Closed giswqs closed 2 years ago

giswqs commented 2 years ago

This PR adds a binder link to README. https://github.com/pyvista/pyvista-xarray/issues/22

rabernat commented 2 years ago

The binder launches, but there are two problems:

  1. There is no notebook to open.
  2. The environment doesn't actually work

Regarding 2, I tried to run the first code block from the README

import pvxarray
import xarray as xr

ds = xr.tutorial.load_dataset("air_temperature")
da = ds.air[dict(time=0)]  # Select DataArray for a timestep

# Plot in 3D
da.pyvista.plot(show_edges=True, cpos='xy')

# Or grab the mesh object for use with PyVista
mesh = da.pyvista.mesh

and got

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/tmp/ipykernel_87/2822697919.py in <module>
----> 1 import pvxarray
      2 import xarray as xr
      3 
      4 ds = xr.tutorial.load_dataset("air_temperature")
      5 da = ds.air[dict(time=0)]  # Select DataArray for a timestep

~/pvxarray/__init__.py in <module>
      1 # flake8: noqa: F401
      2 from pvxarray._version import __version__
----> 3 from pvxarray.accessor import PyVistaRectilinearGridAccessor, PyVistaStructuredGridAccessor
      4 from pvxarray.knowledge import register_coord_names, register_xy_names, register_z_name
      5 from pvxarray.report import Report

~/pvxarray/accessor.py in <module>
      2 
      3 import numpy as np
----> 4 import pyvista as pv
      5 import xarray as xr
      6 

/srv/conda/envs/notebook/lib/python3.7/site-packages/pyvista/__init__.py in <module>
     10 # Load default theme.  Must be loaded first.
     11 from pyvista._version import __version__
---> 12 from pyvista.plotting import *
     13 from pyvista.utilities import *
     14 from pyvista.core import *

/srv/conda/envs/notebook/lib/python3.7/site-packages/pyvista/plotting/__init__.py in <module>
      2 
      3 from pyvista import MAX_N_COLOR_BARS
----> 4 from .charts import Chart2D, ChartMPL, ChartBox, ChartPie
      5 from .colors import (
      6     Color,

/srv/conda/envs/notebook/lib/python3.7/site-packages/pyvista/plotting/charts.py in <module>
     11 
     12 import pyvista
---> 13 from pyvista import _vtk
     14 
     15 from .colors import Color, color_synonyms, hexcolors

/srv/conda/envs/notebook/lib/python3.7/site-packages/pyvista/_vtk.py in <module>
    430     from vtkmodules.vtkRenderingFreeType import vtkVectorText
    431     from vtkmodules.vtkRenderingLabel import vtkLabelPlacementMapper, vtkPointSetToLabelHierarchy
--> 432     from vtkmodules.vtkRenderingOpenGL2 import (
    433         vtkCameraPass,
    434         vtkEDLShading,

ImportError: libGL.so.1: cannot open shared object file: No such file or directory

In my experience, a conda environment is required to get vtk working reliably.

giswqs commented 2 years ago

@rabernat Yes, I just noticed the same problem as after submitting the PR. I am testing a env.yml now. Will update the PR shortly after the build passes.

codecov-commenter commented 2 years ago

Codecov Report

Merging #24 (49304c1) into main (c234539) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##             main      #24   +/-   ##
=======================================
  Coverage   92.12%   92.12%           
=======================================
  Files           7        7           
  Lines         165      165           
=======================================
  Hits          152      152           
  Misses         13       13           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c234539...49304c1. Read the comment docs.

giswqs commented 2 years ago

@rabernat I tried setting up a conda environment and encountered the same libGL.so.1 error. Therefore, I used a Dockerfile adapted from pyvista-examples and it solved the issue. I also added a notebook with three examples. You can test it at https://mybinder.org/v2/gh/giswqs/pyvista-xarray/binder.

The first two examples should work just fine. The thrid example needs to download a sample dataset to Binder, but the docker container has some permission issues. I am not a docker expert. @banesullivan can probably help out.

banesullivan commented 2 years ago

@giswqs, thanks for getting this started! I just refactored the API for the next version and will handle this PR from here.

re: vtk working

VTK will work fine with the PyPI wheels or from a conda env - the trick is making sure the headless display is configured in the environment. The Docker images I helped make for PyVista greatly simplify this, so those are precisely what we should use here.

banesullivan commented 2 years ago

Superseding this with #26