Skip to content

Commit

Permalink
Merge branch 'master' into 416-s3-awareness
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondb authored Jan 9, 2025
2 parents c25748b + 9c593b6 commit 7856b79
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 48 deletions.
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cdasws>=1.7.24
netCDF4
pywavelets
astropy
pytplot-mpl-temp>=2.2.50
pytplot-mpl-temp>=2.2.51
geopack>=1.0.11
viresclient
hapiclient
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ dependencies = [
"pywavelets",
"astropy",
"hapiclient>=0.2.2",
"pytplot-mpl-temp>=2.2.50",
"pytplot-mpl-temp>=2.2.51",
"viresclient",
]

Expand Down
2 changes: 1 addition & 1 deletion pyproject_pdm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies = [
"numpy>=1.20.0",
"requests",
"cdflib",
"pytplot-mpl-temp>=2.2.50",
"pytplot-mpl-temp>=2.2.51",
"cdasws>=1.7.24",
"netCDF4",
"astropy",
Expand Down
2 changes: 1 addition & 1 deletion pyspedas/projects/maven/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from datetime import datetime

# We need sleep time to avoid "HTTP Error 429: Too Many Requests"
sleep_time = 30
sleep_time = 45


def get_kp_dict():
Expand Down
76 changes: 34 additions & 42 deletions pyspedas/projects/psp/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,62 +302,54 @@ def load(trange=['2018-11-5', '2018-11-6'],
local_path=CONFIG['local_data_dir'], no_download=no_update,last_version=last_version, force_download=force_download)

elif instrument == 'spc':

# try secure server first
# secure server may have two file names,
# the publicly released data will be prefixed 'psp_swp_spc_'
# so check that filename first, as it will have the most
# up to date version of the data

try:
if last_version:
try:
print("Downloading unpublished SWEAP Data....")
prefix = user_prefix + 'psp_spc_'
pathformat = 'sweap/spc/' + level + '/%Y/%m/psp_swp_spc_' + datatype + '_%Y%m%d_v0?.cdf'
# find the full remote path names using the trange
remote_names_spc = dailynames(file_format=pathformat, trange=trange, res=file_resolution)
remote_dates = dailynames(file_format='%Y-%m-%d', trange=trange, res=file_resolution)
files = download(
remote_file=remote_names_spc, remote_path=CONFIG['sweap_remote_data_dir'],
local_path=CONFIG['local_data_dir'], no_download=no_update,
username=username, password=password, basic_auth=True,last_version=last_version, force_download=force_download
)
print("Downloading unpublished SWEAP/SPC Data ('psp' prefix)....")
prefix = user_prefix + 'psp_spc_'
pathformat = 'sweap/spc/' + level + '/%Y/%m/psp_swp_spc_' + datatype + '_%Y%m%d_v0?.cdf'
# find the full remote path names using the trange
remote_names_spc = dailynames(file_format=pathformat, trange=trange, res=file_resolution)
remote_dates = dailynames(file_format='%Y-%m-%d', trange=trange, res=file_resolution)
files = download(
remote_file=remote_names_spc, remote_path=CONFIG['sweap_remote_data_dir'],
local_path=CONFIG['local_data_dir'], no_download=no_update,
username=username, password=password, basic_auth=True,last_version=last_version, force_download=force_download
)

if len(files) != len(remote_dates): # I think this is a temp-fix, the logic of these blocks doesnt work now that download() doesnt raise an exception
trange_temp = [remote_dates[len(files)],trange[1]] # set new trange to check for spp prefixes
raise RuntimeError("No links found.")
except:
# then, if a date does not have 'psp_swp_spc_' prefix
# then check for prefix 'spp_swp_spc_' which is the pre-released data
prefix = user_prefix + 'spp_spc_'
pathformat = 'sweap/spc/' + level + '/%Y/%m/spp_swp_spc_' + datatype + '_%Y%m%d_v0?.cdf'
# find the full remote path names using the trange
remote_names_spc = dailynames(file_format=pathformat, trange=trange_temp, res=file_resolution)
print("Downloading unpublished SWEAP Data....")
files = download(
remote_file=remote_names_spc, remote_path=CONFIG['sweap_remote_data_dir'],
local_path=CONFIG['local_data_dir'], no_download=no_update,
username=username, password=password, basic_auth=True,last_version=last_version, force_download=force_download
)
if files == []: # I think this is a temp-fix, the logic of these blocks doesnt work now that download() doesnt raise an exception
raise RuntimeError("No links found.")
else:
prefix = user_prefix + 'psp_spc_'
pathformat = 'sweap/spc/' + level + '/%Y/%m/*_swp_spc_' + datatype + '_%Y%m%d_v0?.cdf'
remote_names_spc = dailynames(file_format=pathformat, trange=trange, res=file_resolution)
if len(files) != len(remote_dates): # I think this is a temp-fix, the logic of these blocks doesnt work now that download() doesnt raise an exception
if str(type(trange[1])) == "<class 'datetime.datetime'>" : #Handle case when user input is type <datetime.datetime>
t_end = trange[1].strftime('%Y-%m-%d')
trange_temp = [remote_dates[len(files)],trange[1]] # set new trange to check for spp prefixes
raise RuntimeError("No 'psp...' prefix links found.")
except RuntimeError as e:
print(e)
try :

# then, if a date does not have 'psp_swp_spc_' prefix
# then check for prefix 'spp_swp_spc_' which is the pre-released data
prefix = user_prefix + 'spp_spc_'
pathformat = 'sweap/spc/' + level + '/%Y/%m/spp_swp_spc_' + datatype + '_%Y%m%d_v0?.cdf'
# find the full remote path names using the trange
remote_names_spc = dailynames(file_format=pathformat, trange=trange_temp, res=file_resolution)
print("Downloading unpublished SWEAP/SPC Data ('spp' prefix)....")
files = download(
remote_file=remote_names_spc, remote_path=CONFIG['sweap_remote_data_dir'],
local_path=CONFIG['local_data_dir'], no_download=no_update,
username=username, password=password, basic_auth=True,last_version=last_version, force_download=force_download
)
if files == []: # I think this is a temp-fix, the logic of these blocks doesnt work now that download() doesnt raise an exception
raise RuntimeError("No links found.")

# if all else fails switch to the NASA spdf server.
except:
files = download(remote_file=remote_names, remote_path=CONFIG['remote_data_dir'],
local_path=CONFIG['local_data_dir'], no_download=no_update,last_version=last_version, force_download=force_download)
raise RuntimeError("No 'spp...' prefix links found.")
# if all else fails switch to the NASA spdf server.
except RuntimeError as e :
print(e)
print("Trying public data....")
files = download(remote_file=remote_names, remote_path=CONFIG['remote_data_dir'],
local_path=CONFIG['local_data_dir'], no_download=no_update,last_version=last_version, force_download=force_download)

if files is not None:
for file in files:
Expand Down
2 changes: 1 addition & 1 deletion pyspedas/projects/psp/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_load_spc_data_suffix_none(self):
spc_vars = pyspedas.projects.psp.spc(trange=['2018-11-5', '2018-11-6'], datatype='l3i', level='l3', suffix=None)
self.assertTrue(data_exists('psp_spc_np_fit'))

def test_load_spc_data_suffix_none(self):
def test_load_spc_data_suffix(self):
spc_vars = pyspedas.projects.psp.spc(trange=['2018-11-5', '2018-11-6'], datatype='l3i', level='l3', prefix='pre_', suffix='_suf')
self.assertTrue(data_exists('pre_psp_spc_np_fit_suf'))

Expand Down
26 changes: 26 additions & 0 deletions pyspedas/utilities/tests/plot_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,5 +468,31 @@ def test_save_with_plot_objects(self):
tplot('tha_pos',display=global_display,return_plot_objects=True, save_png='ret_plot_objs.png')
self.assertTrue(os.path.exists('ret_plot_objs.png'))

def test_erg_tplot_vlabels(self):
# Test alternate varlabel implementation from Tomo Hori
del_data("*")
import pyspedas

from pyspedas.projects.erg import mgf, orb
mgf()
orb()
from pytplot import tplot_options, options, tplot_names, split_vec, get_data, tplot_opt_glob, tnames

split_vec('erg_orb_l2_pos_rmlatmlt')
split_vec('erg_orb_l2_pos_Lm')
options('erg_orb_l2_pos_rmlatmlt_x', 'ytitle', 'R')
options('erg_orb_l2_pos_rmlatmlt_y', 'ytitle', 'Mlat')
options('erg_orb_l2_pos_rmlatmlt_z', 'ytitle', 'MLT')

var_label = ['erg_orb_l2_pos_Lm_x', 'erg_orb_l2_pos_rmlatmlt_x', 'erg_orb_l2_pos_rmlatmlt_y',
'erg_orb_l2_pos_rmlatmlt_z']
# tplot_options('var_label', var_label)

plot_vars = ['erg_mgf_l2_mag_8sec_sm', 'erg_mgf_l2_igrf_8sec_sm', 'erg_orb_l2_pos_Lm_x']

from pytplot import tplot_vl
fig = tplot_vl(plot_vars, var_label=var_label, display=global_display, save_png='erg_varlabel.png')


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
numpy>=1.20.0
requests
cdflib>=1.0.0
pytplot-mpl-temp>=2.2.50
pytplot-mpl-temp>=2.2.51
cdasws>=1.7.24
netCDF4
pywavelets
Expand Down

0 comments on commit 7856b79

Please sign in to comment.