Skip to content

Commit

Permalink
Merge a560e70 into c2f4182
Browse files Browse the repository at this point in the history
  • Loading branch information
aburrell committed Oct 5, 2022
2 parents c2f4182 + a560e70 commit 3188282
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 24 deletions.
1 change: 1 addition & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Summary of all changes made since the first stable release
* ENH: Changed attributes in VectorData into properties to ensure expected
behaviour if altering the class data after initialisation
* ENH: Added IMAGE SI12, SI13, and WIC DMSP corrections to `harmonic`
* ENH: Made scaling optional for SuperMAG and SuperDARN vorticity data
* MAINT: Removed support for Python 2.7, 3.5, and 3.6; added support for 3.10
* MAINT: Improved PEP8 compliance
* MAINT: Updated pysat routines to v3.0.0 standards
Expand Down
4 changes: 2 additions & 2 deletions docs/citing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ AMPERE Boundaries
-----------------

Please follow the AMPERE data usage requirements provided by
`APL <http://ampere.jhuapl.edu/AMPERE-README.pdf>`_ and cite the R1/R2 FAC
boundary retrieval method and the OCB correction method.
`APL <https://ampere.jhuapl.edu/info/?page=infoRulesTab>`_ and cite the R1/R2
FAC boundary retrieval method and the OCB correction method.

* **FAC**: Milan, S. E. (2019): AMPERE R1/R2 FAC radii. figshare. Dataset.
https://doi.org/10.25392/leicester.data.11294861.v1
Expand Down
11 changes: 7 additions & 4 deletions ocbpy/instruments/supermag.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

