Skip to content

Commit

Permalink
Merge pull request #52 from rstoneback/develop
Browse files Browse the repository at this point in the history
pysat v3.X compatibility
  • Loading branch information
rstoneback authored Jun 15, 2021
2 parents 8a3dcea + 46ce90e commit 7711872
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 77 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.5.5] - 2021-06-16
- Updated setup.py
- Added compatibility with pysat v3.x

## [0.5.4] - 2020-03-03
- Updated to latest IGRF reference code

Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
include OMMBV/version.txt
include LICENSE
include CONTRIBUTING.md
prune OMMBV/tests
14 changes: 7 additions & 7 deletions OMMBV/tests/test_apex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import datetime
import datetime as dt
import numpy as np
import matplotlib.pyplot as plt
import pandas as pds
Expand All @@ -16,7 +16,7 @@ class TestMaxApexHeight():

def test_plot_apex_heights(self):
"""Check meridional vector along max in apex height gradient"""
date = pysat.datetime(2010, 1, 1)
date = dt.datetime(2010, 1, 1)

delta = 1.

Expand Down Expand Up @@ -94,7 +94,7 @@ def test_apex_info_accuracy(self):
.0001953125 / 128., .0001953125 / 256., .0001953125 / 512.,
.0001953125 / 1024., .0001953125 / 2048., .0001953125 / 4096.])

date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
dx = []
dy = []
dz = []
Expand Down Expand Up @@ -186,7 +186,7 @@ def test_apex_plots(self):
# recasting alts into a more convenient form for later calculation
p_alts = [p_alts[0]] * len(p_longs)
# set the date
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# memory for results
apex_lat = np.zeros((len(p_lats), len(p_longs) + 1))
apex_lon = np.zeros((len(p_lats), len(p_longs) + 1))
Expand Down Expand Up @@ -292,7 +292,7 @@ def test_apex_diff_plots(self):
# recasting alts into a more convenient form for later calculation
p_alts = [p_alts[0]] * len(p_longs)
# set the date
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# memory for results
apex_lat = np.zeros((len(p_lats), len(p_longs) + 1))
apex_lon = np.zeros((len(p_lats), len(p_longs) + 1))
Expand Down Expand Up @@ -428,7 +428,7 @@ def test_apex_fine_max_step_diff_plots(self):
# recasting alts into a more convenient form for later calculation
p_alts = [p_alts[0]] * len(p_longs)
# set the date
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# memory for results
apex_lat = np.zeros((len(p_lats), len(p_longs) + 1))
apex_lon = np.zeros((len(p_lats), len(p_longs) + 1))
Expand Down Expand Up @@ -564,7 +564,7 @@ def test_ecef_geodetic_apex_diff_plots(self):
# recasting alts into a more convenient form for later calculation
p_alts = [p_alts[0]] * len(p_longs)
# set the date
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# memory for results
apex_x = np.zeros((len(p_lats), len(p_longs) + 1))
apex_y = np.zeros((len(p_lats), len(p_longs) + 1))
Expand Down
3 changes: 2 additions & 1 deletion OMMBV/tests/test_comparison.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime as dt
import numpy as np
import matplotlib.pyplot as plt

Expand All @@ -14,7 +15,7 @@ def __init__(self):
self.inst = pysat.Instrument('pysat', 'testing')
self.inst.yr = 2019
self.inst.doy = 365
self.inst.date = pysat.datetime(2019, 12, 31)
self.inst.date = dt.datetime(2019, 12, 31)

return

Expand Down
27 changes: 14 additions & 13 deletions OMMBV/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime as dt
import itertools
import os

Expand Down Expand Up @@ -165,7 +166,7 @@ def test_unit_vector_step_size_sensitivity(self):
steps_goal = np.arange(7)
steps_goal = 20. / 2 ** steps_goal

date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
dzx = []
dzy = []
dzz = []
Expand Down Expand Up @@ -289,7 +290,7 @@ def test_D_vector_step_size_sensitivity(self):
steps_goal = np.arange(7)
steps_goal = 20. / 2 ** steps_goal

