forked from cmoestl/heliocats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicmecat.py
1708 lines (1168 loc) · 62.3 KB
/
icmecat.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
#!/usr/bin/env python
# coding: utf-8
# ## icmecat
#
# Makes the interplanetary coronal mass ejection catalog ICMECAT, available at https://helioforecast.space/icmecat.
#
# **latest release: version 2.1, 2021 November 29, updated 2022 December 1**
#
#
# **Author**: C. Möstl, Austrian Space Weather Office, Geosphere Austria
#
# https://twitter.com/chrisoutofspace / https://mastodon.social/@chrisoutofspace
#
# This notebook is part of the heliocats package https://github.com/cmoestl/heliocats
#
#
# **doi 10.6084/m9.figshare.6356420** https://10.6084/m9.figshare.6356420
#
# Install a specific conda environment to run this code, see readme at https://github.com/cmoestl/heliocats
#
# **Adding a new ICME event:**
# - edit the file icmecat/HELCATS_ICMECAT_v21_master.xlsx to add 3 times, the id and spacecraft name
# - delete the file for the respective spacecraft under icmecat/indices_icmecat/
# - run section 3 in this notebook or script.
#
#
# **Updating data**
# - Solar Orbiter http://soar.esac.esa.int/soar/ 1 min rtn files, then use read_solo.ipynb
# - Bepi Colombo manual download, then read_bepi.ipynb
# - PSP use cell in this notebook, beware of unfinished file downloads - redo!
# - STEREO-Ahead prel. PLASTIC ASCII files, IMPACT as usual (via heliosat), beacon data automatic every day
# - Wind automatic everyday, add spike and gap times under hd.remove_wind_spikes_gaps, or use ascii files (cell in this notebook)
#
#
#
# Convert this notebook to a script with jupyter nbconvert --to script icmecat.ipynb (automatically done in first cell)
# In[1]:
last_update='2023-February-TBD'
# In[2]:
import numpy as np
import scipy.io
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib.dates import DateFormatter
from datetime import timedelta
import seaborn as sns
import datetime
import astropy
import astropy.constants as const
from sunpy.time import parse_time
import time
import pickle
import sys
import os
import urllib
import json
import importlib
import pandas as pd
import copy
import openpyxl
import h5py
#get heliosat from github or pip https://pypi.org/project/HelioSat/
import heliosat
import heliopy.data.spice as spicedata
import heliopy.spice as spice
import cdflib
import pickle5
import astropy.units as u
from astropy.coordinates import SkyCoord
from sunpy.coordinates import frames
from heliocats import plot as hp
importlib.reload(hp) #reload again while debugging
from heliocats import data as hd
importlib.reload(hd) #reload again while debugging
from heliocats import cats as hc
importlib.reload(hc) #reload again while debugging
from heliocats import stats as hs
importlib.reload(hs) #reload again while debugging
#where the in situ data files are located is read
#from config.py
import config
importlib.reload(config)
from config import data_path
from config import data_path_ML
########### make directories first time if not there
resdir='results'
if os.path.isdir(resdir) == False: os.mkdir(resdir)
datadir='data'
if os.path.isdir(datadir) == False: os.mkdir(datadir)
indexdir='icmecat/indices_icmecat'
if os.path.isdir(indexdir) == False: os.mkdir(indexdir)
catdir='icmecat'
if os.path.isdir(catdir) == False: os.mkdir(catdir)
icplotsdir='icmecat/plots_icmecat/'
if os.path.isdir(icplotsdir) == False: os.mkdir(icplotsdir)
#Convert this notebook to a script with jupyter nbconvert --to script icmecat.ipynb
os.system('jupyter nbconvert --to script icmecat.ipynb')
import warnings
warnings.filterwarnings('ignore')
print('done')
print(heliosat.__version__)
# ## (0) process new in situ data into similar format
#
# ### for Bepi Colombo, got to read_bepi.ipynb
#
# ### for Solar Orbiter, got to read_solo.ipynb
#
#
# ### Parker Solar Probe
# #### file downloads
# In[ ]:
################### FIELDS
#generate datestrings for filenames
time1=[]
tstart1=datetime.datetime(2022, 3, 31)
tend1=datetime.datetime(2023, 1, 1)
while tstart1 < tend1:
time1.append(tstart1)
tstart1 += timedelta(days=1)
#version 1 until 2020 July 31
#version 2 from 2020 Oct 21
os.chdir('/nas/helio/data/heliosat/data/psp_fields_l2')
#download each file
for i in np.arange(0,len(time1)):
time1str=time1[i].strftime('%Y%m%d')
time1year=time1[i].strftime('%Y')
os.system('wget -nc https://spdf.gsfc.nasa.gov/pub/data/psp/fields/l2/mag_rtn_1min/'+time1year+'/psp_fld_l2_mag_rtn_1min_'+time1str+'_v02.cdf')
os.chdir('/home/heliofc/pycode/heliocats')
############# SWEAP
time1=[]
tstart1=datetime.datetime(2022, 7, 31)
tend1=datetime.datetime(2023, 1, 1)
while tstart1 < tend1:
time1.append(tstart1)
tstart1 += timedelta(days=1)
os.chdir('/nas/helio/data/heliosat/data/psp_spc_l3')
for i in np.arange(0,len(time1)):
time1str=time1[i].strftime('%Y%m%d')
time1year=time1[i].strftime('%Y')
os.system('wget -nc https://spdf.gsfc.nasa.gov/pub/data/psp/sweap/spc/l3/l3i/'+time1year+'/psp_swp_spc_l3i_'+time1str+'_v02.cdf')
os.chdir('/home/heliofc/pycode/heliocats')
# #### process to pickle file
# In[ ]:
from heliocats import data as hd
importlib.reload(hd) #reload again while debugging
#print('save PSP data') #from heliosat, converted to SCEQ similar to STEREO-A/B
#+**change end date in function
filepsp='psp_2022_rtn_new_jan2023.p'
hd.save_psp_data_mag_only(data_path,filepsp, sceq=False)
print('rtn done')
filepsp='psp_2022_sceq_new_jan2023.p'
hd.save_psp_data_mag_only(data_path,filepsp, sceq=True)
print('sceq done')
#filepsp='psp_2022_sceq_new_nov2022.p'
#hd.save_psp_data(data_path,filepsp, sceq=True)
#print('sceq done')
#print('load PSP data RTN')
#
import warnings
warnings.filterwarnings('ignore')
filepsp='psp_2022_rtn_new_jan2023.p'
[psp,hpsp]=pickle.load(open(data_path+filepsp, "rb" ) )
# #### plot PSP data
# In[5]:
#print('load PSP data RTN')
#
import warnings
warnings.filterwarnings('ignore')
filepsp='psp_2022_rtn_new_jan2023.p'
[psp,hpsp]=pickle.load(open(data_path+filepsp, "rb" ) )
#orbit 10
#start=datetime.datetime(2021,11,15)
#end=datetime.datetime(2021,11,25)
start=datetime.datetime(2022,1,1)
end=datetime.datetime(2022,7,31)
################ plot new psp data for checking
sns.set_context("talk")
sns.set_style('darkgrid')
fig=plt.figure(3,figsize=(20,10),dpi=100)
ax1=plt.subplot(311)
# #ax1.plot(psp.time,psp.bt,'-k',lw=0.5,label='Btotal')
# #ax1.plot(psp.time,psp.bx,'-r',lw=0.2,label='Br')
# #ax1.plot(psp.time,psp.by,'-g',lw=0.2,label='Bt')
# #ax1.plot(psp.time,psp.bz,'-b',lw=0.2,label='Bn')
ax1.plot(psp.time,psp.bt,'-k',lw=1,label='Btotal')
ax1.plot(psp.time,psp.bx,'-r',lw=1,label='Br')
ax1.plot(psp.time,psp.by,'-g',lw=1,label='Bt')
ax1.plot(psp.time,psp.bz,'-b',lw=1,label='Bn')
ax1.set_xlim(start,end)
ax1.set_ylabel('FIELDS magnetic field [nT]')
ax1.legend(loc=2)
#ax1.set_ylim(-20,20)
from astropy.constants import mu0,m_p
va=(psp.bt*1e-9)/np.sqrt(mu0.value*(psp.np*1e6)*m_p.value)*1e-3
ax2=plt.subplot(312,sharex=ax1)
ax2.plot(psp.time,psp.vt/va,'--',lw=1,label='M_A')
ax2.set_ylim(0.5,1.5)
ax3=plt.subplot(313,sharex=ax1)
ax3.plot(psp.time,psp.r,'-b')
ax3.set_ylim(0.034,0.09)
ax3.set_ylabel('Heliocentric distance [AU]')
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%b-%d'))
ax3.xaxis.set_major_formatter(mdates.DateFormatter('%b-%d'))
plt.title('Parker Solar Probe orbit Nr. 10, Nov / Dec 2021')
plt.tight_layout()
# plt.savefig('results/parker_orbit_venus.png',dpi=200)
plt.savefig('results/parker_orbit9.png')
plt.savefig('results/parker_orbit9.pdf')
# ## Other spacecraft
# In[5]:
############################# make Ulysses files
#hd.save_ulysses_data(data_path)
############################## make STEREO-B data files
# STEREO-B
# filestb_all='stereob_2007_2014_rtn.p'
# hd.save_all_stereob_science_data(data_path, filestb_all,sceq=False)
# [sb1,hsb1]=pickle.load(open(data_path+filestb_all, "rb" ) )
# filestb_all='stereob_2007_2014_sceq.p'
# hd.save_all_stereob_science_data(data_path, filestb_all,sceq=True)
# [sb2,hsb2]=pickle.load(open(data_path+filestb_all, "rb" ) )
# plt.plot(stb.time,stb.by,'-g',linewidth=5)
# plt.plot(sb2.time,sb2.by,'-k')
# plt.plot(sb1.time,sb1.by,'-b')
# #plt.plot(stb.time,stb.lat,'-r')
# plt.xlim(parse_time('2007-08-15').plot_date,parse_time('2007-08-15 12:00').plot_date)
# plt.ylim(-5,4)
############################## make Wind data files
# ################################# Wind
# filewin="wind_2018_2019_gse.p"
# start=datetime.datetime(2018, 1, 1)
# end=datetime.datetime(2020, 1, 1)
# hd.save_wind_data(data_path,filewin,start,end,heeq=False)
# filewin="wind_2018_2019_heeq.p"
# start=datetime.datetime(2018, 1, 1)
# #end=datetime.datetime(2019, 12, 31)
# end=datetime.datetime.utcnow()
# hd.save_wind_data(data_path,filewin,start,end,heeq=True)
# filewin1="wind_2007_2018_heeq_helcats.p"
# [win1,hwin1]=pickle.load(open(data_path+filewin1, "rb" ) )
# filewin2="wind_2018_2019_heeq.p"
# [win2,hwin2]=pickle.load(open(data_path+filewin2, "rb" ) )
# filewin3="wind_2018_2019_gse.p"
# [win3,hwin3]=pickle.load(open(data_path+filewin3, "rb" ) )
#filewin="wind_2018_2019_gse.p"
#for updating data
#start=datetime.datetime(2018, 1, 1)
#end=datetime.datetime(2020, 1, 1)
#hd.save_wind_data(data_path,filewin,start,end,heeq=False)
########## check GSE to HEEQ conversion
#save=1
#if save > 0:
# filewin="wind_2018_2020_sept_heeq.p"
# start=datetime.datetime(2018, 1 , 1)
# end=datetime.datetime(2020, 8, 31)
#filewin="wind_heeq_test.p"
#start=datetime.datetime(2019, 8, 1)
#end=datetime.datetime(2019, 10, 1)
#end=datetime.datetime.utcnow()
# hd.save_wind_data(data_path,filewin,start,end,heeq=True)
#filewin="wind_2018_2020_sept_gse.p"
#start=datetime.datetime(2018, 1, 1)
#end=datetime.datetime(2020, 7, 31)
#filewin="wind_gse_test.p"
#start=datetime.datetime(2019, 8, 1)
#end=datetime.datetime(2019, 10, 1)
#end=datetime.datetime.utcnow()
#hd.save_wind_data(data_path,filewin,start,end,heeq=False)
#filewin="wind_2018_now_gse.p"
#[wing,hwing]=pickle.load(open(data_path+filewin, "rb" ) )
#filewin="wind_2018_2020_sept_heeq.p"
#[winh,hwinh]=pickle.load(open(data_path+filewin, "rb" ) )
#plt.plot(wing.time,wing.bx,'-k',label='gse')
#plt.plot(winh.time,winh.bx,'-g',label='heeq')
#plt.plot(sc.time,ang[:,1],'-r',label='theta')
#plt.plot(sc.time,ang[:,2],'-b',label='lambda - omega mod 360')
#plt.legend()
########################## SAVE MSL rad data into recarray as pickle
#hd.save_msl_rad()
############################# make STEREO-A science data files
#filesta_all='stereoa_2007_2019_rtn.p'
#hd.save_all_stereoa_science_data(data_path, filesta_all,sceq=False)
#[sa1,hsa1]=pickle.load(open(data_path+filesta_all, "rb" ) )
#filesta_all='stereoa_2007_2019_sceq.p'
#hd.save_all_stereoa_science_data(data_path, filesta_all,sceq=True)
#[sa2,hsa2]=pickle.load(open(data_path+filesta_all, "rb" ) )
########################### STEREO-A science data after December 2019, ascii plastic files
# start=datetime.datetime(2020, 1,1)
# end=datetime.datetime(2020, 5, 1)
# #filesta="stereoa_2020_april_rtn.p"
# filesta="stereoa_2020_april_sceq.p"
# hd.save_stereoa_science_data(data_path,filesta,start, end,sceq=True)
# start=datetime.datetime(2020, 5,1)
# end=datetime.datetime(2020, 8, 1)
# #filesta="stereoa_2020_may_july_rtn.p"
# filesta="stereoa_2020_may_july_sceq.p"
# hd.save_stereoa_science_data(data_path,filesta,start, end,sceq=True)
#delete 2020 IMPACT March 11, April 17, May 18, July9 -corrupt cdf
#hd.save_stereoa_science_data(data_path,filesta,start, end,sceq=False)
#hd.save_stereoa_science_data_new(data_path,filesta,start, end,sceq=True)
#[sta2,hsta2]=pickle.load(open(data_path+filesta, "rb"))
#plt.figure(100,dpi=300)
#plt.plot(sta2.time,sta2.bt)
#plt.plot(sta2.time,sta2.bx)
#plt.plot(sta2.time,sta2.by)
#plt.plot(sta2.time,sta2.bz)
#plt.figure(101,dpi=300)
#plt.plot(sta2.time,sta2.vt)
########################## stitch together all science data files
#filesta="stereoa_2007_2020_rtn.p"
#hd.save_stereoa_science_data_merge_rtn(data_path,filesta)
#filesta="stereoa_2007_2020_sceq.p"
#hd.save_stereoa_science_data_merge_sceq(data_path,filesta)
# sta=pickle.load(open(data_path+filesta, "rb" ) )
# plt.figure(101,dpi=300)
# plt.plot(sta.time,sta.bx)
# plt.plot(sta.time,sta.by)
# plt.plot(sta.time,sta.bz)
# plt.figure(102,dpi=300)
# plt.plot(sta.time,sta.vt)
################################### STEREO-A beacon
#filesta="stereoa_2020_now_sceq_beacon_test.p"
# start=datetime.datetime(2020, 8, 1)
# #end=datetime.datetime(2020, 8, 15)
# end=datetime.datetime.utcnow()
# filesta="stereoa_2020_august_november_rtn_beacon.p"
# hd.save_stereoa_beacon_data(data_path,filesta,start,end,sceq=False)
# filesta="stereoa_2020_august_november_sceq_beacon.p"
# hd.save_stereoa_beacon_data(data_path,filesta,start,end,sceq=True)
# [sta,hsta]=pickle.load(open(data_path+filesta, "rb" ) )
# plt.figure(1,dpi=300)
# plt.plot(sta.time,sta.bt)
# plt.plot(sta.time,sta.bx)
# plt.plot(sta.time,sta.by)
# plt.plot(sta.time,sta.bz)
# plt.figure(2,dpi=300)
# plt.plot(sta.time,sta.vt)
# print('done')
# ### process Wind data since 1995
# In[ ]:
get_ipython().run_cell_magic('time', '', '\nfrom heliocats import data as hd\nimportlib.reload(hd) #reload again while debugging\n\n#download ascii files\n#hd.wind_download_ascii()\n\nstart=datetime.datetime(1995,1,1)\nend=datetime.datetime(2022,5,30)\n\n\n#end=datetime.datetime.utcnow() \npath=\'/nas/helio/data/insitu_python/\'\n\n\nfile=\'wind_1995_2022_heeq.p\'\nhd.save_wind_data_ascii(path,file,start,end,coord=\'HEEQ\')\n\nfile=\'wind_1995_2022_gse.p\'\nhd.save_wind_data_ascii(path,file,start,end,coord=\'GSE\')\n\n\nfile=\'wind_1995_2022_gsm.p\'\nhd.save_wind_data_ascii(path,file,start,end,coord=\'GSM\')\n\n#filewin="wind_1995_2021_gsm.p" \n#[win,hwin]=pickle.load(open(data_path+filewin, "rb" ) ) \n\n\n\n#GSE GSM comparison\n\n#win=win[3000000:7056000]\n\n#filewin="wind_1995_2021_heeq.p" \n#[winh,hwin]=pickle.load(open(data_path+filewin, "rb" ) ) \n\n#winh=winh[3000000:7056000]\n\n\n#np.nanstd(winh.bz-win.bz)\n#np.nanmean(winh.bz-win.bz)\n\n\n')
# ## (1) load data
# In[3]:
#made with HelioSat and heliocats.data
load_data=1
if load_data > 0:
print('load Ulysses RTN') #made with heliocats.data.save_ulysses_data
fileuly='ulysses_1990_2009_rtn.p'
[uly,huly]=pickle.load(open(data_path+fileuly, "rb" ) )
print('load VEX data (Venus magnetosphere removed) SCEQ') #legacy from HELCATS project in SCEQ, removed magnetosphere
filevex='vex_2007_2014_sceq_removed.p'
[vex,hvex]=pickle.load(open(data_path+filevex, 'rb' ) )
print('load MESSENGER data (Mercury magnetosphere removed) SCEQ') #legacy from HELCATS project in SCEQ, removed magnetosphere
filemes='messenger_2007_2015_sceq_removed.p'
[mes,hmes]=pickle.load(open(data_path+filemes, 'rb' ) )
print('load STEREO-B data SCEQ') #yearly magplasma files from stereo science center, conversion to SCEQ
filestb='stereob_2007_2014_sceq.p'
[stb,hstb]=pickle.load(open(data_path+filestb, "rb" ) )
#use pickle5 to read
#print('load Juno data ') #Emma Davies https://figshare.com/articles/dataset/Juno_Cruise_Phase_Magnetometer_and_Position_Data/19517257
#juno_df = pd.read_pickle(data_path+'juno_2011_2016_rtn.pkl')
########### CURRENT ACTIVE SPACECRAFT
############### convert MAVEN from Cyril's MAT file to pickle
#from heliocats import data as hd
#importlib.reload(hd) #reload again while debugging
#file_input=data_path+'input/Data-MAVEN-MAG_SolarWind_102014-012021.mat'
#filename=data_path+'maven_2014_2021_removed_no_plasma.p'
#hd.convert_MAVEN_mat_removed(file_input,filename)
#filemav=data_path+'maven_2014_2021_removed_no_plasma.p'
#filename=data_path+'maven_2014_2021_removed_smoothed_no_plasma.p'
#hd.MAVEN_smooth_orbit(filemav,filename)
print('load MAVEN data MSO')
#filemav='maven_2014_2018.p'
#[mav,hmav]=pickle.load(open(filemav, 'rb' ) )
#combined plasma and mag
filemav='maven_2014_2018_removed.p'
[mavr,hmavr]=pickle.load(open(data_path+filemav, 'rb' ) )
filemav='maven_2014_2018_removed_smoothed.p'
[mav,hmav]=pickle.load(open(data_path+filemav, 'rb' ) )
#only mag
filemav='maven_2014_2021_removed_no_plasma.p'
[mav2,hmav2]=pickle.load(open(data_path+filemav, 'rb' ) )
filemav='maven_2014_2021_removed_smoothed_no_plasma.p'
[mavr2,hmavr2]=pickle.load(open(data_path+filemav, 'rb' ) )
#removed magnetosphere by C. Simon Wedlund, 1 data point per orbit, MSO
#filemav='maven_2014_2021_removed_smoothed.p'
#[mav,hmav]=pickle.load(open(data_path+filemav, 'rb' ) )
#use hd.save_msl_rad() first to convert data doseE_sol_filter_2019.dat to pickle file
print('load MSL RAD')
#MSL RAD
rad=hd.load_msl_rad()#, rad.time,rad.dose_sol
##############################################
#data to 2021 Aug 2
print('load Bepi Colombo SCEQ')
filebepi='bepi_2019_2021_sceq.p'
bepi1=pickle.load(open(data_path+filebepi, "rb" ) )
#data from 2021 Aug 3
filebepi2='bepi_2021_2022_ib_sceq.p'
bepi2=pickle.load(open(data_path+filebepi2, "rb" ) )
#make array
bepi=np.zeros(np.size(bepi1.time)+np.size(bepi2.time),dtype=[('time',object),('bx', float),('by', float),\
('bz', float),('bt', float),\
('x', float),('y', float),('z', float),\
('r', float),('lat', float),('lon', float)])
#convert to recarray
bepi = bepi.view(np.recarray)
bepi.time=np.hstack((bepi1.time,bepi2.time))
bepi.bx=np.hstack((bepi1.bx,bepi2.bx))
bepi.by=np.hstack((bepi1.by,bepi2.by))
bepi.bz=np.hstack((bepi1.bz,bepi2.bz))
bepi.bt=np.hstack((bepi1.bt,bepi2.bt))
bepi.x=np.hstack((bepi1.x,bepi2.x))
bepi.y=np.hstack((bepi1.y,bepi2.y))
bepi.z=np.hstack((bepi1.z,bepi2.z))
bepi.r=np.hstack((bepi1.r,bepi2.r))
bepi.lon=np.hstack((bepi1.lon,bepi2.lon))
bepi.lat=np.hstack((bepi1.lat,bepi2.lat))
print('Bepi Merging done')
##############################################
print('load Solar Orbiter SCEQ')
filesolo='solo_2020_april_2022_june_sceq.p'
solo=pickle.load(open(data_path+filesolo, "rb" ) )
#set all plasma data to NaN
solo.vt=np.nan
solo.np=np.nan
solo.tp=np.nan
##############################################
print('load PSP data SCEQ') #from heliosat, converted to SCEQ similar to STEREO-A/B
filepsp='psp_2018_2022_sceq.p'
[psp1,hpsp]=pickle.load(open(data_path+filepsp, "rb" ) )
#add file with mag only for 2022, plasma needs to be added in heliosat
#psp_2022_sceq_new_nov2022.p
filepsp2='psp_2022_sceq_new_nov2022.p'
[psp2,hpsp2]=pickle.load(open(data_path+filepsp2, "rb" ) )
psp=np.zeros(np.size(psp1.time)+np.size(psp2.time),dtype=[('time',object),('bx', float),('by', float),\
('bz', float),('bt', float),('vt', float),('np', float),('tp', float),\
('x', float),('y', float),('z', float),\
('r', float),('lat', float),('lon', float)])
#convert to recarray
psp = psp.view(np.recarray)
psp.time=np.hstack((psp1.time,psp2.time))
psp.bx=np.hstack((psp1.bx,psp2.bx))
psp.by=np.hstack((psp1.by,psp2.by))
psp.bz=np.hstack((psp1.bz,psp2.bz))
psp.bt=np.hstack((psp1.bt,psp2.bt))
psp.vt=np.hstack((psp1.vt,psp2.vt))
psp.np=np.hstack((psp1.np,psp2.np))
psp.tp=np.hstack((psp1.tp,psp2.tp))
psp.x=np.hstack((psp1.x,psp2.x))
psp.y=np.hstack((psp1.y,psp2.y))
psp.z=np.hstack((psp1.z,psp2.z))
psp.r=np.hstack((psp1.r,psp2.r))
psp.lon=np.hstack((psp1.lon,psp2.lon))
psp.lat=np.hstack((psp1.lat,psp2.lat))
print('psp Merging done')
########### STA
print('load and merge STEREO-A data SCEQ') #yearly magplasma files from stereo science center, conversion to SCEQ
filesta1='stereoa_2007_2020_sceq.p'
sta1=pickle.load(open(data_path+filesta1, "rb" ) )
#beacon data
#filesta2="stereoa_2019_2020_sceq_beacon.p"
#filesta2='stereoa_2019_2020_sept_sceq_beacon.p'
#filesta2='stereoa_2019_now_sceq_beacon.p'
#filesta2="stereoa_2020_august_november_sceq_beacon.p"
filesta2='stereoa_2020_now_sceq_beacon.p'
[sta2,hsta2]=pickle.load(open(data_path+filesta2, "rb" ) )
#cutoff with end of science data
sta2=sta2[np.where(sta2.time >= parse_time('2020-Aug-01 00:00').datetime)[0]]
#make array
sta=np.zeros(np.size(sta1.time)+np.size(sta2.time),dtype=[('time',object),('bx', float),('by', float),\
('bz', float),('bt', float),('vt', float),('np', float),('tp', float),\
('x', float),('y', float),('z', float),\
('r', float),('lat', float),('lon', float)])
#convert to recarray
sta = sta.view(np.recarray)
sta.time=np.hstack((sta1.time,sta2.time))
sta.bx=np.hstack((sta1.bx,sta2.bx))
sta.by=np.hstack((sta1.by,sta2.by))
sta.bz=np.hstack((sta1.bz,sta2.bz))
sta.bt=np.hstack((sta1.bt,sta2.bt))
sta.vt=np.hstack((sta1.vt,sta2.vt))
sta.np=np.hstack((sta1.np,sta2.np))
sta.tp=np.hstack((sta1.tp,sta2.tp))
sta.x=np.hstack((sta1.x,sta2.x))
sta.y=np.hstack((sta1.y,sta2.y))
sta.z=np.hstack((sta1.z,sta2.z))
sta.r=np.hstack((sta1.r,sta2.r))
sta.lon=np.hstack((sta1.lon,sta2.lon))
sta.lat=np.hstack((sta1.lat,sta2.lat))
print('STA Merging done')
#### Wind
filewin="wind_1995_2021_heeq.p"
[win1,hwin1]=pickle.load(open(data_path+filewin, "rb" ) )
#add new data from 2021 October 31
filewin2="wind_2018_now_heeq.p"
[win2,hwin2]=pickle.load(open(data_path+filewin2, "rb" ) )
#function for spike removal, see list with times in that function
win2=hd.remove_wind_spikes_gaps(win2)
#merge Wind old and new data
win1=win1[np.where(win1.time < parse_time('2021-Oct-31 00:00').datetime)[0]]
#make array
win=np.zeros(np.size(win1.time)+np.size(win2.time),dtype=[('time',object),('bx', float),('by', float),\
('bz', float),('bt', float),('vt', float),('np', float),('tp', float),\
('x', float),('y', float),('z', float),\
('r', float),('lat', float),('lon', float)])
#convert to recarray
win = win.view(np.recarray)
win.time=np.hstack((win1.time,win2.time))
win.bx=np.hstack((win1.bx,win2.bx))
win.by=np.hstack((win1.by,win2.by))
win.bz=np.hstack((win1.bz,win2.bz))
win.bt=np.hstack((win1.bt,win2.bt))
win.vt=np.hstack((win1.vt,win2.vt))
win.np=np.hstack((win1.np,win2.np))
win.tp=np.hstack((win1.tp,win2.tp))
win.x=np.hstack((win1.x,win2.x))
win.y=np.hstack((win1.y,win2.y))
win.z=np.hstack((win1.z,win2.z))
win.r=np.hstack((win1.r,win2.r))
win.lon=np.hstack((win1.lon,win2.lon))
win.lat=np.hstack((win1.lat,win2.lat))
print('Wind merging done')
#wind data from 1995
#LOAD HELCATS catalogs
#HIGEOCAT
higeocat=hc.load_higeocat_vot('data/HCME_WP3_V06.vot')
higeocat_time=parse_time(higeocat['Date']).datetime
#load arrcat as pandas dataframe
file='arrcat/HELCATS_ARRCAT_v20_pandas.p'
[ac_pandas,h]=pickle.load( open(file, 'rb'))
print()
print()
print('time ranges of the in situ data: ')
print()
print('active spacecraft:')
print('Solar Orbiter ',str(solo.time[0])[0:10],str(solo.time[-1])[0:10])
print('Bepi Colombo ',str(bepi.time[0])[0:10],str(bepi.time[-1])[0:10])
print('Parker Solar Probe ',str(psp.time[0])[0:10],str(psp.time[-1])[0:10])
print('Wind ',str(win.time[0])[0:10],str(win.time[-1])[0:10])
print('STEREO-A ',str(sta.time[0])[0:10],str(sta.time[-1])[0:10])
print('MAVEN ',str(mav.time[0])[0:10],str(mav.time[-1])[0:10])
print('MSL/RAD ',str(rad.time[0])[0:10],str(rad.time[-1])[0:10])
print()
print('missions finished:')
print('VEX ',str(vex.time[0])[0:10],str(vex.time[-1])[0:10])
print('MESSENGER ',str(mes.time[0])[0:10],str(mes.time[-1])[0:10])
print('STEREO-B ',str(stb.time[0])[0:10],str(stb.time[-1])[0:10])
print('Ulysses ',str(uly.time[0])[0:10],str(uly.time[-1])[0:10])
#print('Juno cruise phase ',str(uly.time[0])[0:10],str(uly.time[-1])[0:10])
print()
print('catalogs:')
print()
print('HELCATS HIGeoCAT ',str(higeocat_time[0])[0:10],str(higeocat_time[-1])[0:10])
print('HELCATS ARRCAT ',np.sort(ac_pandas.sse_launch_time)[0][0:10],np.sort(ac_pandas.sse_launch_time)[-1][0:10])
print('done')
# ### 1a save data as numpy structured arrays for machine learning
# In[ ]:
data_to_numpy_1=0
if data_to_numpy_1 > 0:
print('convert data to numpy structured arrays suitable for machine learning')
####################### These are finished missions
print('STEREO-B')
#STEREO-B
#make extra header with variable attributes
hstb_att='dtype=[(time [matplotlib format], < f8], (bt [nT], <f8), (bx, [nT, SCEQ], <f8), (by [nT, SCEQ], <f8),\
(bz, SCEQ [nT], <f8), (vt [km/s], <f8), (np [ccm -3], <f8), (tp [K], <f8), (x [AU, HEEQ], <f8), (y [AU, HEEQ], <f8),\
(z [AU, HEEQ], <f8), (r, <f8), (lat [deg, HEEQ], <f8), (lon [deg, HEEQ], <f8 )]'
stb_nd=hd.recarray_to_numpy_array(stb)
#change dtype everywhere to float
stb_nd=stb_nd.astype(dtype=[('time', '<f8'), ('bx', '<f8'), ('by', '<f8'), ('bz', '<f8'), ('bt', '<f8'), \
('vt', '<f8'), ('np', '<f8'), ('tp', '<f8'), ('x', '<f8'), ('y', '<f8'), \
('z', '<f8'), ('r', '<f8'), ('lat', '<f8'), ('lon', '<f8')])
pickle.dump([stb_nd,hstb_att], open(data_path_ML+ "stereob_2007_2014_sceq_ndarray.p", "wb" ) )
#####
print('Ulysses')
huly_att='dtype=[(time [matplotlib format]), (bt [nT], <f8), (bx [nT, RTN], <f8), (by [nT, RTN], <f8), \
(bz [nT, RTN], <f8), (vt [km/s], <f8), (np [ccm -3], <f8), (tp [K], <f8), (x [AU, HEEQ], <f8),\
(y [AU, HEEQ], <f8), (z [AU, HEEQ], <f8), (r [AU], <f8), (lat [deg, HEEQ], <f8), (lon [deg, HEEQ], <f8 )]'
uly_nd=hd.recarray_to_numpy_array(uly)
uly_nd=uly_nd.astype(dtype=[('time', '<f8'), ('bx', '<f8'), ('by', '<f8'), ('bz', '<f8'), ('bt', '<f8'), \
('vt', '<f8'), ('np', '<f8'), ('tp', '<f8'), ('x', '<f8'), ('y', '<f8'), \
('z', '<f8'), ('r', '<f8'), ('lat', '<f8'), ('lon', '<f8')])
pickle.dump([uly_nd,huly_att], open(data_path_ML+ "ulysses_1990_2009_rtn_ndarray.p", "wb" ) )
#####
print('VEX')
#header no plasma, with planetary orbit
hatt6='dtype=[(time [matplotlib format]), (bt [nT], <f8), (bx [nT, SCEQ], <f8), (by [nT, SCEQ], <f8), \
(bz [nT, SCEQ], <f8), (x [AU, HEEQ], <f8), (y [AU, HEEQ], <f8), (z [AU, HEEQ], <f8), (r [AU], <f8), \
(lat [deg, HEEQ], <f8), (lon [deg, HEEQ]), (xo [km, VSO], <f8), (yo [km, VSO], <f8), (zo [km, VSO], <f8), \
(ro [km], <f8), (lato [deg, VSO], <f8), (lono [deg, VSO], <f8)]'
vex_nd=hd.recarray_to_numpy_array(vex)
vex_nd=vex_nd.astype(dtype=[('time', '<f8'), ('bx', '<f8'), ('by', '<f8'), ('bz', '<f8'), ('bt', '<f8'),\
('x', '<f8'), ('y', '<f8'), ('z', '<f8'), ('r', '<f8'), ('lat', '<f8'), ('lon', '<f8'),\
('xo', '<f8'), ('yo', '<f8'), ('zo', '<f8'), ('ro', '<f8'), ('lato', '<f8'), ('lono', '<f8')])
pickle.dump([vex_nd,hatt6], open(data_path_ML+ "vex_2007_2014_sceq_removed_ndarray.p", "wb" ) )
#####
print('MESSENGER') #no plasma, no planetary orbit
hatt7='dtype=[(time [matplotlib format]), (bt [nT], <f8), (bx [nT, SCEQ], <f8), (by [nT, SCEQ], <f8), \
(bz [nT, SCEQ], <f8), (x [AU, HEEQ], <f8), (y [AU, HEEQ], <f8), (z [AU, HEEQ], <f8), (r [AU], <f8), \
(lat [deg, HEEQ], <f8), (lon [deg, HEEQ])'
mes_nd=hd.recarray_to_numpy_array(mes)
mes_nd=mes_nd.astype(dtype=[('time', '<f8'), ('bx', '<f8'), ('by', '<f8'), ('bz', '<f8'), ('bt', '<f8'),\
('x', '<f8'), ('y', '<f8'), ('z', '<f8'), ('r', '<f8'), ('lat', '<f8'), ('lon', '<f8')])
pickle.dump([mes_nd,hatt7], open(data_path_ML+ "mes_2007_2015_sceq_removed_ndarray.p", "wb" ) )
####################### These are live missions
data_to_numpy_2=0
if data_to_numpy_2 > 0:
print('STEREO-A')
hsta_att='dtype=[(time [matplotlib format], < f8], (bt [nT], <f8), (bx, [nT, SCEQ], <f8), (by [nT, SCEQ], <f8),\
(bz, SCEQ [nT], <f8), (vt [km/s], <f8), (np [ccm -3], <f8), (tp [K], <f8), (x [AU, HEEQ], <f8), (y [AU, HEEQ], <f8),\
(z [AU, HEEQ], <f8), (r, <f8), (lat [deg, HEEQ], <f8), (lon [deg, HEEQ], <f8 )]'
sta_nd=hd.recarray_to_numpy_array(sta)
sta_nd=sta_nd.astype(dtype=[('time', '<f8'), ('bx', '<f8'), ('by', '<f8'), ('bz', '<f8'), ('bt', '<f8'), \
('vt', '<f8'), ('np', '<f8'), ('tp', '<f8'), ('x', '<f8'), ('y', '<f8'), \
('z', '<f8'), ('r', '<f8'), ('lat', '<f8'), ('lon', '<f8')])
pickle.dump([sta_nd,hsta_att], open(data_path_ML+ "stereoa_2007_2021_sceq_ndarray.p", "wb" ) )
#print('BepiColombo')
#hbepi_att='dtype=[(time [matplotlib format], < f8], (bt [nT], <f8), (bx, [nT, SCEQ], <f8), (by [nT, SCEQ], <f8),\
#(bz, SCEQ [nT], <f8), (x [AU, HEEQ], <f8), (y [AU, HEEQ], <f8),\
#(z [AU, HEEQ], <f8), (r, <f8), (lat [deg, HEEQ], <f8), (lon [deg, HEEQ], <f8 )]'
#make new array
#bepi_nd=np.zeros(np.size(bepi),dtype=[('time',object),('bt', '<f8'),('bx', '<f8'),\
# ('by', float),('bz', '<f8'),('x', '<f8'),('y', '<f8'),\
# ('z', float),('r', '<f8'),('lat', '<f8'),('lon', '<f8')])
#bepi_nd['time']=bepi.time
#bepi_nd['bt']=bepi.bt
#bepi_nd['bx']=bepi.bx
#bepi_nd['by']=bepi.by
#bepi_nd['bz']=bepi.bz
#bepi_nd['x']=bepi.x
#bepi_nd['y']=bepi.y
#bepi_nd['z']=bepi.z
#bepi_nd['r']=bepi.r
#bepi_nd['lat']=bepi.lat
#bepi_nd['lon']=bepi.lon
#pickle.dump([bepi_nd,hbepi_att], open(data_path_ML+ "bepi_2019_2021_sceq_ndarray.p", "wb" ) )
print('Wind')
hwind_att='dtype=[((time [matplotlib format]), (bt [nT], <f8), (bx [nT, HEEQ], <f8), (by [nT, HEEQ], <f8), \
(bz [nT, HEEQ], <f8), (vt [km/s], <f8), (np [ccm -3], <f8), \
(tp [K], <f8), (x [AU, HEEQ], <f8), (y [AU, HEEQ], <f8), (z [AU, HEEQ], <f8), (r [AU], <f8),\
(lat [deg, HEEQ], <f8), (lon [deg, HEEQ],<f8 )]'
win_nd=hd.recarray_to_numpy_array(win)
win_nd=win_nd.astype(dtype=[('time', '<f8'), ('bx', '<f8'), ('by', '<f8'), ('bz', '<f8'), ('bt', '<f8'), \
('vt', '<f8'), ('np', '<f8'), ('tp', '<f8'), ('x', '<f8'), ('y', '<f8'), \
('z', '<f8'), ('r', '<f8'), ('lat', '<f8'), ('lon', '<f8')])
pickle.dump([win_nd,hwind_att], open(data_path_ML+ "wind_2007_2021_heeq_ndarray.p", "wb" ) )
print('PSP')
hpsp_att='dtype=[(time, matplotlib), (bt [nT], <f8), (bx, SCEQ [nT], <f8), (by [nT, SCEQ], <f8),\
(bz, SCEQ [nT], <f8), (vt [km/s], <f8),(vx [km/s, SCEQ], <f8)(vy [km/s, SCEQ], <f8),\
(vz [km/s, SCEQ], <f8), (np [ccm -3], <f8), (tp [K], <f8), (x [AU, HEEQ], <f8), (y [AU, HEEQ], <f8),\
(z [AU, HEEQ], <f8), (r, <f8), (lat [deg, HEEQ], <f8), (lon [deg, HEEQ], <f8])'
psp_nd=hd.recarray_to_numpy_array(psp)
psp_nd=psp_nd.astype(dtype=[('time', '<f8'), ('bx', '<f8'), ('by', '<f8'), ('bz', '<f8'), ('bt', '<f8'), \
('vt', '<f8'),('vx', '<f8'),('vy', '<f8'),('vz', '<f8'), ('np', '<f8'), ('tp', '<f8'),\
('x', '<f8'), ('y', '<f8'), ('z', '<f8'), ('r', '<f8'), ('lat', '<f8'), ('lon', '<f8')])
pickle.dump([psp_nd,hpsp_att], open(data_path_ML+ "psp_2018_2021_sceq_ndarray.p", "wb" ) )
print('Solar Orbiter')
hsolo_att='dtype=[(time [matplotlib format], < f8], (bt [nT], <f8), (bx, [nT, SCEQ], <f8), (by [nT, SCEQ], <f8),\
(bz, SCEQ [nT], <f8), (vt [km/s], <f8), (np [ccm -3], <f8), (tp [K], <f8), (x [AU, HEEQ], <f8), (y [AU, HEEQ], <f8),\
(z [AU, HEEQ], <f8), (r, <f8), (lat [deg, HEEQ], <f8), (lon [deg, HEEQ], <f8 )]'
solo_nd=hd.recarray_to_numpy_array(solo)
solo_nd=solo_nd.astype(dtype=[('time', '<f8'), ('bx', '<f8'), ('by', '<f8'), ('bz', '<f8'), ('bt', '<f8'), \
('vt', '<f8'), ('np', '<f8'), ('tp', '<f8'), ('x', '<f8'), ('y', '<f8'), \
('z', '<f8'), ('r', '<f8'), ('lat', '<f8'), ('lon', '<f8')])
pickle.dump([solo_nd,hsolo_att], open(data_path_ML+ "solo_2020_2021_sceq_ndarray.p", "wb" ) )
print('done')
#for Wind 1995 data
data_to_numpy_3=0
if data_to_numpy_3 > 0:
print('Wind')
hwind_att='dtype=[((time [matplotlib format]), (bt [nT], <f8), (bx [nT, HEEQ], <f8), (by [nT, HEEQ], <f8), \
(bz [nT, HEEQ], <f8), (vt [km/s], <f8), (np [ccm -3], <f8), \
(tp [K], <f8), (x [AU, HEEQ], <f8), (y [AU, HEEQ], <f8), (z [AU, HEEQ], <f8), (r [AU], <f8),\
(lat [deg, HEEQ], <f8), (lon [deg, HEEQ],<f8 )]'
win_nd=hd.recarray_to_numpy_array(win)
win_nd=win_nd.astype(dtype=[('time', '<f8'), ('bx', '<f8'), ('by', '<f8'), ('bz', '<f8'), ('bt', '<f8'), \
('vt', '<f8'), ('np', '<f8'), ('tp', '<f8'), ('x', '<f8'), ('y', '<f8'), \
('z', '<f8'), ('r', '<f8'), ('lat', '<f8'), ('lon', '<f8')])
pickle.dump([win_nd,hwind_att], open(data_path_ML+ "wind_1995_2021_heeq_ndarray.p", "wb" ) )
# ## (2) measure new events with notebook measure.ipynb
# ## (3) make ICMECAT
# In[35]:
get_ipython().run_line_magic('matplotlib', 'inline')
print('data loaded')
from heliocats import cats as hc