From d33da728c2077afcc362119dc63c058d912a9e9b Mon Sep 17 00:00:00 2001 From: jwu Date: Fri, 22 Sep 2023 14:45:51 -0700 Subject: [PATCH] add download test files from elfin server --- pyspedas/elfin/tests/test_epd_l1.py | 43 ++++++++++++++++++--- pyspedas/elfin/tests/test_epd_l2.py | 60 ++++++++++++++++++++++------- pyspedas/elfin/tests/test_state.py | 14 ++++++- 3 files changed, 96 insertions(+), 21 deletions(-) diff --git a/pyspedas/elfin/tests/test_epd_l1.py b/pyspedas/elfin/tests/test_epd_l1.py index b80d5eb7..e7dfcd95 100644 --- a/pyspedas/elfin/tests/test_epd_l1.py +++ b/pyspedas/elfin/tests/test_epd_l1.py @@ -10,9 +10,12 @@ import pytplot.get_data from pytplot.importers.tplot_restore import tplot_restore from numpy.testing import assert_allclose + import pyspedas.elfin +from pyspedas.utilities.download import download +from pyspedas.elfin.config import CONFIG -TEST_DATASET_PATH="pyspedas/elfin/tests/test_dataset/" +TEST_DATASET_PATH="test/" class TestELFL1Validation(unittest.TestCase): """Tests of the data been identical to SPEDAS (IDL).""" @@ -24,26 +27,54 @@ def setUpClass(cls): The IDL script that creates data file: epd_level1_check.pro """ # Testing time range - cls.t = ['2022-04-12/19:00:00','2022-04-12/19:15:00'] + cls.t = ['2022-04-12/19:00:00','2022-04-12/19:15:00'] cls.probe = 'b' # load epd l1 raw flux - filename = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l1_raw_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile_name = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l1_raw_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile = download(remote_file=calfile_name, + remote_path=CONFIG['remote_data_dir'], + local_path=CONFIG['local_data_dir'], + no_download=False) + if not calfile: + raise unittest.SkipTest(f"Cannot download validation file {calfile_name}") + filename = CONFIG['local_data_dir'] + calfile_name tplot_restore(filename) cls.elf_pef_raw = pytplot.get_data(f"el{cls.probe}_pef_raw") # load epd l1 cps flux - filename = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l1_cps_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile_name = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l1_cps_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile = download(remote_file=calfile_name, + remote_path=CONFIG['remote_data_dir'], + local_path=CONFIG['local_data_dir'], + no_download=False) + if not calfile: + raise unittest.SkipTest(f"Cannot download validation file {calfile_name}") + filename = CONFIG['local_data_dir'] + calfile_name tplot_restore(filename) cls.elf_pef_cps = pytplot.get_data(f"el{cls.probe}_pef_cps") # load epd l1 nflux flux - filename = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l1_nflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile_name = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l1_nflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile = download(remote_file=calfile_name, + remote_path=CONFIG['remote_data_dir'], + local_path=CONFIG['local_data_dir'], + no_download=False) + if not calfile: + raise unittest.SkipTest(f"Cannot download validation file {calfile_name}") + filename = CONFIG['local_data_dir'] + calfile_name tplot_restore(filename) cls.elf_pef_nflux = pytplot.get_data(f"el{cls.probe}_pef_nflux") # load epd l1 eflux spectrogram - filename = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l1_eflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile_name = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l1_eflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile = download(remote_file=calfile_name, + remote_path=CONFIG['remote_data_dir'], + local_path=CONFIG['local_data_dir'], + no_download=False) + if not calfile: + raise unittest.SkipTest(f"Cannot download validation file {calfile_name}") + filename = CONFIG['local_data_dir'] + calfile_name tplot_restore(filename) cls.elf_pef_eflux = pytplot.get_data(f"el{cls.probe}_pef_eflux") cls.elf_pef_sectnum = pytplot.get_data(f"el{cls.probe}_pef_sectnum") diff --git a/pyspedas/elfin/tests/test_epd_l2.py b/pyspedas/elfin/tests/test_epd_l2.py index e1f1b711..90f0fdd9 100644 --- a/pyspedas/elfin/tests/test_epd_l2.py +++ b/pyspedas/elfin/tests/test_epd_l2.py @@ -10,10 +10,13 @@ from numpy.testing import assert_allclose import pytplot.get_data from pytplot.importers.tplot_restore import tplot_restore + import pyspedas.elfin from pyspedas.elfin.epd.calibration_l2 import spec_pa_sort +from pyspedas.utilities.download import download +from pyspedas.elfin.config import CONFIG -TEST_DATASET_PATH="pyspedas/elfin/tests/test_dataset/" +TEST_DATASET_PATH="test/" class TestELFL2Validation(unittest.TestCase): """Tests of the data been identical to SPEDAS (IDL).""" @@ -31,8 +34,16 @@ def setUpClass(cls): cls.t = ['2022-08-28/15:54','2022-08-28/16:15'] # pass cls.probe = 'a' - # load epd l2 hs nflux spectrogram - filename = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l2_hs_nflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + # load epd l2 hs nflux spectrogram + calfile_name = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l2_hs_nflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile = download(remote_file=calfile_name, + remote_path=CONFIG['remote_data_dir'], + local_path=CONFIG['local_data_dir'], + no_download=False) + if not calfile: + # Skip tests + raise unittest.SkipTest(f"Cannot download validation file {calfile_name}") + filename = CONFIG['local_data_dir'] + calfile_name tplot_restore(filename) cls.elf_pef_hs_nflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_hs_nflux_ch0") cls.elf_pef_hs_nflux_ch1 = pytplot.get_data(f"el{cls.probe}_pef_hs_nflux_ch1") @@ -46,12 +57,19 @@ def setUpClass(cls): cls.elf_pef_hs_LCdeg = pytplot.get_data(f"el{cls.probe}_pef_hs_LCdeg") cls.elf_pef_Et_nflux = pytplot.get_data(f"el{cls.probe}_pef_Et_nflux") cls.elf_pef_pa = pytplot.get_data(f"el{cls.probe}_pef_pa") - cls.elf_pef_hs_Epat_nflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_hs_Epat_nflux_ch0") + cls.elf_pef_hs_Epat_nflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_hs_Epat_nflux_ch0") # Epat is 3d, can't save it with idl cls.elf_pef_hs_Epat_nflux_ch1 = pytplot.get_data(f"el{cls.probe}_pef_hs_Epat_nflux_ch1") # load epd l2 hs eflux spectrogram - filename = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l2_hs_eflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile_name = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l2_hs_eflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile = download(remote_file=calfile_name, + remote_path=CONFIG['remote_data_dir'], + local_path=CONFIG['local_data_dir'], + no_download=False) + if not calfile: + raise unittest.SkipTest(f"Cannot download validation file {calfile_name}") + filename = CONFIG['local_data_dir'] + calfile_name tplot_restore(filename) cls.elf_pef_hs_eflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_hs_eflux_ch0") cls.elf_pef_hs_eflux_ch1 = pytplot.get_data(f"el{cls.probe}_pef_hs_eflux_ch1") @@ -62,12 +80,20 @@ def setUpClass(cls): cls.elf_pef_hs_eflux_anti = pytplot.get_data(f"el{cls.probe}_pef_hs_eflux_anti") cls.elf_pef_hs_eflux_perp = pytplot.get_data(f"el{cls.probe}_pef_hs_eflux_perp") cls.elf_pef_Et_eflux = pytplot.get_data(f"el{cls.probe}_pef_Et_eflux") - cls.elf_pef_hs_Epat_eflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_hs_Epat_eflux_ch0") + cls.elf_pef_hs_Epat_eflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_hs_Epat_eflux_ch0") # Epat is 3d, can't save it with idl cls.elf_pef_hs_Epat_eflux_ch1 = pytplot.get_data(f"el{cls.probe}_pef_hs_Epat_eflux_ch1") - - # load epd l2 fs nflux spectrogram - filename = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l2_fs_nflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + + + # load epd l2 fs nflux spectrogram + calfile_name = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l2_fs_nflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile = download(remote_file=calfile_name, + remote_path=CONFIG['remote_data_dir'], + local_path=CONFIG['local_data_dir'], + no_download=False) + if not calfile: + raise unittest.SkipTest(f"Cannot download validation file {calfile_name}") + filename = CONFIG['local_data_dir'] + calfile_name tplot_restore(filename) cls.elf_pef_fs_nflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_fs_nflux_ch0") cls.elf_pef_fs_nflux_ch1 = pytplot.get_data(f"el{cls.probe}_pef_fs_nflux_ch1") @@ -77,12 +103,20 @@ def setUpClass(cls): cls.elf_pef_fs_nflux_perp = pytplot.get_data(f"el{cls.probe}_pef_fs_nflux_perp") cls.elf_pef_fs_antiLCdeg = pytplot.get_data(f"el{cls.probe}_pef_fs_antiLCdeg") cls.elf_pef_fs_LCdeg = pytplot.get_data(f"el{cls.probe}_pef_fs_LCdeg") - cls.elf_pef_fs_Epat_nflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_fs_Epat_nflux_ch0") + cls.elf_pef_fs_Epat_nflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_fs_Epat_nflux_ch0") # Epat is 3d, can't save it with idl cls.elf_pef_fs_Epat_nflux_ch1 = pytplot.get_data(f"el{cls.probe}_pef_fs_Epat_nflux_ch1") - # load epd l2 fs eflux spectrogram - filename = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l2_fs_eflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + + # load epd l2 fs eflux spectrogram + calfile_name = f"{TEST_DATASET_PATH}validation_el{cls.probe}_epd_l2_fs_eflux_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile = download(remote_file=calfile_name, + remote_path=CONFIG['remote_data_dir'], + local_path=CONFIG['local_data_dir'], + no_download=False) + if not calfile: + raise unittest.SkipTest(f"Cannot download validation file {calfile_name}") + filename = CONFIG['local_data_dir'] + calfile_name tplot_restore(filename) cls.elf_pef_fs_eflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_fs_eflux_ch0") cls.elf_pef_fs_eflux_ch1 = pytplot.get_data(f"el{cls.probe}_pef_fs_eflux_ch1") @@ -90,7 +124,7 @@ def setUpClass(cls): cls.elf_pef_fs_eflux_para = pytplot.get_data(f"el{cls.probe}_pef_fs_eflux_para") cls.elf_pef_fs_eflux_anti = pytplot.get_data(f"el{cls.probe}_pef_fs_eflux_anti") cls.elf_pef_fs_eflux_perp = pytplot.get_data(f"el{cls.probe}_pef_fs_eflux_perp") - cls.elf_pef_fs_Epat_eflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_fs_Epat_eflux_ch0") + cls.elf_pef_fs_Epat_eflux_ch0 = pytplot.get_data(f"el{cls.probe}_pef_fs_Epat_eflux_ch0") # Epat is 3d, can't save it with idl cls.elf_pef_fs_Epat_eflux_ch1 = pytplot.get_data(f"el{cls.probe}_pef_fs_Epat_eflux_ch1") diff --git a/pyspedas/elfin/tests/test_state.py b/pyspedas/elfin/tests/test_state.py index 123a19c5..968ad4c7 100644 --- a/pyspedas/elfin/tests/test_state.py +++ b/pyspedas/elfin/tests/test_state.py @@ -10,9 +10,12 @@ import pytplot.get_data from pytplot.importers.tplot_restore import tplot_restore from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal + import pyspedas.elfin +from pyspedas.utilities.download import download +from pyspedas.elfin.config import CONFIG -TEST_DATASET_PATH="pyspedas/elfin/tests/test_dataset/" +TEST_DATASET_PATH="test/" class TestELFStateValidation(unittest.TestCase): """Tests of the data been identical to SPEDAS (IDL).""" @@ -28,7 +31,14 @@ def setUpClass(cls): cls.probe = 'b' # Load validation variables from the test file - filename = f"{TEST_DATASET_PATH}validation_el{cls.probe}_state_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile_name = f"{TEST_DATASET_PATH}validation_el{cls.probe}_state_{cls.t[0][0:4]+cls.t[0][5:7]+cls.t[0][8:10]}.tplot" + calfile = download(remote_file=calfile_name, + remote_path=CONFIG['remote_data_dir'], + local_path=CONFIG['local_data_dir'], + no_download=False) + if not calfile: + raise unittest.SkipTest(f"Cannot download validation file {calfile_name}") + filename = CONFIG['local_data_dir'] + calfile_name tplot_restore(filename) cls.elf_pos_gei = pytplot.get_data(f"el{cls.probe}_pos_gei") cls.elf_vel_gei = pytplot.get_data(f"el{cls.probe}_vel_gei")