date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
dzx = []
dzy = []
dzz = []
Expand Down Expand Up @@ -416,7 +417,7 @@ def test_E_vector_step_size_sensitivity(self):
steps_goal = np.arange(7)
steps_goal = 20. / 2 ** steps_goal

date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
dzx = []
dzy = []
dzz = []
Expand Down Expand Up @@ -585,7 +586,7 @@ def test_unit_vector_component_plots(self):
e_fay = d_zvx.copy()
e_faz = d_zvx.copy()

date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# set up multi
if self.dc is not None:
targets = itertools.cycle(dc.ids)
Expand Down Expand Up @@ -1459,7 +1460,7 @@ def test_unit_vector_component_plots_edge_steps(self):
d2_my = d_zvx.copy();
d2_mz = d_zvx.copy()

date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# set up multi
if self.dc is not None:
targets = itertools.cycle(dc.ids)
Expand Down Expand Up @@ -1589,7 +1590,7 @@ def test_simple_geomagnetic_basis_interface(self):
# the full range of points obtained by iterating over all
# recasting alts into a more convenient form for later calculation
p_alts = [p_alts[0]] * len(p_longs)
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)

if self.dc is not None:
targets = itertools.cycle(dc.ids)
Expand Down Expand Up @@ -1637,7 +1638,7 @@ def test_unit_vector_component_stepsize_sensitivity_plots(self):
bx = zvx.copy();
by = zvx.copy();
bz = zvx.copy()
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# set up multi
if self.dc is not None:
targets = itertools.cycle(dc.ids)
Expand Down Expand Up @@ -1921,7 +1922,7 @@ def step_along_mag_unit_vector_sensitivity_plots(self, direction=None):
z2 = x2.copy();
h2 = x.copy()

date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
dates = [date]*len(p_longs)
# set up multi
if self.dc is not None:
Expand Down Expand Up @@ -2138,7 +2139,7 @@ def test_geomag_efield_scalars_plots(self):
eq_zonald = north_zonal.copy()
eq_merd = north_zonal.copy()

date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# set up multi
if self.dc is not None:
targets = itertools.cycle(dc.ids)
Expand Down Expand Up @@ -2375,7 +2376,7 @@ def test_heritage_geomag_efield_scalars_plots(self):
eq_zonald = north_zonal.copy()
eq_merd = north_zonal.copy()

date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# set up multi
if self.dc is not None:
targets = itertools.cycle(dc.ids)
Expand Down Expand Up @@ -2619,7 +2620,7 @@ def test_unit_vector_and_field_line_plots(self):


#
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
ecef_x, ecef_y, ecef_z = OMMBV.geocentric_to_ecef(p_lat, p_long, p_alt)

