-
Notifications
You must be signed in to change notification settings - Fork 7
/
api.py
2954 lines (2477 loc) · 118 KB
/
api.py
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# encoding=utf-8
"""
"""
import datetime
from urllib.parse import urljoin
from pandas import DataFrame
import requests
class Nasa(object):
r"""
Class object containing the methods for interacting with NASA API endpoints that require an API key.
Parameters
----------
key : str, default None
The generated API key received from the NASA API. Registering for an API key can be done on the `NASA API
webpage <https://api.nasa.gov/>`_. If :code:`None`, a 'DEMO_KEY' with a much more restricted access limit
is used.
Attributes
----------
key : str, None
The specified key when initializing the class.
limit_remaining : int
The number of API calls available.
mars_weather_limit_remaining : int
The number of API calls available for the :code:`mars_weather` method.
Methods
-------
picture_of_the_day
Returns the URL and other information for the NASA Picture of the Day.
mars_weather
Returns per-Sol (Martian Days) summary data for each of the last seven available Sols.
asteroid_feed
Returns a list of asteroids based on their closest approach date to Earth.
get_asteroids
Returns data from the overall asteroid data-set or specific asteroids given an ID.
coronal_mass_ejection
Returns data collected on coronal mass ejection events from the Space Weather Database of Notifications,
Knowledge, Information (DONKI).
geomagnetic_storm
Returns data collected on geomagnetic storm events from the Space Weather Database of Notifications, Knowledge,
Information (DONKI).
interplantary_shock
Returns data collected on interplantary shock events from the Space Weather Database of Notifications,
Knowledge, Information (DONKI).
solar_flare
Returns data on solar flare events from the Space Weather Database of Notifications, Knowledge, Information
(DONKI).
solar_energetic_particle
Returns data available from the Space Weather Database of Notifications, Knowledge, Information
(DONKI) API related to solar energetic particle events.
magnetopause_crossing
Returns data available from the Space Weather Database of Notifications, Knowledge, Information
(DONKI) API related to magnetopause crossing events.
radiation_belt_enhancement
Returns data available from the Space Weather Database of Notifications, Knowledge, Information
(DONKI) API related to radiation belt enhancement events.
hight_speed_stream
Returns data available from the Space Weather Database of Notifications, Knowledge, Information
(DONKI) API related to hight speed stream events.
wsa_enlil_simulation
Returns data available from the Space Weather Database of Notifications, Knowledge, Information
(DONKI) API.
epic
The EPIC API provides data on the imagery collected by the DSCOVR's Earth Polychromatic Imaging Camera
(EPIC).
earth_imagery
Retrieves the URL and other information from the Landsat 8 image database for the specified lat/lon location
and date.
earth_assets
Retrieves the datetimes and asset names of available imagery for a specified lat-lon location over a given
date range. The satellite that takes the images passes over each point approximately once every sixteen days.
mars_rover
Retrieves image data collected by the Mars rovers Curiosity, Discovery and Spirit.
genelab_search
Retrieves available data from the GeneLab and other bioinformatics databases such as the National Institutes
of Health (NIH) / National Center for Biotechnology Information (NCBI), Gene Expression Omnibus (GEO), the
European Bioinformatics Institute's (EBI) Proteomics Identification (PRIDE), and the Argonne National
Laboratory's (ANL) Metagenomics Rapid Annotations using Subsystems Technology (MG-RAST).
techport
Retrieves available NASA project data.
"""
def __init__(self, key=None):
self.api_key = key
self.host = 'https://api.nasa.gov'
self.limit_remaining = None
self.mars_weather_limit_remaining = None
@property
def api_key(self):
return self.__api_key
@property
def limit_remaining(self):
return self.__limit_remaining
@property
def mars_weather_limit_remaining(self):
return self.__mars_weather_limit_remaining
@api_key.setter
def api_key(self, api_key):
if api_key is not None:
self.__api_key = api_key
else:
self.__api_key = 'DEMO_KEY'
@limit_remaining.setter
def limit_remaining(self, remaining):
self.__limit_remaining = remaining
@mars_weather_limit_remaining.setter
def mars_weather_limit_remaining(self, remaining):
self.__mars_weather_limit_remaining = remaining
def picture_of_the_day(self, date=None, hd=False):
r"""
Returns the URL and other information for the NASA Astronomy Picture of the Day.
Parameters
----------
date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to the current
date.
hd : bool, default False
If True, returns the associated high-definition image of the Astrononmy Picture of the Day.
Raises
------
TypeError
Raised if the parameter :code:`date` is not a string or a datetime object.
TypeError
Raised if the parameter :code:`hd` is not boolean.
HTTPError
Raised if the returned status code is not 200 (success).
Returns
-------
dict
Dictionary object of the JSON data returned from the API.
Examples
--------
# Initialize Nasa API Class with a demo key
>>> n = Nasa()
# Return today's picture of the day
>>> n.picture_of_the_day()
# Return a previous date's picture of the day with the high-definition URL included.
>>> n.picture_of_the_day('2019-01-01', hd=True)
"""
if date is not None:
if not isinstance(date, (str, datetime.datetime)):
raise TypeError('date parameter must be a string representing a date in YYYY-MM-DD format or a '
'datetime object.')
if not isinstance(hd, bool):
raise TypeError('hd parameter must be True or False (boolean).')
if isinstance(date, datetime.datetime):
date = date.strftime('%Y-%m-%d')
url = urljoin(self.host + '/planetary/', 'apod')
r = requests.get(url,
params={
'api_key': self.api_key,
'date': date,
'hd': hd
})
if r.status_code != 200:
raise requests.exceptions.HTTPError(r.reason)
else:
self.__limit_remaining = r.headers['X-RateLimit-Remaining']
return r.json()
def mars_weather(self):
r"""
Returns per-Sol (Martian Days) summary data for each of the last seven available Sols.
Raises
------
HTTPError
Raised when the returned status code is not 200 (success).
Returns
-------
dict
Dictionary object repreenting the returned JSON data from the API.
Examples
--------
# Initialize NASA API object with a demo key
>>> n = NASA()
# Return the most recent data for the previous seven Sols (Martian Days)
>>> n.mars_weather()
Notes
-----
Data is provided by NASA's InSight Mars lander and as such data for particular Sols may be recalculated as
more data is received.
For more information on the data returned, please see
`NASA's documentation
<https://github.com/nasa/api-docs/blob/gh-pages/InSight%20Weather%20API%20Documentation.pdf>`_
"""
url = self.host + '/insight_weather/'
r = requests.get(url,
params={
'api_key': self.__api_key,
'ver': 1.0,
'feedtype': 'json'
})
if r.status_code != 200:
raise requests.exceptions.HTTPError(r.reason, r.url)
else:
self.__mars_weather_limit_remaining = r.headers['X-RateLimit-Remaining']
return r.json()
def asteroid_feed(self, start_date, end_date=None):
r"""
Returns a list of asteroids based on their closest approach date to Earth.
Parameters
----------
start_date : str, datetime
String representing a date in YYYY-MM-DD format or a datetime object.
end_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to seven days
after the provided :code:`start_date`.
Raises
------
TypeError
Raised if the :code:`start_date` parameter is not a string or a datetime object.
TypeError
Raised if the :code:`end_date` parameter is not a string or a datetime object.
HTTPError
Raised if the returned status code is not 200 (success).
Returns
-------
dict
Dictionary representing the returned JSON data from the API.
Examples
--------
# Initialize the NASA API with a demo key.
>>> n = NASA()
# Get asteroids approaching Earth at the beginning of 2019.
>>> n.asteroid_feed(start_date='2019-01-01')
Notes
-----
All the data is from the NASA JPL Asteroid team (http://neo.jpl.nasa.gov/). The API is maintained by the
`SpaceRocks team <https://github.com/SpaceRocks/>`_
"""
url = self.host + '/neo/rest/v1/feed'
start_date, end_date = _check_dates(start_date=start_date, end_date=end_date)
r = requests.get(url,
params={
'api_key': self.__api_key,
'start_date': start_date,
'end_date': end_date
})
if r.status_code != 200:
raise requests.exceptions.HTTPError(r.reason, r.url)
else:
self.__limit_remaining = r.headers['X-RateLimit-Remaining']
return r.json()
def get_asteroids(self, asteroid_id=None):
r"""
Returns data from the overall asteroid data-set or specific asteroids given an ID.
Parameters
----------
asteroid_id : str, int, default None
If None, the entire asteroid data set is returned. If an :code:`asteroid_id` is provided, data on that
specific asteroid is returned.
Raises
------
HTTPError:
Raised if the returned status code from the API is not 200 (success).
Returns
-------
dict
Dictionary object representing the returned JSON data from the NASA API.
Examples
--------
# Initialize NASA API with a demo key.
>>> n = Nasa()
# Get entire asteroid data set.
>>> n.get_asteroids()
# Get asteroid with ID 3542519
>>> n.get_asteroids(asteroid_id=3542519)
Notes
-----
All the data is from the NASA JPL Asteroid team (http://neo.jpl.nasa.gov/). The API is maintained by the
`SpaceRocks team <https://github.com/SpaceRocks/>`_
"""
url = self.host + '/neo/rest/v1/neo/'
if asteroid_id is not None:
url = url + str(asteroid_id)
else:
url = url + 'browse/'
r = requests.get(url,
params={
'api_key': self.__api_key
})
if r.status_code != 200:
raise requests.exceptions.HTTPError(r.reason, r.url)
else:
self.__limit_remaining = r.headers['X-RateLimit-Remaining']
return r.json()
def coronal_mass_ejection(self, start_date=None, end_date=None,
accurate_only=True, speed=0, complete_entry=True, half_angle=0,
catalog='ALL', keyword=None):
r"""
Returns data collected on coronal mass ejection events from the Space Weather Database of Notifications,
Knowledge, Information (DONKI).
Parameters
----------
start_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to 30 days prior
to the current date in UTC time.
end_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to the current
date in UTC time.
accurate_only : bool, default True
If True (default), only the most accurate results collected are returned.
complete_entry : bool, default True
If True (default), only results with complete data is returned.
speed : int, default 0
The lower limit of the speed of the CME event. Default is 0
half_angle : int, default 0
The lower limit half angle of the CME event. Default is 0.
catalog : str, {'ALL', 'SWRC_CATALOG', 'JANG_ET_AL_CATALOG'}
Specifies which catalog of data to return results. Defaults to 'ALL'.
keyword : str, default None
Filter results by a specific keyword.
Raises
------
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
ValueError
Raised if the :code:`catalog` parameter is not one of {'ALL', 'SWRC_CATALOG', 'JANG_ET_AL_CATALOG'}.
TypeError
Raised if parameter :code:`complete_entry` is not boolean (True or False).
TypeError
Raised if parameter :code:`accurate_only` is not boolean (True or False).
Returns
-------
list
List of results representing returned JSON data. If no data is returned, an empty dictionary is returned.
Examples
--------
# Initialize NASA API with a demo key
>>> n = Nasa()
# View data from coronal mass ejection events from the last thirty days
>>> n.coronal_mass_ejection()
# View all CME events from the beginning of 2019.
>>> n.coronal_mass_ejection(start_date='2019-01-01', end_date=datetime.datetime.today())
"""
start_date, end_date = _check_dates(start_date=start_date, end_date=end_date)
if catalog not in ('ALL', 'SWRC_CATALOG', 'JANG_ET_AL_CATALOG'):
raise ValueError("catalog parameter must be one of ('ALL', 'SWRC_CATALOG', 'JANG_ET_AL_CATALOG')")
if not isinstance(complete_entry, bool):
raise TypeError('complete_entry parameter must be boolean (True or False).')
if not isinstance(accurate_only, bool):
raise TypeError('accurate_only parameter must be boolean (True or False).')
url = self.host + '/DONKI/CMEAnalysis'
r = requests.get(url,
params={
'api_key': self.__api_key,
'startDate': start_date,
'endDate': end_date,
'mostAccurateOnly': accurate_only,
'completeEntryOnly': complete_entry,
'speed': speed,
'halfAngle': half_angle,
'catalog': catalog,
'keyword': keyword
})
if r.status_code != 200:
raise requests.exceptions.HTTPError(r.reason, r.url)
self.__limit_remaining = r.headers['X-RateLimit-Remaining']
if r.text == '':
r = {}
else:
r = r.json()
return r
def geomagnetic_storm(self, start_date=None, end_date=None):
r"""
Returns data collected on geomagnetic storm events from the Space Weather Database of Notifications, Knowledge,
Information (DONKI).
Parameters
----------
start_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to 30 days prior
to the current date in UTC time.
end_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to the current
date in UTC time.
Raises
------
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
Returns
-------
list
List of results representing returned JSON data. If no data is returned, an empty dictionary is returned.
Examples
--------
# Initialize API connection with a Demo Key
>>> n = Nasa()
# Get geomagnetic storm events from the last thirty days.
>>> n.geomagnetic_storm()
[{'gstID': '2019-08-31T12:00:00-GST-001',
'startTime': '2019-08-31T12:00Z',
'allKpIndex': [{'observedTime': '2019-08-31T15:00Z',
'kpIndex': 6,
'source': 'NOAA'},
{'observedTime': '2019-09-01T15:00Z', 'kpIndex': 6, 'source': 'NOAA'}],
'linkedEvents': [{'activityID': '2019-08-30T12:17:00-HSS-001'}]}]
"""
start_date, end_date = _check_dates(start_date=start_date, end_date=end_date)
url = self.host + '/DONKI/GST'
r = requests.get(url,
params={
'api_key': self.__api_key,
'startDate': start_date,
'endDate': end_date
})
if r.status_code != 200:
raise requests.exceptions.HTTPError(r.reason, r.url)
self.__limit_remaining = r.headers['X-RateLimit-Remaining']
if r.text == '':
r = {}
else:
r = r.json()
return r
def interplantary_shock(self, start_date=None, end_date=None, location='ALL', catalog='ALL'):
r"""
Returns data collected on interplantary shock events from the Space Weather Database of Notifications,
Knowledge, Information (DONKI).
Parameters
----------
start_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to 30 days prior
to the current date in UTC time.
end_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to the current
date in UTC time.
location : str, {'ALL', 'Earth', 'MESSENGER', 'STEREO A', 'STEREO B'}
Filters returned results to specified location of the interplantary shock event. Defaults to 'ALL'.
catalog : str, {'ALL', 'SWRC_CATALOG', 'WINSLOW_MESSENGER_ICME_CATALOG'}
Filters results to a specified catalog of collected data. Defaults to 'ALL'.
Raises
------
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
ValueError
Raised if :code:`location` parameter is not one of {'ALL', 'Earth', 'MESSENGER', 'STEREO A', 'STEREO B'}
ValueError
Raised if :code:`catalog` parameter is not one of {'ALL', 'SWRC_CATALOG', 'WINSLOW_MESSENGER_ICME_CATALOG'}
TypeError
Raised if :code:`location` parameter is not a string.
TypeError
Raised if :code:`catalog` parameter is not a string.
Returns
-------
list
List of results representing returned JSON data. If no data is returned, an empty list is returned.
Examples
--------
"""
start_date, end_date = _check_dates(start_date=start_date, end_date=end_date)
if not isinstance(location, str):
raise TypeError('location parameter must be a string')
if not isinstance(catalog, str):
raise TypeError('catalog parameter must be a string')
if location not in ('ALL', 'Earth', 'MESSENGER', 'STEREO A', 'STEREO B'):
raise ValueError(
"location parameter must be one of {'ALL' (default), 'Earth', 'MESSENGER', 'STEREO A', 'STEREO B'}")
if catalog not in ('ALL', 'SWRC_CATALOG', 'WINSLOW_MESSENGER_ICME_CATALOG'):
raise ValueError(
"catalog parameter must be one of {'ALL' (default) 'SWRC_CATALOG', 'WINSLOW_MESSENGER_ICME_CATALOG'}")
url = self.host + '/DONKI/IPS'
r = requests.get(url,
params={
'api_key': self.__api_key,
'startDate': start_date,
'endDate': end_date,
'location': location,
'catalog': catalog
})
if r.status_code != 200:
raise requests.exceptions.HTTPError(r.reason, r.url)
self.__limit_remaining = r.headers['X-RateLimit-Remaining']
if r.text == '':
r = {}
else:
r = r.json()
return r
def solar_flare(self, start_date=None, end_date=None):
r"""
Returns data on solar flare events from the Space Weather Database of Notifications, Knowledge, Information
(DONKI).
Parameters
----------
start_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to 30 days prior
to the current date in UTC time.
end_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to the current
date in UTC time.
Raises
------
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
Returns
-------
list
If data is available in the specified date range, a list of dictionary objects representing the data from
the API is returned. If no data is available, an empty dictionary is returned.
Examples
--------
# Initialize API connection with a Demo Key
>>> n = Nasa()
# Get solar flare events from May of 2019
>>> n.solar_flare(start_date='2019-05-01', end_date='2019-05-31')
[{'flrID': '2019-05-06T05:04:00-FLR-001',
'instruments': [{'id': 11, 'displayName': 'GOES15: SEM/XRS 1.0-8.0'}],
'beginTime': '2019-05-06T05:04Z',
'peakTime': '2019-05-06T05:10Z',
'endTime': None,
'classType': 'C9.9',
'sourceLocation': 'N08E50',
'activeRegionNum': 12740,
'linkedEvents': None}]
"""
self.__limit_remaining, r = _donki_request(url=self.host + '/DONKI/FLR',
key=self.__api_key,
start_date=start_date,
end_date=end_date)
return r
def solar_energetic_particle(self, start_date=None, end_date=None):
r"""
Returns data available from the Space Weather Database of Notifications, Knowledge, Information
(DONKI) API related to solar energetic particle events.
Parameters
----------
start_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to 30 days prior
to the current date in UTC time.
end_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to the current
date in UTC time.
Raises
------
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
Returns
-------
list
If data is available in the specified date range, a list of dictionary objects representing the data from
the API is returned. If no data is available, an empty dictionary is returned.
Examples
--------
# Initialize API connection with a Demo Key
>>> n = Nasa()
# Get data from April 2017
>>> n.solar_energetic_particle(start_date='2017-04-01', end_date='2017-04-30')
[{'sepID': '2017-04-18T23:39:00-SEP-001',
'eventTime': '2017-04-18T23:39Z',
'instruments': [{'id': 6, 'displayName': 'STEREO A: IMPACT 13-100 MeV'}],
'linkedEvents': [{'activityID': '2017-04-18T19:15:00-FLR-001'},
{'activityID': '2017-04-18T19:48:00-CME-001'}]}]
"""
self.__limit_remaining, r = _donki_request(url=self.host + '/DONKI/SEP',
key=self.__api_key,
start_date=start_date,
end_date=end_date)
return r
def magnetopause_crossing(self, start_date=None, end_date=None):
r"""
Returns data available from the Space Weather Database of Notifications, Knowledge, Information
(DONKI) API related to magnetopause crossing events.
Parameters
----------
start_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to 30 days prior
to the current date in UTC time.
end_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to the current
date in UTC time.
Raises
------
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
Returns
-------
list
If data is available in the specified date range, a list of dictionary objects representing the data from
the API is returned. If no data is available, an empty dictionary is returned.
Examples
--------
# Initialize API connection with a Demo Key
>>> n = Nasa()
# Get data on magnetopause crossing events from 2018 to the current date.
>>> n.magnetopause_crossing(start_date='2018-01-01')
[{'mpcID': '2018-05-05T14:33:00-MPC-001',
'eventTime': '2018-05-05T14:33Z',
'instruments': [{'id': 15, 'displayName': 'MODEL: SWMF'}],
'linkedEvents': [{'activityID': '2018-05-05T09:27:00-HSS-001'}]}]
"""
self.__limit_remaining, r = _donki_request(url=self.host + '/DONKI/MPC',
key=self.__api_key,
start_date=start_date,
end_date=end_date)
return r
def radiation_belt_enhancement(self, start_date=None, end_date=None):
r"""
Returns data available from the Space Weather Database of Notifications, Knowledge, Information
(DONKI) API related to radiation belt enhancement events.
Parameters
----------
start_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to 30 days prior
to the current date in UTC time.
end_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to the current
date in UTC time.
Raises
------
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
Returns
-------
list
If data is available in the specified date range, a list of dictionary objects representing the data from
the API is returned. If no data is available, an empty dictionary is returned.
Examples
--------
# Initialize API connection with a Demo Key
>>> n = Nasa()
# Get data on radiation belt enhancement events from the last 30 days.
>>> n.radiation_belt_enhancement()
[{'rbeID': '2019-08-31T18:50:00-RBE-001',
'eventTime': '2019-08-31T18:50Z',
'instruments': [{'id': 14, 'displayName': 'GOES13: SEM/EPS >0.8 MeV'}],
'linkedEvents': [{'activityID': '2019-08-30T12:17:00-HSS-001'}]}]
"""
self.__limit_remaining, r = _donki_request(url=self.host + '/DONKI/RBE',
key=self.__api_key,
start_date=start_date,
end_date=end_date)
return r
def hight_speed_stream(self, start_date=None, end_date=None):
r"""
Returns data available from the Space Weather Database of Notifications, Knowledge, Information
(DONKI) API related to hight speed stream events.
Parameters
----------
start_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to 30 days prior
to the current date in UTC time.
end_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to the current
date in UTC time.
Raises
------
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
Returns
-------
list
If data is available in the specified date range, a list of dictionary objects representing the data from
the API is returned. If no data is available, an empty dictionary is returned.
Examples
--------
# Initialize API connection with a Demo Key
>>> n = Nasa()
# Get data on hight speed stream events from the beginning of September 2019.
>>> n.hight_speed_stream()
[{'hssID': '2019-09-09T01:22:00-HSS-001',
'eventTime': '2019-09-09T01:22Z',
'instruments': [{'id': 9, 'displayName': 'ACE: SWEPAM'}],
'linkedEvents': None},
{'hssID': '2019-09-12T20:21:00-HSS-001',
'eventTime': '2019-09-12T20:21Z',
'instruments': [{'id': 9, 'displayName': 'ACE: SWEPAM'},
{'id': 10, 'displayName': 'ACE: MAG'}],
'linkedEvents': None},
{'hssID': '2019-09-17T03:00:00-HSS-001',
'eventTime': '2019-09-17T03:00Z',
'instruments': [{'id': 20, 'displayName': 'STEREO A: IMPACT'},
{'id': 21, 'displayName': 'STEREO A: PLASTIC'}],
'linkedEvents': None}]
"""
self.__limit_remaining, r = _donki_request(url=self.host + '/DONKI/HSS',
key=self.__api_key,
start_date=start_date,
end_date=end_date)
return r
def wsa_enlil_simulation(self, start_date=None, end_date=None):
r"""
Returns data available from the Space Weather Database of Notifications, Knowledge, Information
(DONKI) API.
Parameters
----------
start_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to 30 days prior
to the current date in UTC time.
end_date : str, datetime, default None
String representing a date in YYYY-MM-DD format or a datetime object. If None, defaults to the current
date in UTC time.
Raises
------
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
TypeError
Raised if parameter :code:`start_date` is not a string representing a date in YYYY-MM-DD format or
a datetime object.
Returns
-------
list
If data is available in the specified date range, a list of dictionary objects representing the data from
the API is returned. If no data is available, an empty dictionary is returned.
Examples
--------
# Initialize API connection with a Demo Key
>>> n = Nasa()
# Get data from the first simulation performed in 2019.
>>> wsa = n.wsa_enlil_simulation(start_date='2019-01-01')
>>> wsa[0]
{'simulationID': 'WSA-ENLIL/14394/1',
'modelCompletionTime': '2019-01-03T18:26Z',
'au': 2.0,
'cmeInputs': [{'cmeStartTime': '2019-01-02T23:12Z',
'latitude': -27.0,
'longitude': 45.0,
'speed': 430.0,
'halfAngle': 18.0,
'time21_5': '2019-01-03T07:15Z',
'isMostAccurate': True,
'levelOfData': 1,
'ipsList': [],
'cmeid': '2019-01-02T23:12:00-CME-001'}],
'estimatedShockArrivalTime': None,
'estimatedDuration': None,
'rmin_re': None,
'kp_18': None,
'kp_90': None,
'kp_135': None,
'kp_180': None,
'isEarthGB': False,
'impactList': None}
"""
self.__limit_remaining, r = _donki_request(url=self.host + '/DONKI/WSAEnlilSimulations',
key=self.__api_key,
start_date=start_date,
end_date=end_date)
return r
def epic(self, color='natural', date=None, available=False):
r"""
The EPIC API provides data on the imagery collected by the DSCOVR's Earth Polychromatic Imaging Camera
(EPIC).
Parameters
----------
color : str, {'natural', 'enhanced'}
Specifies the type of imagery to return. Must be one of 'natural' (default) or 'enhanced'
date : str, datetime, default None
String representing a date in 'YYYY-MM-DD' format or a datetime object
available : bool, default False
Alternative listing of all dates with specified color imagery
Raises
------
TypeError
Raised if parameter :code:`available` is not boolean (True or False).
TypeError
Raised if parameter :code:`date` is not a string or a datetime object.
ValueError
Raised if parameter :code:`color` is not one of 'natural' or 'enhanced'
Returns
-------
list
List of dictionaries representing the returned JSON data from the EPIC API.
Examples
--------
# Initialize API connection with a Demo Key
>>> n = Nasa()
# Get EPIC data from the beginning of 2019.
>>> e = n.epic(date='2019-01-01')
# Print the first result
>>> e[0]
{'identifier': '20190101015633',
'caption': "This image was taken by NASA's EPIC camera onboard the NOAA DSCOVR spacecraft",
'image': 'epic_RGB_20190101015633',
'version': '02',
'centroid_coordinates': {'lat': -27.281877, 'lon': 155.325443},
'dscovr_j2000_position': {'x': 350941.733992,
'y': -1329357.949188,
'z': -711000.841667},
'lunar_j2000_position': {'x': -281552.637877,
'y': -263898.385852,
'z': 34132.662255},
'sun_j2000_position': {'x': 25746688.614416,
'y': -132882102.563308,
'z': -57603901.841971},
'attitude_quaternions': {'q0': 0.621256,
'q1': 0.675002,
'q2': 0.397198,
'q3': 0.025296},
'date': '2019-01-01 01:51:44',
'coords': {'centroid_coordinates': {'lat': -27.281877, 'lon': 155.325443},
'dscovr_j2000_position': {'x': 350941.733992,
'y': -1329357.949188,
'z': -711000.841667},
'lunar_j2000_position': {'x': -281552.637877,
'y': -263898.385852,
'z': 34132.662255},
'sun_j2000_position': {'x': 25746688.614416,
'y': -132882102.563308,
'z': -57603901.841971},
'attitude_quaternions': {'q0': 0.621256,
'q1': 0.675002,
'q2': 0.397198,
'q3': 0.025296}}}
Notes
-----
If a :code:`date` is not given and :code:`available` is :code:`False`, a listing of all dates with the
specified color imagery is returned using the :code:`all` endpoint of the EPIC API.
The EPIC API provides information on the daily imagery collected by DSCOVR's Earth Polychromatic Imaging
Camera (EPIC) instrument. Uniquely positioned at the Earth-Sun Lagrange point, EPIC provides full disc
imagery of the Earth and captures unique perspectives of certain astronomical events such as lunar transits
using a 2048x2048 pixel CCD (Charge Coupled Device) detector coupled to a 30-cm aperture Cassegrain telescope.
"""
url = self.host + '/EPIC/api/'
if color not in ('natural', 'enhanced'):