Skip to content

Commit

Permalink
Merge branch 'develop' into maint/pysat_depr
Browse files Browse the repository at this point in the history
  • Loading branch information
jklenzing committed Jun 7, 2023
2 parents 78ad434 + 70b5b96 commit 42b02ca
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
if: ${{ matrix.test_config == 'Ops'}}
run: |
pip install --no-cache-dir numpy==${{ matrix.numpy_ver }}
pip install "cdflib<1.0"
pip install -r requirements.txt
pip install -r test_requirements.txt
pip install .
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
* Set pysat 3.1.0 minimum
* Use pysat logger to raise non-deprecation warnings
* Update syntax based on latest pysat deprecations to make the code compatible with pysat 3.2.0.
* Updated syntax compliance with cdflib 1.0+

## [0.0.4] - 2022-11-07
* Update instrument tests with new test class
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Python 3.6+.

| Common modules | Community modules | Optional Modules |
| ---------------- | ----------------- |------------------|
| beautifulsoup4 | cdflib | pysatCDF |
| beautifulsoup4 | cdflib>=0.4.4 | pysatCDF |
| lxml | pysat>=3.1.0 | |
| netCDF4 | | |
| numpy | | |
Expand Down
4 changes: 2 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Prerequisites

pysatNASA uses common Python modules, as well as modules developed by
and for the Space Physics community. This module officially supports
Python 3.8+ and pysat 3.1.0+.
Python 3.6+ and pysat 3.1.0+.

================== =================
Common modules Community modules
Expand All @@ -25,7 +25,7 @@ Python 3.8+ and pysat 3.1.0+.
numpy
pandas
requests
xarray<2022.11
xarray
================== =================


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ keywords = [
dependencies = [
"beautifulsoup4",
"cdasws",
"cdflib >= 0.4.4, <1.0",
"cdflib >= 0.4.4",
"lxml",
"netCDF4",
"numpy",
Expand Down
40 changes: 28 additions & 12 deletions pysatNASA/instruments/methods/_cdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ def __init__(self, filename,
self.meta = {}
self._dependencies = {}

self._variable_names = (self._cdf_info['rVariables']
+ self._cdf_info['zVariables'])
if hasattr(self._cdf_info, 'rVariables'):
self._variable_names = (self._cdf_info.rVariables
+ self._cdf_info.zVariables)
else:
# cdflib < 1.0 stores info as a dict
self._variable_names = (self._cdf_info['rVariables']
+ self._cdf_info['zVariables'])

self.load_variables()

Expand Down Expand Up @@ -156,8 +161,13 @@ def set_epoch(self, x_axis_var):
"""

data_type_description = self._cdf_file.varinq(
x_axis_var)['Data_Type_Description']
if hasattr(self._cdf_file.varinq(x_axis_var), 'Data_Type_Description'):
data_type_description = self._cdf_file.varinq(
x_axis_var).Data_Type_Description
else:
# cdflib < 1.0 stores this as a dict
data_type_description = self._cdf_file.varinq(
x_axis_var)['Data_Type_Description']

center_measurement = self._center_measurement
cdf_file = self._cdf_file
Expand Down Expand Up @@ -298,7 +308,12 @@ def load_variables(self):
if not re.match(var_regex, variable_name):
# Skip this variable
continue
var_atts = self._cdf_file.varattsget(variable_name, to_np=True)
try:
var_atts = self._cdf_file.varattsget(variable_name, to_np=True)
except TypeError:
# cdflib 1.0+ drops to_np kwarg, assumes True
var_atts = self._cdf_file.varattsget(variable_name)

for k in var_atts:
var_atts[k] = var_atts[k] # [0]

Expand All @@ -319,13 +334,14 @@ def load_variables(self):
continue

if "FILLVAL" in var_atts:
if (var_properties['Data_Type_Description'] == 'CDF_FLOAT'
or var_properties['Data_Type_Description']
== 'CDF_REAL4'
or var_properties['Data_Type_Description']
== 'CDF_DOUBLE'
or var_properties['Data_Type_Description']
== 'CDF_REAL8'):
if hasattr(var_properties, 'Data_Type_Description'):
data_type_desc = var_properties.Data_Type_Description
else:
# cdflib < 1.0 stores this as a dict
data_type_desc = var_properties['Data_Type_Description']

if data_type_desc in ['CDF_FLOAT', 'CDF_REAL4', 'CDF_DOUBLE',
'CDF_REAL8']:

if ydata[ydata == var_atts["FILLVAL"]].size != 0:
ydata[ydata == var_atts["FILLVAL"]] = np.nan
Expand Down
10 changes: 8 additions & 2 deletions pysatNASA/instruments/methods/cdaweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""

import cdflib
import datetime as dt
import numpy as np
import os
Expand All @@ -26,6 +25,13 @@
from pysat.utils import io
from pysatNASA.instruments.methods import CDF as libCDF

try:
# cdflib 1.0 syntax
from cdflib.xarray import cdf_to_xarray
except ModuleNotFoundError:
# cdflib 0.4 syntax required for backwards compatibility
from cdflib import cdf_to_xarray

try:
import pysatCDF
auto_CDF = pysatCDF.CDF
Expand Down Expand Up @@ -372,7 +378,7 @@ def load_xarray(fnames, tag='', inst_id='',
lfnames = fnames

for lfname in lfnames:
temp_data = cdflib.cdf_to_xarray(lfname, to_datetime=True)
temp_data = cdf_to_xarray(lfname, to_datetime=True)
if drop_dims:
temp_data = temp_data.drop_dims(drop_dims)
if var_translation:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
beautifulsoup4
cdasws
cdflib>=0.4.4,<1.0
cdflib>=0.4.4
lxml
netCDF4
numpy
Expand Down

0 comments on commit 42b02ca

Please sign in to comment.