Skip to content

Commit f7f4b0b

Browse files
authored
Merge pull request #84 from jgieseler/main
add tests for new jupyterhub_data_path()
2 parents ce9845f + 064784d commit f7f4b0b

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

seppy/tests/test_time_shift_analysis.ipynb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@
3636
},
3737
{
3838
"cell_type": "code",
39-
"execution_count": 2,
39+
"execution_count": null,
4040
"id": "2a6f4f3b",
4141
"metadata": {},
4242
"outputs": [],
4343
"source": [
4444
"from seppy.tools import Event\n",
4545
"import seppy.tools.widgets as w\n",
46+
"from seppy.util import jupyterhub_data_path\n",
4647
"import datetime, os"
4748
]
4849
},
@@ -145,13 +146,14 @@
145146
},
146147
{
147148
"cell_type": "code",
148-
"execution_count": 5,
149+
"execution_count": null,
149150
"id": "c8b4570e",
150151
"metadata": {},
151152
"outputs": [],
152153
"source": [
153-
"# The path to where data is located / to be downloaded (by default the current directory)\n",
154-
"data_path = f\"{os.getcwd()}/data/\"\n",
154+
"# Set your local path where you want to save the data files. If run on the project's JupyterHub server, it's set to a common data folder in the base directory. \n",
155+
"data_path = f\"{os.getcwd()}{os.sep}data\"\n",
156+
"data_path = jupyterhub_data_path(data_path)\n",
155157
"\n",
156158
"# Format of date: year, month, day\n",
157159
"startdate = datetime.date(2024, 5, 10)\n",
@@ -264,7 +266,7 @@
264266
],
265267
"metadata": {
266268
"kernelspec": {
267-
"display_name": "Python 3 (ipykernel)",
269+
"display_name": "serpentine",
268270
"language": "python",
269271
"name": "python3"
270272
},

seppy/tests/test_tools.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from astropy.utils.data import get_pkg_data_filename
22
from pathlib import Path
33
from seppy.tools import Event
4+
from seppy.util import jupyterhub_data_path
45
import datetime
56
import os
67
import matplotlib.pyplot as plt
@@ -14,7 +15,8 @@
1415
def test_onset_spectrum_tsa_SOLO_STEP_ions_old_data_online():
1516
startdate = datetime.date(2020, 9, 21)
1617
enddate = datetime.date(2020, 9, 21)
17-
lpath = f"{os.getcwd()}/data/"
18+
lpath = f"{os.getcwd()}{os.sep}data"
19+
lpath = jupyterhub_data_path(lpath)
1820
background_range = (datetime.datetime(2020, 9, 21, 0, 0, 0), datetime.datetime(2020, 9, 21, 2, 0, 0))
1921
#
2022
# ions
@@ -51,7 +53,8 @@ def test_onset_spectrum_tsa_SOLO_STEP_ions_old_data_online():
5153
def test_onset_spectrum_tsa_SOLO_STEP_ions_new_data_online():
5254
startdate = datetime.date(2022, 1, 9)
5355
enddate = datetime.date(2022, 1, 9)
54-
lpath = f"{os.getcwd()}/data/"
56+
lpath = f"{os.getcwd()}{os.sep}data"
57+
lpath = jupyterhub_data_path(lpath)
5558
background_range = (datetime.datetime(2022, 1, 9, 10, 0, 0), datetime.datetime(2022, 1, 9, 12, 0, 0))
5659
# ions
5760
Event1 = Event(spacecraft='Solar Orbiter', sensor='STEP', viewing='Pixel averaged', data_level='l2', species='ions', start_date=startdate, end_date=enddate, data_path=lpath)
@@ -91,7 +94,8 @@ def test_onset_spectrum_tsa_SOLO_STEP_ions_new_data_online():
9194
def test_onset_spectrum_tsa_SOLO_HET_online():
9295
startdate = datetime.date(2022, 11, 8)
9396
enddate = datetime.date(2022, 11, 8)
94-
lpath = f"{os.getcwd()}/data/"
97+
lpath = f"{os.getcwd()}{os.sep}data"
98+
lpath = jupyterhub_data_path(lpath)
9599
background_range = (datetime.datetime(2022, 11, 8, 0, 0, 0), datetime.datetime(2022, 11, 8, 1, 0, 0))
96100
# viewing "sun", single channel, protons
97101
Event1 = Event(spacecraft='Solar Orbiter', sensor='HET', viewing='sun', data_level='l2', species='protons', start_date=startdate, end_date=enddate, data_path=lpath)
@@ -129,7 +133,8 @@ def test_onset_spectrum_tsa_SOLO_HET_online():
129133
def test_onset_spectrum_tsa_SOLO_EPT_online():
130134
startdate = datetime.date(2022, 6, 6)
131135
enddate = datetime.date(2022, 6, 6)
132-
lpath = f"{os.getcwd()}/data/"
136+
lpath = f"{os.getcwd()}{os.sep}data"
137+
lpath = jupyterhub_data_path(lpath)
133138
background_range = (datetime.datetime(2022, 6, 6, 0, 0, 0), datetime.datetime(2022, 6, 6, 1, 0, 0))
134139
# viewing "sun", single channel, ions
135140
Event1 = Event(spacecraft='Solar Orbiter', sensor='EPT', viewing='sun', data_level='l2', species='ions', start_date=startdate, end_date=enddate, data_path=lpath)
@@ -167,7 +172,8 @@ def test_onset_spectrum_tsa_SOLO_EPT_online():
167172
def test_onset_spectrum_tsa_PSP_ISOIS_EPIHI_online():
168173
startdate = datetime.date(2021, 10, 28)
169174
enddate = datetime.date(2021, 10, 29)
170-
lpath = f"{os.getcwd()}/data/"
175+
lpath = f"{os.getcwd()}{os.sep}data"
176+
lpath = jupyterhub_data_path(lpath)
171177
background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0))
172178
# viewing "A", single channel, electrons
173179
Event1 = Event(spacecraft='PSP', sensor='isois-epihi', viewing='A', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath)
@@ -205,7 +211,8 @@ def test_onset_spectrum_tsa_PSP_ISOIS_EPIHI_online():
205211
def test_onset_spectrum_tsa_PSP_ISOIS_EPILO_e_online():
206212
startdate = datetime.date(2021, 10, 28)
207213
enddate = datetime.date(2021, 10, 29)
208-
lpath = f"{os.getcwd()}/data/"
214+
lpath = f"{os.getcwd()}{os.sep}data"
215+
lpath = jupyterhub_data_path(lpath)
209216
Event1 = Event(spacecraft='PSP', sensor='isois-epilo', viewing='7', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath)
210217
print(Event1.print_energies())
211218
background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0))
@@ -241,7 +248,8 @@ def test_onset_spectrum_tsa_PSP_ISOIS_EPILO_e_online():
241248
def test_onset_spectrum_tsa_Wind_3DP_p_online():
242249
startdate = datetime.date(2021, 10, 28)
243250
enddate = datetime.date(2021, 10, 29)
244-
lpath = f"{os.getcwd()}/data/"
251+
lpath = f"{os.getcwd()}{os.sep}data"
252+
lpath = jupyterhub_data_path(lpath)
245253
Event1 = Event(spacecraft='Wind', sensor='3DP', data_level='l2', viewing="Sector 3", species='protons', start_date=startdate, end_date=enddate, data_path=lpath)
246254
print(Event1.print_energies())
247255
background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0))
@@ -278,7 +286,8 @@ def test_onset_spectrum_tsa_Wind_3DP_p_online():
278286
def test_onset_spectrum_tsa_Wind_3DP_e_online():
279287
startdate = datetime.date(2021, 10, 28)
280288
enddate = datetime.date(2021, 10, 29)
281-
lpath = f"{os.getcwd()}/data/"
289+
lpath = f"{os.getcwd()}{os.sep}data"
290+
lpath = jupyterhub_data_path(lpath)
282291
Event1 = Event(spacecraft='Wind', sensor='3DP', viewing="Sector 3", data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath) # TODO: radio_spacecraft=('wind', 'WIND')
283292
print(Event1.print_energies())
284293
background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0))
@@ -315,7 +324,8 @@ def test_onset_spectrum_tsa_Wind_3DP_e_online():
315324
def test_onset_spectrum_tsa_STEREOB_HET_p_online():
316325
startdate = datetime.date(2006, 12, 13)
317326
enddate = datetime.date(2006, 12, 14)
318-
lpath = f"{os.getcwd()}/data/"
327+
lpath = f"{os.getcwd()}{os.sep}data"
328+
lpath = jupyterhub_data_path(lpath)
319329
Event1 = Event(spacecraft='STEREO-B', sensor='HET', data_level='l2', species='protons', start_date=startdate, end_date=enddate, data_path=lpath)
320330
print(Event1.print_energies())
321331
background_range = (datetime.datetime(2006, 12, 13, 0, 0, 0), datetime.datetime(2006, 12, 13, 2, 0, 0))
@@ -342,7 +352,8 @@ def test_onset_spectrum_tsa_STEREOB_HET_p_online():
342352
def test_onset_spectrum_tsa_STEREOB_HET_e_online():
343353
startdate = datetime.date(2006, 12, 13)
344354
enddate = datetime.date(2006, 12, 14)
345-
lpath = f"{os.getcwd()}/data/"
355+
lpath = f"{os.getcwd()}{os.sep}data"
356+
lpath = jupyterhub_data_path(lpath)
346357
Event1 = Event(spacecraft='STEREO-B', sensor='HET', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath, radio_spacecraft=('behind', 'STEREO-B'))
347358
print(Event1.print_energies())
348359
background_range = (datetime.datetime(2006, 12, 13, 0, 0, 0), datetime.datetime(2006, 12, 13, 2, 0, 0))
@@ -369,7 +380,8 @@ def test_onset_spectrum_tsa_STEREOB_HET_e_online():
369380
def test_onset_spectrum_tsa_STEREOA_SEPT_p_online():
370381
startdate = datetime.date(2021, 10, 28)
371382
enddate = datetime.date(2021, 10, 28)
372-
lpath = f"{os.getcwd()}/data/"
383+
lpath = f"{os.getcwd()}{os.sep}data"
384+
lpath = jupyterhub_data_path(lpath)
373385
Event1 = Event(spacecraft='STEREO-A', sensor='SEPT', viewing="north", data_level='l2', species='ions', start_date=startdate, end_date=enddate, data_path=lpath)
374386
print(Event1.print_energies())
375387
background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0))
@@ -396,7 +408,8 @@ def test_onset_spectrum_tsa_STEREOA_SEPT_p_online():
396408
def test_onset_spectrum_tsa_STEREOA_SEPT_e_online():
397409
startdate = datetime.date(2021, 10, 28)
398410
enddate = datetime.date(2021, 10, 28)
399-
lpath = f"{os.getcwd()}/data/"
411+
lpath = f"{os.getcwd()}{os.sep}data"
412+
lpath = jupyterhub_data_path(lpath)
400413
Event1 = Event(spacecraft='STEREO-A', sensor='SEPT', viewing="asun", data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath, radio_spacecraft=('ahead', 'STEREO-A'))
401414
print(Event1.print_energies())
402415
background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0))
@@ -423,7 +436,8 @@ def test_onset_spectrum_tsa_STEREOA_SEPT_e_online():
423436
def test_onset_spectrum_tsa_SOHO_EPHIN_online():
424437
startdate = datetime.date(2021, 10, 28)
425438
enddate = datetime.date(2021, 10, 28)
426-
lpath = f"{os.getcwd()}/data/"
439+
lpath = f"{os.getcwd()}{os.sep}data"
440+
lpath = jupyterhub_data_path(lpath)
427441
Event1 = Event(spacecraft='SOHO', sensor='EPHIN', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath)
428442
print(Event1.print_energies())
429443
background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0))
@@ -457,7 +471,8 @@ def test_onset_spectrum_tsa_SOHO_EPHIN_online():
457471
def test_onset_spectrum_tsa_SOHO_ERNE_online():
458472
startdate = datetime.date(2021, 10, 28)
459473
enddate = datetime.date(2021, 10, 29)
460-
lpath = f"{os.getcwd()}/data/"
474+
lpath = f"{os.getcwd()}{os.sep}data"
475+
lpath = jupyterhub_data_path(lpath)
461476
Event1 = Event(spacecraft='SOHO', sensor='ERNE-HED', data_level='l2', species='protons', start_date=startdate, end_date=enddate, data_path=lpath, radio_spacecraft=('ahead', 'STEREO-A'))
462477
print(Event1.print_energies())
463478
background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0))

0 commit comments

Comments
 (0)