Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: routines for omni #205

Merged
merged 10 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ 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
* Documentation
* Added example of how to export data for archival
* Maintenance
* Implemented unit tests for cleaning warnings
* Use pip install for readthedocs
* Moved references and acknowledgements to methods files
* Added tests for OMNI HRO routines

## [0.0.5] - 2023-06-27
* New Instruments
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Python 3.6+.
| numpy | | |
| pandas | | |
| requests | | |
| scipy>=1.4.0 | | |
| xarray | | |

## PyPi Installation
Expand Down
1 change: 1 addition & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Python 3.6+ and pysat 3.1.0+.
numpy
pandas
requests
scipy>=1.4.0
xarray
================== =================

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies = [
"pandas",
"pysat >= 3.1",
"requests",
"scipy >= 1.4",
"xarray"
]

Expand Down
25 changes: 6 additions & 19 deletions pysatNASA/instruments/methods/omni.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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",
Expand All @@ -141,24 +141,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
Expand Down
33 changes: 32 additions & 1 deletion pysatNASA/tests/test_omni_hro.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Unit tests for OMNI HRO special functions."""

import datetime as dt
import logging
import numpy as np
import warnings

Expand Down Expand Up @@ -145,7 +146,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)
Expand All @@ -163,6 +164,36 @@ 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

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`."""
Expand Down
Loading