# Time Parameters t0 = dt.datetime(2016, 5, 30, 0) t1 = dt.datetime(2016, 6, 30, 0) #t1 = t0 + dt.timedelta(hours=23.99) # EDI Data edi_data = edi.load_data('mms1', 'srvy', optdesc='efield', start_date=t0, end_date=t1) edi_data = edi_data.rename({'Epoch': 'time'}) # FGM Data fgm_data = fgm.load_data('mms1', 'fgm', 'srvy', 'l2', t0, t1) # MEC Data sdc = api.MrMMS_SDC_API(sc, 'edp', 'fast', level, optdesc='dce', start_date=t0, end_date=t1) r_gse_vname = '_'.join((sc, 'mec', 'r', 'gse')) r_lbl_vname = '_'.join((sc, 'mec', 'r', 'gse', 'label')) v_gse_vname = '_'.join((sc, 'mec', 'v', 'gse')) v_lbl_vname = '_'.join((sc, 'mec', 'v', 'gse', 'label'))
def kinetic_entropy(sc, mode, start_date, end_date): # Read the data b = fgm.load_data(sc, mode, start_date, end_date) dis_moms = fpi.load_moms(sc, mode, 'i', start_date, end_date) des_moms = fpi.load_moms(sc, mode, 'e', start_date, end_date) dis_dist = fpi.load_dist(sc, mode, 'i', start_date, end_date) des_dist = fpi.load_dist(sc, mode, 'e', start_date, end_date) # Philosopy # - For the Maxwellian distributions, use the FPI moments data # whenever possible # - For the integrated moments, do not mix them with FPI moments # Equivalent Maxwellian distribution dis_max_dist = fpi.maxwellian_distribution(dis_dist, N=dis_moms['density'], bulkv=dis_moms['velocity'], T=dis_moms['t']) des_max_dist = fpi.maxwellian_distribution(des_dist, N=des_moms['density'], bulkv=des_moms['velocity'], T=des_moms['t']) # Spacecraft potential correction edp_mode = mode if mode == 'brst' else 'fast' scpot = edp.load_scpot(sc, edp_mode, start_date, end_date) scpot_dis = scpot.interp_like(dis_moms, method='nearest') scpot_des = scpot.interp_like(des_moms, method='nearest') # Maxwellian entropy density # - Calculated from FPI moments to stick with philosophy # si_dist = fpi.entropy(dis_dist, scpot=scpot_dis) # se_dist = fpi.entropy(des_dist, scpot=scpot_des) si_max = fpi.maxwellian_entropy(dis_moms['density'], dis_moms['p']) se_max = fpi.maxwellian_entropy(des_moms['density'], des_moms['p']) # Velocity space entropy density siv_dist = fpi.vspace_entropy(dis_dist, # N=dis_moms['density'], # s=si_dist, scpot=scpot_dis) sev_dist = fpi.vspace_entropy(des_dist, # N=des_moms['density'], # s=se_dist, scpot=scpot_des) siv_max = fpi.vspace_entropy(dis_max_dist, N=dis_moms['density'], s=si_max, scpot=scpot_dis) sev_max = fpi.vspace_entropy(des_max_dist, N=des_moms['density'], s=se_max, scpot=scpot_des) # M-bar miv_bar = np.abs(siv_max - siv_dist) / siv_max mev_bar = np.abs(sev_max - sev_dist) / sev_max # Anisotropy Ai = dis_moms['temppara'] / dis_moms['tempperp'] - 1 Ae = des_moms['temppara'] / des_moms['tempperp'] - 1 nrows = 8 ncols = 1 figsize = (5.5, 7.0) fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=figsize, squeeze=False) # B ax = axes[0,0] ax = util.plot([b['B'][:,3], b['B'][:,0], b['B'][:,1], b['B'][:,2]], ax=ax, labels=['|B|', 'Bx', 'By', 'Bz'], xaxis='off', ylabel='B\n(nT)' ) # N ax = axes[1,0] ax = util.plot([dis_moms['density'], des_moms['density']], ax=ax, labels=['Ni', 'Ne'], xaxis='off', ylabel='N\n($cm^{-3}$)' ) # Velocity space ion entropy density ax = axes[2,0] ax = util.plot([siv_max, siv_dist], ax=ax, labels=['$s_{i,V,max}$', '$s_{i,V}$'], xaxis='off', ylabel='$s_{V}$\n$J/K/m^{3}$ $ln()$' ) # Velocity space electron entropy density ax = axes[3,0] ax = util.plot([sev_max, sev_dist], ax=ax, labels=['$s_{e,V,max}$', '$s_{e,V}$'], xaxis='off', ylabel='$s_{V}$' ) # Velocity space M-bar ax = axes[4,0] ax = util.plot([miv_bar, mev_bar], ax=ax, labels=['$\overline{M}_{i,V}$', '$\overline{M}_{e,V}$'], xaxis='off', ylabel='$\overline{M}_{V}$' ) # Ion temperature ax = axes[5,0] ax = util.plot([dis_moms['temppara'], dis_moms['tempperp'], dis_moms['t']], ax=ax, labels=['$T_{\parallel}$', '$T_{\perp}$, $T$'], xaxis='off', ylabel='$T_{i}$\n(eV)' ) # Electron temperature ax = axes[6,0] ax = util.plot([des_moms['temppara'], des_moms['tempperp'], des_moms['t']], ax=ax, labels=['$T_{\parallel}$', '$T_{\perp}$, $T$'], xaxis='off', ylabel='$T_{e}$\n(eV)' ) # Anisotropy ax = axes[7,0] ax = util.plot([Ai, Ae], ax=ax, labels=['$A_{i}$', '$A_{e}$'], ylabel='A' ) fig.suptitle('Plasma Parameters for Kinetic and Boltzmann Entropy') plt.subplots_adjust(left=0.2, right=0.85, top=0.95, hspace=0.4) # plt.setp(axes, xlim=xlim) return fig, axes
def vspace_entropy(sc, mode, start_date, end_date): # Read the data b = fgm.load_data(sc, mode, start_date, end_date) dis_moms = fpi.load_moms(sc, mode, optdesc='dis-moms', start_date=start_date, end_date=end_date) des_moms = fpi.load_moms(sc, mode, optdesc='des-moms', start_date=start_date, end_date=end_date) dis_dist = fpi.load_dist(sc, mode, optdesc='dis-dist', start_date=start_date, end_date=end_date) des_dist = fpi.load_dist(sc, mode, optdesc='des-dist', start_date=start_date, end_date=end_date) # Precondition the distributions dis_kwargs = fpi.precond_params(sc, mode, 'l2', 'dis-dist', start_date, end_date, time=dis_dist['time']) des_kwargs = fpi.precond_params(sc, mode, 'l2', 'des-dist', start_date, end_date, time=des_dist['time']) f_dis = fpi.precondition(dis_dist['dist'], **dis_kwargs) f_des = fpi.precondition(des_dist['dist'], **des_kwargs) # Calculate moments # - Use calculated moments for the Maxwellian distribution Ni = fpi.density(f_dis) Vi = fpi.velocity(f_dis, N=Ni) Ti = fpi.temperature(f_dis, N=Ni, V=Vi) Pi = fpi.pressure(f_dis, N=Ni, T=Ti) ti = ((Ti[:,0,0] + Ti[:,1,1] + Ti[:,2,2]) / 3.0).drop(['t_index_dim1', 't_index_dim2']) pi = ((Pi[:,0,0] + Pi[:,1,1] + Pi[:,2,2]) / 3.0).drop(['t_index_dim1', 't_index_dim2']) Ne = fpi.density(f_des) Ve = fpi.velocity(f_des, N=Ne) Te = fpi.temperature(f_des, N=Ne, V=Ve) Pe = fpi.pressure(f_des, N=Ne, T=Te) te = ((Te[:,0,0] + Te[:,1,1] + Te[:,2,2]) / 3.0).drop(['t_index_dim1', 't_index_dim2']) pe = ((Pe[:,0,0] + Pe[:,1,1] + Pe[:,2,2]) / 3.0).drop(['t_index_dim1', 't_index_dim2']) # Equivalent (preconditioned) Maxwellian distributions # fi_max = fpi.maxwellian_distribution(f_dis, N=Ni, bulkv=Vi, T=ti) # fe_max = fpi.maxwellian_distribution(f_des, N=Ne, bulkv=Ve, T=te) fi_max = fpi.maxwellian_distribution(f_dis, N=Ni, bulkv=Vi, T=ti) fe_max = fpi.maxwellian_distribution(f_des, N=Ne, bulkv=Ve, T=te) # Analytically derived Maxwellian entropy density # si_max = fpi.maxwellian_entropy(Ni, pi) # se_max = fpi.maxwellian_entropy(Ne, pe) si_max = fpi.entropy(fi_max) se_max = fpi.entropy(fe_max) # Velocity space entropy density siv_dist = fpi.vspace_entropy(f_dis) sev_dist = fpi.vspace_entropy(f_des) # The Maxwellian is already preconditioned # - There are three options for calculating the v-space entropy of # the Maxwellian distribution: using # 1) FPI integrated moments, # 2) Custom moments of the measured distribution # 3) Custom moments of the equivalent Maxwellian distribution # Because the Maxwellian is built with discrete v-space bins, its # density, velocity, and temperature do not match that of the # measured distribution on which it is based. If NiM is used, the # M-bar term will be negative, which is unphysical, so here we use # the density of the measured distribution and the entropy of the # equivalent Maxwellian. siv_max = fpi.vspace_entropy(fi_max, N=Ni, s=si_max) sev_max = fpi.vspace_entropy(fe_max, N=Ne, s=se_max) # M-bar miv_bar = (siv_max - siv_dist) / siv_max mev_bar = (sev_max - sev_dist) / sev_max # Anisotropy Ai = dis_moms['temppara'] / dis_moms['tempperp'] - 1 Ae = des_moms['temppara'] / des_moms['tempperp'] - 1 nrows = 8 ncols = 1 figsize = (5.5, 7.0) fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=figsize, squeeze=False) # B ax = axes[0,0] ax = util.plot([b['B_GSE'][:,3], b['B_GSE'][:,0], b['B_GSE'][:,1], b['B_GSE'][:,2]], ax=ax, labels=['|B|', 'Bx', 'By', 'Bz'], xaxis='off', ylabel='B\n(nT)' ) # N ax = axes[1,0] ax = util.plot([dis_moms['density'], des_moms['density']], ax=ax, labels=['Ni', 'Ne'], xaxis='off', ylabel='N\n($cm^{-3}$)' ) # Velocity space ion entropy density ax = axes[2,0] ax = util.plot([siv_max, siv_dist], ax=ax, labels=['$s_{i,V,max}$', '$s_{i,V}$'], xaxis='off', ylabel='$s_{V}$\n$J/K/m^{3}$' ) # Velocity space electron entropy density ax = axes[3,0] ax = util.plot([sev_max, sev_dist], ax=ax, labels=['$s_{e,V,max}$', '$s_{e,V}$'], xaxis='off', ylabel='$s_{V}$' ) # Velocity space M-bar ax = axes[4,0] ax = util.plot([miv_bar, mev_bar], ax=ax, labels=['$\overline{M}_{i,V}$', '$\overline{M}_{e,V}$'], xaxis='off', ylabel='$\overline{M}_{V}$' ) # Ion temperature ax = axes[5,0] ax = util.plot([dis_moms['temppara'], dis_moms['tempperp'], dis_moms['t']], ax=ax, labels=['$T_{\parallel}$', '$T_{\perp}$', 'T'], xaxis='off', ylabel='$T_{i}$\n(eV)' ) # Electron temperature ax = axes[6,0] ax = util.plot([des_moms['temppara'], des_moms['tempperp'], des_moms['t']], ax=ax, labels=['$T_{\parallel}$', '$T_{\perp}$', 'T'], xaxis='off', ylabel='$T_{e}$\n(eV)' ) # Anisotropy ax = axes[7,0] ax = util.plot([Ai, Ae], ax=ax, labels=['$A_{i}$', '$A_{e}$'], ylabel='A' ) fig.suptitle('Velocity Space Entropy') plt.subplots_adjust(left=0.2, right=0.85, top=0.95, hspace=0.4) return fig, axes
def kinetic_entropy(sc, mode, start_date, end_date, **kwargs): # Read the data b = fgm.load_data(sc, mode, start_date, end_date) dis_moms = fpi.load_moms(sc, mode, 'i', start_date, end_date) des_moms = fpi.load_moms(sc, mode, 'e', start_date, end_date) dis_dist = fpi.load_dist(sc, mode, 'i', start_date, end_date) des_dist = fpi.load_dist(sc, mode, 'e', start_date, end_date) # Equivalent Maxwellian distribution dis_max_dist = fpi.maxwellian_distribution(dis_dist, N=dis_moms['density'], bulkv=dis_moms['velocity'], T=dis_moms['t']) des_max_dist = fpi.maxwellian_distribution(des_dist, N=des_moms['density'], bulkv=des_moms['velocity'], T=des_moms['t']) # Entropy density si_dist = fpi.entropy(dis_dist, **kwargs) se_dist = fpi.entropy(des_dist, **kwargs) # si_max = fpi.maxwellian_entropy(dis_moms['density'], dis_moms['p']) # se_max = fpi.maxwellian_entropy(des_moms['density'], des_moms['p']) si_max = fpi.entropy(dis_max_dist, **kwargs) se_max = fpi.entropy(des_max_dist, **kwargs) # Velcoity space entropy density siv_dist = fpi.vspace_entropy(dis_dist, N=dis_moms['density'], s=si_dist, **kwargs) sev_dist = fpi.vspace_entropy(des_dist, N=des_moms['density'], s=se_dist, **kwargs) siv_max = fpi.vspace_entropy(des_max_dist, N=dis_moms['density'], s=si_max, **kwargs) sev_max = fpi.vspace_entropy(des_max_dist, N=des_moms['density'], s=se_max, **kwargs) # M-bar mi_bar = np.abs(si_max - si_dist) / si_max me_bar = np.abs(se_max - se_dist) / se_max miv_bar = np.abs(siv_max - siv_dist) / siv_max mev_bar = np.abs(sev_max - sev_dist) / sev_max # Epsilon ei = fpi.epsilon(dis_dist, N=dis_moms['density'], V=dis_moms['velocity'], T=dis_moms['t'], **kwargs) ee = fpi.epsilon(des_dist, N=des_moms['density'], V=des_moms['velocity'], T=des_moms['t'], **kwargs) # Setup the plot nrows = 9 ncols = 1 figsize = (5.5, 7.0) fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=figsize, squeeze=False) # B ax = axes[0, 0] ax = util.plot([b['B'][:, 3], b['B'][:, 0], b['B'][:, 1], b['B'][:, 2]], ax=ax, labels=['|B|', 'Bx', 'By', 'Bz'], xaxis='off', ylabel='B\n(nT)') # Ion entropy density ax = axes[1, 0] ax = util.plot([si_max, si_dist], ax=ax, labels=['$s_{i,max}$', '$s_{i}$'], xaxis='off', ylabel='s\n$J/K/m^{3}$ $ln(s^{3}/m^{6})$') # Electron entropy density ax = axes[2, 0] ax = util.plot([se_max, se_dist], ax=ax, labels=['$s_{e,max}$', '$s_{e}$'], xaxis='off', ylabel='s') # Ion M-bar ax = axes[3, 0] ax = util.plot(mi_bar, ax=ax, legend=False, xaxis='off', ylabel='$\overline{M}_{i}$') # Ion Epsilon ax = ax.twinx() ei.plot(ax=ax, color='g') ax.set_ylabel('$\epsilon_{i}$\n$(s/m)^{3/2}$') ax.yaxis.label.set_color('g') ax.tick_params(axis='y', colors='g') ax.set_xticklabels([]) # Electron M-bar ax = axes[4, 0] ax = util.plot(me_bar, ax=ax, legend=False, xaxis='off', ylabel='$\overline{M}_{e}$') # Electron Epsilon ax = ax.twinx() ee.plot(ax=ax, color='r') ax.set_ylabel('$\epsilon_{e}$\n$(s/m)^{3/2}$') ax.yaxis.label.set_color('r') ax.tick_params(axis='y', colors='r') ax.set_xticklabels([]) # Velocity space ion entropy density ax = axes[5, 0] ax = util.plot([siv_max, siv_dist], ax=ax, labels=['$s_{i,V,max}$', '$s_{i,V}$'], xaxis='off', ylabel='$s_{V}$\n$J/K/m^{3}$ $ln()$') # Velocity space electron entropy density ax = axes[6, 0] ax = util.plot([sev_max, sev_dist], ax=ax, labels=['$s_{e,V,max}$', '$s_{e,V}$'], xaxis='off', ylabel='$s_{V}$') # Velocity space ion M-bar ax = axes[7, 0] ax = util.plot(miv_bar, ax=ax, legend=False, xaxis='off', ylabel='$\overline{M}_{i,V}$') # Velocity space electron M-bar ax = axes[8, 0] ax = util.plot(mev_bar, ax=ax, legend=False, ylabel='$\overline{M}_{e,V}$') fig.suptitle('Total and Velocity Space Entropy Density') plt.subplots_adjust(left=0.2, right=0.85, top=0.95, hspace=0.4) # plt.setp(axes, xlim=xlim) return fig, axes
def kinetic_entropy(sc, mode, start_date, end_date, **kwargs): # Read the data b = fgm.load_data(sc=sc, mode=mode, start_date=start_date, end_date=end_date) dis_dist = fpi.load_dist(sc=sc, mode=mode, optdesc='dis-dist', start_date=start_date, end_date=end_date) des_dist = fpi.load_dist(sc=sc, mode=mode, optdesc='des-dist', start_date=start_date, end_date=end_date) # Precondition the distributions dis_kwargs = fpi.precond_params(sc, mode, 'l2', 'dis-dist', start_date, end_date, time=dis_dist['time']) des_kwargs = fpi.precond_params(sc, mode, 'l2', 'des-dist', start_date, end_date, time=des_dist['time']) f_dis = fpi.precondition(dis_dist['dist'], **dis_kwargs) f_des = fpi.precondition(des_dist['dist'], **des_kwargs) # Calculate Moments Ni = fpi.density(f_dis) Vi = fpi.velocity(f_dis, N=Ni) Ti = fpi.temperature(f_dis, N=Ni, V=Vi) Pi = fpi.pressure(f_dis, N=Ni, T=Ti) ti = ((Ti[:,0,0] + Ti[:,1,1] + Ti[:,2,2]) / 3.0).drop(['t_index_dim1', 't_index_dim2']) pi = ((Pi[:,0,0] + Pi[:,1,1] + Pi[:,2,2]) / 3.0).drop(['t_index_dim1', 't_index_dim2']) Ne = fpi.density(f_des) Ve = fpi.velocity(f_des, N=Ne) Te = fpi.temperature(f_des, N=Ne, V=Ve) Pe = fpi.pressure(f_des, N=Ne, T=Te) te = ((Te[:,0,0] + Te[:,1,1] + Te[:,2,2]) / 3.0).drop(['t_index_dim1', 't_index_dim2']) pe = ((Pe[:,0,0] + Pe[:,1,1] + Pe[:,2,2]) / 3.0).drop(['t_index_dim1', 't_index_dim2']) # Equivalent (preconditioned) Maxwellian distributions fi_max = fpi.maxwellian_distribution(f_dis, N=Ni, bulkv=Vi, T=ti) fe_max = fpi.maxwellian_distribution(f_des, N=Ne, bulkv=Ve, T=te) # Entropy density si_dist = fpi.entropy(f_dis) se_dist = fpi.entropy(f_des) si_max = fpi.entropy(fi_max) se_max = fpi.entropy(fe_max) # Velcoity space entropy density siv_dist = fpi.vspace_entropy(f_dis, N=Ni, s=si_dist) sev_dist = fpi.vspace_entropy(f_des, N=Ne, s=se_dist) # The Maxwellian is already preconditioned # - There are three options for calculating the v-space entropy of # the Maxwellian distribution: using # 1) FPI integrated moments, # 2) Custom moments of the measured distribution # 3) Custom moments of the equivalent Maxwellian distribution # Because the Maxwellian is built with discrete v-space bins, its # density, velocity, and temperature do not match that of the # measured distribution on which it is based. If NiM is used, the # M-bar term will be negative, which is unphysical, so here we use # the density of the measured distribution and the entropy of the # equivalent Maxwellian. siv_max = fpi.vspace_entropy(fi_max, N=Ni, s=si_max) sev_max = fpi.vspace_entropy(fe_max, N=Ne, s=se_max) # M-bar mi_bar = np.abs(si_max - si_dist) / si_max me_bar = np.abs(se_max - se_dist) / se_max miv_bar = np.abs(siv_max - siv_dist) / siv_max mev_bar = np.abs(sev_max - sev_dist) / sev_max # Epsilon ei = fpi.epsilon(f_dis, N=Ni, V=Vi, T=ti) ee = fpi.epsilon(f_des, N=Ne, V=Ve, T=te) # Setup the plot nrows = 9 ncols = 1 figsize = (5.5, 7.0) fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=figsize, squeeze=False) # B ax = axes[0,0] ax = util.plot([b['B_GSE'][:,3], b['B_GSE'][:,0], b['B_GSE'][:,1], b['B_GSE'][:,2]], ax=ax, labels=['|B|', 'Bx', 'By', 'Bz'], xaxis='off', ylabel='B\n(nT)' ) # Ion entropy density ax = axes[1,0] ax = util.plot([si_max, si_dist], ax=ax, labels=['$s_{i,max}$', '$s_{i}$'], xaxis='off', ylabel='s\n$J/K/m^{3}$ $ln(s^{3}/m^{6})$' ) # Electron entropy density ax = axes[2,0] ax = util.plot([se_max, se_dist], ax=ax, labels=['$s_{e,max}$', '$s_{e}$'], xaxis='off', ylabel='s' ) # Ion M-bar ax = axes[3,0] ax = util.plot(mi_bar, ax=ax, legend=False, xaxis='off', ylabel='$\overline{M}_{i}$' ) # Ion Epsilon ax = ax.twinx() ei.plot(ax=ax, color='g') ax.set_ylabel('$\epsilon_{i}$\n$(s/m)^{3/2}$') ax.yaxis.label.set_color('g') ax.tick_params(axis='y', colors='g') ax.set_xticklabels([]) ax.set_title('') # Electron M-bar ax = axes[4,0] ax = util.plot(me_bar, ax=ax, legend=False, xaxis='off', ylabel='$\overline{M}_{e}$' ) # Electron Epsilon ax = ax.twinx() ee.plot(ax=ax, color='r') ax.set_ylabel('$\epsilon_{e}$\n$(s/m)^{3/2}$') ax.yaxis.label.set_color('r') ax.tick_params(axis='y', colors='r') ax.set_xticklabels([]) ax.set_title('') # Velocity space ion entropy density ax = axes[5,0] ax = util.plot([siv_max, siv_dist], ax=ax, labels=['$s_{i,V,max}$', '$s_{i,V}$'], xaxis='off', ylabel='$s_{V}$\n$J/K/m^{3}$ $ln()$' ) # Velocity space electron entropy density ax = axes[6,0] ax = util.plot([sev_max, sev_dist], ax=ax, labels=['$s_{e,V,max}$', '$s_{e,V}$'], xaxis='off', ylabel='$s_{V}$' ) # Velocity space ion M-bar ax = axes[7,0] ax = util.plot(miv_bar, ax=ax, legend=False, xaxis='off', ylabel='$\overline{M}_{i,V}$' ) # Velocity space electron M-bar ax = axes[8,0] ax = util.plot(mev_bar, ax=ax, legend=False, ylabel='$\overline{M}_{e,V}$' ) fig.suptitle('Total and Velocity Space Entropy Density') plt.subplots_adjust(left=0.2, right=0.85, top=0.95, hspace=0.4) # plt.setp(axes, xlim=xlim) return fig, axes
def overview(sc, mode, start_date, end_date, **kwargs): # Read the data b = fgm.load_data(sc=sc, mode=mode, start_date=start_date, end_date=end_date) e = edp.load_data(sc=sc, mode=mode, start_date=start_date, end_date=end_date) dis_moms = fpi.load_moms(sc=sc, mode=mode, optdesc='dis-moms', start_date=start_date, end_date=end_date) des_moms = fpi.load_moms(sc=sc, mode=mode, optdesc='des-moms', start_date=start_date, end_date=end_date) nrows = 7 ncols = 1 figsize = (6.0, 7.0) fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=figsize, squeeze=False) locator = mdates.AutoDateLocator() formatter = mdates.ConciseDateFormatter(locator) # B ax = axes[0,0] b['B_GSE'][:,3].plot(ax=ax, label='|B|') b['B_GSE'][:,0].plot(ax=ax, label='Bx') b['B_GSE'][:,1].plot(ax=ax, label='By') b['B_GSE'][:,2].plot(ax=ax, label='Bz') ax.set_xlabel('') ax.set_xticklabels([]) ax.set_ylabel('B [nT]') ax.set_title('') # Create the legend outside the right-most axes leg = ax.legend(bbox_to_anchor=(1.05, 1), borderaxespad=0.0, frameon=False, handlelength=0, handletextpad=0, loc='upper left') # Color the legend text the same color as the lines for line, text in zip(ax.get_lines(), leg.get_texts()): text.set_color(line.get_color()) # Ion energy spectrogram nt = dis_moms['omnispectr'].shape[0] nE = dis_moms['omnispectr'].shape[1] x0 = mdates.date2num(dis_moms['time'])[:, np.newaxis].repeat(nE, axis=1) x1 = dis_moms['energy'] y = np.where(dis_moms['omnispectr'] == 0, 1, dis_moms['omnispectr']) y = np.log(y[0:-1,0:-1]) ax = axes[1,0] im = ax.pcolorfast(x0, x1, y, cmap='nipy_spectral') ax.images.append(im) ax.xaxis.set_major_locator(locator) ax.xaxis.set_major_formatter(formatter) ax.set_xticklabels([]) ax.set_xlabel('') ax.set_yscale('log') ax.set_ylabel('E ion\n(eV)') cbaxes = inset_axes(ax, width='2%', height='100%', loc=4, bbox_to_anchor=(0, 0, 1.05, 1), bbox_transform=ax.transAxes, borderpad=0) cb = plt.colorbar(im, cax=cbaxes, orientation='vertical') cb.set_label('$log_{10}$DEF\nkeV/($cm^{2}$ s sr keV)') # Electron energy spectrogram nt = des_moms['omnispectr'].shape[0] nE = des_moms['omnispectr'].shape[1] x0 = mdates.date2num(des_moms['time'])[:, np.newaxis].repeat(nE, axis=1) x1 = des_moms['energy'] y = np.where(des_moms['omnispectr'] == 0, 1, des_moms['omnispectr']) y = np.log(y[0:-1,0:-1]) ax = axes[2,0] im = ax.pcolorfast(x0, x1, y, cmap='nipy_spectral') ax.images.append(im) ax.xaxis.set_major_locator(locator) ax.xaxis.set_major_formatter(formatter) ax.set_xticklabels([]) ax.set_xlabel('') ax.set_yscale('log') ax.set_ylabel('E e-\n(eV)') cbaxes = inset_axes(ax, width='2%', height='100%', loc=4, bbox_to_anchor=(0, 0, 1.05, 1), bbox_transform=ax.transAxes, borderpad=0) cb = plt.colorbar(im, cax=cbaxes, orientation='vertical') cb.set_label('$log_{10}$DEF') # N ax = axes[3,0] dis_moms['density'].plot(ax=ax, label='Ni') des_moms['density'].plot(ax=ax, label='Ne') ax.set_xlabel('') ax.set_xticklabels([]) ax.set_ylabel('N\n($cm^{-3}$)') ax.set_title('') leg = ax.legend(bbox_to_anchor=(1.05, 1), borderaxespad=0.0, frameon=False, handlelength=0, handletextpad=0, loc='upper left') for line, text in zip(ax.get_lines(), leg.get_texts()): text.set_color(line.get_color()) # Vi ax = axes[4,0] dis_moms['velocity'][:,0].plot(ax=ax, label='Vx') dis_moms['velocity'][:,1].plot(ax=ax, label='Vy') dis_moms['velocity'][:,2].plot(ax=ax, label='Vz') ax.set_xlabel('') ax.set_xticklabels([]) ax.set_ylabel('Vi\n(km/s)') ax.set_title('') leg = ax.legend(bbox_to_anchor=(1.05, 1), borderaxespad=0.0, frameon=False, handlelength=0, handletextpad=0, loc='upper left') for line, text in zip(ax.get_lines(), leg.get_texts()): text.set_color(line.get_color()) # Ve ax = axes[5,0] des_moms['velocity'][:,0].plot(ax=ax, label='Vx') des_moms['velocity'][:,1].plot(ax=ax, label='Vy') des_moms['velocity'][:,2].plot(ax=ax, label='Vz') ax.set_xlabel('') ax.set_xticklabels([]) ax.set_ylabel('Ve\n(km/s)') ax.set_title('') leg = ax.legend(bbox_to_anchor=(1.05, 1), borderaxespad=0.0, frameon=False, handlelength=0, handletextpad=0, loc='upper left') for line, text in zip(ax.get_lines(), leg.get_texts()): text.set_color(line.get_color()) # E ax = axes[6,0] e['E_GSE'][:,0].plot(ax=ax, label='Ex') e['E_GSE'][:,1].plot(ax=ax, label='Ey') e['E_GSE'][:,2].plot(ax=ax, label='Ez') ax.set_xlabel('') ax.set_xticklabels([]) ax.set_ylabel('E\n(mV/m)') ax.set_title('') ax.xaxis.set_major_locator(locator) ax.xaxis.set_major_formatter(formatter) for tick in ax.get_xticklabels(): tick.set_rotation(45) leg = ax.legend(bbox_to_anchor=(1.05, 1), borderaxespad=0.0, frameon=False, handlelength=0, handletextpad=0, loc='upper left') for line, text in zip(ax.get_lines(), leg.get_texts()): text.set_color(line.get_color()) fig.suptitle(sc.upper()) plt.subplots_adjust(left=0.2, right=0.8, top=0.95, hspace=0.2) return fig, axes
def fsm_spectra(sc, start_date, end_date): # FSM only has burst mode data mode = 'brst' # Load the data fgm_data = fgm.load_data(sc=sc, mode=mode, start_date=start_date, end_date=end_date) scm_data = scm.load_data(sc=sc, mode=mode, level='l2', start_date=start_date, end_date=end_date) fsm_data = fsm.load_data(sc=sc, start_date=start_date, end_date=end_date) # Determine sample rate fs_fgm = (np.diff(fgm_data['time']).mean().astype(int) / 1e9)**(-1) fs_scm = (np.diff(scm_data['time']).mean().astype(int) / 1e9)**(-1) fs_fsm = (np.diff(fsm_data['time']).mean().astype(int) / 1e9)**(-1) # Length of FFT -- aim for 10 second increments duration = (end_date - start_date).total_seconds() tperseg = 10.0 nseg = duration // tperseg if nseg == 0: nseg = 1 tperseg = duration nperseg_fgm = tperseg * fs_fgm nperseg_scm = tperseg * fs_scm nperseg_fsm = tperseg * fs_fsm # PWelch f_fgm, pxx_fgm = welch(fgm_data['B_GSE'], axis=0, fs=fs_fgm, window='hanning', nperseg=nperseg_fgm, detrend='linear', return_onesided=True, scaling='density') f_scm, pxx_scm = welch(scm_data['B_GSE'], axis=0, fs=fs_scm, window='hanning', nperseg=nperseg_scm, detrend='linear', return_onesided=True, scaling='density') f_fsm, pxx_fsm = welch(fsm_data['B_GSE'], axis=0, fs=fs_fsm, window='hanning', nperseg=nperseg_fsm, detrend='linear', return_onesided=True, scaling='density') # Plot the data fig, axes = plt.subplots(nrows=3, ncols=1, squeeze=False, figsize=(8.5, 5)) # Bx PSD ax = axes[0,0] ax.plot(f_fsm, np.sqrt(pxx_fsm[:,0]), label='FSM') ax.plot(f_scm, np.sqrt(pxx_scm[:,0]), label='SCM') ax.plot(f_fgm, np.sqrt(pxx_fgm[:,0]), label='FGM') ax.set_xscale('log') ax.set_xlabel('f (Hz)') ax.set_yscale('log') ax.set_ylabel('Bx PSD\n(nT/$\sqrt{Hz}$)') ax.legend() # By PSD ax = axes[1,0] ax.plot(f_fsm, np.sqrt(pxx_fsm[:,1]), label='FSM') ax.plot(f_scm, np.sqrt(pxx_scm[:,1]), label='SCM') ax.plot(f_fgm, np.sqrt(pxx_fgm[:,1]), label='FGM') ax.set_xscale('log') ax.set_xlabel('f (Hz)') ax.set_yscale('log') ax.set_ylabel('By PSD\n(nT/$\sqrt{Hz}$)') ax.legend() # Bz PSD ax = axes[2,0] ax.plot(f_fsm, np.sqrt(pxx_fsm[:,2]), label='FSM') ax.plot(f_scm, np.sqrt(pxx_scm[:,2]), label='SCM') ax.plot(f_fgm, np.sqrt(pxx_fgm[:,2]), label='FGM') ax.set_xscale('log') ax.set_xlabel('f (Hz)') ax.set_yscale('log') ax.set_ylabel('Bz PSD\n(nT/$\sqrt{Hz}$)') ax.legend() # Timestamp if start_date.date() == end_date.date(): tstamp = ' '.join((start_date.strftime('%Y-%m-%d'), start_date.strftime('%H:%M:%S'), '-', end_date.strftime('%H:%M:%S'))) else: tstamp = ' '.join((start_date.strftime('%Y-%m-%d'), start_date.strftime('%H:%M:%S'), '-', end_date.strftime('%Y-%m-%d'), end_date.strftime('%H:%M:%S'))) fig.suptitle('FGM, SCM, & FSM Spectra Comparison\n{0}' .format(tstamp)) plt.subplots_adjust(left=0.12, right=0.95, top=0.9, bottom=0.12, hspace=0.2, wspace=0.4) return fig, axes
from pymms.data import fgm, anc from matplotlib import pyplot as plt # Use the Torbert Science (2018) data interval to test sc = 'mms1' t0 = dt.datetime(2017, 7, 11, 22, 33, 30) t1 = dt.datetime(2017, 7, 11, 22, 34, 30) # Load the data # - Expand the time interval for DSS so the sun pulses encompass the data # - FGM L2Pre has BCS and DBCS data dss_data = load_sunpulse(sc=sc, start_date=t0 - dt.timedelta(seconds=40), end_date=t1 + dt.timedelta(seconds=40)) fgm_data = fgm.load_data(sc=sc, instr='dfg', mode='srvy', level='l2pre', start_date=t0, end_date=t1, coords=('bcs', 'dmpa'), team_site=True) # Get the major principal axis vector anc_data = anc.load_ancillary(sc, 'defatt', t0, t1) # Rotate to MPA mpa = anc_data.attrs['MPA'] z_bcs2smpa = mpa / np.linalg.norm(np.array(mpa)) y_bcs2smpa = np.cross(z_bcs2smpa, np.array([1, 0, 0])) x_bcs2smpa = np.cross(y_bcs2smpa, z_bcs2smpa) bcs2smpa = xr.DataArray(np.stack([x_bcs2smpa, y_bcs2smpa, z_bcs2smpa], axis=1), dims=['bcs', 'smpa'], coords={'bcs': ['x', 'y', 'z'], 'smpa': ['x', 'y', 'z']})
def fsm_timeseries(sc, start_date, end_date): # FSM only has burst mode data mode = 'brst' # Load the data fgm_data = fgm.load_data(sc=sc, mode=mode, start_date=start_date, end_date=end_date) scm_data = scm.load_data(sc=sc, mode=mode, start_date=start_date, end_date=end_date) fsm_data = fsm.load_data(sc=sc, start_date=start_date, end_date=end_date) # High-pass filter FSM data at 1 Hz to compare with SCM f_Nyquist = 0.5 / (np.diff(fsm_data['time']).mean().astype(int) / 1e9) order = 3 # filter order fc = 1.0 # 1 Hz cut-off frequency fc_norm = fc / f_Nyquist b, a = butter(order, fc_norm, btype='high', analog=False) fsm_data['dB_GSE'] = xr.DataArray(filtfilt(b, a, fsm_data['B_GSE'], axis=0), dims=['time', 'b_index']) # Plot the data fig, axes = plt.subplots(nrows=4, ncols=2, squeeze=False, figsize=(8.5, 6)) # Bx ax = axes[0,0] ax = util.plot([fgm_data['B_GSE'].loc[:,'x'], fsm_data['B_GSE'].loc[:,'x']], ax=ax, labels=['FGM', 'FSM'], xaxis='off', ylabel='Bx\n(nT)' ) # By ax = axes[1,0] ax = util.plot([fgm_data['B_GSE'].loc[:,'z'], fsm_data['B_GSE'].loc[:,'z']], ax=ax, labels=['FGM', 'FSM'], xaxis='off', ylabel='By\n(nT)' ) # Bz ax = axes[2,0] ax = util.plot([fgm_data['B_GSE'].loc[:,'z'], fsm_data['B_GSE'].loc[:,'z']], ax=ax, labels=['FGM', 'FSM'], xaxis='off', ylabel='Bz\n(nT)' ) # |B| ax = axes[3,0] ax = util.plot([fgm_data['B_GSE'].loc[:,'t'], fsm_data['|B|']], ax=ax, labels=['FGM', 'FSM'], ylabel='|B|\n(nT)' ) # dBx ax = axes[0,1] ax = util.plot([scm_data['B_GSE'].loc[:,'x'], fsm_data['dB_GSE'].loc[:,'x']], ax=ax, labels=['SCM', 'FSM'], xaxis='off', ylabel='$\delta$Bx\n(nT)' ) # dBy ax = axes[1,1] ax = util.plot([scm_data['B_GSE'].loc[:,'y'], fsm_data['dB_GSE'].loc[:,'y']], ax=ax, labels=['SCM', 'FSM'], xaxis='off', ylabel='$\delta$By\n(nT)' ) # dBz ax = axes[2,1] ax = util.plot([scm_data['B_GSE'].loc[:,'z'], fsm_data['dB_GSE'].loc[:,'z']], ax=ax, labels=['SCM', 'FSM'], ylabel='$\delta$Bz\n(nT)' ) fig.suptitle('FGM, SCM, & FSM Timeseries Comparison') plt.subplots_adjust(left=0.1, right=0.90, top=0.95, bottom=0.12, hspace=0.2, wspace=0.4) # |dB| ax = axes[3,1] ax.axis('off') return fig, axes