def plot_hozt_vgradrho_rho(read=True): if read: gradrho = [] for fn1, fn2 in zip(fns1,fns2): g1, g2 = gitm.read(fn1), gitm.read(fn2) lon1 = np.array(g1['Longitude']) lat1 = np.array(g1['Latitude']) alt1 = np.array(g1['Altitude']) Re = 6371*1000 # Earth radius, unit: m RR = Re+alt1 omega = 2*np.pi/(24*3600) rho1 = np.array(g1['Rho']) nwind1 = np.array(g1['V!Dn!N (north)']) ewind1 = np.array(g1['V!Dn!N (east)']) + omega*RR*np.cos(lat1) vgradrho1 = \ (nwind1*cr.calc_rusanov_lats(lat1,alt1,rho1)\ +ewind1*cr.calc_rusanov_lons(lon1,lat1,alt1,rho1))/rho1 lon2 = np.array(g2['Longitude']) lat2 = np.array(g2['Latitude']) alt2 = np.array(g2['Altitude']) Re = 6371*1000 # Earth radius, unit: m RR = Re+alt2 omega = 2*np.pi/(24*3600) rho2 = np.array(g2['Rho']) nwind2 = np.array(g2['V!Dn!N (north)']) ewind2 = np.array(g2['V!Dn!N (east)']) + omega*RR*np.cos(lat2) vgradrho2 = \ (nwind2*cr.calc_rusanov_lats(lat2,alt2,rho2)\ +ewind2*cr.calc_rusanov_lons(lon2,lat2,alt2,rho2))/rho2 vgradrhod = vgradrho1 - vgradrho2 gradrho1 = [] for alt in alts: ialt = np.argmin(np.abs(g1['Altitude'][0, 0, 2:-2]-alt*1000))+2 gradrho2 = [] for lt in lts: ilt = np.argmin(np.abs(g1['LT'][2:-2, 0, 0]-lt))+2 gradrho2.append( np.array(vgradrhod[ilt, 2:-2, ialt]).reshape(1,1,1,-1)) gradrho2 = np.concatenate(gradrho2, axis=2) gradrho1.append(gradrho2) gradrho1 = np.concatenate(gradrho1, axis=1) gradrho.append(gradrho1) gradrho = np.concatenate(gradrho, axis=0) lat = g1['dLat'][0, 2:-2, 0] np.savez('/home/guod/tmp/hozt_vgradrho', gradrho=gradrho, lat=lat) ldf = np.load('/home/guod/tmp/hozt_vgradrho.npz') gradrho, lat = ldf['gradrho'], ldf['lat'] plt.close() plt.contourf( timeidx, lat, gradrho[:,3, 1, :].T, levels=np.linspace(-1,1,21)*1e-4, cmap='seismic') plt.ylim(-90, -40) plt.show() return
def plot_hozt_vgradrho_rho_diff(show=True, save=False): plt.close('all') plt.figure() lon1 = np.array(g1a['Longitude']) lat1 = np.array(g1a['Latitude']) alt1 = np.array(g1a['Altitude']) Re = 6371*1000 # Earth radius, unit: m RR = Re+alt1 omega = 2*np.pi/(24*3600) rho1 = np.array(g1a['Rho']) nwind1 = np.array(g1a['V!Dn!N (north)']) ewind1 = np.array(g1a['V!Dn!N (east)']) + omega*RR*np.cos(lat1) vgradrho1 = (nwind1*cr.calc_rusanov_lats(lat1,alt1,rho1)\ +ewind1*cr.calc_rusanov_lons(lon1,lat1,alt1,rho1))/rho1 lon2 = np.array(g2a['Longitude']) lat2 = np.array(g2a['Latitude']) alt2 = np.array(g2a['Altitude']) Re = 6371*1000 # Earth radius, unit: m RR = Re+alt2 omega = 2*np.pi/(24*3600) rho2 = np.array(g2a['Rho']) nwind2 = np.array(g2a['V!Dn!N (north)']) ewind2 = np.array(g2a['V!Dn!N (east)']) + omega*RR*np.cos(lat2) vgradrho2 = (nwind2*cr.calc_rusanov_lats(lat2,alt2,rho2)\ +ewind2*cr.calc_rusanov_lons(lon2,lat2,alt2,rho2))/rho2 ilt = np.argmin(np.abs(g1a['LT'][2:-2, 0, 0]-whichlt))+2 vgradrho1 = vgradrho1[ilt,2:-2,2:-2] vgradrho2 = vgradrho2[ilt,2:-2,2:-2] dvgradrho = np.array(vgradrho1-vgradrho2).T lat = np.array(g1a['dLat'][ilt, 2:-2, 2:-2]).T alt = np.array(g1a['Altitude'][ilt, 2:-2, 2:-2]/1000).T plt.contourf(lat, alt, dvgradrho, levels=np.linspace(-1, 1, 21)*1e-4, cmap='seismic', extend='both') plt.xlim(-90, -40) plt.xlabel('Latitude') plt.ylabel('Altitude') plt.text(0.5, 0.95, 'Time: '+tstring, fontsize=15, horizontalalignment='center', transform=plt.gcf().transFigure) if show: plt.show() if save: plt.savefig(spath+'07_hozt_vgradrho_rho_diff_%s.pdf' % tstring) return
for iax in [ax1, ax2]: plt.sca(iax) plt.xlim([-nlat,180+nlat]) if iax == ax2: plt.ylim([-35,5]) plt.xticks(np.arange(-nlat,181+nlat,30), np.concatenate( [np.arange(nlat,-90,-30), np.arange(-90,nlat+1,30)])) if i<2: plt.xticks(np.arange(-nlat,181+nlat,30),[]) if i==2: ax1.set_xlabel('Latitude') ax2.set_xlabel('Latitude') plt.figure() lon2 = np.array(g2['Longitude']) lat2 = np.array(g2['Latitude']) alt2 = np.array(g2['Altitude']) rho2 = np.array(g2['Rho']) gradrho_rho = np.sqrt(cr.calc_rusanov_lats(lat2,alt2,rho2)**2 + cr.calc_rusanov_lons(lon2,lat2,alt2,rho2)**2)/rho2 for lt in [0, 3, 6, 9, 12, 15, 18, 21]: ilt = np.argmin(np.abs(g2['LT'][2:-2,0,0]-lt))+2 ilat = np.argmin(np.abs(g2['dLat'][0,2:-2,0]-75))+2 plt.plot(gradrho_rho[ilt,ilat,2:-2],g2['Altitude'][0,0,2:-2]/1000) plt.xlabel(r'$\frac{\nabla\rho}{\rho}$ ($m^{-1}$)') plt.ylabel(r'Altitude (km)') plt.show()
RR = Re + alttp omega = 2 * np.pi / (24 * 3600) rhotp = gall['Rho'] nwindtp = gall['V!Dn!N (north)'] ewindtp = gall['V!Dn!N (east)'] + omega * RR * np.cos(lattp) uwindtp = gall['V!Dn!N (up)'] gall['div_rhov'] = \ -(cr.calc_div_hozt(lontp, lattp, alttp, rhotp*nwindtp, rhotp*ewindtp)\ +cr.calc_div_vert(alttp, rhotp*uwindtp))/rhotp gall['vert_divv'] = -cr.calc_div_vert(alttp, uwindtp) gall['hozt_divv'] = -cr.calc_div_hozt(lontp, lattp, alttp, nwindtp, ewindtp) gall['vert_vgradrho'] = -uwindtp * cr.calc_rusanov_alts_ausm(alttp, rhotp) / rhotp gall['hozt_vgradrho'] = \ -(nwindtp*cr.calc_rusanov_lats(lattp,alttp,rhotp)\ +ewindtp*cr.calc_rusanov_lons(lontp,lattp,alttp,rhotp))/rhotp gp.calc_pressure(gall) gthm = gitm.read(gthmfn) gthm['total energy'] =\ gthm['EUV Heating'] + gthm['Conduction'] + \ gthm['Chemical Heating'] + gthm['Auroral Heating'] + \ gthm['Joule Heating'] - gthm['NO Cooling'] - gthm['O Cooling'] savepath = '/Users/guod/tmp/' def multiple_alts_const_alt(): # print('Density and temperature distribution at different heights.') # for alt in [100, 105, 110, 115, 120, 125, 135, 145]: # if not os.path.exists(savepath+str(alt)): # os.mkdir(savepath+str(alt)) # fig, hc = g3ca.test(
def plot_hozt_vgradrho_rho_diff(show=True, save=True): lon1 = np.array(g1a['Longitude']) lat1 = np.array(g1a['Latitude']) alt1 = np.array(g1a['Altitude']) Re = 6371 * 1000 # Earth radius, unit: m RR = Re + alt1 omega = 2 * np.pi / (24 * 3600) rho1 = np.array(g1a['Rho']) nwind1 = np.array(g1a['V!Dn!N (north)']) ewind1 = np.array(g1a['V!Dn!N (east)']) + omega * RR * np.cos(lat1) vgradrho1 = \ (nwind1*cr.calc_rusanov_lats(lat1,alt1,rho1)\ +ewind1*cr.calc_rusanov_lons(lon1,lat1,alt1,rho1))/rho1 lon2 = np.array(g2a['Longitude']) lat2 = np.array(g2a['Latitude']) alt2 = np.array(g2a['Altitude']) Re = 6371 * 1000 # Earth radius, unit: m RR = Re + alt2 omega = 2 * np.pi / (24 * 3600) rho2 = np.array(g2a['Rho']) nwind2 = np.array(g2a['V!Dn!N (north)']) ewind2 = np.array(g2a['V!Dn!N (east)']) + omega * RR * np.cos(lat2) vgradrho2 = \ (nwind2*cr.calc_rusanov_lats(lat2,alt2,rho2)\ +ewind2*cr.calc_rusanov_lons(lon2,lat2,alt2,rho2))/rho2 g1a['hozt_vgradrho_diff'] = vgradrho1 - vgradrho2 apex = Apex(date=2003) qlat, qlon = apex.convert(-90, 0, source='apex', dest='geo', height=400) plt.close('all') plt.figure(figsize=(7.26, 9.25)) for ialt, alt in enumerate([130, 200, 300, 400, 500, 600]): alt_ind = np.argmin(np.abs(g1a['Altitude'][0, 0, :] / 1000 - alt)) alt_str = '%6.2f' % (g1a['Altitude'][0, 0, alt_ind] / 1000) ax, projection = gcc.create_map(3, 2, ialt + 1, 'polar', nlat=nlat, slat=slat, dlat=10, centrallon=g3ca.calculate_centrallon( g1a, 'polar', useLT=True), coastlines=False) lon0, lat0, zdata0 = g3ca.contour_data('hozt_vgradrho_diff', g1a, alt=alt) fp = (lat0[:, 0] > slat) & (lat0[:, 0] < nlat) lon0, lat0, zdata0 = lon0[fp, :], lat0[fp, :], zdata0[fp, :] hc = ax.contourf(lon0, lat0, zdata0, np.linspace(-1, 1, 21) * 1e-4, transform=ccrs.PlateCarree(), cmap='seismic', extend='both') hc = plt.colorbar(hc, pad=0.17) hc.formatter.set_powerlimits((0, 0)) hc.update_ticks() hc.set_label(r'-$\vec{u}\cdot\frac{\nabla\rho}{\rho}$ (horizontal)') # wind difference lon1, lat1, ewind1, nwind1 = g3ca.vector_data(g1a, 'neutral', alt=alt) lon2, lat2, ewind2, nwind2 = g3ca.vector_data(g2a, 'neutral', alt=alt) lon0, lat0 = lon1, lat1 lon0, lat0, ewind0, nwind0 = g3ca.convert_vector(lon0, lat0, ewind2 - ewind1, nwind2 - nwind1, plot_type='polar', projection=projection) hq = ax.quiver(lon0, lat0, ewind0, nwind0, scale=1000, scale_units='inches', regrid_shape=20, headwidth=5) ax.quiverkey(hq, 0.93, -0.1, 500, '500 m/s') ax.scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree()) plt.title('%s km' % alt_str, y=1.05) plt.text(0.5, 0.95, 'Time: ' + tstring, fontsize=15, horizontalalignment='center', transform=plt.gcf().transFigure) if show: plt.show() if save: plt.savefig(spath + '07_hozt_vgradrho_rho_diff_%s%s.pdf' % (tstrday, tstring)) return
def animate_vgradrho_rho(i): g1 = gitm.GitmBin(fn1[i]) g2 = gitm.GitmBin(fn2[i]) alt_ind = np.argmin( np.abs(g1['Altitude'][0, 0, 2:-2] / 1000 - which_alt)) + 2 # create axis ax = list(range(2)) projection = ax.copy() for ins in range(2): nlat, slat = [90, 40] if ins == 0 else [-40, -90] ax[ins], projection[ins] = gcc.create_map( 1, 2, 1 + ins, 'polar', nlat=nlat, slat=slat, dlat=10, centrallon=g3ca.calculate_centrallon(g1, 'polar', useLT=True), coastlines=False) lon1 = np.array(g1['Longitude']) lat1 = np.array(g1['Latitude']) alt1 = np.array(g1['Altitude']) nwind1 = np.array(g1['V!Dn!N (north)']) RR = 6371 * 1000 + alt1 omega = (2 * np.pi) / (24 * 3600) ewind1 = np.array(g1['V!Dn!N (east)']) + omega * RR * np.cos(lat1) uwind1 = np.array(g1['V!Dn!N (up)']) rho1 = np.array(g1['Rho']) vgradrho1 = nwind1*cr.calc_rusanov_lats(lat1,alt1,rho1)/rho1 \ +ewind1*cr.calc_rusanov_lons(lon1,lat1,alt1,rho1)/rho1 lon2 = np.array(g2['Longitude']) lat2 = np.array(g2['Latitude']) alt2 = np.array(g2['Altitude']) nwind2 = np.array(g2['V!Dn!N (north)']) RR = 6371 * 1000 + alt2 omega = (2 * np.pi) / (24 * 3600) ewind2 = np.array(g2['V!Dn!N (east)']) + omega * RR * np.cos(lat2) uwind2 = np.array(g2['V!Dn!N (up)']) rho2 = np.array(g2['Rho']) vgradrho2 = nwind2*cr.calc_rusanov_lats(lat2,alt2,rho2)/rho2 \ +ewind2*cr.calc_rusanov_lons(lon2,lat2,alt2,rho2)/rho2 g1['vgradrho'] = vgradrho1 - vgradrho2 lon0, lat0, vgradrho = g3ca.contour_data('vgradrho', g1, alt=which_alt) hc = ax[0].contourf(lon0, lat0, vgradrho, np.linspace(-1, 1, 21) * 1e-4, transform=ccrs.PlateCarree(), cmap='seismic', extend='both') ax[0].set_title(g1['time'].strftime('%d-%b-%y %H:%M') + ' UT', y=1.05) hc = ax[1].contourf(lon0, lat0, vgradrho, np.linspace(-1, 1, 21) * 1e-4, transform=ccrs.PlateCarree(), cmap='seismic', extend='both') ax[1].set_title(g1['time'].strftime('%d-%b-%y %H:%M') + ' UT', y=1.05) # low density center lon3, lat3, zdata3 = g3ca.contour_data('Rho', g1, alt=which_alt) lon4, lat4, zdata4 = g3ca.contour_data('Rho', g2, alt=which_alt) diffrho = 100 * (zdata4 - zdata3) / zdata3 hc = [ ax[k].contour(lon0, lat0, diffrho, [-10], transform=ccrs.PlateCarree(), colors='g', linestyles='-') for k in [0, 1] ] # wind difference lon1, lat1, ewind1, nwind1 = g3ca.vector_data(g1, 'neutral', alt=which_alt) lon2, lat2, ewind2, nwind2 = g3ca.vector_data(g2, 'neutral', alt=which_alt) lon0, lat0, ewind, nwind = (lon1.copy(), lat1.copy(), ewind2 - ewind1, nwind2 - nwind1) for ins in [0, 1]: lon0t, lat0t, ewindt, nwindt = g3ca.convert_vector( lon0, lat0, ewind, nwind, plot_type='polar', projection=projection[ins]) hq = ax[ins].quiver(lon0t, lat0t, ewindt, nwindt, scale=1500, scale_units='inches', color='k', regrid_shape=20)
plt.sca(iax) plt.xlim([-nlat, 180 + nlat]) if iax == ax2: plt.ylim([-35, 5]) plt.xticks( np.arange(-nlat, 181 + nlat, 30), np.concatenate( [np.arange(nlat, -90, -30), np.arange(-90, nlat + 1, 30)])) if i < 2: plt.xticks(np.arange(-nlat, 181 + nlat, 30), []) if i == 2: ax1.set_xlabel('Latitude') ax2.set_xlabel('Latitude') plt.figure() lon2 = np.array(g2['Longitude']) lat2 = np.array(g2['Latitude']) alt2 = np.array(g2['Altitude']) rho2 = np.array(g2['Rho']) gradrho_rho = np.sqrt( cr.calc_rusanov_lats(lat2, alt2, rho2)**2 + cr.calc_rusanov_lons(lon2, lat2, alt2, rho2)**2) / rho2 for lt in [0, 3, 6, 9, 12, 15, 18, 21]: ilt = np.argmin(np.abs(g2['LT'][2:-2, 0, 0] - lt)) + 2 ilat = np.argmin(np.abs(g2['dLat'][0, 2:-2, 0] - 75)) + 2 plt.plot(gradrho_rho[ilt, ilat, 2:-2], g2['Altitude'][0, 0, 2:-2] / 1000) plt.xlabel(r'$\frac{\nabla\rho}{\rho}$ ($m^{-1}$)') plt.ylabel(r'Altitude (km)') plt.show()
def animate_vgradrho_rho(i): g1 = gitm.GitmBin(fn1[i]) g2 = gitm.GitmBin(fn2[i]) alt_ind = np.argmin(np.abs(g1['Altitude'][0, 0, 2:-2]/1000-which_alt))+2 # create axis ax = list(range(2)) projection = ax.copy() for ins in range(2): nlat, slat = [90, 40] if ins==0 else [-40, -90] ax[ins], projection[ins] = gcc.create_map( 1, 2, 1+ins, 'polar', nlat=nlat, slat=slat, dlat=10, centrallon=g3ca.calculate_centrallon( g1, 'polar', useLT=True), coastlines=False) lon1 = np.array(g1['Longitude']) lat1 = np.array(g1['Latitude']) alt1 = np.array(g1['Altitude']) nwind1 = np.array(g1['V!Dn!N (north)']) RR = 6371*1000+alt1 omega = (2*np.pi)/(24*3600) ewind1 = np.array(g1['V!Dn!N (east)'])+omega*RR*np.cos(lat1) uwind1 = np.array(g1['V!Dn!N (up)']) rho1 = np.array(g1['Rho']) vgradrho1 = nwind1*cr.calc_rusanov_lats(lat1,alt1,rho1)/rho1 \ +ewind1*cr.calc_rusanov_lons(lon1,lat1,alt1,rho1)/rho1 lon2 = np.array(g2['Longitude']) lat2 = np.array(g2['Latitude']) alt2 = np.array(g2['Altitude']) nwind2 = np.array(g2['V!Dn!N (north)']) RR = 6371*1000+alt2 omega = (2*np.pi)/(24*3600) ewind2 = np.array(g2['V!Dn!N (east)'])+omega*RR*np.cos(lat2) uwind2 = np.array(g2['V!Dn!N (up)']) rho2 = np.array(g2['Rho']) vgradrho2 = nwind2*cr.calc_rusanov_lats(lat2,alt2,rho2)/rho2 \ +ewind2*cr.calc_rusanov_lons(lon2,lat2,alt2,rho2)/rho2 g1['vgradrho'] = vgradrho1-vgradrho2 lon0,lat0,vgradrho = g3ca.contour_data('vgradrho',g1,alt=which_alt) hc = ax[0].contourf( lon0, lat0, vgradrho, np.linspace(-1,1,21)*1e-4, transform=ccrs.PlateCarree(), cmap='seismic', extend='both') ax[0].set_title(g1['time'].strftime('%d-%b-%y %H:%M')+' UT', y=1.05) hc = ax[1].contourf( lon0, lat0, vgradrho, np.linspace(-1,1,21)*1e-4, transform=ccrs.PlateCarree(), cmap='seismic', extend='both') ax[1].set_title(g1['time'].strftime('%d-%b-%y %H:%M')+' UT', y=1.05) # low density center lon3, lat3, zdata3 = g3ca.contour_data('Rho', g1, alt=which_alt) lon4, lat4, zdata4 = g3ca.contour_data('Rho', g2, alt=which_alt) diffrho = 100*(zdata4-zdata3)/zdata3 hc = [ax[k].contour( lon0, lat0, diffrho, [-10], transform=ccrs.PlateCarree(), colors='g',linestyles='-') for k in [0, 1]] # wind difference lon1, lat1, ewind1, nwind1 = g3ca.vector_data(g1, 'neutral', alt=which_alt) lon2, lat2, ewind2, nwind2 = g3ca.vector_data(g2, 'neutral', alt=which_alt) lon0, lat0, ewind, nwind = ( lon1.copy(), lat1.copy(), ewind2-ewind1, nwind2-nwind1) for ins in [0, 1]: lon0t, lat0t, ewindt, nwindt = g3ca.convert_vector( lon0, lat0, ewind, nwind, plot_type='polar', projection=projection[ins]) hq = ax[ins].quiver( lon0t, lat0t, ewindt, nwindt, scale=1500, scale_units='inches', color='k', regrid_shape=20)
def plot_hozt_vgradrho_rho_diff(show=True, save=True): lon1 = np.array(g1a['Longitude']) lat1 = np.array(g1a['Latitude']) alt1 = np.array(g1a['Altitude']) Re = 6371*1000 # Earth radius, unit: m RR = Re+alt1 omega = 2*np.pi/(24*3600) rho1 = np.array(g1a['Rho']) nwind1 = np.array(g1a['V!Dn!N (north)']) ewind1 = np.array(g1a['V!Dn!N (east)']) + omega*RR*np.cos(lat1) vgradrho1 = \ (nwind1*cr.calc_rusanov_lats(lat1,alt1,rho1)\ +ewind1*cr.calc_rusanov_lons(lon1,lat1,alt1,rho1))/rho1 lon2 = np.array(g2a['Longitude']) lat2 = np.array(g2a['Latitude']) alt2 = np.array(g2a['Altitude']) Re = 6371*1000 # Earth radius, unit: m RR = Re+alt2 omega = 2*np.pi/(24*3600) rho2 = np.array(g2a['Rho']) nwind2 = np.array(g2a['V!Dn!N (north)']) ewind2 = np.array(g2a['V!Dn!N (east)']) + omega*RR*np.cos(lat2) vgradrho2 = \ (nwind2*cr.calc_rusanov_lats(lat2,alt2,rho2)\ +ewind2*cr.calc_rusanov_lons(lon2,lat2,alt2,rho2))/rho2 g1a['hozt_vgradrho_diff'] = vgradrho1-vgradrho2 apex = Apex(date=2003) qlat, qlon = apex.convert(-90, 0, source='apex', dest='geo', height=400) plt.close('all') plt.figure(figsize=(7.26, 9.25)) for ialt, alt in enumerate([130, 200, 300, 400, 500, 600]): alt_ind = np.argmin(np.abs(g1a['Altitude'][0, 0, :]/1000-alt)) alt_str = '%6.2f' % (g1a['Altitude'][0, 0, alt_ind]/1000) ax, projection = gcc.create_map( 3, 2, ialt+1, 'polar', nlat=nlat, slat=slat, dlat=10, centrallon=g3ca.calculate_centrallon(g1a, 'polar', useLT=True), coastlines=False) lon0, lat0, zdata0 = g3ca.contour_data('hozt_vgradrho_diff', g1a, alt=alt) fp = (lat0[:,0]>slat) & (lat0[:,0]<nlat) lon0, lat0, zdata0 = lon0[fp, :], lat0[fp,:], zdata0[fp,:] hc = ax.contourf( lon0, lat0, zdata0, np.linspace(-1,1,21)*1e-4, transform=ccrs.PlateCarree(), cmap='seismic', extend='both') hc = plt.colorbar(hc, pad=0.17) hc.formatter.set_powerlimits((0,0)) hc.update_ticks() hc.set_label(r'-$\vec{u}\cdot\frac{\nabla\rho}{\rho}$ (horizontal)') # wind difference lon1, lat1, ewind1, nwind1 = g3ca.vector_data(g1a, 'neutral', alt=alt) lon2, lat2, ewind2, nwind2 = g3ca.vector_data(g2a, 'neutral', alt=alt) lon0, lat0 = lon1, lat1 lon0, lat0, ewind0, nwind0 = g3ca.convert_vector( lon0, lat0, ewind2-ewind1, nwind2-nwind1, plot_type='polar', projection=projection) hq = ax.quiver( lon0, lat0, ewind0, nwind0, scale=1000, scale_units='inches', regrid_shape=20, headwidth=5) ax.quiverkey(hq, 0.93, -0.1, 500, '500 m/s') ax.scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree()) plt.title('%s km' % alt_str, y=1.05) plt.text(0.5, 0.95, 'Time: '+tstring, fontsize=15, horizontalalignment='center', transform=plt.gcf().transFigure) if show: plt.show() if save: plt.savefig(spath+'07_hozt_vgradrho_rho_diff_%s%s.pdf' % (tstrday,tstring)) return
Re = 6371*1000 # Earth radius, unit: m RR = Re+alttp omega = 2*np.pi/(24*3600) rhotp = gall['Rho'] nwindtp = gall['V!Dn!N (north)'] ewindtp = gall['V!Dn!N (east)'] + omega*RR*np.cos(lattp) uwindtp = gall['V!Dn!N (up)'] gall['div_rhov'] = \ -(cr.calc_div_hozt(lontp, lattp, alttp, rhotp*nwindtp, rhotp*ewindtp)\ +cr.calc_div_vert(alttp, rhotp*uwindtp))/rhotp gall['vert_divv'] = -cr.calc_div_vert(alttp, uwindtp) gall['hozt_divv'] = -cr.calc_div_hozt(lontp, lattp, alttp, nwindtp, ewindtp) gall['vert_vgradrho'] = -uwindtp*cr.calc_rusanov_alts_ausm(alttp,rhotp)/rhotp gall['hozt_vgradrho'] = \ -(nwindtp*cr.calc_rusanov_lats(lattp,alttp,rhotp)\ +ewindtp*cr.calc_rusanov_lons(lontp,lattp,alttp,rhotp))/rhotp gp.calc_pressure(gall) gthm = gitm.read(gthmfn) gthm['total energy'] =\ gthm['EUV Heating'] + gthm['Conduction'] + \ gthm['Chemical Heating'] + gthm['Auroral Heating'] + \ gthm['Joule Heating'] - gthm['NO Cooling'] - gthm['O Cooling'] savepath='/Users/guod/tmp/' def multiple_alts_const_alt(): # print('Density and temperature distribution at different heights.') # for alt in [100, 105, 110, 115, 120, 125, 135, 145]: # if not os.path.exists(savepath+str(alt)): # os.mkdir(savepath+str(alt)) # fig, hc = g3ca.test( # gall, alt=alt, contour=True, zstr='Rho',levels=None, vector=True,
def figure5_7(alt=150): times = pd.to_datetime([ '2003-03-22 00:00:00', '2003-03-22 00:30:00', '2003-03-22 01:00:00', '2003-03-22 02:00:00', '2003-03-22 03:00:00', '2003-03-22 06:00:00']) plt.close('all') plt.figure(figsize=(9.5, 9.25)) xtitle = [ r'$-\nabla\cdot w$', r'$-\nabla\cdot u$', r'$-\frac{w\cdot\nabla\rho}{\rho}$', r'$-\frac{u\cdot\nabla\rho}{\rho}$', r'$\frac{\partial \rho}{\rho\partial t}$', r'$\delta\rho$ (%)'] ylabel = times.strftime('%H:%M') qlat, qlon = convert(-90, 0, 0, date=dt.date(2003,3,22), a2g=True) for itime, time in enumerate(times): strtime = time.strftime('%y%m%d_%H%M') fn1 = glob.glob( '/home/guod/simulation_output/momentum_analysis/'\ 'run_no_shrink_iondrift_4_1/data/3DALL_t%s*.bin' % strtime) fn2 = glob.glob( '/home/guod/simulation_output/momentum_analysis/'\ 'run_shrink_iondrift_4_c1/data/3DALL_t%s*.bin' % strtime) g1 = gitm.read(fn1[0]) g2 = gitm.read(fn2[0]) lon1 = g1['Longitude'] lat1 = g1['Latitude'] alt1 = g1['Altitude'] Re = 6371*1000 # Earth radius, unit: m RR = Re+alt1 omega = 2*pi/(24*3600) rho1 = np.array(g1['Rho']) nwind1 = g1['V!Dn!N (north)'] ewind1 = g1['V!Dn!N (east)'] + omega*RR*np.cos(lat1) uwind1 = g1['V!Dn!N (up)'] div_rhov1 = \ (cr.calc_div_hozt(lon1, lat1, alt1, rho1*nwind1, rho1*ewind1)\ +cr.calc_div_vert(alt1, rho1*uwind1))/rho1 vert_divv1 = cr.calc_div_vert(alt1, uwind1) hozt_divv1 = cr.calc_div_hozt(lon1, lat1, alt1, nwind1, ewind1) vert_vgradrho1 = uwind1*cr.calc_rusanov_alts_ausm(alt1,rho1)/rho1 hozt_vgradrho1 = \ (nwind1*cr.calc_rusanov_lats(lat1,alt1,rho1)\ +ewind1*cr.calc_rusanov_lons(lon1,lat1,alt1,rho1))/rho1 dc1 = [ vert_divv1, hozt_divv1, vert_vgradrho1, hozt_vgradrho1, div_rhov1, rho1] lon2 = g2['Longitude'] lat2 = g2['Latitude'] alt2 = g2['Altitude'] Re = 6371*1000 # Earth radius, unit: m RR = Re+alt2 omega = 2*pi/(24*3600) rho2 = g2['Rho'] nwind2 = g2['V!Dn!N (north)'] ewind2 = g2['V!Dn!N (east)'] + omega*RR*np.cos(lat2) uwind2 = g2['V!Dn!N (up)'] div_rhov2 = \ (cr.calc_div_hozt(lon2, lat2, alt2, rho2*nwind2, rho2*ewind2)\ +cr.calc_div_vert(alt2, rho2*uwind2))/rho2 vert_divv2 = cr.calc_div_vert(alt2, uwind2) hozt_divv2 = cr.calc_div_hozt(lon2, lat2, alt2, nwind2, ewind2) vert_vgradrho2 = uwind2*cr.calc_rusanov_alts_ausm(alt2,rho2)/rho2 hozt_vgradrho2 = \ (nwind2*cr.calc_rusanov_lats(lat2,alt2,rho2)\ +ewind2*cr.calc_rusanov_lons(lon2,lat2,alt2,rho2))/rho2 dc2 = [ vert_divv2, hozt_divv2, vert_vgradrho2, hozt_vgradrho2, div_rhov2, rho2] alt_ind = np.argmin(np.abs(alt1[0, 0, :]/1000-alt)) alt_str = '%6.0f' % (alt1[0, 0, alt_ind]/1000) for idc in range(6): lonticklabel = [0, 0, 0, 0] if idc == 0: lonticklabel[3] = lonticklabel[-1]+1 if idc == 5: lonticklabel[1] = lonticklabel[-1]+1 if itime == 0: lonticklabel[0] = lonticklabel[-2]+1 if itime == 5: lonticklabel[2] = lonticklabel[-2]+1 ax, projection = gcc.create_map( 6, 6, itime*6+idc+1, 'polar', nlat=nlat, slat=slat, dlat=10, centrallon=g3ca.calculate_centrallon(g1, 'polar', useLT=True), coastlines=False, lonticklabel=lonticklabel) g1['temp'] = -(dc1[idc] - dc2[idc]) if idc==5: g1['temp'] = 100*(dc1[idc] - dc2[idc])/dc2[idc] lon0, lat0, zdata0 = g3ca.contour_data('temp', g1, alt=alt) fp = (lat0[:,0]>slat) & (lat0[:,0]<nlat) lon0, lat0, zdata0 = lon0[fp, :], lat0[fp,:], zdata0[fp,:] levels = np.linspace(-8,8,21)*1e-5 if idc==5: levels = np.linspace(-30,30,21) hc = ax.contourf( lon0, lat0, zdata0, levels, transform=ccrs.PlateCarree(), cmap='seismic', extend='both') # wind difference alt_ind = np.argmin(np.abs(alt1[0, 0, :]/1000-alt)) alt_str = '%6.0f' % (alt1[0, 0, alt_ind]/1000) lon1, lat1, ewind1, nwind1 = g3ca.vector_data( g1, 'neutral', alt=alt) lon2, lat2, ewind2, nwind2 = g3ca.vector_data( g2, 'neutral', alt=alt) lon0, lat0 = lon1, lat1 lon0, lat0, ewind0, nwind0 = g3ca.convert_vector( lon0, lat0, ewind1-ewind2, nwind1-nwind2, plot_type='polar', projection=projection) hq = ax.quiver( lon0, lat0, ewind0, nwind0, scale=1500, scale_units='inches', regrid_shape=20, headwidth=5) ax.scatter( qlon, qlat, s=10, color='k', transform=ccrs.PlateCarree()) ax.scatter( 0, -90, color='w', s=10, transform=ccrs.PlateCarree(), zorder=1000) if idc==0: plt.text( -0.3, 0.5, ylabel[itime], rotation=90, transform=ax.transAxes, verticalalignment='center') if itime==0: plt.title(xtitle[idc], y=1.15, fontsize=14) texts = ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)'] plt.text(0.05,1,texts[idc],transform=plt.gca().transAxes, color='r') if itime==5: axp = ax.get_position() cax = [axp.x0, axp.y0-0.03, axp.x1-axp.x0, 1/20*(axp.y1-axp.y0)] cax = plt.axes(cax) ticks = np.arange(-8e-5, 8.1e-5, 4e-5) if idc<5 else \ np.arange(-30, 31, 15) hcb = plt.colorbar( hc, cax=cax, extendrect=True, orientation='horizontal', ticks=ticks) if idc<5: hcb.formatter.set_powerlimits((0,0)) hcb.update_ticks() plt.subplots_adjust(wspace=0, hspace=0) if alt==300: plt.savefig(savepath+'Figure5.eps') plt.savefig(savepath+'Figure5.jpeg') if alt==600: plt.savefig(savepath+'Figure7.eps') plt.savefig(savepath+'Figure7.jpeg') return