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

h5netcdf read #307

Merged
merged 93 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
06cd592
h5
davidhassell Jan 18, 2024
20c3886
h5
davidhassell Jan 19, 2024
41e75ce
h5
davidhassell Jan 19, 2024
581ad89
h5
davidhassell Jan 19, 2024
6d2f5f5
h5
davidhassell Jan 22, 2024
8492d21
dev
davidhassell Jan 22, 2024
0bccae4
Merge branch 'h5-read' of github.com:davidhassell/cfdm into h5-read
davidhassell Jan 23, 2024
75a4c1c
dev
davidhassell Jan 23, 2024
b54d37e
dev
davidhassell Jan 23, 2024
21942d5
dev
davidhassell Jan 24, 2024
85d5d88
dev
davidhassell Jan 24, 2024
4427c83
dev
davidhassell Jan 24, 2024
3061454
dev
davidhassell Jan 24, 2024
5b2287a
dev
davidhassell Jan 25, 2024
cb4e5c2
h5py, h5netcdf, s3fs requirements
davidhassell Jan 25, 2024
6045ab5
dev
davidhassell Jan 25, 2024
45bcfab
dev
davidhassell Jan 26, 2024
03808df
dev
davidhassell Jan 26, 2024
c28e36d
dev
davidhassell Jan 27, 2024
03733fa
dev
davidhassell Jan 30, 2024
2e7f76f
dev
davidhassell Jan 30, 2024
f36c143
dev
davidhassell Jan 31, 2024
be74775
dev
davidhassell Jan 31, 2024
29faa9d
dev
davidhassell Feb 1, 2024
f811f93
dev
davidhassell Feb 2, 2024
8c3eb5c
dev
davidhassell Feb 2, 2024
a3aa8d8
dev
davidhassell Feb 3, 2024
cf0fd2c
dev
davidhassell Feb 3, 2024
1cff2d0
dev
davidhassell Feb 4, 2024
740f4cd
dev
davidhassell Feb 5, 2024
c2321be
dev
davidhassell Feb 6, 2024
0009c31
dev
davidhassell Feb 7, 2024
d19d6c3
dev
davidhassell Feb 8, 2024
92f59eb
dev
davidhassell Feb 9, 2024
59669a1
dev
davidhassell Feb 12, 2024
589dc13
dev
davidhassell Feb 13, 2024
6366990
client_kwargs endpoint_url
davidhassell Feb 22, 2024
0e7ef66
netcdf_flatten tidy and docs
davidhassell Feb 27, 2024
b00f4f5
netcdf_flatten tidy and docs
davidhassell Feb 27, 2024
0ae5bf6
dev
davidhassell Feb 28, 2024
23852a7
dev
davidhassell Mar 4, 2024
3374b31
fix upstream merge conflicts
davidhassell Mar 4, 2024
d0bb0ce
fix upstream merge conflicts
davidhassell Mar 4, 2024
123bd37
dev
davidhassell Mar 4, 2024
1c0eb30
dev
davidhassell Mar 4, 2024
0255859
dev
davidhassell Mar 4, 2024
dc00a05
dev
davidhassell Mar 4, 2024
00a15e9
dev
davidhassell Mar 7, 2024
17e67c3
dev
davidhassell Mar 7, 2024
2899d96
dev
davidhassell Mar 8, 2024
7312b53
dev
davidhassell Mar 15, 2024
fdab1c9
orthogonal indexing
davidhassell Mar 21, 2024
a715c23
dev
davidhassell Mar 21, 2024
6b2049a
dev
davidhassell Mar 22, 2024
995c285
Merge branch 'main' of github.com:NCAS-CMS/cfdm into h5-read
davidhassell Mar 26, 2024
3d90bef
dev
davidhassell Mar 26, 2024
01687fc
dev
davidhassell Mar 28, 2024
c68b7a0
dev
davidhassell Apr 5, 2024
4335e02
dev
davidhassell Apr 5, 2024
4283f44
dev
davidhassell Apr 5, 2024
889490a
dev
davidhassell Apr 8, 2024
d590fd9
dev
davidhassell May 13, 2024
3703495
upstream merge conflicts
davidhassell Jun 20, 2024
b3a1b56
dev
davidhassell Jun 20, 2024
a1e8bc8
dev
davidhassell Jun 20, 2024
283e9dd
Typos
davidhassell Jul 23, 2024
e1cba05
Update Changelog.rst
davidhassell Jul 23, 2024
d4fbbbd
netcdf_indexer
davidhassell Jul 23, 2024
cb84a9c
remove h5py dependency
davidhassell Jul 23, 2024
ea7e229
Merge branch 'h5-read' of github.com:davidhassell/cfdm into h5-read
davidhassell Jul 23, 2024
50c5b9f
Typo
davidhassell Jul 23, 2024
040e0a2
Remove incorrect logic
davidhassell Jul 23, 2024
d79d4b3
Typo
davidhassell Jul 23, 2024
c4945a1
Typo
davidhassell Jul 23, 2024
3fd8b43
Typo
davidhassell Jul 23, 2024
c687796
Typo
davidhassell Jul 23, 2024
de8402c
Typos
davidhassell Jul 23, 2024
82fc7dd
netcdf_flattener licence
davidhassell Jul 23, 2024
40db78c
Typos
davidhassell Jul 23, 2024
6ff5a4a
Improved docstrings
davidhassell Jul 23, 2024
4633880
Typos
davidhassell Jul 23, 2024
8cf9594
rename variables
davidhassell Jul 23, 2024
e97d14f
Improved docstrings
davidhassell Jul 23, 2024
66c711f
rename variables
davidhassell Jul 23, 2024
1642521
remove debugging code
davidhassell Jul 23, 2024
3b62cbf
rename variables for clarity
davidhassell Jul 23, 2024
fe41003
unskip opendap test
davidhassell Jul 23, 2024
e3ad717
Tidy docs
davidhassell Jul 23, 2024
dad52b9
No NetCDFIndexer class
davidhassell Jul 23, 2024
4874560
Non deprecated in new class docs
davidhassell Jul 23, 2024
065ccc6
Better docstring
davidhassell Jul 23, 2024
31919a9
remove TODO (all OK)
davidhassell Jul 24, 2024
6f1c397
tidy
davidhassell Jul 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
Version NEXTRELEASE
Version NEXTVERSION
-------------------

