-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathhapi_demo.py
More file actions
139 lines (103 loc) · 3.75 KB
/
hapi_demo.py
File metadata and controls
139 lines (103 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Basic demo of hapiclient. Install package using
# pip install hapiclient --upgrade
# from command line.
# Note:
# In IPython, enter
# %matplotlib qt
# on command line to open plots in new window. Enter
# %matplotlib inline
# to revert.
# For more extensive demos and examples, see
# https://colab.research.google.com/drive/11Zy99koiE90JKJ4u_KPTaEBMQFzbfU3P?usp=sharing
def main(plot):
demos = [omniweb, sscweb, cdaweb, lisird]
#demos = [testdata]
for demo in demos:
try:
demo(plot)
except Exception as e:
print("\033[0;31mError:\033[0m " + str(e))
def testdata(plot):
from hapiclient import hapi
server = 'http://hapi-server.org/servers/TestData2.0/hapi'
dataset = 'dataset1'
parameters = 'scalar'
start = '1970-01-01T00:00:00'
stop = '1970-01-02T00:01:00'
parameters = 'scalar,vector'
opts = {'logging': True, 'usecache': True}
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
# Plot all parameters
hapiplot(data, meta)
def omniweb(plot):
from hapiclient import hapi
server = 'https://cdaweb.gsfc.nasa.gov/hapi'
dataset = 'OMNI2_H0_MRG1HR'
start = '2003-09-01T00:00:00'
stop = '2003-12-01T00:00:00'
parameters = 'DST1800'
opts = {'logging': True, 'usecache': False}
# Get data
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
# Plot all parameters
hapiplot(data, meta)
def sscweb(plot):
from hapiclient import hapi
from hapiplot import hapiplot
# SSCWeb data
server = 'http://hapi-server.org/servers/SSCWeb/hapi'
dataset = 'ace'
start = '2001-01-01T05:00:00'
stop = '2001-01-01T10:00:00'
parameters = 'X_GSE,Y_GSE,Z_GSE'
opts = {'logging': True, 'usecache': True}
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
hapiplot(data, meta, **opts)
def cdaweb(plot):
from hapiclient import hapi
from hapiplot import hapiplot
# CDAWeb data - Magnitude and BGSEc from dataset AC_H0_MFI
server = 'https://cdaweb.gsfc.nasa.gov/hapi'
dataset = 'AC_H0_MFI'
start = '2001-01-01T05:00:00'
stop = '2001-01-01T10:00:00'
parameters = 'Magnitude,BGSEc'
opts = {'logging': True, 'usecache': True}
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
hapiplot(data, meta, **opts)
# CDAWeb metadata for AC_H0_MFI
server = 'https://cdaweb.gsfc.nasa.gov/hapi'
dataset = 'AC_H0_MFI'
meta = hapi(server, dataset, **opts)
print('Parameters in %s' % dataset)
for i in range(0, len(meta['parameters'])):
print(' %s' % meta['parameters'][i]['name'])
print('')
# CDAWeb metadata for all datasets
server = 'https://cdaweb.gsfc.nasa.gov/hapi'
meta = hapi(server, **opts)
print('%d CDAWeb datasets' % len(meta['catalog']))
for i in range(0, 3):
print(' %d. %s' % (i, meta['catalog'][i]['id']))
print(' ...')
print(' %d. %s' % (len(meta['catalog']), meta['catalog'][-1]['id']))
print('')
def lisird(plot):
from hapiclient import hapi
from hapiplot import hapiplot
server = 'http://lasp.colorado.edu/lisird/hapi'
dataset = 'sme_ssi'
parameters = 'irradiance'
start = '1981-10-09T00:00:00.000Z'
stop = '1981-10-14T00:00:00.000Z'
opts = {'usecache': True, 'logging': True}
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
hapiplot(data, meta)
if __name__ == '__main__':
plot = True
try:
from hapiplot import hapiplot
except:
plot = False
print('Package hapiplot is not installed. Will not plot results.')
main(plot)