-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathACE_annual_variations.py
2078 lines (1597 loc) · 80.6 KB
/
ACE_annual_variations.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
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 18 14:58:38 2023
@author: mathe
"""
import pandas as pd
import numpy as np
import os
import astropy.units as u
from astropy.time import Time, TimeDelta
import datetime as datetime
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from mpl_toolkits.axes_grid1 import make_axes_locatable
import h5py
from scipy import interpolate
import helio_time as htime
import ReadICMElist_CaneRichardson as ICMElist
# set the directory of this file as the working directory
cwd = os.path.abspath(os.path.dirname(__file__))
fig_dir = os.path.join(cwd, 'figures')
data_dir = os.path.join(cwd, 'data')
ephem_file = os.path.join(data_dir, 'ephemeris.hdf5')
icme_file = os.path.join(data_dir, 'List of Richardson_Cane ICMEs Since January1996_2022.csv')
#solar min and max definitions
sai_thresh_low = 0.25
sai_thresh_high = 0.67
#plot limits for the solar wind interdependence plots
vmax = 850
vmin = 250
bmin = 0
bmax = 20
nmin = 0
nmax = 20
nbins = 25 # number of bins for histograms
fsize = 14
mpl.rc("axes", labelsize=fsize)
mpl.rc("ytick", labelsize=fsize)
mpl.rc("xtick", labelsize=fsize)
mpl.rc("legend", fontsize=fsize)
# <codecell> data processing
process64secnow = False
if process64secnow:
data_res_hrs = 1
#load the 64-second data in
ace64sec = pd.read_hdf(os.path.join(data_dir, 'ace64sec.h5'))
#average to required res (variable labelled 1hr)
res_str = str(data_res_hrs) + 'H'
ace1hr = ace64sec.copy()
ace1hr.set_index('datetime', inplace=True)
ace1hr = ace1hr.resample(res_str).mean()
#correct for PANDAS insane time stamp butchering
ace1hr.index = ace1hr.index + datetime.timedelta(hours = data_res_hrs/2)
ace1hr = ace1hr.reset_index()
del ace64sec
#save the 1hr data
ace1hr.to_hdf(os.path.join(data_dir, 'ace1hr.h5'), key = 'data', mode = 'w')
else:
ace1hr = pd.read_hdf(os.path.join(data_dir, 'ace1hr.h5'))
#add an AstroPy Time object for fractional year calculation
ace1hr['Time'] = Time(ace1hr['datetime'])
rs = 696340
#add Earth ephemeris
ephem = h5py.File(ephem_file, 'r')
E_time = Time(ephem['EARTH']['HEEQ']['time'], format='jd').mjd
E_r = ephem['EARTH']['HEEQ']['radius'][:]/rs
E_lat = ephem['EARTH']['HEEQ']['latitude'][:]
#interpolate the Earth ephem on the ACE time step
f = interpolate.interp1d( E_time, E_r, fill_value = np.nan, kind = 'nearest')
ace1hr['Earth_r'] = f(ace1hr['mjd'])
ace1hr['pos_r'] = ace1hr['Earth_r'] - ace1hr['pos_gse_x']/rs
f = interpolate.interp1d( E_time, E_lat, fill_value = np.nan, kind = 'nearest')
ace1hr['Earth_lat'] = f(ace1hr['mjd'])
#compute the frac of year
temp = (ace1hr['Time'].to_numpy())
decyr = np.ones((len(ace1hr)))
for n in range(0,len(ace1hr)):
this_decyr = temp[n].decimalyear
decyr[n] = this_decyr - np.floor(this_decyr)
ace1hr['frac_of_yr'] = decyr
#compute the angular variation of ACE about the E-S line
#yz = np.sqrt(ace1hr['pos_gse_y']*ace1hr['pos_gse_y'] +
# ace1hr['pos_gse_z']*ace1hr['pos_gse_z'])
ace1hr['pos_lat'] = ace1hr['Earth_lat'] + \
np.arctan2(ace1hr['pos_gse_z']/rs,ace1hr['pos_r']) * 180/np.pi
def LoadSSN(filepath='null'):
#(dowload from http://www.sidc.be/silso/DATA/SN_m_tot_V2.0.csv)
if filepath == 'null':
filepath= os.environ['DBOX'] + 'Data\\SN_m_tot_V2.0.csv'
col_specification =[(0, 4), (5, 7), (8,16),(17,23),(24,29),(30,35)]
ssn_df=pd.read_fwf(filepath, colspecs=col_specification,header=None)
dfdt=np.empty_like(ssn_df[0],dtype=datetime.datetime)
for i in range(0,len(ssn_df)):
dfdt[i] = datetime.datetime(int(ssn_df[0][i]),int(ssn_df[1][i]),15)
#replace the index with the datetime objects
ssn_df['datetime']=dfdt
ssn_df['ssn']=ssn_df[3]
ssn_df['mjd'] = htime.datetime2mjd(dfdt)
#delete the unwanted columns
ssn_df.drop(0,axis=1,inplace=True)
ssn_df.drop(1,axis=1,inplace=True)
ssn_df.drop(2,axis=1,inplace=True)
ssn_df.drop(3,axis=1,inplace=True)
ssn_df.drop(4,axis=1,inplace=True)
ssn_df.drop(5,axis=1,inplace=True)
#add the 13-month running smooth
window = 13*30
temp = ssn_df.rolling(str(window)+'D', on='datetime').mean()
ssn_df['smooth'] = np.interp(ssn_df['mjd'],temp['mjd'],temp['ssn'],
left =np.nan, right =np.nan)
#add in a solar activity index, which normalises the cycle magnitude
#approx solar cycle length, in months
nwindow = int(11*12)
#find maximum value in a 1-solar cycle bin centred on current time
ssn_df['rollingmax'] = ssn_df.rolling(nwindow, center = True).max()['smooth']
#fill the max value at the end of the series
fillval = ssn_df['rollingmax'].dropna().values[-1]
ssn_df['rollingmax'] = ssn_df['rollingmax'].fillna(fillval)
#create a Solar Activity Index, as SSN normalised to the max smoothed value in
#1-sc window centred on current tim
ssn_df['sai'] = ssn_df['smooth']/ssn_df['rollingmax']
return ssn_df
ssn = LoadSSN()
#interpolate the SSN on the ACE time step
f = interpolate.interp1d( ssn['mjd'], ssn['smooth'], fill_value = np.nan, kind = 'linear')
ace1hr['ssn'] = f(ace1hr['mjd'])
f = interpolate.interp1d( ssn['mjd'], ssn['sai'], fill_value = np.nan, kind = 'linear')
ace1hr['sai'] = f(ace1hr['mjd'])
#remove ICMEs
ace1hr['Vr nocme'] = ace1hr['Vr']
ace1hr['n_p nocme'] = ace1hr['n_p']
ace1hr['Bmag nocme'] = ace1hr['Bmag']
icmes = ICMElist.ICMElist(icme_file)
for i in range(0,len(icmes)):
mask = ((ace1hr['datetime'] >= icmes['Shock_time'][i])
& (ace1hr['datetime'] < icmes['ICME_end'][i]) )
ace1hr.loc[mask,'Vr nocme'] = np.nan
ace1hr.loc[mask,'n_p nocme'] = np.nan
ace1hr.loc[mask,'Bmag nocme'] = np.nan
# <codecell> SPE functions
#bin up the data
def binxdata(xdata, ydata, bins):
#check whether the number of bins or the bin edges have been specified
if isinstance(bins,np.ndarray):
xbinedges=bins
else:
xbinedges = np.arange(xdata.min(), xdata.max()+0.01,
(xdata.max()-xdata.min())/(bins+1))
numbins = len(xbinedges) - 1
xbindata = np.zeros((numbins,4))*np.nan
for n in range(0,numbins):
#time at bin centre
xbindata[n,0] = (xbinedges[n]+xbinedges[n+1])/2
#find the data of interest
mask = (xdata >= xbinedges[n]) & (xdata < xbinedges[n+1])
if np.nansum(mask) > 0:
xbindata[n,1] = np.nanmean(ydata[mask])
xbindata[n,2] = np.nanstd(ydata[mask])
xbindata[n,3] = np.nansum(mask)
return xbindata
def hist2d(xdata, ydata, fighandle=np.nan, axhandle=np.nan,
nxbins = 10, nybins = 15, xmin = np.nan, xmax = np.nan,
ymin = np.nan, ymax = np.nan,
normcounts = True, plotmedian = True, plotcbar = True, logcounts = True):
if np.isnan(xmin):
xmin = xdata.min()
if np.isnan(xmax):
xmax = xdata.max()
if np.isnan(ymin):
ymin = ydata.min()
if np.isnan(ymax):
ymax = ydata.max()
dx = (xmax-xmin)/(nxbins)
dy = (ymax-ymin)/(nybins)
xbinedges = np.arange(xmin, xmax + dx/1000, dx)
ybinedges = np.arange(ymin, ymax + dy/1000, dy)
xcentres=(xbinedges[1:] + xbinedges[0:-1]) / 2
#ycentres=(ybinedges[1:]+ybinedges[0:-1])/2
xybindata = np.zeros((nybins, nxbins))*np.nan
ymedian = np.zeros((nxbins))*np.nan
for x in range(0,nxbins):
#find the data of interest
mask = (xdata >= xbinedges[x]) & (xdata < xbinedges[x+1])
if np.nansum(mask) > 0:
xybindata[:,x], bin_edges = np.histogram(ydata[mask], bins=ybinedges)
ymedian[x] = ydata[mask].median()
if logcounts:
xybindata[:,x] = np.log10(xybindata[:,x])
#normalise
if normcounts:
N = np.sum(xybindata[:,x])
xybindata[:,x] = xybindata[:,x] / N
#x, y = np.meshgrid(xcentres, ycentres)
# if no fig and axis handles are given, create a new figure
if isinstance(fighandle, float):
fig, ax = plt.subplots(figsize=(8, 6))
else:
fig = fighandle
ax = axhandle
pcol = ax.pcolor(xbinedges,ybinedges,xybindata)
if plotmedian:
ax.plot(xcentres,ymedian,'w')
ax.plot(xcentres,ymedian,'k+')
if plotcbar:
#fig.subplots_adjust(bottom=0.5)
clabel = 'Counts'
if logcounts:
clabel = r'$\log_{10}$ (counts)'
fig.colorbar(pcol, ax = ax, orientation='vertical', label=clabel)
return fig, ax, pcol
def contour2d(xdata, ydata, fighandle=np.nan, axhandle=np.nan,
nxbins = 10, nybins = 15, xmin = np.nan, xmax = np.nan,
ymin = np.nan, ymax = np.nan, logcounts = True,
plotcbar = True, plotmedian = True):
if np.isnan(xmin):
xmin = xdata.min()
if np.isnan(xmax):
xmax = xdata.max()
if np.isnan(ymin):
ymin = ydata.min()
if np.isnan(ymax):
ymax = ydata.max()
dx = (xmax-xmin)/(nxbins)
dy = (ymax-ymin)/(nybins)
xbinedges = np.arange(xmin, xmax + dx/1000, dx)
ybinedges = np.arange(ymin, ymax + dy/1000, dy)
xcentres=(xbinedges[1:] + xbinedges[0:-1]) / 2
ycentres=(ybinedges[1:]+ybinedges[0:-1])/2
xybindata = np.zeros((nybins, nxbins))*np.nan
ymedian = np.zeros((nxbins))*np.nan
for x in range(0,nxbins):
#find the data of interest
mask = (xdata >= xbinedges[x]) & (xdata < xbinedges[x+1])
if np.nansum(mask) > 0:
xybindata[:,x], bin_edges = np.histogram(ydata[mask], bins=ybinedges)
ymedian[x] = ydata[mask].median()
if logcounts:
xybindata[:,x] = np.log10(xybindata[:,x])
x, y = np.meshgrid(xcentres, ycentres)
# if no fig and axis handles are given, create a new figure
if isinstance(fighandle, float):
fig, ax = plt.subplots(figsize=(8, 6))
else:
fig = fighandle
ax = axhandle
pcon = ax.contourf(x,y,xybindata)
ax.set_ylim([ymin, ymax])
ax.set_xlim([xmin, xmax])
if plotmedian:
ax.plot(xcentres,ymedian,'w')
ax.plot(xcentres,ymedian,'k+')
if plotcbar:
#fig.subplots_adjust(bottom=0.5)
clabel = 'Counts'
if logcounts:
clabel = r'$\log_{10}$ (counts)'
fig.colorbar(pcon, ax = ax, orientation='vertical', label=clabel)
return fig, ax, pcon
def binned_box_plots(xdata, ydata, fighandle=np.nan, axhandle=np.nan,
nxbins = 10, xmin = np.nan, xmax = np.nan):
if np.isnan(xmin):
xmin = xdata.min()
if np.isnan(xmax):
xmax = xdata.max()
dx = (xmax-xmin)/(nxbins)
xbinedges = np.arange(xmin, xmax + dx/1000, dx)
xcentres=(xbinedges[1:] + xbinedges[0:-1]) / 2
# if no fig and axis handles are given, create a new figure
if isinstance(fighandle, float):
fig, ax = plt.subplots(figsize=(8, 6))
else:
fig = fighandle
ax = axhandle
xybindata = []
for x in range(0,nxbins):
#find the data of interest
mask = (xdata >= xbinedges[x]) & (xdata < xbinedges[x+1])
#if np.nansum(mask) > 0:
xybindata.append(ydata[mask].dropna())
boxes = ax.boxplot(xybindata, positions = xcentres, widths = dx/2,
notch=True, patch_artist=True,showfliers=False,whis=1.5)
#ax.tick_params(reset=True)
#set up the x-axis labels
ax.set_xlim(xmin - 3*dx/4, xmax + 3*dx/4)
ax.xaxis.set_major_locator(ticker.MaxNLocator(nbins=5))
xtickvals = ax.get_xticks()
xlabs = []
for x in xtickvals:
xlabs.append(str(x))
ax.set_xticklabels(xlabs)
return fig, ax, boxes
def binned_median_plot(xdata, ydata, fighandle=np.nan, axhandle=np.nan,
nxbins = 10, xmin = np.nan, xmax = np.nan, fmt=''):
if np.isnan(xmin):
xmin = xdata.min()
if np.isnan(xmax):
xmax = xdata.max()
dx = (xmax-xmin)/(nxbins)
xbinedges = np.arange(xmin, xmax + dx/1000, dx)
xcentres=(xbinedges[1:] + xbinedges[0:-1]) / 2
ymedian_upper = np.zeros((nxbins))*np.nan
ymedian_lower = np.zeros((nxbins))*np.nan
ymedian = np.zeros((nxbins))*np.nan
tempfig, tempax = plt.subplots(figsize=(8, 6))
for x in range(0,nxbins):
#find the data of interest
mask = (xdata >= xbinedges[x]) & (xdata < xbinedges[x+1])
#use matplotlib boxplot to get medians and confidence interval
box = tempax.boxplot(ydata[mask].dropna(), notch=True, showfliers=False, showcaps = False)
box_y = plt.getp(box['boxes'][0], 'ydata')
ymedian_upper[x] = box_y[4]
ymedian_lower[x] = box_y[2]
ymedian[x] = box_y[3]
#ymedian[x] = np.nanmean(ydata[mask])
plt.close(tempfig)
# if no fig and axis handles are given, create a new figure
if isinstance(fighandle, float):
fig, ax = plt.subplots(figsize=(8, 6))
else:
fig = fighandle
ax = axhandle
markers, caps, bars = ax.errorbar(xcentres, ymedian,
yerr = [ymedian - ymedian_lower, ymedian_upper-ymedian],
capsize = 2, fmt=fmt, alpha = 0.5)
# loop through bars and caps and set the alpha value
[bar.set_alpha(1) for bar in bars]
[cap.set_alpha(1) for cap in caps]
#[marker.set_alpha(1) for marker in markers]
ax.set_xlim(xmin - 3*dx/4, xmax + 3*dx/4)
return fig, ax
# <codecell> Map everything to 1 AU
@u.quantity_input(v_outer=u.km / u.s)
@u.quantity_input(r_outer=u.solRad)
@u.quantity_input(lon_outer=u.rad)
@u.quantity_input(r_inner=u.solRad)
def map_v_inwards(v_orig, r_orig, lon_orig, r_new):
"""
Function to map v from r_orig (in rs) to r_inner (in rs) accounting for
residual acceleration, but neglecting stream interactions.
Args:
v_orig: Solar wind speed at original radial distance. Units of km/s.
r_orig: Radial distance at original radial distance. Units of km.
lon_orig: Carrington longitude at original distance. Units of rad
r_new: Radial distance at new radial distance. Units of km.
Returns:
v_new: Solar wind speed mapped from r_orig to r_new. Units of km/s.
lon_new: Carrington longitude at r_new. Units of rad.
"""
# Get the acceleration parameters
alpha = 0.15 # Scale parameter for residual SW acceleration
rH = (50*u.solRad).to(u.kilometer).value # Spatial scale parameter for residual SW acceleration
r_orig = r_orig.to(u.km).value
r_new = r_new.to(u.km).value
r_0 = (30*u.solRad).to(u.km).value
# Compute the 30 rS speed
v0 = v_orig.value / (1 + alpha * (1 - np.exp(-(r_orig - r_0) / rH)))
#comppute new speed
vnew = v0 * (1 + alpha * (1 - np.exp(-(r_new - r_0) / rH)))
# Work out the longitudinal shift
phi_new = 0
return vnew * u.km / u.s, phi_new * u.rad
rref = 215
# scale density by r^2
ace1hr['n_p scaled'] = ace1hr['n_p']*ace1hr['pos_r']*ace1hr['pos_r']/rref/rref
#scale speed using the acceleration equation
vorig = ace1hr['Vr'].to_numpy() * u.km/u.s
rorig = ace1hr['pos_r'].to_numpy() * u.solRad
lon = ace1hr['Earth_lat'].to_numpy() *0 *u.deg
rnew = (ace1hr['pos_r'].to_numpy() *0 +rref)*u.solRad
Bmag = ace1hr['Bmag'].to_numpy()
v_215, phi = map_v_inwards(vorig, rorig, lon, rnew)
ace1hr['Vr scaled'] = v_215.value
#scale B by ideal Parker spiral value
sidereal_period = 25.38 * 24*60*60 # Solar sidereal rotation period
#compute the Parker spiral angle
phi_parker_r = np.arctan(2*np.pi * rorig.to(u.km).value
/ (sidereal_period*vorig.value))
#compute Br from Bmag and the spiral angle
Br_parker_r = Bmag * np.cos(phi_parker_r)
#scale to reference distance
Br_parker_215 = Br_parker_r* rorig*rorig/rref/rref
#compute the Parker spiral at teh reference distance
phi_parker_215 = np.arctan(2*np.pi * rnew.to(u.km).value
/ (sidereal_period*v_215.value))
#computer Bmag at the reference distance
ace1hr['Bmag scaled'] = Br_parker_215 / np.cos(phi_parker_215 )
#compute ram pressure
ace1hr['rho'] = ace1hr['n_p']*100*100*100*1.67262192e-27 # kg/m^3
ace1hr['Pdyn'] = ace1hr['rho'] * ace1hr['Vr'] *1000 * ace1hr['Vr'] *1000
ace1hr['Pdyn'] = ace1hr['Pdyn'] /1e-9 #nPa
ace1hr['rho nocme'] = ace1hr['n_p nocme']*100*100*100*1.67262192e-27 # kg/m^3
ace1hr['Pdyn nocme'] = ace1hr['rho nocme'] * ace1hr['Vr nocme'] *1000 * ace1hr['Vr nocme'] *1000
ace1hr['Pdyn nocme'] = ace1hr['Pdyn nocme'] /1e-9 #nPa
ace1hr['P_B'] = ace1hr['Bmag'] *ace1hr['Bmag']*1e-9 * 1e-9/(2*1.26e-6)
ace1hr['P_B'] = ace1hr['P_B'] /1e-9 #nPa
#include alphas
ace1hr['Pdyn_alpha'] = ace1hr['Pdyn'] + 4* ace1hr['ratio_a2p'] * ace1hr['Pdyn']
#compute scaled ram pressure
ace1hr['rho scaled'] = ace1hr['n_p scaled']*100*100*100*1.67262192e-27 # kg/m^3
ace1hr['Pdyn scaled'] = ace1hr['rho scaled'] * ace1hr['Vr scaled'] *1000 * ace1hr['Vr scaled'] *1000
ace1hr['Pdyn scaled'] = ace1hr['Pdyn scaled'] /1e-9 #nPa
#compute coupling function
a = 0.3
ace1hr['Pinput'] = ( pow(ace1hr['Bmag']*1e-9, 2*a)
* pow(ace1hr['rho'], (2/3 - a))
* pow(ace1hr['Vr']*1000, 7/3 - 2*a)
)
ace1hr['Pinput scaled'] = ( pow(ace1hr['Bmag scaled']*1e-9, 2*a)
* pow(ace1hr['rho scaled'], (2/3 - a))
* pow(ace1hr['Vr scaled']*1000, 7/3 - 2*a)
)
ace1hr['Pinput nocme'] = ( pow(ace1hr['Bmag nocme']*1e-9, 2*a)
* pow(ace1hr['rho nocme'], (2/3 - a))
* pow(ace1hr['Vr nocme']*1000, 7/3 - 2*a)
)
# <codecell> Orbital and SSN time series plots
# plt.figure()
# plt.plot(ace1hr['datetime'],ace1hr['pos_gse_x'],label='GSE X')
# plt.plot(ace1hr['datetime'],ace1hr['pos_gse_y'],label='GSE Y')
# plt.plot(ace1hr['datetime'],ace1hr['pos_gse_z'],label='GSE Z')
# plt.legend()
fig, axs = plt.subplots(nrows = 4, ncols = 1, figsize=(7, 10))
axs[0].plot(ace1hr['datetime'], ace1hr['pos_lat'],'r', label='ACE')
axs[0].plot(ace1hr['datetime'], ace1hr['Earth_lat'] , 'k', label='EARTH')
axs[0].set_ylabel(r'$\theta$, helio latitude [deg]')
axs[0].text(0.03,0.07,'(a)', fontsize = 14, transform=axs[0].transAxes, backgroundcolor = 'w')
#axs[0].set_ylim(bottom=0)
axs[0].legend()
xx = axs[0].get_xlim()
axs[0].plot(xx, [0,0], 'k')
axs[0].set_xlim(xx)
axs[1].plot(ace1hr['datetime'], ace1hr['pos_r'], 'r', label='ACE')
axs[1].plot(ace1hr['datetime'], ace1hr['Earth_r'] , 'k', label='EARTH')
axs[1].set_ylabel(r'$R$, radial distance [$r_\odot$]')
#axs[1].set_ylim(bottom=0)
axs[1].legend()
axs[1].text(0.03,0.07,'(b)', fontsize = 14, transform=axs[1].transAxes, backgroundcolor = 'w')
axs[1].set_xlim(xx)
#plot the fractional variation of r with time
axs[2].plot(ace1hr['datetime'], (ace1hr['Earth_r']-ace1hr['pos_r'])/ace1hr['Earth_r'], 'k')
axs[2].set_ylabel(r'$R _{AE} / R_{ES}$')
axs[2].set_ylim(bottom=0)
axs[2].text(0.03,0.07,'(c)', fontsize = 14, transform=axs[2].transAxes, backgroundcolor = 'w')
axs[2].set_xlim(xx)
#axs[0].set_ylim(bottom=0)
axs[3].plot(ace1hr['datetime'], ace1hr['ssn']/200, 'k', label = 'SSN/200')
axs[3].plot(ace1hr['datetime'], ace1hr['sai'], 'r', label = 'SAI')
axs[3].legend(fontsize = 14, loc = 'upper right')
axs[3].plot([ace1hr['datetime'][0], ace1hr['datetime'][len(ace1hr)-1]],
[sai_thresh_low, sai_thresh_low], 'r--')
axs[3].plot([ace1hr['datetime'][0], ace1hr['datetime'][len(ace1hr)-1]],
[sai_thresh_high, sai_thresh_high], 'r--')
axs[3].text(0.03,0.07,'(d)', fontsize = 14, transform=axs[3].transAxes, backgroundcolor = 'w')
axs[3].set_ylabel(r'Solar activity')
axs[3].set_xlabel('Year')
axs[3].set_xlim(xx)
#save the figure
fig.set_tight_layout(True)
fig.savefig( os.path.join(fig_dir, 'orbit_timeseries.pdf'))
# <codecell> Orbital param SPE
N_bins_orbit = 100
datachunk = ace1hr
xdata = ace1hr['frac_of_yr']
ydata = ace1hr['Earth_r']
rE_binned = binxdata(xdata, ydata, N_bins_orbit)
xdata = ace1hr['frac_of_yr']
ydata = ace1hr['pos_r']
rACE_binned = binxdata(xdata, ydata, N_bins_orbit)
xdata = ace1hr['frac_of_yr']
ydata = ace1hr['Earth_lat']
latE_binned = binxdata(xdata, ydata, N_bins_orbit)
xdata = ace1hr['frac_of_yr']
ydata = ace1hr['pos_lat']
latACE_binned = binxdata(xdata, ydata, N_bins_orbit)
xdata = ace1hr['frac_of_yr']
ydata = np.abs(ace1hr['Earth_lat'])
latE_abs_binned = binxdata(xdata, ydata, N_bins_orbit)
xdata = ace1hr['frac_of_yr']
ydata = np.abs(ace1hr['pos_lat'])
latACE_abs_binned = binxdata(xdata, ydata, N_bins_orbit)
fig, axs = plt.subplots(nrows = 3, ncols = 1, figsize=(6, 8.5))
axs[0].set_xticks([0, 0.25, 0.5, 0.75, 1])
axs[0].xaxis.set_minor_locator(ticker.AutoMinorLocator())
axs[0].errorbar(rE_binned[:,0], rE_binned[:,1], fmt='k', capsize = 2, yerr = rE_binned[:,2],
label = 'EARTH')
axs[0].errorbar(rACE_binned[:,0], rACE_binned[:,1], fmt='r', capsize = 2, yerr = rACE_binned[:,2],
label = 'ACE')
axs[0].set_ylabel(r'$R$, radial distance [$r_\odot$]')
axs[0].text(0.03,0.05,'(a)', fontsize = 14, transform=axs[0].transAxes, backgroundcolor = 'w')
axs[0].legend()
xx = axs[0].get_xlim();
axs[0].set_xlim(xx)
yy = axs[0].get_ylim(); axs[0].plot([0.5, 0.5] ,yy ,'k')
axs[1].set_xticks([0, 0.25, 0.5, 0.75, 1])
axs[1].xaxis.set_minor_locator(ticker.AutoMinorLocator())
axs[1].errorbar(latE_binned[:,0], latE_binned[:,1], fmt='k',capsize = 2, yerr = latE_binned[:,2],
label = 'EARTH')
axs[1].errorbar(latACE_binned[:,0], latACE_binned[:,1], fmt='r', capsize = 2, yerr = latACE_binned[:,2],
label = 'ACE')
axs[1].set_ylabel(r'$\theta$, helio latitude [deg]')
axs[1].text(0.03,0.05,'(b)', fontsize = 14, transform=axs[1].transAxes, backgroundcolor = 'w')
axs[1].legend()
axs[1].plot(xx, [0,0], 'k')
axs[1].set_xlim(xx)
yy = axs[1].get_ylim(); axs[1].plot([0.5, 0.5] ,yy ,'k')
axs[2].set_xticks([0, 0.25, 0.5, 0.75, 1])
axs[2].xaxis.set_minor_locator(ticker.AutoMinorLocator())
axs[2].errorbar(latE_abs_binned[:,0], latE_abs_binned[:,1], fmt='k', capsize = 2, yerr = latE_abs_binned[:,2],
label = 'EARTH')
axs[2].errorbar(latACE_abs_binned[:,0], latACE_abs_binned[:,1], fmt='r', capsize = 2, yerr = latACE_abs_binned[:,2],
label = 'ACE')
axs[2].set_ylabel(r'$|\theta|$, absolute' '\n' 'helio latitude [deg]')
axs[2].text(0.03,0.05,'(c)', fontsize = 14, transform=axs[2].transAxes, backgroundcolor = 'w')
axs[2].legend(loc = 'upper right')
axs[2].set_xlabel('Fraction of year, $F$')
axs[2].set_xlim(xx)
yy = axs[2].get_ylim(); axs[2].plot([0.5, 0.5] ,yy ,'k')
#save the figure
fig.set_tight_layout(True)
fig.savefig( os.path.join(fig_dir,'orbit_SPE.pdf'))
# <codecell> r and lat interdependence
#cut out the datachunk of interest
mask = (ace1hr['ssn'] <= 30000)
datachunk = ace1hr.loc[mask]
fig, axs = plt.subplots(nrows = 2, ncols = 1, figsize=(6, 8))
dx = 0.5
xdata = np.abs(datachunk['Earth_r'])
ydata = (datachunk['Earth_lat'])
hist2d(xdata, ydata, nxbins = 25, nybins = 25, fighandle = fig, axhandle = axs[0],
xmin = xdata.min() - dx, xmax = xdata.max() + dx,
plotmedian = False, logcounts = True, normcounts = False, plotcbar = True)
axs[0].set_ylabel(r'$\theta$, helio latitude [deg]')
axs[0].text(0.02,0.93,'(a)', fontsize = 14, transform=axs[0].transAxes, backgroundcolor = 'w')
xdata = np.abs(datachunk['Earth_r'])
ydata = np.abs(datachunk['Earth_lat'])
fig, ax, pcol = hist2d(xdata, ydata, nxbins = 25, nybins = 25, fighandle = fig, axhandle = axs[1],
xmin = xdata.min() - dx, xmax = xdata.max() + dx,
ymin = 0, plotmedian = False, logcounts = True, normcounts = False, plotcbar = True)
axs[1].set_ylabel(r'$|\theta|$, absolute helio latitude [deg]')
axs[1].set_xlabel(r'$R$, radial distance [$r_\odot$]')
axs[1].text(0.02,0.93,'(b)', fontsize = 14, transform=axs[1].transAxes, backgroundcolor = 'w')
#cbar = fig.colorbar(pcol, ax=axs, shrink=0.6)
#cbar.set_label('log(counts)')
fig.set_tight_layout(True)
fig.savefig( os.path.join(fig_dir, 'orbit_r_lat_interdependence.pdf'))
# <codecell> Solar wind param interdependence
mask = (ace1hr['sai'] >= 0)
datachunk = ace1hr.loc[mask]
# fig, axs = plt.subplots(nrows = 3, ncols = 1, figsize=(6, 10))
# xdata = np.abs(datachunk['Vr'])
# ydata = np.abs(datachunk['n_p'])
# contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[0],
# xmin = vmin, xmax = vmax, ymin = nmin, ymax = nmax)
# axs[0].set_xlabel(r'$V_{SW}$ [km s$^{-1}$]')
# axs[0].set_ylabel(r'$n_{P}$ [cm$^{-3}$]')
# axs[0].text(0.02,0.9,'(a)', fontsize = 14, transform=axs[0].transAxes, backgroundcolor = 'w')
# xdata = np.abs(datachunk['Vr'])
# ydata = np.abs(datachunk['Bmag'])
# contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[1],
# xmin = vmin, xmax = vmax, ymin = bmin, ymax = bmax)
# axs[1].set_xlabel(r'$V_{SW}$ [km s$^{-1}$]')
# axs[1].set_ylabel(r'$|$B$|$ [nT]')
# axs[1].text(0.02,0.9,'(b)', fontsize = 14, transform=axs[1].transAxes, backgroundcolor = 'w')
# xdata = np.abs(datachunk['n_p'])
# ydata = np.abs(datachunk['Bmag'])
# contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[2],
# xmin = nmin, xmax = nmax, ymin = bmin, ymax = bmax)
# axs[2].set_xlabel(r'$n_{P}$ [cm$^{-3}$]')
# axs[2].set_ylabel(r'$|$B$|$ [nT]')
# axs[2].text(0.02,0.9,'(c)', fontsize = 14, transform=axs[2].transAxes, backgroundcolor = 'w')
# fig.set_tight_layout(True)
# fig.savefig(fig_dir + 'solarwindparam_interdependence.pdf')
# fig, axs = plt.subplots(nrows = 3, ncols = 1, figsize=(6, 10))
# xdata = np.abs(datachunk['Vr'])
# ydata = np.abs(datachunk['n_p'])
# binned_box_plots(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[0],
# xmin = vmin, xmax = vmax, )
# axs[0].set_xlabel(r'$V_{SW}$ [km s$^{-1}$]')
# axs[0].set_ylabel(r'$n_{P}$ [cm$^{-3}$]')
# axs[0].text(0.02,0.9,'(a)', fontsize = 14, transform=axs[0].transAxes, backgroundcolor = 'w')
# xdata = np.abs(datachunk['Vr'])
# ydata = np.abs(datachunk['Bmag'])
# binned_box_plots(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[1],
# xmin = vmin, xmax = vmax, )
# axs[1].set_xlabel(r'$V_{SW}$ [km s$^{-1}$]')
# axs[1].set_ylabel(r'$|$B$|$ [nT]')
# axs[1].text(0.02,0.9,'(b)', fontsize = 14, transform=axs[1].transAxes, backgroundcolor = 'w')
# xdata = np.abs(datachunk['n_p'])
# ydata = np.abs(datachunk['Bmag'])
# binned_box_plots(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[2],
# xmin = nmin, xmax = nmax, )
# axs[2].set_xlabel(r'$n_{P}$ [cm$^{-3}$]')
# axs[2].set_ylabel(r'$|$B$|$ [nT]')
# axs[2].text(0.02,0.9,'(c)', fontsize = 14, transform=axs[2].transAxes, backgroundcolor = 'w')
# fig.set_tight_layout(True)
# fig.savefig(fig_dir + 'solarwindparam_interdependence_boxplots.pdf')
fig, axs = plt.subplots(nrows = 3, ncols = 1, figsize=(6, 10))
xdata = np.abs(datachunk['Vr'])
ydata = np.abs(datachunk['n_p'])
binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[0],
xmin = vmin, xmax = vmax, fmt='k' )
xdata = np.abs(datachunk['Vr scaled'])
ydata = np.abs(datachunk['n_p scaled'])
binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[0],
xmin = vmin, xmax = vmax, fmt='r' )
xdata = np.abs(datachunk['Vr nocme'])
ydata = np.abs(datachunk['n_p nocme'])
binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[0],
xmin = vmin, xmax = vmax, fmt='b' )
axs[0].set_xlabel(r'$V_{R}$ [km s$^{-1}$]')
axs[0].set_ylabel(r'$n_{P}$ [cm$^{-3}$]')
axs[0].text(0.02,0.9,'(a)', fontsize = 14, transform=axs[0].transAxes, backgroundcolor = 'w')
axs[0].legend([r'Observed', r'$R$-scaled', 'No ICMEs'], loc = 'upper right')
xdata = np.abs(datachunk['Vr'])
ydata = np.abs(datachunk['Bmag'])
binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[1],
xmin = vmin, xmax = vmax , fmt='k')
xdata = np.abs(datachunk['Vr scaled'])
ydata = np.abs(datachunk['Bmag scaled'])
binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[1],
xmin = vmin, xmax = vmax , fmt='r')
xdata = np.abs(datachunk['Vr nocme'])
ydata = np.abs(datachunk['Bmag nocme'])
binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[1],
xmin = vmin, xmax = vmax , fmt='b')
axs[1].set_xlabel(r'$V_{R}$ [km s$^{-1}$]')
axs[1].set_ylabel(r'$|$B$|$ [nT]')
axs[1].text(0.02,0.9,'(b)', fontsize = 14, transform=axs[1].transAxes, backgroundcolor = 'w')
xdata = np.abs(datachunk['n_p'])
ydata = np.abs(datachunk['Bmag'])
binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[2],
xmin = nmin, xmax = nmax , fmt='k')
xdata = np.abs(datachunk['n_p scaled'])
ydata = np.abs(datachunk['Bmag scaled'])
binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[2],
xmin = nmin, xmax = nmax , fmt='r')
xdata = np.abs(datachunk['n_p nocme'])
ydata = np.abs(datachunk['Bmag nocme'])
binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[2],
xmin = nmin, xmax = nmax , fmt='b')
axs[2].set_xlabel(r'$n_{P}$ [cm$^{-3}$]')
axs[2].set_ylabel(r'$|$B$|$ [nT]')
axs[2].text(0.02,0.9,'(c)', fontsize = 14, transform=axs[2].transAxes, backgroundcolor = 'w')
fig.set_tight_layout(True)
fig.savefig( os.path.join(fig_dir, 'solarwindparam_interdependence_medians.pdf'))
# #flip x and y params
# fig, axs = plt.subplots(nrows = 3, ncols = 1, figsize=(6, 10))
# ydata = np.abs(datachunk['Vr'])
# xdata = np.abs(datachunk['n_p'])
# binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[0],
# xmin = nmin, xmax = nmax, fmt='k' )
# ydata = np.abs(datachunk['Vr scaled'])
# xdata = np.abs(datachunk['n_p scaled'])
# binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[0],
# xmin = nmin, xmax = nmax, fmt='r' )
# ydata = np.abs(datachunk['Vr nocme'])
# xdata = np.abs(datachunk['n_p nocme'])
# binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[0],
# xmin = nmin, xmax = nmax, fmt='b' )
# axs[0].set_ylabel(r'$V_{R}$ [km s$^{-1}$]')
# axs[0].set_xlabel(r'$n_{P}$ [cm$^{-3}$]')
# axs[0].text(0.02,0.9,'(a)', fontsize = 14, transform=axs[0].transAxes, backgroundcolor = 'w')
# axs[0].legend([r'Observed', r'$R$-scaled', 'No ICMEs'], loc = 'upper right')
# ydata = np.abs(datachunk['Vr'])
# xdata = np.abs(datachunk['Bmag'])
# binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[1],
# xmin = bmin, xmax = bmax , fmt='k')
# ydata = np.abs(datachunk['Vr scaled'])
# xdata = np.abs(datachunk['Bmag scaled'])
# binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[1],
# xmin = bmin, xmax = bmax , fmt='r')
# ydata = np.abs(datachunk['Vr nocme'])
# xdata = np.abs(datachunk['Bmag nocme'])
# binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[1],
# xmin = bmin, xmax = bmax , fmt='b')
# axs[1].set_ylabel(r'$V_{R}$ [km s$^{-1}$]')
# axs[1].set_xlabel(r'$|$B$|$ [nT]')
# axs[1].text(0.02,0.9,'(b)', fontsize = 14, transform=axs[1].transAxes, backgroundcolor = 'w')
# ydata = np.abs(datachunk['n_p'])
# xdata = np.abs(datachunk['Bmag'])
# binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[2],
# xmin = bmin, xmax = bmax , fmt='k')
# ydata = np.abs(datachunk['n_p scaled'])
# xdata = np.abs(datachunk['Bmag scaled'])
# binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[2],
# xmin = bmin, xmax = bmax , fmt='r')
# ydata = np.abs(datachunk['n_p nocme'])
# xdata = np.abs(datachunk['Bmag nocme'])
# binned_median_plot(xdata, ydata, nxbins = nbins, fighandle = fig, axhandle = axs[2],
# xmin = bmin, xmax = bmax , fmt='b')
# axs[2].set_ylabel(r'$n_{P}$ [cm$^{-3}$]')
# axs[2].set_xlabel(r'$|$B$|$ [nT]')
# axs[2].text(0.02,0.9,'(c)', fontsize = 14, transform=axs[2].transAxes, backgroundcolor = 'w')
# fig.set_tight_layout(True)
# fig.savefig(fig_dir + 'solarwindparam_interdependence_medians_inv.pdf')
# <codecell> solar wind variations with r and lat
def plotparam(datachunk, param, ymin, ymax, ylab, nbins, ssn_thresh):
fig, axs = plt.subplots(nrows = 3, ncols = 3, figsize=(10, 10))
mask = (ace1hr['ssn'] <= 30000)
datachunk = ace1hr.loc[mask]
xdata = np.abs(datachunk['pos_r'])
ydata = np.abs(datachunk[param])
contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[0,0],
ymin = ymin, ymax = ymax, plotcbar = False)
axs[0,0].set_title('All data')
axs[0,0].set_ylabel(ylab)
axs[0,0].set_xlabel(r'R [$r_\odot$]')
axs[0,0].text(0.03,0.9,'(a)', fontsize = 14, transform=axs[0,0].transAxes, backgroundcolor = 'w')
xdata = (datachunk['pos_lat'])
ydata = np.abs(datachunk[param])
contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[1,0],
ymin = ymin, ymax = ymax, plotcbar = False)
axs[1,0].set_ylabel(ylab)
axs[1,0].set_xlabel(r'$\theta$ [deg]')
axs[1,0].text(0.03,0.9,'(d)', fontsize = 14, transform=axs[1,0].transAxes, backgroundcolor = 'w')
xdata = np.abs(datachunk['pos_lat'])
ydata = np.abs(datachunk[param])
contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[2,0],
xmin = 0, ymin = ymin, ymax = ymax, plotcbar = False)
axs[2,0].set_ylabel(ylab)
axs[2,0].set_xlabel(r'$|\theta|$ [deg]')
axs[2,0].text(0.03,0.9,'(g)', fontsize = 14, transform=axs[2,0].transAxes, backgroundcolor = 'w')
mask = (ace1hr['ssn'] <= ssn_thresh)
datachunk = ace1hr.loc[mask]
xdata = np.abs(datachunk['pos_r'])
ydata = np.abs(datachunk[param])
contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[0,1],
ymin = ymin, ymax = ymax, plotcbar = False)
axs[0,1].set_title('SSN <= ' +str(ssn_thresh))
axs[0,1].set_xlabel(r'R [$r_\odot$]')
axs[0,1].text(0.03,0.9,'(b)', fontsize = 14, transform=axs[0,1].transAxes, backgroundcolor = 'w')
xdata = (datachunk['pos_lat'])
ydata = np.abs(datachunk[param])
contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[1,1],
ymin = ymin, ymax = ymax, plotcbar = False)
axs[1,1].set_xlabel(r'$\theta$ [deg]')
axs[1,1].text(0.03,0.9,'(d)', fontsize = 14, transform=axs[1,1].transAxes, backgroundcolor = 'w')
xdata = np.abs(datachunk['pos_lat'])
ydata = np.abs(datachunk[param])
contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[2,1],
xmin = 0, ymin = ymin, ymax = ymax, plotcbar = False)
axs[2,1].set_xlabel(r'$|\theta|$ [deg]')
axs[2,1].text(0.03,0.9,'(h)', fontsize = 14, transform=axs[2,1].transAxes, backgroundcolor = 'w')
mask = (ace1hr['ssn'] > ssn_thresh)
datachunk = ace1hr.loc[mask]
xdata = np.abs(datachunk['pos_r'])
ydata = np.abs(datachunk[param])
contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[0,2],
ymin = ymin, ymax = ymax, plotcbar = False)
axs[0,2].set_title('SSN > ' +str(ssn_thresh))
axs[0,2].set_xlabel(r'R [$r_\odot$]')
axs[0,2].text(0.03,0.9,'(c)', fontsize = 14, transform=axs[0,2].transAxes, backgroundcolor = 'w')
xdata = (datachunk['pos_lat'])
ydata = np.abs(datachunk[param])
contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[1,2],
ymin = ymin, ymax = ymax, plotcbar = False)
axs[1,2].set_xlabel(r'$\theta$ [deg]')
axs[1,2].text(0.03,0.9,'(f)', fontsize = 14, transform=axs[1,2].transAxes, backgroundcolor = 'w')
xdata = np.abs(datachunk['pos_lat'])
ydata = np.abs(datachunk[param])
fig, ax,cmap = contour2d(xdata, ydata, nxbins = nbins, nybins = nbins, fighandle = fig, axhandle = axs[2,2],
xmin = 0, ymin = ymin, ymax = ymax, plotcbar = False)
axs[2,2].set_xlabel(r'$|\theta|$ [deg]')