Skip to content

Commit

Permalink
Merge pull request #132 from pysat/maint_try_except_data
Browse files Browse the repository at this point in the history
MAINT: support for pysat behaviour changes
  • Loading branch information
aburrell authored Oct 24, 2023
2 parents baaf37e + cc4c9ff commit 1a44957
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 43 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
* Updated package documentation, yamls, and other supporting files
* Updated the LISIRD download routine to reflect new behaviour
* Changed F10.7 daily test day to ensure new pysat padding tests work
* Removed try/except loop that was a fix for pysat < 3.1.0
* Updated 'use_header' kwarg use for pysat 3.2.0 changes

[0.0.10] - 2023-06-01
---------------------
Expand Down
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'
html_theme_path = ["_themes", ]
html_logo = os.path.join(os.path.abspath('.'), 'figures',
'pysatSpaceWeather.png')
html_theme_options = {'logo_only': True}

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ routines to load common historic, real-time, and forecasted space weather
indices as pysat.Instrument objects.

.. toctree::
:maxdepth: -1
:maxdepth: 2

overview.rst
installation.rst
Expand Down
11 changes: 9 additions & 2 deletions pysatSpaceWeather/instruments/methods/f107.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ def combine_f107(standard_inst, forecast_inst, start=None, stop=None):
# Set the load kwargs, which vary by pysat version and tag
load_kwargs = {'date': itime}

if Version(pysat.__version__) > Version('3.0.1'):
# TODO(#131): Remove version check after minimum version
# supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
load_kwargs['use_header'] = True

if standard_inst.tag == 'daily':
Expand Down Expand Up @@ -214,7 +217,11 @@ def combine_f107(standard_inst, forecast_inst, start=None, stop=None):
for filename in files:
if filename is not None:
load_kwargs = {'fname': filename}
if Version(pysat.__version__) > Version('3.0.1'):

# TODO(#131): Remove version check after minimum version
# supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
load_kwargs['use_header'] = True