for j, (x, y, z) in enumerate(zip(ecef_x, ecef_y, ecef_z)):
Expand Down Expand Up @@ -2661,8 +2662,8 @@ def test_unit_vector_and_field_line_plots(self):
self.inst[:, 'sc_xhat_x'], self.inst[:, 'sc_xhat_y'], self.inst[:, 'sc_xhat_z'] = 1., 0., 0.
self.inst[:, 'sc_yhat_x'], self.inst[:, 'sc_yhat_y'], self.inst[:, 'sc_yhat_z'] = 0., 1., 0.
self.inst[:, 'sc_zhat_x'], self.inst[:, 'sc_zhat_y'], self.inst[:, 'sc_zhat_z'] = 0., 0., 1.
self.inst.data.index = pysat.utils.time.create_date_range(pysat.datetime(2000, 1, 1),
pysat.datetime(2000, 1, 1) +
self.inst.data.index = pysat.utils.time.create_date_range(dt.datetime(2000, 1, 1),
dt.datetime(2000, 1, 1) +
pds.DateOffset(
seconds=len(self.inst.data) - 1),
freq='S')
Expand Down
14 changes: 7 additions & 7 deletions OMMBV/tests/test_former_methods.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import datetime
import datetime as dt
import numpy as np

import OMMBV
Expand Down Expand Up @@ -38,7 +38,7 @@ def test_integrated_unit_vector_component_plots(self):
bx = zvx.copy()
by = zvx.copy()
bz = zvx.copy()
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# set up multi
if self.dc is not None:
import itertools
Expand Down Expand Up @@ -220,7 +220,7 @@ def closed_loop_footpoint_sensitivity_plots(self, direction, vector_direction):
mx = zvx.copy();
my = zvx.copy();
mz = zvx.copy()
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# set up multi
if self.dc is not None:
import itertools
Expand Down Expand Up @@ -373,7 +373,7 @@ def closed_loop_footpoint_value_plots(self, direction, vector_direction):
mx = zvx.copy()
my = zvx.copy()
mz = zvx.copy()
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# set up multi
if self.dc is not None:
import itertools
Expand Down Expand Up @@ -504,7 +504,7 @@ def test_integrated_unit_vector_component_stepsize_sensitivity_plots(self):
bx = zvx.copy()
by = zvx.copy()
bz = zvx.copy()
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# set up multi
if self.dc is not None:
import itertools
Expand Down Expand Up @@ -800,7 +800,7 @@ def test_integrated_unit_vector_component_refheight_sensitivity_plots(self):
bx = zvx.copy();
by = zvx.copy();
bz = zvx.copy()
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# set up multi
if self.dc is not None:
import itertools
Expand Down Expand Up @@ -1094,7 +1094,7 @@ def test_vector_method_sensitivity_plots(self):
bx = zvx.copy();
by = zvx.copy();
bz = zvx.copy()
date = datetime.datetime(2000, 1, 1)
date = dt.datetime(2000, 1, 1)
# set up multi
if self.dc is not None:
import itertools
Expand Down
2 changes: 1 addition & 1 deletion OMMBV/tests/test_satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestSatellite():

def setup(self):

self.inst = pysat.Instrument('pysat', 'testing', sat_id='32')
self.inst = pysat.Instrument('pysat', 'testing', num_samples=32)
return

def test_application_add_unit_vectors(self):
Expand Down
40 changes: 20 additions & 20 deletions OMMBV/tests/test_transformations_and_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ def test_field_line_tracing_against_vitmo(self):
trace_s['z'])

# ensure longitudes are all 0-360
idx, = np.where(omni['n_long'] < 0)
omni.ix[idx, 'n_long'] += 360.
idx, = np.where(omni['s_long'] < 0)
omni.ix[idx, 's_long'] += 360.
# idx, = np.where(omni['n_long'] < 0)
omni.loc[omni['n_long'] < 0, 'n_long'] += 360.
# idx, = np.where(omni['s_long'] < 0)
omni.loc[omni['s_long'] < 0, 's_long'] += 360.

idx, = np.where(trace_n['long'] < 0)
trace_n.ix[idx, 'long'] += 360.
idx, = np.where(trace_s['long'] < 0)
trace_s.ix[idx, 'long'] += 360.
# idx, = np.where(trace_n['long'] < 0)
trace_n.loc[trace_n['long'] < 0, 'long'] += 360.
# idx, = np.where(trace_s['long'] < 0)
trace_s.loc[trace_s['long'] < 0, 'long'] += 360.

# compute difference between OMNI and local calculation
# there is a difference near 0 longitude, ignore this area
Expand Down Expand Up @@ -183,9 +183,9 @@ def test_tracing_accuracy(self):
out.append(pt)

