From 656dbe25b5c40db1826c63bf608fbee1a3e27ec2 Mon Sep 17 00:00:00 2001 From: jklenzing Date: Thu, 7 Sep 2023 14:38:59 -0400 Subject: [PATCH 1/9] BUG: fix docstring --- pysatNASA/tests/test_omni_hro.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysatNASA/tests/test_omni_hro.py b/pysatNASA/tests/test_omni_hro.py index b3032024..4551bb63 100644 --- a/pysatNASA/tests/test_omni_hro.py +++ b/pysatNASA/tests/test_omni_hro.py @@ -145,7 +145,7 @@ def test_clock_angle_std(self): return def test_dayside_recon(self): - """Test the IMF steadiness standard deviation calculation.""" + """Test the dayside reconnection calculation.""" # Run the clock angle and steadiness routines omni.calculate_clock_angle(self.test_inst) From 162971161b1bb6f6c2d4f545b53df857063e7e3a Mon Sep 17 00:00:00 2001 From: jklenzing Date: Thu, 7 Sep 2023 14:39:25 -0400 Subject: [PATCH 2/9] TST: test time_shift --- pysatNASA/tests/test_omni_hro.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pysatNASA/tests/test_omni_hro.py b/pysatNASA/tests/test_omni_hro.py index 4551bb63..3e9fc3e3 100644 --- a/pysatNASA/tests/test_omni_hro.py +++ b/pysatNASA/tests/test_omni_hro.py @@ -163,6 +163,22 @@ def test_dayside_recon(self): assert np.all(test_diff < 1.0e-6) return + def test_time_shift_to_magnetic_poles(self): + """Test the time shift routines.""" + + # Choose values to result in 1 hour shift + self.test_inst['Vx'] = 6371.2 + self.test_inst['BSN_x'] = 3600.0 + + old_index = self.test_inst.index.copy() + omni.time_shift_to_magnetic_poles(self.test_inst) + + # Check shifted index + assert (old_index[0] - self.test_inst.index[0]).seconds == 3600 + # Check new cadence + assert (self.test_inst.index[1] - self.test_inst.index[0]).seconds == 60 + return + class TestDeprecation(object): """Unit tests for deprecation warnings in `pysat.instrument.omni_hro`.""" From fcb5f17abc30db30a6dcbf75ff20bd4b46404565 Mon Sep 17 00:00:00 2001 From: jklenzing Date: Thu, 7 Sep 2023 14:39:48 -0400 Subject: [PATCH 3/9] DOC: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2091a7c1..f54ef2ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). * Maintenance * Implemented unit tests for cleaning warnings * Use pip install for readthedocs + * Add tests for omni hro routines ## [0.0.5] - 2023-06-27 * New Instruments From 6d7e95a4dc24b78bbc058abc3e889304631bb07c Mon Sep 17 00:00:00 2001 From: jklenzing Date: Thu, 7 Sep 2023 14:57:24 -0400 Subject: [PATCH 4/9] MAINT: remove older scipy support --- pysatNASA/instruments/methods/omni.py | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/pysatNASA/instruments/methods/omni.py b/pysatNASA/instruments/methods/omni.py index 2844b0cb..9f7fdb26 100644 --- a/pysatNASA/instruments/methods/omni.py +++ b/pysatNASA/instruments/methods/omni.py @@ -130,24 +130,11 @@ def calculate_imf_steadiness(inst, steady_window=15, min_window_frac=0.75, # Calculate the running circular standard deviation of the clock angle circ_kwargs = {'high': 360.0, 'low': 0.0, 'nan_policy': 'omit'} - try: - ca_std = \ - inst['clock_angle'].rolling(min_periods=min_wnum, - window=steady_window, - center=True).apply(stats.circstd, - kwargs=circ_kwargs, - raw=True) - except TypeError: - pysat.logger.warn(' '.join(['To automatically remove NaNs from the', - 'calculation, please upgrade to scipy 1.4', - 'or newer.'])) - circ_kwargs.pop('nan_policy') - ca_std = \ - inst['clock_angle'].rolling(min_periods=min_wnum, - window=steady_window, - center=True).apply(stats.circstd, - kwargs=circ_kwargs, - raw=True) + ca_std = inst['clock_angle'].rolling(min_periods=min_wnum, + window=steady_window, + center=True).apply(stats.circstd, + kwargs=circ_kwargs, + raw=True) inst['clock_angle_std'] = pds.Series(ca_std, index=inst.data.index) # Determine how long the clock angle and IMF magnitude are steady From 9db34f72448f87221a1583767a1914ae189dc7b8 Mon Sep 17 00:00:00 2001 From: jklenzing Date: Thu, 7 Sep 2023 14:57:38 -0400 Subject: [PATCH 5/9] MAINT: set minimum scipy version --- README.md | 1 + docs/installation.rst | 1 + pyproject.toml | 1 + 3 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 9c96b121..86d45ad5 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Python 3.6+. | numpy | | | | pandas | | | | requests | | | +| scipy>=1.4.0 | | | | xarray | | | ## PyPi Installation diff --git a/docs/installation.rst b/docs/installation.rst index 7b5858b7..2722700f 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -25,6 +25,7 @@ Python 3.6+ and pysat 3.1.0+. numpy pandas requests + scipy>=1.4.0 xarray ================== ================= diff --git a/pyproject.toml b/pyproject.toml index 29252aa9..a2f0fc20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,7 @@ dependencies = [ "pandas", "pysat >= 3.1", "requests", + "scipy >= 1.4", "xarray" ] From 1e7d39c8e6d6892455dae4136180af29762e2474 Mon Sep 17 00:00:00 2001 From: jklenzing Date: Thu, 7 Sep 2023 16:24:34 -0400 Subject: [PATCH 6/9] BUG: integer --- pysatNASA/instruments/methods/omni.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysatNASA/instruments/methods/omni.py b/pysatNASA/instruments/methods/omni.py index 9f7fdb26..ba4fc584 100644 --- a/pysatNASA/instruments/methods/omni.py +++ b/pysatNASA/instruments/methods/omni.py @@ -113,7 +113,7 @@ def calculate_imf_steadiness(inst, steady_window=15, min_window_frac=0.75, sample_rate = int(rates[inst.tag]) max_wnum = np.floor(steady_window / sample_rate) if max_wnum != steady_window / sample_rate: - steady_window = max_wnum * sample_rate + steady_window = int(max_wnum * sample_rate) pysat.logger.warning(" ".join(("sample rate is not a factor of the", "statistical window"))) pysat.logger.warning(" ".join(("new statistical window is", From b3ec0be60758d69727e00039d4d001bc3ba7f3e1 Mon Sep 17 00:00:00 2001 From: jklenzing Date: Thu, 7 Sep 2023 16:24:46 -0400 Subject: [PATCH 7/9] TST: test for warnings --- pysatNASA/tests/test_omni_hro.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pysatNASA/tests/test_omni_hro.py b/pysatNASA/tests/test_omni_hro.py index 3e9fc3e3..1bd95fc4 100644 --- a/pysatNASA/tests/test_omni_hro.py +++ b/pysatNASA/tests/test_omni_hro.py @@ -1,6 +1,7 @@ """Unit tests for OMNI HRO special functions.""" import datetime as dt +import logging import numpy as np import warnings @@ -179,6 +180,20 @@ def test_time_shift_to_magnetic_poles(self): assert (self.test_inst.index[1] - self.test_inst.index[0]).seconds == 60 return + def test_calculate_imf_steadiness_warnings(self, caplog): + """Test imf steadiness routine.""" + + omni.calculate_clock_angle(self.test_inst) + with caplog.at_level(logging.INFO, logger='pysat'): + omni.calculate_imf_steadiness(self.test_inst, steady_window=5.1, + min_window_frac=0.8) + captured = caplog.text + warn_msgs = ["sample rate is not a factor", + "new statistical window"] + for msg in warn_msgs: + assert msg in captured + return + class TestDeprecation(object): """Unit tests for deprecation warnings in `pysat.instrument.omni_hro`.""" From 7ca5c4f5ec91e1a64bcd2a9a4b0d4c1d2e16e554 Mon Sep 17 00:00:00 2001 From: jklenzing Date: Thu, 7 Sep 2023 16:26:04 -0400 Subject: [PATCH 8/9] DOC: update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f54ef2ff..6c89673b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). ## [0.X.X] - 2023-XX-XX +* Bug Fix + * New window needs to be integer for calculate_imf_steadiness * Maintenance * Implemented unit tests for cleaning warnings * Use pip install for readthedocs - * Add tests for omni hro routines + * Added tests for omni hro routines ## [0.0.5] - 2023-06-27 * New Instruments From 4bc6d2e3bac146109770417c8cc235e857f1da8d Mon Sep 17 00:00:00 2001 From: Jeff Klenzing <19592220+jklenzing@users.noreply.github.com> Date: Fri, 8 Sep 2023 10:21:06 -0400 Subject: [PATCH 9/9] Update CHANGELOG.md Co-authored-by: Angeline Burrell --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c89673b..fe10a139 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). * Maintenance * Implemented unit tests for cleaning warnings * Use pip install for readthedocs - * Added tests for omni hro routines + * Added tests for OMNI HRO routines ## [0.0.5] - 2023-06-27 * New Instruments