Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NetCDFCFReader support Network Common Data Form #6027

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6ee4f7b
Add `NetCDFReader` support Network Common Data Form
tkoyama010 May 4, 2024
7dc20ae
Merge branch 'main' into feat/add-netcdf-reader
tkoyama010 May 4, 2024
402ea82
Update NetCDFReader.py
tkoyama010 May 4, 2024
f401704
Merge branch 'feat/add-netcdf-reader' of github.com:pyvista/pyvista i…
tkoyama010 May 4, 2024
c17b981
Update NetCDFReader.py
tkoyama010 May 4, 2024
e94401c
Update NetCDFReader.py
tkoyama010 May 4, 2024
1307894
Update NetCDFReader.py
tkoyama010 May 4, 2024
1109ed0
Delete tos_O1_2001-2002.nc
tkoyama010 May 4, 2024
df016f2
Update NetCDFReader.py
tkoyama010 May 4, 2024
bdeeea9
Update NetCDFReader.py
tkoyama010 May 4, 2024
8f93348
Update NetCDFReader.py
tkoyama010 May 4, 2024
9ae6a0b
Delete NetCDFReader.py
tkoyama010 May 4, 2024
a40f0c3
Merge branch 'main' into feat/add-netcdf-reader
tkoyama010 May 4, 2024
f4a3798
Apply suggestions from code review
tkoyama010 May 4, 2024
373ee4b
Update index.rst
tkoyama010 May 4, 2024
c565d29
Apply suggestions from code review
tkoyama010 May 4, 2024
ba0d936
Update reader.py
tkoyama010 May 4, 2024
2b26084
Update downloads.py
tkoyama010 May 4, 2024
b3317b9
Merge branch 'main' into feat/add-netcdf-reader
tkoyama010 May 4, 2024
cc922c9
Apply suggestions from code review
tkoyama010 May 4, 2024
68ed704
Merge branch 'main' into feat/add-netcdf-reader
tkoyama010 May 4, 2024
50489ca
Update pyvista/core/utilities/reader.py
tkoyama010 May 8, 2024
9d0c665
Apply suggestions from code review
tkoyama010 May 9, 2024
3d98911
Update pyvista/core/utilities/reader.py
tkoyama010 May 9, 2024
592588d
Merge branch 'main' into feat/add-netcdf-reader
tkoyama010 May 9, 2024
8348fe4
Merge branch 'main' into feat/add-netcdf-reader
tkoyama010 May 10, 2024
fe18f03
Merge branch 'main' into feat/add-netcdf-reader
tkoyama010 May 11, 2024
2e1b830
Update pyvista/core/utilities/reader.py
tkoyama010 May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/api/readers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Reader Classes
MFIXReader
MetaImageReader
MultiBlockPlot3DReader
NetCDFCFReader
NIFTIReader
NRRDReader
OBJReader
Expand Down
1 change: 1 addition & 0 deletions pyvista/core/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
MetaImageReader,
MFIXReader,
MultiBlockPlot3DReader,
NetCDFCFReader,
NIFTIReader,
NRRDReader,
OBJReader,
Expand Down
24 changes: 24 additions & 0 deletions pyvista/core/utilities/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def get_reader(filename, force_ext=None):
+----------------+---------------------------------------------+
| ``.mhd`` | :class:`pyvista.MetaImageReader` |
+----------------+---------------------------------------------+
| ``.nc`` | :class:`pyvista.NetCDFReader` |
+----------------+---------------------------------------------+
| ``.nii`` | :class:`pyvista.NIFTIReader` |
+----------------+---------------------------------------------+
| ``.nii.gz`` | :class:`pyvista.NIFTIReader` |
Expand Down Expand Up @@ -2577,6 +2579,27 @@ class GambitReader(BaseReader):
_vtk_class_name = "vtkGAMBITReader"


class NetCDFCFReader(BaseReader):
"""NetCDFCFReader for .nc files.
tkoyama010 marked this conversation as resolved.
Show resolved Hide resolved

.. versionadded:: 0.44.0

Examples
--------
>>> import pyvista as pv
>>> from pyvista import examples
>>> filename = examples.download_tos_O1_2001_2002(load=False)
>>> reader = pv.get_reader(filename)
>>> grid = reader.read()
>>> _ = grid.set_active_scalars("tos")
>>> grid.plot()

"""

_vtk_module_name = "vtkIONetCDF"
_vtk_class_name = "vtkNetCDFCFReader"


CLASS_READERS = {
# Standard dataset readers:
'.bmp': BMPReader,
Expand All @@ -2601,6 +2624,7 @@ class GambitReader(BaseReader):
'.jpg': JPEGReader,
'.mha': MetaImageReader,
'.mhd': MetaImageReader,
'.nc': NetCDFCFReader,
'.neu': GambitReader,
'.nhdr': NRRDReader,
'.nii': NIFTIReader,
Expand Down
41 changes: 41 additions & 0 deletions pyvista/examples/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -7750,3 +7750,44 @@ def download_prism(load=True): # pragma: no cover


_dataset_prism = _SingleFileDownloadableDatasetLoader('prism.neu')


def download_tos_O1_2001_2002(load=True): # pragma: no cover
"""Download the TOS_O1_2001_2002 dataset.

Sea surface temperatures collected by PCMDI for use by the IPCC.
tkoyama010 marked this conversation as resolved.
Show resolved Hide resolved
From `Example netCDF files <https://www.unidata.ucar.edu/software/netcdf/examples/files.html>`_ .

.. versionadded:: 0.44.0

Parameters
----------
load : bool, default: True
Load the dataset after downloading it when ``True``. Set this
to ``False`` and only the filename will be returned.

Returns
-------
pyvista.ImageData | str
DataSet or filename depending on ``load``.

Examples
--------
>>> import pyvista as pv
>>> from pyvista import examples
>>> filename = examples.download_tos_O1_2001_2002(load=False)
>>> reader = pv.get_reader(filename)
>>> grid = reader.read()
>>> _ = grid.set_active_scalars("tos")
>>> grid.plot()

.. seealso::

:ref:`TOS_O1_2001_2002 Dataset <tos_o1_2001_2002_dataset>`
See this dataset in the Dataset Gallery for more info.

"""
return _download_dataset(_dataset_tos_O1_2001_2002, load=load)


_dataset_tos_O1_2001_2002 = _SingleFileDownloadableDatasetLoader('tos_O1_2001-2002.nc')
10 changes: 10 additions & 0 deletions tests/core/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,3 +1036,13 @@ def test_gambitreader():

mesh = reader.read()
assert all([mesh.n_points, mesh.n_cells])


def test_netcdfcfreader():
filename = examples.download_tos_O1_2001_2002(load=False)
reader = pv.get_reader(filename)
assert isinstance(reader, pv.NetCDFCFReader)
assert reader.path == filename

mesh = reader.read()
assert all([mesh.n_points, mesh.n_cells])