**2024-??-??**

* Upgrades to allow cfdm to work with Python 3.12
(https://github.com/NCAS-CMS/cfdm/issues/302)
* New function `cfdm.netcdf_flattener` that replaces the import of
`netcdf_flattener` (https://github.com/NCAS-CMS/cfdm/issues/286)
* New function `cfdm.netcdf_indexer` that applies netCDF masking and
unpacking to arbitrary arrays
(https://github.com/NCAS-CMS/cfdm/issues/285)
* Allow access to netCDF-4 files in S3 object stores
(https://github.com/NCAS-CMS/cfdm/issues/285)
* Allow a choice of netCDF engines
(https://github.com/NCAS-CMS/cfdm/issues/285)
* Fix bug that caused `cfdm.write` to fail when a parametric Z
dimension coordinate did not have a ``computed_standard_name``
attribute (https://github.com/NCAS-CMS/cfdm/issues/303)
* New class `cfdm.H5netcdfArray`
* New class `cfdm.NetCDF4Array`
* New dependency: ``h5netcdf>=1.3.0``
davidhassell marked this conversation as resolved.
Show resolved Hide resolved
* New dependency: ``h5py>=3.10.0``
* New dependency: ``s3fs>=2024.6.0``
* New dependency: ``dask>=2024.6.0``
* Removed dependency: ``netcdf_flattener``

----

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ inspecting it:

The ``cfdm`` package can:

* read field and domain constructs from netCDF and CDL datasets,
* read field and domain constructs from netCDF and CDL datasets with a
choice of netCDF backends,
* create new field and domain constructs in memory,
* write and append field and domain constructs to netCDF datasets on disk,
* read, write, and manipulate UGRID mesh topologies,
Expand Down
86 changes: 73 additions & 13 deletions cfdm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,105 @@
__cf_version__ = core.__cf_version__
__version__ = core.__version__

_requires = ("cftime", "netcdf_flattener", "scipy")
_requires = core._requires + (
"cftime",
"netCDF4",
"scipy",
"h5netcdf",
"s3fs",
)

_error0 = f"cfdm requires the modules {', '.join(_requires)}. "

# Check the version of cftime
try:
import cftime
except ImportError as error1:
raise ImportError(_error0 + str(error1))

# Check the version of cftime
_minimum_vn = "1.6.0"
if Version(cftime.__version__) < Version(_minimum_vn):
raise ValueError(
f"Bad cftime version: cfdm requires cftime>={_minimum_vn}. "
f"Got {cftime.__version__} at {cftime.__file__}"
)

# Check the version of netCDF4
try:
import netcdf_flattener
import netCDF4
except ImportError as error1:
raise ImportError(_error0 + str(error1))

# Check the version of netcdf_flattener
_minimum_vn = "1.2.0"
if Version(netcdf_flattener.__version__) < Version(_minimum_vn):
_minimum_vn = "1.5.4"
if Version(netCDF4.__version__) < Version(_minimum_vn):
raise ValueError(
f"Bad netcdf_flattener version: cfdm requires "
f"netcdf_flattener>={_minimum_vn}. Got {netcdf_flattener.__version__} "
f"at {netcdf_flattener.__file__}"
f"Bad netCDF4 version: cfdm requires netCDF4>={_minimum_vn}. "
f"Got {netCDF4.__version__} at {netCDF4.__file__}"
)

# Check the version of h5netcdf
try:
import scipy
import h5netcdf
except ImportError as error1:
raise ImportError(_error0 + str(error1))

_minimum_vn = "1.3.0"
if Version(h5netcdf.__version__) < Version(_minimum_vn):
raise ValueError(
f"Bad h5netcdf version: cfdm requires h5netcdf>={_minimum_vn}. "
f"Got {h5netcdf.__version__} at {h5netcdf.__file__}"
)

# Check the version of h5py
try:
import h5py
except ImportError as error1:
raise ImportError(_error0 + str(error1))

_minimum_vn = "3.10.0"
if Version(h5py.__version__) < Version(_minimum_vn):
raise ValueError(
f"Bad h5py version: cfdm requires h5py>={_minimum_vn}. "
f"Got {h5py.__version__} at {h5py.__file__}"
)

# Check the version of s3fs
try:
import s3fs
except ImportError as error1:
raise ImportError(_error0 + str(error1))

_minimum_vn = "2024.6.0"
if Version(s3fs.__version__) < Version(_minimum_vn):
raise ValueError(
f"Bad s3fs version: cfdm requires s3fs>={_minimum_vn}. "
f"Got {s3fs.__version__} at {s3fs.__file__}"
)

# Check the version of scipy
try:
import scipy
except ImportError as error1:
raise ImportError(_error0 + str(error1))

_minimum_vn = "1.10.0"
if Version(scipy.__version__) < Version(_minimum_vn):
raise ValueError(
f"Bad scipy version: cfdm requires "
f"scipy>={_minimum_vn}. Got {scipy.__version__} "
f"at {scipy.__file__}"
f"Bad scipy version: cfdm requires scipy>={_minimum_vn}. "
f"Got {scipy.__version__} at {scipy.__file__}"
)

# Check the version of dask
try:
import dask
except ImportError as error1:
raise ImportError(_error0 + str(error1))

_minimum_vn = "2024.6.0"
if Version(dask.__version__) < Version(_minimum_vn):
raise ValueError(
f"Bad scipy version: cfdm requires dask>={_minimum_vn}. "
f"Got {dask.__version__} at {dask.__file__}"
)

from .constants import masked
Expand Down Expand Up @@ -140,7 +196,10 @@
CompressedArray,
Data,
GatheredArray,
H5netcdfArray,
NetCDFArray,
NetCDF4Array,
netcdf_indexer,
NumpyArray,
PointTopologyArray,
RaggedArray,
Expand Down Expand Up @@ -196,6 +255,7 @@
from .cfdmimplementation import CFDMImplementation, implementation

from .read_write import read, write
from .read_write.netcdf.flatten import netcdf_flatten

from .examplefield import example_field, example_fields, example_domain

Expand Down
2 changes: 1 addition & 1 deletion cfdm/abstract/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def classes(self):
'Index',
'InteriorRing',
'List',
'NetCDFArray',
'NetCDF4Array',
'NodeCountProperties',
'PartNodeCountProperties',
'RaggedContiguousArray',
Expand Down
81 changes: 29 additions & 52 deletions cfdm/cfdmimplementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
CellConnectivityArray,
Data,
GatheredArray,
NetCDFArray,
H5netcdfArray,
NetCDF4Array,
PointTopologyArray,
RaggedContiguousArray,
RaggedIndexedArray,
Expand Down Expand Up @@ -1358,10 +1359,10 @@ def get_data_maximum(self, parent):

:Returns:

Data instance
Scalar `Data` instance

"""
return parent.data.maximum()
return parent.data.maximum(squeeze=True)

def get_data_sum(self, parent):
"""Return the sum of the data.
Expand All @@ -1372,10 +1373,10 @@ def get_data_sum(self, parent):

:Returns:

Data instance
Scalar `Data` instance

"""
return parent.data.sum()
return parent.data.sum(squeeze=True)

def get_count(self, construct):
"""Return the count variable of compressed data.
Expand Down Expand Up @@ -2291,67 +2292,41 @@ def initialise_TiePointIndex(self):
cls = self.get_class("TiePointIndex")
return cls()

def initialise_NetCDFArray(
self,
filename=None,
address=None,
dtype=None,
shape=None,
mask=True,
units=False,
calendar=None,
missing_values=None,
):
"""Return a netCDF array instance.
def initialise_NetCDF4Array(self, **kwargs):
"""Return a `NetCDF4Array` instance.

:Parameters:

filename: `str`

address: `str`

dytpe: `numpy.dtype`
kwargs: optional
Initialisation parameters to pass to the new instance.

shape: sequence of `int`, optional
.. versionadded:: (cfdm) NEXTVERSION

mask: `bool`, optional
:Returns:

units: `str` or `None` or False, optional
The units of the netCDF variable. Set to `None` to
indicate that there are no units. If False (the
default) then the units are considered unset.
`NetCDF4Array`

.. versionadded:: (cfdm) 1.10.0.2
"""
cls = self.get_class("NetCDF4Array")
return cls(**kwargs)

calendar: `str` or `None`, optional
The calendar of the netCDF variable. By default, or if
set to `None`, then the CF default calendar is
assumed, if applicable.
def initialise_H5netcdfArray(self, **kwargs):
"""Return a `H5netcdfArray` instance.

.. versionadded:: (cfdm) 1.10.0.2
.. versionadded:: (cfdm) NEXTVERSION

missing_values: `dict`, optional
The missing value indicators defined by the netCDF
variable attributes.
:Parameters:

.. versionadded:: (cfdm) 1.10.0.3
kwargs: optional
Initialisation parameters to pass to the new instance.

:Returns:

`NetCDFArray`
`H5netcdfArray`

"""
cls = self.get_class("NetCDFArray")
return cls(
filename=filename,
address=address,
dtype=dtype,
shape=shape,
mask=mask,
units=units,
calendar=calendar,
missing_values=missing_values,
)
cls = self.get_class("H5netcdfArray")
return cls(**kwargs)

def initialise_BoundsFromNodesArray(self, **kwargs):
"""Return a node bounds array.
Expand Down Expand Up @@ -3707,7 +3682,8 @@ def squeeze(self, construct, axes=None):
Data=Data,
BoundsFromNodesArray=BoundsFromNodesArray,
GatheredArray=GatheredArray,
NetCDFArray=NetCDFArray,
H5netcdfArray=H5netcdfArray,
NetCDF4Array=NetCDF4Array,
PointTopologyArray=PointTopologyArray,
RaggedContiguousArray=RaggedContiguousArray,
RaggedIndexedArray=RaggedIndexedArray,
Expand Down Expand Up @@ -3750,7 +3726,8 @@ def implementation():
'Datum': <class 'cfdm.datum.Datum'>,
'Data': <class 'cfdm.data.data.Data'>,
'GatheredArray': <class 'cfdm.data.gatheredarray.GatheredArray'>,
'NetCDFArray': <class 'cfdm.data.netcdfarray.NetCDFArray'>,
'H5netcdfArray': <class 'cfdm.data.h5netcdfarray.H5netcdfArray'>,
'NetCDF4Array': <class 'cfdm.data.netcdf4array.NetCDF4Array'>,
'PointTopologyArray': <class 'cfdm.data.pointtopologyarray.PointTopologyArray'>,
'RaggedContiguousArray': <class 'cfdm.data.raggedcontiguousarray.RaggedContiguousArray'>,
'RaggedIndexedArray': <class 'cfdm.data.raggedindexedarray.RaggedIndexedArray'>,
Expand Down
36 changes: 14 additions & 22 deletions cfdm/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,20 @@

"""

__date__ = "2024-03-01"
__date__ = "2024-??-??"
__cf_version__ = "1.11"
__version__ = "1.11.1.0"
__version__ = "1.11.2.0"
davidhassell marked this conversation as resolved.
Show resolved Hide resolved

from packaging import __version__ as _packaging_ver
from packaging import __file__ as _packaging_file
from packaging.version import Version

import platform

_requires = ("numpy", "netCDF4", "packaging")
_requires = ("numpy", "packaging")

_error0 = f"cfdm.core requires the modules {', '.join(_requires)}. "

try:
import netCDF4
except ImportError as error1:
raise ImportError(_error0 + str(error1))

try:
import numpy as np
except ImportError as error1:
raise ImportError(_error0 + str(error1))

# Check the version of python
_minimum_vn = "3.8.0"
if Version(platform.python_version()) < Version(_minimum_vn):
Expand All @@ -44,22 +34,24 @@
)

# Check the version of packaging
try:
import packaging
except ImportError as error1:
raise ImportError(_error0 + str(error1))

_minimum_vn = "20.0"
if Version(_packaging_ver) < Version(_minimum_vn):
raise ValueError(
f"Bad packaging version: cfdm requires packaging>={_minimum_vn}. "
f"Bad packaging version: cfdm.core requires packaging>={_minimum_vn}. "
f"Got {_packaging_ver} at {_packaging_file}"
)

# Check the version of netCDF4
_minimum_vn = "1.5.4"
if Version(netCDF4.__version__) < Version(_minimum_vn):
raise ValueError(
f"Bad netCDF4 version: cfdm.core requires netCDF4>={_minimum_vn}. "
f"Got {netCDF4.__version__} at {netCDF4.__file__}"
)

# Check the version of numpy
try:
import numpy as np
except ImportError as error1:
raise ImportError(_error0 + str(error1))

_minimum_vn = "1.15"
if Version(np.__version__) < Version(_minimum_vn):
raise ValueError(
Expand Down
Loading