Skip to content

Commit

Permalink
Migrate to pycdfpp>=0.6
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Jeandet <[email protected]>
  • Loading branch information
jeandet committed Oct 18, 2023
1 parent 2bab5e8 commit 160b219
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyistp/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _get_attributes(cdf: object, var: str):
value = cdf.variable_attribute_value(var, attr)
if attr.endswith("_PTR") or attr[:-1].endswith("_PTR_"):
if cdf.has_variable(value):
value = cdf.values(value)
value = cdf.values(value, is_metadata_variable=True)
if hasattr(value, 'tolist'):
attrs[attr] = value.tolist()
else:
Expand Down
25 changes: 19 additions & 6 deletions pyistp/drivers/pycdfpp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import pycdfpp
import numpy as np


def _drop_first_dim_if_nrv(is_nrv: bool, values):
if is_nrv:
if values.shape[0] == 1:
return values[0]
else:
return np.array([], dtype=values.dtype)
else:
return values


class Driver:
Expand All @@ -24,7 +35,7 @@ def has_variable(self, name):
return name in self.cdf

def is_char(self, var):
return self.cdf[var].type == pycdfpp.CDF_CHAR
return self.cdf[var].type == pycdfpp.DataType.CDF_CHAR

def variable_attributes(self, var):
if self.cdf:
Expand All @@ -36,8 +47,10 @@ def variable_attribute_value(self, var, attr):
return self.cdf[var].attributes[attr][0]
return None

def values(self, var):
v = self.cdf[var]
if v.type in (pycdfpp.CDF_EPOCH, pycdfpp.CDF_EPOCH16, pycdfpp.CDF_TIME_TT2000):
return pycdfpp.to_datetime64(v)
return v.values
def values(self, var, is_metadata_variable=False):
v: pycdfpp.Variable = self.cdf[var]
if v.type in (pycdfpp.DataType.CDF_EPOCH, pycdfpp.DataType.CDF_EPOCH16, pycdfpp.DataType.CDF_TIME_TT2000):
return _drop_first_dim_if_nrv(v.is_nrv, pycdfpp.to_datetime64(v))
if is_metadata_variable and self.is_char(var):
return _drop_first_dim_if_nrv(v.is_nrv, v.values_encoded)
return _drop_first_dim_if_nrv(v.is_nrv, v.values)
2 changes: 1 addition & 1 deletion pyistp/drivers/spacepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def variable_attribute_value(self, var, attr):
return self.cdf[var].attrs[attr]
return None

def values(self, var):
def values(self, var, is_metadata_variable=False):
v = self.cdf[var]
if v.type() in (pycdf.const.CDF_EPOCH, pycdf.const.CDF_EPOCH16, pycdf.const.CDF_TIME_TT2000):
return np.vectorize(np.datetime64)(v[:])
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = ['pycdfpp<=0.4.6']
dependencies = ['pycdfpp>=0.6.0']
[project.urls]
homepage = "https://github.com/SciQLop/PyISTP"
repository = "https://github.com/SciQLop/PyISTP"
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pycdfpp
pycdfpp>=0.6.0
pip
bump2version
wheel
Expand Down

0 comments on commit 160b219

Please sign in to comment.