Skip to content

Commit

Permalink
speeding up FPI code
Browse files Browse the repository at this point in the history
fixing issue with OMNI test
  • Loading branch information
ericthewizard committed Oct 9, 2022
1 parent ad70d49 commit 792569c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
6 changes: 3 additions & 3 deletions pyspedas/mms/fpi/mms_fpi_make_compressionlossbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
from fnmatch import fnmatch
from pytplot import get_data, store_data, options
from pyspedas import time_double
from pyspedas import time_datetime


def mms_fpi_make_compressionlossbars(tname, lossy=False):
Expand Down Expand Up @@ -58,7 +58,7 @@ def mms_fpi_make_compressionlossbars(tname, lossy=False):
logging.error('Unable to determine data rate from variable name.')
return

data = get_data(tname)
data = get_data(tname, dt=True)
metadata = get_data(tname, metadata=True)

if data is None:
Expand All @@ -72,7 +72,7 @@ def mms_fpi_make_compressionlossbars(tname, lossy=False):
version = file_id.split('_v')[1].split('.')
if version[0] == '2':
if version[1] == '1':
if data.times[0] < time_double('2016-04-01'):
if data.times[0] < time_datetime('2016-04-01'):
lossy = 3
else:
lossy = 1
Expand Down
2 changes: 1 addition & 1 deletion pyspedas/mms/fpi/mms_fpi_make_errorflagbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def mms_fpi_make_errorflagbars(tname, level='l2'):
instrument = tname.split('_')[1].upper()
data_rate = tname.split('_')[3].capitalize()

data = get_data(tname)
data = get_data(tname, dt=True)
metadata = get_data(tname, metadata=True)

if metadata is None:
Expand Down
2 changes: 1 addition & 1 deletion pyspedas/mms/fpi/mms_fpi_split_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def mms_fpi_split_tensor(tensor_variable):
List of variables created.
"""

data = get_data(tensor_variable)
data = get_data(tensor_variable, dt=True)

if data is None:
logging.error('Problem returning data from the variable: ' + tensor_variable)
Expand Down
12 changes: 6 additions & 6 deletions pyspedas/mms/fpi/mms_load_fpi_calc_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def mms_load_fpi_calc_pad(probe='1', level='sitl', datatype='', data_rate='', su

pad_avg_name = obsstr+'PitchAngDist_avg'+suffix

low_en = get_data(pad_vars[0])
mid_en = get_data(pad_vars[1])
high_en = get_data(pad_vars[2])
low_en = get_data(pad_vars[0], dt=True)
mid_en = get_data(pad_vars[1], dt=True)
high_en = get_data(pad_vars[2], dt=True)

if low_en is None or mid_en is None or high_en is None:
v3_low_pad = tnames(pad_vars[0].lower()+'_'+data_rate)
Expand All @@ -78,9 +78,9 @@ def mms_load_fpi_calc_pad(probe='1', level='sitl', datatype='', data_rate='', su
if v3_low_pad == [] or v3_mid_pad == [] or v3_high_pad == []:
continue

low_en = get_data(v3_low_pad[0])
mid_en = get_data(v3_mid_pad[0])
high_en = get_data(v3_high_pad[0])
low_en = get_data(v3_low_pad[0], dt=True)
mid_en = get_data(v3_mid_pad[0], dt=True)
high_en = get_data(v3_high_pad[0], dt=True)
pad_avg_name = pad_avg_name.lower()

e_pad_sum = low_en.y+mid_en.y+high_en.y
Expand Down
10 changes: 5 additions & 5 deletions pyspedas/mms/tests/fpi_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def test_pad(self):
pa_dist = mms_pad_fpi(dists_e, trange=trange, mag_data='mms1_fgm_b_gse_brst_l2_bvec')
pa_dist = mms_pad_fpi(dists, time='2015-10-16/13:06:30', units='eflux', mag_data='mms1_fgm_b_gse_brst_l2_bvec')
pa_dist = mms_pad_fpi(dists,
subtract_bulk=True,
time='2015-10-16/13:06:30',
units='eflux',
mag_data='mms1_fgm_b_gse_brst_l2_bvec',
vel_data='mms1_dis_bulkv_gse_brst')
subtract_bulk=True,
time='2015-10-16/13:06:30',
units='eflux',
mag_data='mms1_fgm_b_gse_brst_l2_bvec',
vel_data='mms1_dis_bulkv_gse_brst')

def test_split_tensors(self):
data = pyspedas.mms.fpi(trange=['2015-10-16/13:06', '2015-10-16/13:07'],
Expand Down
4 changes: 1 addition & 3 deletions pyspedas/omni/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import unittest
import pandas as pd
from pyspedas.utilities.data_exists import data_exists
import pyspedas

Expand All @@ -9,8 +8,7 @@ class LoadTestCases(unittest.TestCase):
def test_utc_timestamp_regression(self):
varname = 'BX_GSE'
data_omni = pyspedas.omni.data(trange=['2010-01-01/00:00:00', '2010-01-02/00:00:00'],notplot=True,varformat=varname,time_clip=True)
date_time = pd.to_datetime(data_omni[varname]['x'],unit='s')
self.assertTrue(str(date_time[0]) == '2010-01-01 00:00:00')
self.assertTrue(str(data_omni[varname]['x'][0]) == '2010-01-01 00:00:00')

def test_load_hro2_data(self):
omni_vars = pyspedas.omni.data()
Expand Down
10 changes: 5 additions & 5 deletions pyspedas/particles/spd_slice2d/tplot_average.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import numpy as np
from pytplot import get_data
from pyspedas import time_double
from pyspedas import time_string


def tplot_average(tvar, trange, quiet=False):
Expand All @@ -20,7 +20,7 @@ def tplot_average(tvar, trange, quiet=False):
-------
Average value of the tplot variable
"""
data = get_data(tvar)
data = get_data(tvar, dt=True)

if data is None:
logging.error('Error reading: ' + tvar)
Expand All @@ -30,10 +30,10 @@ def tplot_average(tvar, trange, quiet=False):
logging.error('Error: time range must be two element array.')
return

trange = time_double(trange)
trange = time_string(trange)

t0 = np.min(trange)
t1 = np.max(trange)
t0 = np.datetime64(trange[0])
t1 = np.datetime64(trange[-1])

if not quiet:
logging.info('Averaging ' + tvar)
Expand Down

0 comments on commit 792569c

Please sign in to comment.