Skip to content

Commit

Permalink
Merge pull request #53 from xylar/add-format-and-engine-attributes
Browse files Browse the repository at this point in the history
Add format and engine attributes to MeshDescriptor
  • Loading branch information
xylar authored Jun 7, 2023
2 parents 01d63b7 + 91270b5 commit 7b06c99
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ci/recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set name = "pyremap" %}
{% set version = "0.0.16" %}
{% set version = "1.0.0" %}

package:
name: {{ name|lower }}
Expand Down
3 changes: 3 additions & 0 deletions docs/versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Documentation On GitHub
`v0.0.14`_ `0.0.14`_
`v0.0.15`_ `0.0.15`_
`v0.0.16`_ `0.0.16`_
`v1.0.0`_ `1.0.0`_
================ ===============

.. _`stable`: ../stable/index.html
Expand All @@ -30,6 +31,7 @@ Documentation On GitHub
.. _`v0.0.14`: ../0.0.14/index.html
.. _`v0.0.15`: ../0.0.15/index.html
.. _`v0.0.16`: ../0.0.16/index.html
.. _`v1.0.0`: ../1.0.0/index.html
.. _`main`: https://github.com/MPAS-Dev/pyremap/tree/main
.. _`0.0.6`: https://github.com/MPAS-Dev/pyremap/tree/0.0.6
.. _`0.0.7`: https://github.com/MPAS-Dev/pyremap/tree/0.0.7
Expand All @@ -42,3 +44,4 @@ Documentation On GitHub
.. _`0.0.14`: https://github.com/MPAS-Dev/pyremap/tree/0.0.14
.. _`0.0.15`: https://github.com/MPAS-Dev/pyremap/tree/0.0.15
.. _`0.0.16`: https://github.com/MPAS-Dev/pyremap/tree/0.0.16
.. _`1.0.0`: https://github.com/MPAS-Dev/pyremap/tree/1.0.0
2 changes: 1 addition & 1 deletion pyremap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
from pyremap.polar import get_polar_descriptor, get_polar_descriptor_from_file
from pyremap.remapper import Remapper

__version_info__ = (0, 0, 16)
__version_info__ = (1, 0, 0)
__version__ = '.'.join(str(vi) for vi in __version_info__)
2 changes: 1 addition & 1 deletion pyremap/descriptor/lat_lon_2d_grid_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def to_scrip(self, scripFileName):
scripFileName : str
The path to which the SCRIP file should be written
"""
outFile = netCDF4.Dataset(scripFileName, 'w')
outFile = netCDF4.Dataset(scripFileName, 'w', format=self.format)

nLat, nLon = self.lat.shape

Expand Down
5 changes: 3 additions & 2 deletions pyremap/descriptor/lat_lon_grid_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def to_scrip(self, scripFileName):
scripFileName : str
The path to which the SCRIP file should be written
"""
outFile = netCDF4.Dataset(scripFileName, 'w')
outFile = netCDF4.Dataset(scripFileName, 'w', format=self.format)

nLat = len(self.lat)
nLon = len(self.lon)
Expand Down Expand Up @@ -296,7 +296,8 @@ def to_esmf(self, esmfFileName):
ds_out.attrs['gridType'] = 'unstructured mesh'
ds_out.attrs['version'] = '0.9'

ds_out.to_netcdf(esmfFileName)
ds_out.to_netcdf(esmfFileName, format=self.format,
engine=self.engine)

def _set_coords(self, latVarName, lonVarName, latDimName,
lonDimName):
Expand Down
10 changes: 10 additions & 0 deletions pyremap/descriptor/mesh_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ class MeshDescriptor:
coords : dict
A dictionary that can be used to construct an xarray.DataArray for each
coordinate in the mesh or grid
format : {'NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_64BIT',
'NETCDF3_CLASSIC'}
The NetCDF file format to use. Default is ``'NETCDF4'``
engine : {'netcdf4', 'scipy', 'h5netcdf'}
The library to use for xarray NetCDF output. The default is
``'netcdf4'``
"""
def __init__(self, meshName=None, regional=None):
"""
Expand All @@ -50,6 +58,8 @@ def __init__(self, meshName=None, regional=None):
self.dims = None
self.dimSizes = None
self.coords = None
self.format = 'NETCDF4'
self.engine = None

def to_scrip(self, scripFileName):
"""
Expand Down
5 changes: 3 additions & 2 deletions pyremap/descriptor/mpas_edge_mesh_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def to_scrip(self, scripFileName):
"""

inFile = netCDF4.Dataset(self.fileName, 'r')
outFile = netCDF4.Dataset(scripFileName, 'w')
outFile = netCDF4.Dataset(scripFileName, 'w', format=self.format)

# Get info from input file
latCell = inFile.variables['latCell'][:]
Expand Down Expand Up @@ -214,4 +214,5 @@ def to_esmf(self, esmfFileName):
ds_out.attrs['gridType'] = 'unstructured mesh'
ds_out.attrs['version'] = '0.9'

ds_out.to_netcdf(esmfFileName)
ds_out.to_netcdf(esmfFileName, format=self.format,
engine=self.engine)
5 changes: 3 additions & 2 deletions pyremap/descriptor/mpas_mesh_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def to_scrip(self, scripFileName):
raise ValueError('A SCRIP file won\'t work for remapping vertices')

inFile = netCDF4.Dataset(self.fileName, 'r')
outFile = netCDF4.Dataset(scripFileName, 'w')
outFile = netCDF4.Dataset(scripFileName, 'w', format=self.format)

# Get info from input file
latCell = inFile.variables['latCell'][:]
Expand Down Expand Up @@ -193,4 +193,5 @@ def to_esmf(self, esmfFileName):
ds_out.attrs['gridType'] = 'unstructured mesh'
ds_out.attrs['version'] = '0.9'

ds_out.to_netcdf(esmfFileName)
ds_out.to_netcdf(esmfFileName, format=self.format,
engine=self.engine)
5 changes: 3 additions & 2 deletions pyremap/descriptor/point_collection_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def to_scrip(self, scripFileName):
The path to which the SCRIP file should be written
"""

outFile = netCDF4.Dataset(scripFileName, 'w')
outFile = netCDF4.Dataset(scripFileName, 'w', format=self.format)

nPoints = len(self.lat)

Expand Down Expand Up @@ -166,4 +166,5 @@ def to_esmf(self, esmfFileName):
ds_out.attrs['gridType'] = 'unstructured mesh'
ds_out.attrs['version'] = '0.9'

ds_out.to_netcdf(esmfFileName)
ds_out.to_netcdf(esmfFileName, format=self.format,
engine=self.engine)
5 changes: 3 additions & 2 deletions pyremap/descriptor/projection_grid_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def to_scrip(self, scripFileName):
scripFileName : str
The path to which the SCRIP file should be written
"""
outFile = netCDF4.Dataset(scripFileName, 'w')
outFile = netCDF4.Dataset(scripFileName, 'w', format=self.format)

nx = len(self.x)
ny = len(self.y)
Expand Down Expand Up @@ -274,7 +274,8 @@ def to_esmf(self, esmfFileName):
ds_out.attrs['gridType'] = 'unstructured mesh'
ds_out.attrs['version'] = '0.9'

ds_out.to_netcdf(esmfFileName)
ds_out.to_netcdf(esmfFileName, format=self.format,
engine=self.engine)

def project_to_lat_lon(self, X, Y):
"""
Expand Down

0 comments on commit 7b06c99

Please sign in to comment.