'2003-03-22 00:00:00', '2003-03-22 04:00:00', freq='10min') spath = '/home/guod/Documents/work/fig/density_cell/'\ 'why_no_low_density_cell_at_high_latitude/lat_alt/' outpdf_vert_wind = PdfFileMerger() outpdf_rho_diff = PdfFileMerger() outpdf_divrhov_rho_diff = PdfFileMerger() outpdf_vert_divv_diff = PdfFileMerger() outpdf_hozt_divv_diff = PdfFileMerger() outpdf_vert_vgradrho_diff = PdfFileMerger() outpdf_hozt_vgradrho_diff = PdfFileMerger() for t in trange: tstring = t.strftime('%H%M') filename = glob.glob( '/media/guod/wd2t/simulation_output/momentum_analysis/run_shrink_iondrift_4_c1'\ '/data/3DALL_t030322_%s*.bin' % tstring)[0] g1a = gitm.GitmBin(filename) filename = glob.glob( '/media/guod/wd2t/simulation_output/momentum_analysis/run_no_shrink_iondrift_4_1'\ '/data/3DALL_t030322_%s*.bin' % tstring)[0] g2a = gitm.GitmBin(filename) # plot_vertical_wind(show=False, save=True) # outpdf_vert_wind.append(PdfFileReader(open(spath+'02_vertical_wind_diff_%s.pdf' % tstring, 'rb'))) # plot_rho_diff(show=False, save=True) # outpdf_rho_diff.append(PdfFileReader(open(spath+'01_rho_diff_%s.pdf' % tstring, 'rb'))) # plot_divrhov_rho_diff(show=False, save=True) # outpdf_divrhov_rho_diff.append(PdfFileReader(open(spath+'03_divrhov_rho_diff_%s.pdf' % tstring, 'rb'))) # plot_vert_divv_diff(show=False, save=True) # outpdf_vert_divv_diff.append(PdfFileReader(open(spath+'04_vert_divv_diff%s.pdf' % tstring, 'rb'))) # plot_hozt_divv_diff(show=False, save=True) # outpdf_hozt_divv_diff.append(PdfFileReader(open(spath+'05_hozt_divv_diff%s.pdf' % tstring, 'rb'))) plot_vert_vgradrho_rho_diff(show=False, save=True)
import gitm import gitm_gradient as gg import gitm_divergence as gd import gitm_3D_const_alt as g3ca import gitm_create_coordinate as gcc import cartopy.crs as ccrs import numpy as np import matplotlib.pyplot as plt Re = 6371*1000 RR = Re+400000 g = gitm.GitmBin('/home/guod/big/raid4/guod/run_imfby/run2c/data/' '3DALL_t100323_013000.bin', varlist=[ 'Rho', 'V!Dn!N (north)', 'V!Dn!N (east)', 'V!Dn!N (up)']) gg.calc_gradient(g, 'Rho', 'gradn', component='north') gg.calc_gradient(g, 'Rho', 'grade', component='east') gg.calc_gradient(g, 'Rho', 'gradr', component='radial') gd.calc_divergence(g, neuion='neutral', name='divergence') lon0, lat0, ewind0 = g3ca.contour_data('V!Dn!N (east)', g, alt=400) lon0, lat0, nwind0 = g3ca.contour_data('V!Dn!N (north)', g, alt=400) lon0, lat0, uwind0 = g3ca.contour_data('V!Dn!N (up)', g, alt=400) ewind0 = ewind0 + ((2*np.pi)/(24*3600))*RR+np.cos(lat0*np.pi/180) lon0, lat0, gradn0 = g3ca.contour_data('gradn', g, alt=400) lon0, lat0, grade0 = g3ca.contour_data('grade', g, alt=400) lon0, lat0, gradr0 = g3ca.contour_data('gradr', g, alt=400) lon0, lat0, rho0 = g3ca.contour_data('Rho', g, alt=400) lon0, lat0, div0 = g3ca.contour_data('divergence', g, alt=400) hadvect = ewind0 * grade0 + nwind0 * gradn0
def animate_vert_divv(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) alt1 = np.array(g1['Altitude']) uwind1 = np.array(g1['V!Dn!N (up)']) divv1 = cr.calc_div_vert(alt1, uwind1) alt2 = np.array(g2['Altitude']) uwind2 = np.array(g2['V!Dn!N (up)']) divv2 = cr.calc_div_vert(alt2, uwind2) g1['divv'] = divv1 - divv2 lon0, lat0, divv = g3ca.contour_data('divv', g1, alt=which_alt) hc = ax[0].contourf(lon0, lat0, divv, 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, divv, 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 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 = uwind1 * cr.calc_rusanov_alts_ausm(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 = uwind2 * cr.calc_rusanov_alts_ausm(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 animate_den_wind(i): g1, g2 = [gitm.GitmBin(k[i]) for k in [fn1, fn2]] # create axis ax = [1, 2, 3, 4, 5, 6, 7, 8, 9] projection = ax.copy() for ialts in range(3): for ird in range(2): # run2 or diff centrallon = g3ca.calculate_centrallon(g1, 'polar', useLT=True) ax[ialts * 2 + ird], projection[ialts * 2 + ird] = gcc.create_map( 3, 2, 1 + ialts * 2 + ird, 'polar', nlat=nlat, slat=slat, dlat=10, centrallon=centrallon, coastlines=False) ax[ialts * 2 + ird].scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree()) ax[0].set_title(g1['time'].strftime('%d-%b-%y %H:%M') + ' UT', y=1.05) ax[1].set_title(g1['time'].strftime('%d-%b-%y %H:%M') + ' UT', y=1.05) #ax[2].set_title(g1['time'].strftime('%d-%b-%y %H:%M')+' UT', y=1.05) # Density and diff for ialt, alt in enumerate(alts): lon1, lat1, zdata1 = g3ca.contour_data('Rho', g1, alt=alt) lon2, lat2, zdata2 = g3ca.contour_data('Rho', g2, alt=alt) diffzdata = 100 * (zdata2 - zdata1) / zdata1 hc = ax[ialt * 2].contourf(lon1, lat1, zdata2, transform=ccrs.PlateCarree(), levels=rholevels[ialt], cmap='jet', extend='both') hc = ax[ialt * 2 + 1].contourf(lon2, lat2, diffzdata, transform=ccrs.PlateCarree(), levels=np.linspace(-20, 20, 21), cmap='seismic', extend='both') # density change rate # for ialt, alt in enumerate(alts): # 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) # uwind1 = np.array(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 # 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) # uwind2 = np.array(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 # g1['divrhov_diff'] = div_rhov1-div_rhov2 # lon2, lat2, zdata2 = g3ca.contour_data('divrhov_diff', g1, alt=alt) # hc = ax[ialt*3+2].contourf( # lon2, lat2, zdata2, transform=ccrs.PlateCarree(), # levels=np.linspace(-1,1,21)*1e-4, cmap='seismic', extend='both') # wind for ialt, alt in enumerate(alts): lon1, lat1, ewind1, nwind1 = \ g3ca.vector_data(g1, 'neutral', alt=alt) lon2, lat2, ewind2, nwind2 = \ g3ca.vector_data(g2, 'neutral', alt=alt) lon0, lat0, ewind, nwind = (lon2.copy(), lat2.copy(), ewind2.copy(), nwind2.copy()) lon0, lat0, ewind, nwind = g3ca.convert_vector( lon0, lat0, ewind, nwind, plot_type='polar', projection=projection[ialt * 2]) hq = ax[ialt * 2].quiver(lon0, lat0, ewind, nwind, scale=1500, scale_units='inches', color='k', regrid_shape=20) lon0, lat0, ewind, nwind = (lon1.copy(), lat1.copy(), ewind2 - ewind1, nwind2 - nwind1) lon0, lat0, ewind, nwind = g3ca.convert_vector( lon0, lat0, ewind, nwind, plot_type='polar', projection=projection[ialt * 2 + 1]) hq = ax[ialt * 2 + 1].quiver(lon0, lat0, ewind, nwind, scale=1500, scale_units='inches', color='k', regrid_shape=20) return
def animate_vert_wind(i): g1, g2 = [gitm.GitmBin(k[i]) for k in [fn1, fn2]] # create axis ax = list(range(6)) projection = ax.copy() for ins in range(2): nlat, slat = [90, 40] if ins == 0 else [-40, -90] for irun in range(3): ax[ins + irun * 2], projection[ins + irun * 2] = gcc.create_map( 3, 2, 1 + ins + irun * 2, 'polar', nlat=nlat, slat=slat, dlat=10, centrallon=g3ca.calculate_centrallon(g1, 'polar', useLT=True), coastlines=False) # vertical wind lon1, lat1, zdata1 = g3ca.contour_data('V!Dn!N (up)', g1, alt=which_alt) lon2, lat2, zdata2 = g3ca.contour_data('V!Dn!N (up)', g2, alt=which_alt) hc = [ ax[k].contourf( lon1, lat1, zdata1, 21, transform=ccrs.PlateCarree(), levels=np.linspace(-20, 20, 21), #levels=np.linspace(15e-13, 25e-13, 21), cmap='seismic', extend='both') for k in [0, 1] ] ax[0].set_title(g1['time'].strftime('%d-%b-%y %H:%M') + ' UT', y=1.05) ax[1].set_title(g1['time'].strftime('%d-%b-%y %H:%M') + ' UT', y=1.05) hc = [ ax[k].contourf(lon2, lat2, zdata2, 21, transform=ccrs.PlateCarree(), levels=np.linspace(-20, 20, 21), cmap='seismic', extend='both') for k in [2, 3] ] diffzdata = zdata2 - zdata1 hc = [ ax[k].contourf(lon2, lat2, diffzdata, 21, transform=ccrs.PlateCarree(), levels=np.linspace(-20, 20, 21), cmap='seismic', extend='both') for k in [4, 5] ] # 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(lon2, lat2, diffrho, [-10], transform=ccrs.PlateCarree(), colors='g', linestyles='-') for k in [4, 5] ] # wind lon1, lat1, ewind1, nwind1 = g3ca.vector_data(g1, 'neutral', alt=which_alt) lon2, lat2, ewind2, nwind2 = g3ca.vector_data(g2, 'neutral', alt=which_alt) for iax in range(6): if iax == 0 or iax == 1: lon0, lat0, ewind, nwind = (lon1.copy(), lat1.copy(), ewind1.copy(), nwind1.copy()) lon0, lat0, ewind, nwind = g3ca.convert_vector( lon0, lat0, ewind, nwind, plot_type='polar', projection=projection[iax]) elif iax == 2 or iax == 3: lon0, lat0, ewind, nwind = (lon2.copy(), lat2.copy(), ewind2.copy(), nwind2.copy()) lon0, lat0, ewind, nwind = g3ca.convert_vector( lon0, lat0, ewind, nwind, plot_type='polar', projection=projection[iax]) elif iax == 4 or iax == 5: lon0, lat0, ewind, nwind = (lon1.copy(), lat1.copy(), ewind2 - ewind1, nwind2 - nwind1) lon0, lat0, ewind, nwind = g3ca.convert_vector( lon0, lat0, ewind, nwind, plot_type='polar', projection=projection[iax]) hq = ax[iax].quiver(lon0, lat0, ewind, nwind, scale=1500, scale_units='inches', color='k', regrid_shape=20) # ax.quiverkey(hq, 0.93, 0, 1000, '1000 m/s') # hc = plt.colorbar(hc, ticks=np.arange(3, 7)*1e-12) # hc.set_label(r'$\rho$ (kg/m$^3$)') # ax[iax].scatter( # qlonn, qlatn, color='k', transform=ccrs.PlateCarree()) # ax[iax].scatter( # qlons, qlats, color='k', transform=ccrs.PlateCarree()) return
import matplotlib.pyplot as plt import gitm import numpy as np import seaborn as sns import calc_rusanov as cr sns.set('paper', 'whitegrid') plt.close('all') plt.figure(figsize=(6.5, 7.2)) fn1 = '/home/guod/simulation_output/momentum_analysis/'\ 'run_shrink_iondrift_4_c1/data/3DALL_t030322_060000.bin' fn2 = '/home/guod/simulation_output/momentum_analysis/'\ 'run_no_shrink_iondrift_4_1/data/3DALL_t030322_060000.bin' g1 = gitm.GitmBin(fn1) g2 = gitm.GitmBin(fn2) g1['diffrho'] = 100 * (g2['Rho'] - g1['Rho']) / g1['Rho'] color = ['b', 'r'] for ig, g in enumerate([g1, g2]): lons, lats, alts = (g[k] for k in ['Longitude', 'Latitude', 'Altitude']) rho = g['Rho'] nlat, slat = -30, -90 for i, alt in enumerate([130, 300, 600]): ax1 = plt.subplot(3, 2, i * 2 + 1) ax2 = plt.subplot(3, 2, i * 2 + 2) lt = 6 ilt = np.argmin(np.abs(g['LT'][2:-2, 0, 0] - lt)) + 2 ialt = np.argmin(np.abs(alts[0, 0, 2:-2] / 1000 - alt)) + 2 ilat = (lats[0, :, 0] / np.pi * 180 < nlat) & (lats[0, :, 0] / np.pi * 180 > slat) ax1.plot(180 + lats[ilt, ilat, ialt] / np.pi * 180,
gdata[name] = dmarray(vort, attrs={ 'units': 'm/s^2', 'scale': 'linear', 'name': neuion + ' velocity ' + component + ' vorticity' }) return #END if __name__ == '__main__': fn = '/home/guod/big/raid4/guod/run_imfby/run2c/data/3DALL_t100323_042000.bin' gdata = gitm.GitmBin(fn) calc_vorticity(gdata, 'neu', name='nvorticity', component='radial') alt = 200 nlat = 90 slat = 50 centrallon = g3ca.calculate_centrallon(gdata, 'polar', useLT=True) ax, projection = gcc.create_map(1, 1, 1, plot_type='polar', nlat=nlat, slat=slat, centrallon=centrallon, coastlines=False, dlat=10)
divvar = calc_rusanov_alts_ausm(alts, var)\ + 2*var/rdist return divvar if __name__ == '__main__': import gitm import numpy as np import gitm_create_coordinate as gcc from cartopy.util import add_cyclic_point import cartopy.crs as ccrs import matplotlib.pyplot as plt import gitm_divergence_new as gd alt = 400 g1 = gitm.GitmBin( '/home/guod/simulation_output/momentum_analysis/' 'run_shrink_iondrift_3_continue/data/3DALL_t030322_013000.bin') alt_ind = np.argmin(np.abs(g1['Altitude'][0, 0, :] - alt * 1000)) lons, lats, alts = (g1[k] for k in ['Longitude', 'Latitude', 'Altitude']) veln = g1['V!Dn!N (north)'] vele = g1['V!Dn!N (east)'] + (2 * np.pi) / (24 * 3600) * ( 6371 * 1000 + alts) * np.cos(lats) velu = g1['V!Dn!N (up)'] rho = g1['Rho'] zdata1 = calc_div_vert(alts, rho * velu) + calc_div_hozt( lons, lats, alts, rho * veln, rho * vele) dglat = np.array(g1['dLat'][0, 2:-2, 0]) dglon = np.array(g1['dLon'][2:-2, 0, 0]) zdata1, dglon = add_cyclic_point(zdata1[2:-2, 2:-2, alt_ind].T, coord=dglon,