diff --git a/docs/requirements.txt b/docs/requirements.txt index c5399986..9278230c 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 7214a4ef..5cd1745a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,7 +91,7 @@ dependencies = [ "pywavelets", "astropy", "hapiclient>=0.2.2", - "pytplot-mpl-temp>=2.2.50", + "pytplot-mpl-temp>=2.2.51", "viresclient", ] diff --git a/pyproject_pdm.toml b/pyproject_pdm.toml index 2aa9a28d..e613a723 100644 --- a/pyproject_pdm.toml +++ b/pyproject_pdm.toml @@ -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", diff --git a/pyspedas/projects/maven/tests/tests.py b/pyspedas/projects/maven/tests/tests.py index 21678d9f..0be15cb8 100644 --- a/pyspedas/projects/maven/tests/tests.py +++ b/pyspedas/projects/maven/tests/tests.py @@ -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(): diff --git a/pyspedas/projects/psp/load.py b/pyspedas/projects/psp/load.py index c3e9491d..caf4f9e8 100644 --- a/pyspedas/projects/psp/load.py +++ b/pyspedas/projects/psp/load.py @@ -302,7 +302,6 @@ 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_' @@ -310,54 +309,47 @@ def load(trange=['2018-11-5', '2018-11-6'], # 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])) == "" : #Handle case when user input is type + 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: diff --git a/pyspedas/projects/psp/tests/tests.py b/pyspedas/projects/psp/tests/tests.py index 665eb817..dd87efa3 100644 --- a/pyspedas/projects/psp/tests/tests.py +++ b/pyspedas/projects/psp/tests/tests.py @@ -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')) diff --git a/pyspedas/utilities/tests/plot_tests.py b/pyspedas/utilities/tests/plot_tests.py index f72fe4a9..a1c65df0 100644 --- a/pyspedas/utilities/tests/plot_tests.py +++ b/pyspedas/utilities/tests/plot_tests.py @@ -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() diff --git a/requirements.txt b/requirements.txt index 3ed8b6d2..de62d607 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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