final_pt = pds.DataFrame(out, columns=['x', 'y', 'z'])
dx.append(np.abs(final_pt.ix[1:, 'x'].values - final_pt.ix[:, 'x'].values[:-1]))
dy.append(np.abs(final_pt.ix[1:, 'y'].values - final_pt.ix[:, 'y'].values[:-1]))
dz.append(np.abs(final_pt.ix[1:, 'z'].values - final_pt.ix[:, 'z'].values[:-1]))
dx.append(np.abs(final_pt.loc[1:, 'x'].values - final_pt.loc[:, 'x'].values[:-1]))
dy.append(np.abs(final_pt.loc[1:, 'y'].values - final_pt.loc[:, 'y'].values[:-1]))
dz.append(np.abs(final_pt.loc[1:, 'z'].values - final_pt.loc[:, 'z'].values[:-1]))
else:
for x, y, z in zip(ecf_x, ecf_y, ecf_z):
out = []
Expand All @@ -197,9 +197,9 @@ def test_tracing_accuracy(self):
out.append(pt)

final_pt = pds.DataFrame(out, columns=['x', 'y', 'z'])
dx.append(np.abs(final_pt.ix[1:, 'x'].values - final_pt.ix[:, 'x'].values[:-1]))
dy.append(np.abs(final_pt.ix[1:, 'y'].values - final_pt.ix[:, 'y'].values[:-1]))
dz.append(np.abs(final_pt.ix[1:, 'z'].values - final_pt.ix[:, 'z'].values[:-1]))
dx.append(np.abs(final_pt.loc[1:, 'x'].values - final_pt.loc[:, 'x'].values[:-1]))
dy.append(np.abs(final_pt.loc[1:, 'y'].values - final_pt.loc[:, 'y'].values[:-1]))
dz.append(np.abs(final_pt.loc[1:, 'z'].values - final_pt.loc[:, 'z'].values[:-1]))

dx = pds.DataFrame(dx)
dy = pds.DataFrame(dy)
Expand Down Expand Up @@ -252,9 +252,9 @@ def test_tracing_accuracy_w_recursion(self):
out.append(pt)

final_pt = pds.DataFrame(out, columns=['x', 'y', 'z'])
dx.append(np.abs(final_pt.ix[1:, 'x'].values - final_pt.ix[:, 'x'].values[:-1]))
dy.append(np.abs(final_pt.ix[1:, 'y'].values - final_pt.ix[:, 'y'].values[:-1]))
dz.append(np.abs(final_pt.ix[1:, 'z'].values - final_pt.ix[:, 'z'].values[:-1]))
dx.append(np.abs(final_pt.loc[1:, 'x'].values - final_pt.loc[:, 'x'].values[:-1]))
dy.append(np.abs(final_pt.loc[1:, 'y'].values - final_pt.loc[:, 'y'].values[:-1]))
dz.append(np.abs(final_pt.loc[1:, 'z'].values - final_pt.loc[:, 'z'].values[:-1]))
dx = pds.DataFrame(dx)
dy = pds.DataFrame(dy)
dz = pds.DataFrame(dz)
Expand Down Expand Up @@ -310,9 +310,9 @@ def test_tracing_accuracy_w_recursion_step_size(self):
out.append(pt)

final_pt = pds.DataFrame(out, columns=['x', 'y', 'z'])
dx.append(np.abs(final_pt.ix[1:, 'x'].values - final_pt.ix[:, 'x'].values[:-1]))
dy.append(np.abs(final_pt.ix[1:, 'y'].values - final_pt.ix[:, 'y'].values[:-1]))
dz.append(np.abs(final_pt.ix[1:, 'z'].values - final_pt.ix[:, 'z'].values[:-1]))
dx.append(np.abs(final_pt.loc[1:, 'x'].values - final_pt.loc[:, 'x'].values[:-1]))
dy.append(np.abs(final_pt.loc[1:, 'y'].values - final_pt.loc[:, 'y'].values[:-1]))
dz.append(np.abs(final_pt.loc[1:, 'z'].values - final_pt.loc[:, 'z'].values[:-1]))
dx = pds.DataFrame(dx)
dy = pds.DataFrame(dy)
dz = pds.DataFrame(dz)
Expand Down
2 changes: 1 addition & 1 deletion OMMBV/version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
0.5.4
0.5.5

Loading

0 comments on commit 7711872

Please sign in to comment.