From 847b9c8faeb7bb213c591644c3c526adabdc5405 Mon Sep 17 00:00:00 2001 From: Jeff Klenzing Date: Mon, 17 May 2021 10:35:51 -0400 Subject: [PATCH 1/3] STY: avoid reserved keyword --- pysatMissions/instruments/pysat_ephem.py | 7 ++++--- pysatMissions/instruments/pysat_sgp4.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pysatMissions/instruments/pysat_ephem.py b/pysatMissions/instruments/pysat_ephem.py index ce5840cf..4f4e3eb4 100644 --- a/pysatMissions/instruments/pysat_ephem.py +++ b/pysatMissions/instruments/pysat_ephem.py @@ -85,7 +85,7 @@ def preprocess(self): def load(fnames, tag=None, inst_id=None, obs_long=0., obs_lat=0., obs_alt=0., - TLE1=None, TLE2=None, num_samples=None, freq='1S'): + TLE1=None, TLE2=None, num_samples=None, cadence='1S'): """ Returns data and metadata in the format required by pysat. Generates position of satellite in both geographic and ECEF co-ordinates. @@ -117,7 +117,7 @@ def load(fnames, tag=None, inst_id=None, obs_long=0., obs_lat=0., obs_alt=0., Second string for Two Line Element. Must be in TLE format (default=None) num_samples : int or NoneType Number of samples per day (default=None) - freq : str + cadence : str Uses pandas.frequency string formatting ('1S', etc) (default='1S') @@ -157,7 +157,8 @@ def load(fnames, tag=None, inst_id=None, obs_long=0., obs_lat=0., obs_alt=0., num_samples = 100 # Extract list of times from filenames and inst_id - times, index, dates = ps_meth.generate_times(fnames, num_samples, freq=freq) + times, index, dates = ps_meth.generate_times(fnames, num_samples, + freq=cadence) # the observer's (ground station) position on the Earth surface site = ephem.Observer() diff --git a/pysatMissions/instruments/pysat_sgp4.py b/pysatMissions/instruments/pysat_sgp4.py index e30756f6..d43749aa 100644 --- a/pysatMissions/instruments/pysat_sgp4.py +++ b/pysatMissions/instruments/pysat_sgp4.py @@ -62,7 +62,7 @@ def init(self): def load(fnames, tag=None, inst_id=None, obs_long=0., obs_lat=0., obs_alt=0., - TLE1=None, TLE2=None, num_samples=None, freq='1S'): + TLE1=None, TLE2=None, num_samples=None, cadence='1S'): """ Returns data and metadata in the format required by pysat. Generates position of satellite in ECI co-ordinates. @@ -94,7 +94,7 @@ def load(fnames, tag=None, inst_id=None, obs_long=0., obs_lat=0., obs_alt=0., Second string for Two Line Element. Must be in TLE format num_samples : int Number of samples per day - freq : str + cadence : str Uses pandas.frequency string formatting ('1S', etc) (default='1S') @@ -141,7 +141,8 @@ def load(fnames, tag=None, inst_id=None, obs_long=0., obs_lat=0., obs_alt=0., satellite = twoline2rv(line1, line2, wgs72) # Extract list of times from filenames and inst_id - times, index, dates = ps_meth.generate_times(fnames, num_samples, freq=freq) + times, index, dates = ps_meth.generate_times(fnames, num_samples, + freq=cadence) # create list to hold satellite position, velocity position = [] From 8a42e3c63774959554ef005fee44a879432b9b69 Mon Sep 17 00:00:00 2001 From: Jeff Klenzing Date: Mon, 17 May 2021 10:36:30 -0400 Subject: [PATCH 2/3] DOC: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fd56b27..742f5c9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Update sat_id to inst_id for pysat 3.0 compatibility - migrate pyglow interface to pysatIncubator - Style updates for consistency with pysat 3.0 + - Use `cadence` instead of `freq` - Migrate CI testing to Github Actions ## [0.2.1] - 2020-07-29 From 1c3d64650dffb5fd1dddc22b9a88c69d8fb95020 Mon Sep 17 00:00:00 2001 From: Jeff Klenzing Date: Mon, 17 May 2021 14:26:25 -0400 Subject: [PATCH 3/3] TST: add unit tests --- pysatMissions/tests/test_instruments.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pysatMissions/tests/test_instruments.py b/pysatMissions/tests/test_instruments.py index 54f8088a..75499c01 100644 --- a/pysatMissions/tests/test_instruments.py +++ b/pysatMissions/tests/test_instruments.py @@ -1,3 +1,5 @@ +import datetime as dt +import numpy as np import tempfile import pytest @@ -66,3 +68,21 @@ def teardown_class(self): pysat.params.data['data_dirs'] = self.saved_path self.tempdir.cleanup() del self.inst_loc, self.saved_path, self.tempdir + + # Custom package unit tests can be added here + + @pytest.mark.parametrize("inst_dict", [x for x in instruments['download']]) + @pytest.mark.parametrize("kwarg,output", [(None, 1), ('10s', 10)]) + def test_inst_cadence(self, inst_dict, kwarg, output): + """Test operation of cadence keyword, including default behavior""" + + if kwarg: + self.test_inst = pysat.Instrument( + inst_module=inst_dict['inst_module'], cadence=kwarg) + else: + self.test_inst = pysat.Instrument( + inst_module=inst_dict['inst_module']) + + self.test_inst.load(2019, 1) + cadence = np.diff(self.test_inst.data.index.to_pydatetime()) + assert np.all(cadence == dt.timedelta(seconds=output))