def supermag2ascii_ocb(smagfile, outfile, hemisphere=0, ocb=None,
ocbfile='default', instrument='', max_sdiff=600,
min_merit=None, max_merit=None, **kwargs):
min_merit=None, max_merit=None,
scale_func=ocbscal.normal_curl_evar, **kwargs):
"""Covert and scales the SuperMAG data into OCB coordinates.
Parameters
Expand Down Expand Up @@ -68,6 +69,9 @@ def supermag2ascii_ocb(smagfile, outfile, hemisphere=0, ocb=None,
min_r : float
Minimum radius for open-closed field line boundary in degrees.
Deprecated, will be removed in version 0.3.1+ (default=10.0)
scale_func : function or NoneType
Scale the magnetic field observations unless None
(default=ocbpy.ocb_scale.normal_curl_evar)
Raises
------
Expand All @@ -76,8 +80,7 @@ def supermag2ascii_ocb(smagfile, outfile, hemisphere=0, ocb=None,
Notes
-----
May only process one hemisphere at a time. Scales the magnetic field
observations using `ocbpy.ocb_scale.normal_curl_evar`.
May only process one hemisphere at a time.
See Also
--------
Expand Down Expand Up @@ -188,7 +191,7 @@ def supermag2ascii_ocb(smagfile, outfile, hemisphere=0, ocb=None,
itime[0], ocb.rec_ind, mdata['MLAT'][itime],
mdata['MLT'][itime], aacgm_n=mdata['BN'][itime],
aacgm_e=mdata['BE'][itime], aacgm_z=mdata['BZ'][itime],
scale_func=ocbscal.normal_curl_evar)
scale_func=scale_func)

vdata.set_ocb(ocb)

Expand Down
12 changes: 9 additions & 3 deletions ocbpy/instruments/vort.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

def vort2ascii_ocb(vortfile, outfile, hemisphere=0, ocb=None,
ocbfile='default', instrument='', max_sdiff=600,
save_all=False, min_merit=None, max_merit=None, **kwargs):
save_all=False, min_merit=None, max_merit=None,
scale_func=ocbscal.normal_curl_evar, **kwargs):
"""Covert the location of vorticity data from AACGM to OCB coordinates.
Parameters
Expand Down Expand Up @@ -70,6 +71,9 @@ def vort2ascii_ocb(vortfile, outfile, hemisphere=0, ocb=None,
min_r : float
Minimum radius for open-closed field line boundary in degrees.
Deprecated, will be removed in version 0.3.1+ (default=10.0)
scale_func : function or NoneType
Scaling function for Vorticity data or None to not scale
(default=ocbpy.ocb_scale.normal_curl_evar)
Raises
------
Expand Down Expand Up @@ -207,8 +211,10 @@ def vort2ascii_ocb(vortfile, outfile, hemisphere=0, ocb=None,
nlat, nmlt, _, ncor = nout
rad = ocb.ocb.r[ocb.rec_ind] + ncor

nvort = ocbscal.normal_curl_evar(vdata['VORTICITY'][ivort],
rad, ref_r)
if scale_func is None:
nvort = vdata['VORTICITY'][ivort]
else:
nvort = scale_func(vdata['VORTICITY'][ivort], rad, ref_r)

# Format the output line
# DATE TIME (SAVE_ALL) OCB_LAT OCB_MLT NORM_VORT
Expand Down
3 changes: 3 additions & 0 deletions ocbpy/tests/test_data/out_smag_unscaled
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#DATE TIME NST STID SML SMU SZA MLAT MLT BMAG BN BE BZ OCB_MLAT OCB_MLT OCB_BMAG OCB_BN OCB_BE OCB_BZ
2000-05-05 13:40:30 2 ALE -195 124 71.53 69.53 15.32 114.79 113.70 -1.60 15.70 64.20 15.60 114.79 113.49 7.07 15.70
2000-05-05 13:40:30 2 THL -195 124 76.97 77.22 15.86 35.04 -23.60 -6.00 -25.20 72.69 16.20 35.04 -22.96 -8.11 -25.20
6 changes: 6 additions & 0 deletions ocbpy/tests/test_data/out_vort_unscaled
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#DATE TIME OCB_LAT OCB_MLT NORM_VORT
2000-05-05 13:39:00 65.85 2.722596 0.001123
2000-05-05 13:39:00 65.54 2.815187 -0.000027
2000-05-05 13:39:00 67.76 2.404329 0.002215
2000-05-05 13:39:00 67.16 2.603255 0.000698
2000-05-05 13:39:00 66.48 2.795501 0.002097
2 changes: 1 addition & 1 deletion ocbpy/tests/test_ocb_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (C) 2017, AGB & GC
# Full license can be found in License.md
# -----------------------------------------------------------------------------
"""Tests the ocboundary class and functions."""
"""Tests the OCB correction functions."""

import numpy as np
import unittest
Expand Down
2 changes: 1 addition & 1 deletion ocbpy/tests/test_ocb_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (C) 2017, AGB & GC
# Full license can be found in License.md
# -----------------------------------------------------------------------------
""" Tests the ocboundary class and functions
""" Tests the time functions
"""

import datetime as dt
Expand Down
19 changes: 16 additions & 3 deletions ocbpy/tests/test_pysat.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,26 @@ def eval_ocb_metadata(self):
if np.isnan(self.test_inst.meta[self.pysat_key][ll]):
self.assertTrue(
np.isnan(self.test_inst.meta[self.ocb_key][ll]))
else:
elif ll != self.test_inst.meta.labels.fill_val:
# The OCB fill value is NaN, regardless of prior value
self.assertEqual(
self.test_inst.meta[self.ocb_key][ll],
self.test_inst.meta[self.pysat_key][ll])
except TypeError:
self.assertRegex(self.test_inst.meta[self.ocb_key][ll],
self.test_inst.meta[self.pysat_key][ll])
ocb_len = len(self.test_inst.meta[self.ocb_key][ll])
pysat_len = len(self.test_inst.meta[self.pysat_key][ll])
if pysat_len == 0:
self.assertGreaterEqual(ocb_len, pysat_len)
else:
self.assertRegex(
self.test_inst.meta[self.ocb_key][ll],
self.test_inst.meta[self.pysat_key][ll],
msg="".join(["Meta label ", ll, ": OCB key ",
self.ocb_key, " value `",
self.test_inst.meta[self.ocb_key][ll],
"` not in pysat key ", self.pysat_key,
" value `", self.test_inst.meta[
self.pysat_key][ll], "`"]))

# Test the elements that have "OCB" appended to the text
sline = self.test_inst.meta[self.ocb_key][
Expand Down
28 changes: 18 additions & 10 deletions ocbpy/tests/test_supermag.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def setUp(self):
"test_eq_smag")
self.test_output_north = os.path.join(self.ocb_dir, "tests",
"test_data", "out_smag")
self.test_unscaled_north = os.path.join(self.ocb_dir, "tests",
"test_data",
"out_smag_unscaled")
self.test_output_dual = os.path.join(self.ocb_dir, "tests",
"test_data", "out_dual_smag")
self.test_output_south = os.path.join(self.ocb_dir, "tests",
Expand All @@ -47,7 +50,7 @@ def tearDown(self):

del self.test_file, self.test_output_north, self.test_ocb
del self.test_output_south, self.temp_output, self.test_eq_file
del self.test_eab, self.test_output_dual
del self.test_eab, self.test_output_dual, self.test_unscaled_north
return

def test_deprecation_kwargs(self):
Expand Down Expand Up @@ -80,18 +83,23 @@ def test_supermag2ascii_ocb_choose_north(self):
self.temp_output, shallow=False))
return

def test_supermag2ascii_north_from_ocb(self):
"""Test SuperMAG data processing choosing north from OCBoundary."""
def test_supermag2ascii_north_from_ocb_w_wo_scaling(self):
"""Test SuperMAG North from OCBoundary with and w/o scaling."""

ocb = ocbpy.ocboundary.OCBoundary(filename=self.test_ocb,
instrument='image', hemisphere=1)
subtests = [(self.test_output_north, {}),
(self.test_unscaled_north, {'scale_func': None})]

ocb_ismag.supermag2ascii_ocb(self.test_file, self.temp_output, ocb=ocb,
hemisphere=0)
ocb = ocbpy.OCBoundary(filename=self.test_ocb, instrument='image',
hemisphere=1)

# Compare created file to stored test file
self.assertTrue(filecmp.cmp(self.test_output_north,
self.temp_output, shallow=False))
for val in subtests:
with self.subTest(val=val):
ocb_ismag.supermag2ascii_ocb(self.test_file, self.temp_output,
ocb=ocb, hemisphere=0, **val[1])

# Compare created file to stored test file
self.assertTrue(filecmp.cmp(val[0], self.temp_output,
shallow=False))
return

def test_supermag2ascii_ocb_choose_south(self):
Expand Down
7 changes: 7 additions & 0 deletions ocbpy/tests/test_vort.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def setUp(self):
"test_empty")
self.test_output_north = os.path.join(self.ocb_dir, "tests",
"test_data", "out_vort")
self.test_unscaled_north = os.path.join(self.ocb_dir, "tests",
"test_data",
"out_vort_unscaled")
self.test_output_dual = os.path.join(self.ocb_dir, "tests",
"test_data", "out_dual_vort")
self.test_output_south = os.path.join(self.ocb_dir, "tests",
Expand All @@ -129,6 +132,7 @@ def tearDown(self):
del self.test_file, self.temp_output, self.test_ocb, self.ocb_dir
del self.test_output_north, self.test_output_south, self.test_eq_file
del self.test_empty, self.test_eab, self.test_output_dual
del self.test_unscaled_north
return

def test_deprecated_kwargs(self):
Expand All @@ -153,6 +157,9 @@ def test_vort2ascii_ocb(self):
subtests = [(self.test_file, self.test_output_north,
{"ocbfile": self.test_ocb, "instrument": "image",
"hemisphere": 1}),
(self.test_file, self.test_unscaled_north,
{"ocbfile": self.test_ocb, "instrument": "image",
"hemisphere": 1, "scale_func": None}),
(self.test_file, self.test_output_south,
{"ocbfile": self.test_ocb, "instrument": "image",
"hemisphere": -1}),
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dmsp_ssj = ssj_auroral_boundaries
[flake8]
max-line-length = 80
ignore =
E275
W503
ocbpy/__init__.py F401, E402
ocbpy/boundaries/__init__.py F401
Expand Down

0 comments on commit 3188282

Please sign in to comment.