forecast_inst.load(**load_kwargs)
Expand Down
31 changes: 21 additions & 10 deletions pysatSpaceWeather/instruments/methods/kp_ap.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,14 @@ def filter_geomag(inst, min_kp=0, max_kp=9, filter_time=24, kp_inst=None,
if kp_inst.empty:
load_kwargs = {'date': inst.index[0], 'end_date': inst.index[-1],
'verifyPad': True}
if Version(pysat.__version__) > Version('3.0.1'):

# TODO(#131): Remove version check after minimum version supported
# is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
load_kwargs['use_header'] = True

# TODO(#117): This gets around a bug in pysat that will be fixed in
# pysat version 3.1.0+
try:
kp_inst.load(**load_kwargs)
except TypeError:
pass
kp_inst.load(**load_kwargs)

if kp_inst.empty:
raise IOError(
Expand Down Expand Up @@ -598,7 +597,11 @@ def combine_kp(standard_inst=None, recent_inst=None, forecast_inst=None,
# Load and save the standard data for as many times as possible
if inst_flag == 'standard':
load_kwargs = {'date': itime}
if Version(pysat.__version__) > Version('3.0.1'):

# TODO(#131): Remove version check after minimum version supported
# is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
load_kwargs['use_header'] = True

standard_inst.load(**load_kwargs)
Expand Down Expand Up @@ -628,7 +631,11 @@ def combine_kp(standard_inst=None, recent_inst=None, forecast_inst=None,
for filename in files:
if filename is not None:
load_kwargs = {'fname': filename}
if Version(pysat.__version__) > Version('3.0.1'):

# TODO(#131): Remove version check after minimum version
# supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
load_kwargs['use_header'] = True
recent_inst.load(**load_kwargs)

Expand Down Expand Up @@ -664,7 +671,11 @@ def combine_kp(standard_inst=None, recent_inst=None, forecast_inst=None,
for filename in files:
if filename is not None:
load_kwargs = {'fname': filename}
if Version(pysat.__version__) > Version('3.0.1'):

# TODO(#131): Remove version check after minimum version
# supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
load_kwargs['use_header'] = True
forecast_inst.load(**load_kwargs)

Expand Down
9 changes: 8 additions & 1 deletion pysatSpaceWeather/tests/test_methods_ace.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ class TestACESWEPAMMethods(object):

def setup_method(self):
"""Create a clean testing setup."""
self.testInst = pysat.Instrument('pysat', 'testing', use_header=True)

# TODO(#131): Remove version check after min version supported is 3.2.0
inst_kwargs = dict()
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
inst_kwargs['use_header'] = True

self.testInst = pysat.Instrument('pysat', 'testing', **inst_kwargs)
self.testInst.load(date=self.testInst.inst_module._test_dates[''][''])

self.omni_keys = ['sw_proton_dens_norm', 'sw_ion_temp_norm']
Expand Down
5 changes: 4 additions & 1 deletion pysatSpaceWeather/tests/test_methods_f107.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ def setup_method(self):
self.combine_times = {"start": self.test_day - dt.timedelta(days=30),
"stop": self.test_day + dt.timedelta(days=3)}
self.load_kwargs = {}
if Version(pysat.__version__) > Version('3.0.1'):

# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
self.load_kwargs['use_header'] = True

return
Expand Down
7 changes: 6 additions & 1 deletion pysatSpaceWeather/tests/test_methods_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ class TestGeneralMethods(object):

def setup_method(self):
"""Create a clean testing setup."""
self.testInst = pysat.Instrument('pysat', 'testing', use_header=True)
# TODO(#131): Remove version check after min version supported is 3.2.0
inst_kwargs = dict()
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
inst_kwargs['use_header'] = True
self.testInst = pysat.Instrument('pysat', 'testing', **inst_kwargs)
self.testInst.load(date=self.testInst.inst_module._test_dates[''][''])
return

Expand Down
90 changes: 63 additions & 27 deletions pysatSpaceWeather/tests/test_methods_kp.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ def setup_method(self):
"""Create a clean testing setup."""
self.test_function = kp_ap.initialize_kp_metadata

inst_dict = {'num_samples': 12}
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
inst_dict['use_header'] = True

# Load a test instrument
self.testInst = pysat.Instrument('pysat', 'testing', num_samples=12,
use_header=True)
self.testInst = pysat.Instrument('pysat', 'testing', **inst_dict)
test_time = pysat.instruments.pysat_testing._test_dates['']['']

load_kwargs = {'date': test_time}
if Version(pysat.__version__) > Version('3.0.1'):
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
load_kwargs['use_header'] = True

self.testInst.load(**load_kwargs)
Expand Down Expand Up @@ -122,13 +129,20 @@ def setup_method(self):
"""Create a clean testing setup."""
self.test_function = kp_ap.initialize_ap_metadata

inst_dict = {'num_samples': 12}
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
inst_dict['use_header'] = True

# Load a test instrument
self.testInst = pysat.Instrument('pysat', 'testing', num_samples=12,
use_header=True)
self.testInst = pysat.Instrument('pysat', 'testing', **inst_dict)
test_time = pysat.instruments.pysat_testing._test_dates['']['']

load_kwargs = {'date': test_time}
if Version(pysat.__version__) > Version('3.0.1'):
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
load_kwargs['use_header'] = True

self.testInst.load(**load_kwargs)
Expand Down Expand Up @@ -170,13 +184,20 @@ def setup_method(self):
"""Create a clean testing setup."""
self.test_function = kp_ap.initialize_bartel_metadata

inst_dict = {'num_samples': 12}
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
inst_dict['use_header'] = True

# Load a test instrument
self.testInst = pysat.Instrument('pysat', 'testing', num_samples=12,
use_header=True)
self.testInst = pysat.Instrument('pysat', 'testing', **inst_dict)
test_time = pysat.instruments.pysat_testing._test_dates['']['']

load_kwargs = {'date': test_time}
if Version(pysat.__version__) > Version('3.0.1'):
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
load_kwargs['use_header'] = True

self.testInst.load(**load_kwargs)
Expand Down Expand Up @@ -267,13 +288,20 @@ class TestSWKp(object):

def setup_method(self):
"""Create a clean testing setup."""
inst_dict = {'num_samples': 12}
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
inst_dict['use_header'] = True

# Load a test instrument
self.testInst = pysat.Instrument('pysat', 'testing', num_samples=12,
use_header=True)
self.testInst = pysat.Instrument('pysat', 'testing', **inst_dict)
test_time = pysat.instruments.pysat_testing._test_dates['']['']

load_kwargs = {'date': test_time}
if Version(pysat.__version__) > Version('3.0.1'):
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
load_kwargs['use_header'] = True

self.testInst.load(**load_kwargs)
Expand Down Expand Up @@ -476,22 +504,23 @@ def setup_method(self):

# Set combination testing input
test_day = dt.datetime(2019, 3, 18)
self.combine = {"standard_inst": pysat.Instrument(inst_module=sw_kp,
tag="def",
update_files=True,
use_header=True),
"recent_inst": pysat.Instrument(inst_module=sw_kp,
tag="recent",
update_files=True,
use_header=True),
"forecast_inst":
pysat.Instrument(inst_module=sw_kp, tag="forecast",
update_files=True, use_header=True),
idict = {'inst_module': sw_kp, 'update_files': True}
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
idict['use_header'] = True

self.combine = {"standard_inst": pysat.Instrument(tag="def", **idict),
"recent_inst": pysat.Instrument(tag="recent", **idict),
"forecast_inst": pysat.Instrument(tag="forecast",
**idict),
"start": test_day - dt.timedelta(days=30),
"stop": test_day + dt.timedelta(days=3),
"fill_val": -1}
self.load_kwargs = {"date": test_day}
if Version(pysat.__version__) > Version('3.0.1'):
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
self.load_kwargs['use_header'] = True

return
Expand Down Expand Up @@ -662,12 +691,19 @@ class TestSWAp(object):

def setup_method(self):
"""Create a clean testing setup."""
self.test_inst = pysat.Instrument('pysat', 'testing', num_samples=10,
use_header=True)
inst_dict = {'num_samples': 10}
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
inst_dict['use_header'] = True

self.test_inst = pysat.Instrument('pysat', 'testing', **inst_dict)
test_time = pysat.instruments.pysat_testing._test_dates['']['']

load_kwargs = {'date': test_time}
if Version(pysat.__version__) > Version('3.0.1'):
# TODO(#131): Remove version check after min version supported is 3.2.0
if all([Version(pysat.__version__) > Version('3.0.1'),
Version(pysat.__version__) < Version('3.2.0')]):
load_kwargs['use_header'] = True

self.test_inst.load(**load_kwargs)
Expand Down

0 comments on commit 1a44957

Please sign in to comment.