Пример #1
0
def f4():
    plt.figure(figsize=(6.88,6.74))
    #geographic coordinates
    ax1, projection1 = gcc.create_map(
        2, 2, 1, 'pol', 90, 50, 0, coastlines=False,useLT=True,
        dlat=10, lonticklabel=(1, 1, 1, 1))
    ax1.plot([45,45],[50,90], 'k--',transform=ccrs.PlateCarree())
    ax1.plot([225,225],[50,90], 'k--',transform=ccrs.PlateCarree())
    ax1.plot([105,105],[50,90], 'k--',transform=ccrs.PlateCarree())
    ax1.plot([285,285],[50,90], 'k--',transform=ccrs.PlateCarree())
    ax1.scatter(
        0, 90, color='r', transform=ccrs.PlateCarree(), zorder=10,
        label='North Pole')
    ax1.text(0,1,'(a)', transform = plt.gca().transAxes)
    plt.legend(loc=[0.5,1.1])

    ax2, projection2 = gcc.create_map(
        2, 2, 2, 'pol', -50, -90, 0, coastlines=False,useLT=True,
        dlat=10, lonticklabel=(1, 1, 1, 1))
    ax2.scatter(
        0, -90, color='b', transform=ccrs.PlateCarree(),label='South Pole')
    ax2.text(0,1,'(b)', transform = plt.gca().transAxes)
    plt.legend(loc=[-0.1,1.1])

    #geomagnetic coordinates
    ax3, projection3 = gcc.create_map(
        2, 2, 3, 'pol', 90, 50, 0, coastlines=False,useLT=True,
        dlat=10, lonticklabel=(1, 1, 1, 1))
    mlatn,mlonn = convert(90,0,0,date=dt.date(2002,3,21))
    for k in range(24):
        mltn = convert_mlt(mlonn[0],dtime=dt.datetime(2003,3,21,k))
        ax3.scatter(mltn*15,mlatn[0],color='r',transform=ccrs.PlateCarree())
    ax3.scatter(180,75,s=50,c='k',marker='x',transform=ccrs.PlateCarree())
    ax3.text(0,1,'(c)', transform = plt.gca().transAxes)

    ax4, projection4 = gcc.create_map(
        2, 2, 4, 'pol', -50, -90, 0, coastlines=False,useLT=True,
        dlat=10, lonticklabel=(1, 1, 1, 1))
    mlats,mlons = convert(-90,0,0,date=dt.date(2002,3,21))
    for k in range(24):
        mlts = convert_mlt(mlons[0],dtime=dt.datetime(2003,3,21,k))
        ax4.scatter(mlts*15,mlats[0],color='b',transform=ccrs.PlateCarree())
    ax4.scatter(180,-75,s=50,c='k',marker='x',transform=ccrs.PlateCarree())
    ax4.text(0,1,'(d)', transform = plt.gca().transAxes)
    plt.savefig(
        '/Users/guod/Documents/Pole_Density_MLT_Change/Figures/'
        '000_Pole_Feature.pdf')
    return
Пример #2
0
def plot_ion_drift(show=True,save=True):
    apex = Apex(date=2003)
    qlat, qlon = apex.convert(-90, 0, source='apex', dest='geo', height=400)
    g = g2a

    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(g['Altitude'][0, 0, :]/1000-alt))
        alt_str = '%6.2f' % (g['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(g, 'polar',  useLT=True),
                coastlines=False)
        lon0, lat0, ewind, nwind = g3ca.vector_data(g, 'ion', alt=alt)
        lon0, lat0, ewind, nwind = g3ca.convert_vector(
                lon0, lat0, ewind, nwind, plot_type='polar',
                projection=projection)
        hq = ax.quiver(
                lon0, lat0, ewind, nwind, scale=1500, scale_units='inches',
                regrid_shape=20, headwidth=5)
        ax.quiverkey(hq, 0.93, -0.1, 1000, '1000 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+'03_ion_drift_%s%s.pdf' % (tstrday,tstring))
    return
Пример #3
0
def plot_polar_contour_vector_diff(nrow,
                                   ncol,
                                   iax,
                                   g1,
                                   g2,
                                   nlat,
                                   slat,
                                   alt,
                                   contour=True,
                                   zstr='Rho',
                                   vector=True,
                                   neuion='neu',
                                   useLT=True,
                                   coastlines=False,
                                   N=21,
                                   levels=None):
    # g1 and g2 have the same time, the same grid

    centrallon = g3ca.calculate_centrallon(g1, 'pol', useLT)
    ax, projection = gcc.create_map(nrow,
                                    ncol,
                                    iax,
                                    'pol',
                                    nlat,
                                    slat,
                                    centrallon,
                                    coastlines=coastlines,
                                    dlat=10,
                                    useLT=useLT,
                                    lonticklabel=(1, 1, 1, 1))
    hc = []
    hq = []
    # contour
    if contour:
        lon0, lat0, zdata1 = g3ca.contour_data(zstr, g1, alt=alt)
        lon0, lat0, zdata2 = g3ca.contour_data(zstr, g2, alt=alt)
        cb = N if levels is None else levels
        hc.append(
            ax.contourf(lon0,
                        lat0,
                        100 * (zdata2 - zdata1) / zdata1,
                        cb,
                        transform=ccrs.PlateCarree(),
                        cmap='jet',
                        extend='both'))
    # vector
    if vector:
        lon0, lat0, ewind1, nwind1 = g3ca.vector_data(g1, neuion, alt=alt)
        lon0, lat0, ewind2, nwind2 = g3ca.vector_data(g2, neuion, alt=alt)
        lon0, lat0, ewind0, nwind0 = g3ca.convert_vector(
            lon0, lat0, ewind2 - ewind1, nwind2 - nwind1, 'pol', projection)
        hq.append(
            ax.quiver(lon0,
                      lat0,
                      ewind0,
                      nwind0,
                      scale=1500,
                      scale_units='inches',
                      regrid_shape=20))
    return ax, projection, hc, hq
Пример #4
0
def plot_polar_contour_vector_diff(
    nrow, ncol, iax, g1, g2, nlat, slat, alt, contour=True, zstr='Rho',
    vector=True, neuion='neu', useLT=True, coastlines=False, N=21, levels=None):
    # g1 and g2 have the same time, the same grid

    centrallon = g3ca.calculate_centrallon(g1, 'pol', useLT)
    ax, projection = gcc.create_map(
            nrow, ncol, iax, 'pol', nlat, slat, centrallon,
            coastlines=coastlines, dlat=10,
            useLT=useLT, lonticklabel=(1, 1, 1, 1))
    hc = []
    hq = []
    # contour
    if contour:
        lon0, lat0, zdata1 = g3ca.contour_data(zstr, g1, alt=alt)
        lon0, lat0, zdata2 = g3ca.contour_data(zstr, g2, alt=alt)
        cb = N if levels is None else levels
        hc.append(ax.contourf(lon0, lat0, 100*(zdata2-zdata1)/zdata1, cb,
            transform=ccrs.PlateCarree(),cmap='jet', extend='both'))
    # vector
    if vector:
        lon0, lat0, ewind1, nwind1 = g3ca.vector_data(g1,neuion,alt=alt)
        lon0, lat0, ewind2, nwind2 = g3ca.vector_data(g2,neuion,alt=alt)
        lon0, lat0, ewind0, nwind0 = g3ca.convert_vector(
            lon0, lat0, ewind2-ewind1, nwind2-nwind1, 'pol', projection)
        hq.append(ax.quiver(
            lon0,lat0,ewind0,nwind0,scale=1500,scale_units='inches',
            regrid_shape=20))
    return ax, projection, hc, hq
Пример #5
0
def plot_temperature():
    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))
    g = g2a
    alts = [130, 400]
    for ialt, alt in enumerate(alts):
        alt_ind = np.argmin(np.abs(g['Altitude'][0, 0, 2:-2]/1000-alt))+2
        alt_str = '%6.2f' % (g['Altitude'][0, 0, alt_ind]/1000)
        ax, projection = gcc.create_map(
                1, 2, ialt+1, 'polar', nlat=nlat, slat=slat, dlat=10,
                centrallon=g3ca.calculate_centrallon(g, 'polar',  useLT=True),
                coastlines=False)
        lon0, lat0, zdata0 = g3ca.contour_data('Temperature', g, alt=alt)
        fp = (lat0[:,0]>slat) & (lat0[:,0]<nlat)
        lon0, lat0, zdata0 = lon0[fp, :], lat0[fp,:], zdata0[fp,:]
        hc = ax.contourf(lon0, lat0, zdata0, 21,
                         transform=ccrs.PlateCarree(), cmap='jet',
                         extend='both')
        hc = plt.colorbar(hc, pad=0.17)
        hc.set_label('Temperature (K)')
        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: '+titletime, fontsize=15,
            horizontalalignment='center', transform=plt.gcf().transFigure)
    plt.show()
    return
Пример #6
0
    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)
Пример #7
0
def plot_vert_vgradrho_rho_diff(show=True, save=True):
    rho1 = np.array(g1a['Rho'])
    vgradrho1 = \
        g1a['V!Dn!N (up)'] \
        * cr.calc_rusanov_alts_ausm(g1a['Altitude'],rho1)/g1a['Rho']

    rho2 = np.array(g2a['Rho'])
    vgradrho2 = \
        g2a['V!Dn!N (up)']\
        * cr.calc_rusanov_alts_ausm(g2a['Altitude'],rho2)/g2a['Rho']

    g1a['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('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')
        hcb = plt.colorbar(hc, pad=0.17)
        hcb.formatter.set_powerlimits((0,0))
        hcb.update_ticks()
        hcb.set_label(r'$-\vec{u}\cdot\frac{\nabla\rho}{\rho}$ (up)')
        # 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+'06_vert_vgradrho_rho_diff_%s%s.pdf' % (tstrday,tstring))
    return
Пример #8
0
def plot_vert_vgradrho_rho_diff(show=True, save=True):
    rho1 = np.array(g1a['Rho'])
    vgradrho1 = \
        g1a['V!Dn!N (up)']\
        *cr.calc_rusanov_alts_ausm(g1a['Altitude'],rho1)/g1a['Rho']

    rho2 = np.array(g2a['Rho'])
    vgradrho2 = \
        g2a['V!Dn!N (up)']\
        *cr.calc_rusanov_alts_ausm(g2a['Altitude'],rho2)/g2a['Rho']

    g1a['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))
    plt.figure(figsize=(8.97, 3.45))
    alts = [130, 400]
    for ialt, alt in enumerate(alts):
        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(
            1, 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('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')
        hcb = plt.colorbar(hc, pad=0.17)
        hcb.formatter.set_powerlimits((0,0))
        hcb.update_ticks()
        hcb.set_label(r'$-\vec{u}\cdot\frac{\nabla\rho}{\rho}$ (up)')

        # 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, 300, '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: '+titletime, fontsize=15,
            horizontalalignment='center', transform=plt.gcf().transFigure)
    plt.show()
    return
Пример #9
0
def plot_temperature_diff(show=True, save=True):
    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)
        # temperature diff
        lon1, lat1, zdata1 = g3ca.contour_data('Temperature', g1a, alt=alt)
        lon2, lat2, zdata2 = g3ca.contour_data('Temperature', g2a, alt=alt)
        fp = (lat1[:,0]>slat) & (lat1[:,0]<nlat)
        lon0, lat0, zdata0 = lon1[fp, :], lat1[fp,:], (zdata2-zdata1)[fp,:]
        hc = ax.contourf(
            lon0, lat0, zdata0, np.linspace(-80,80,21),
            transform=ccrs.PlateCarree(), cmap='seismic', extend='both')
        hc = plt.colorbar(hc, pad=0.17)
        hc.set_label(r'$T_2-T_1$ (K)')
        # geomagnetic pole
        ax.scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree())

        # 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')

        # rho difference
        #lon3, lat3, zdata3 = g3ca.contour_data('Rho', g1a, alt=alt)
        #lon4, lat4, zdata4 = g3ca.contour_data('Rho', g2a, alt=alt)
        #diffrho = 100*(zdata4-zdata3)/zdata3
        #hc = ax.contour(
        #        lon4, lat4, diffrho, [-10], transform=ccrs.PlateCarree(),
        #        colors='g',linestyles='-')
        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+'02_temperature_diff_%s%s.pdf' % (tstrday,tstring))
    return
Пример #10
0
def plot_den_win_diff():
    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))
    plt.figure(figsize=(8.97, 3.45))
    alts = [130, 400]
    for ialt, alt in enumerate(alts):
        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(
                1, 2, ialt+1, 'polar', nlat=nlat, slat=slat, dlat=10,
                centrallon=g3ca.calculate_centrallon(g1a, 'polar',  useLT=True),
                coastlines=False)
        # density difference
        lon1, lat1, zdata1 = g3ca.contour_data('Rho', g1a, alt=alt)
        lon2, lat2, zdata2 = g3ca.contour_data('Rho', g2a, alt=alt)
        fp = (lat1[:,0]>slat) & (lat1[:,0]<nlat)
        lon0, lat0, zdata0 = lon1[fp, :], lat1[fp,:], \
                             (100*(zdata2-zdata1)/zdata1)[fp,:]
        hc = ax.contourf(lon0, lat0, zdata0, np.linspace(-20,20,21),
                         transform=ccrs.PlateCarree(), cmap='seismic',
                         extend='both')
        hc = plt.colorbar(hc, pad=0.17)
        hc.set_label(r'$100*\frac{\rho2-\rho1}{\rho1}$ (%)')
        # 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=500, scale_units='inches',
                regrid_shape=20,headwidth=5)
        ax.quiverkey(hq, 0.93, -0.1, 500, '500m/s')
        ax.scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree())
        # rho difference
        # lon3, lat3, zdata3 = g3ca.contour_data('Rho', g1a, alt=alt)
        # lon4, lat4, zdata4 = g3ca.contour_data('Rho', g2a, alt=alt)
        # diffrho = 100*(zdata4-zdata3)/zdata3
        # hc = ax.contour(
        #         lon4, lat4, diffrho, [-10], transform=ccrs.PlateCarree(),
        #         colors='g',linestyles='-')

        plt.title('%s km' % alt_str, y=1.05)
    plt.text(0.5, 0.95, 'Time: '+titletime, fontsize=15,
            horizontalalignment='center', transform=plt.gcf().transFigure)
    plt.show()
    return
Пример #11
0
def plot_den_win(show=True, save=True):
    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))
    g = g2a
    for ialt, alt in enumerate([130, 200, 300, 400, 500, 600]):
        alt_ind = np.argmin(np.abs(g['Altitude'][0, 0, 2:-2]/1000-alt))+2
        alt_str = '%6.2f' % (g['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(g, 'polar',  useLT=True),
                coastlines=False)
        # density
        lon0, lat0, zdata0 = g3ca.contour_data('Rho', g, alt=alt)
        fp = (lat0[:,0]>slat) & (lat0[:,0]<nlat)
        lon0, lat0, zdata0 = lon0[fp, :], lat0[fp,:], zdata0[fp,:]
        hc = ax.contourf(lon0, lat0, zdata0, 21,
                         transform=ccrs.PlateCarree(), cmap='jet',
                         extend='both')
        hc = plt.colorbar(hc, pad=0.17)
        hc.set_label(r'$\rho$ (kg/m$^3$)')

        # wind
        lon0, lat0, ewind, nwind = g3ca.vector_data(g, 'neutral', alt=alt)
        lon0, lat0, ewind, nwind = g3ca.convert_vector(
                lon0, lat0, ewind, nwind, plot_type='polar',
                projection=projection)
        hq = ax.quiver(
                lon0, lat0, ewind, nwind, scale=1500, scale_units='inches',
                regrid_shape=20)
        ax.quiverkey(hq, 0.93, -0.1, 1000, '1000 m/s')
        ax.scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree())

        # rho difference
        # lon3, lat3, zdata3 = g3ca.contour_data('Rho', g1a, alt=alt)
        # lon4, lat4, zdata4 = g3ca.contour_data('Rho', g2a, alt=alt)
        # diffrho = 100*(zdata4-zdata3)/zdata3
        # hc = ax.contour(
        #         lon4, lat4, diffrho, [-10], transform=ccrs.PlateCarree(),
        #         colors='g',linestyles='-')
        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+'01_den_win_run2_%s%s.pdf' %(tstrday,tstring))
    return
Пример #12
0
def plot_ion_drift(show=True, save=True):
    apex = Apex(date=2003)
    qlat, qlon = apex.convert(-90, 0, source='apex', dest='geo', height=400)
    g = g2a

    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(g['Altitude'][0, 0, :] / 1000 - alt))
        alt_str = '%6.2f' % (g['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(
                                            g, 'polar', useLT=True),
                                        coastlines=False)
        lon0, lat0, ewind, nwind = g3ca.vector_data(g, 'ion', alt=alt)
        lon0, lat0, ewind, nwind = g3ca.convert_vector(lon0,
                                                       lat0,
                                                       ewind,
                                                       nwind,
                                                       plot_type='polar',
                                                       projection=projection)
        hq = ax.quiver(lon0,
                       lat0,
                       ewind,
                       nwind,
                       scale=1500,
                       scale_units='inches',
                       regrid_shape=20,
                       headwidth=5)
        ax.quiverkey(hq, 0.93, -0.1, 1000, '1000 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 + '03_ion_drift_%s%s.pdf' % (tstrday, tstring))
    return
Пример #13
0
def plot_temperature_diff():
    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))
    plt.figure(figsize=(10.3,4.3))
    alts = [130, 400]
    for ialt, alt in enumerate(alts):
        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(
                1, 2, ialt+1, 'polar', nlat=nlat, slat=slat, dlat=10,
                centrallon=g3ca.calculate_centrallon(g1a, 'polar',  useLT=True),
                coastlines=False)
        # temperature diff
        lon1, lat1, zdata1 = g3ca.contour_data('Temperature', g1a, alt=alt)
        lon2, lat2, zdata2 = g3ca.contour_data('Temperature', g2a, alt=alt)
        fp = (lat1[:,0]>slat) & (lat1[:,0]<nlat)
        lon0, lat0, zdata0 = lon1[fp, :], lat1[fp,:], (zdata2-zdata1)[fp,:]
        hc = ax.contourf(lon0, lat0, zdata0, np.linspace(-80,80,21),
                         transform=ccrs.PlateCarree(), cmap='seismic',
                         extend='both')
        hc = plt.colorbar(hc, pad=0.17)
        hc.set_label(r'$T_2-T_1$ (K)')
        # geomagnetic pole
        ax.scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree())
        # 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, 300, '500 m/s')
        # rho difference
        plt.title('%s km' % alt_str, y=1.05)
    plt.text(0.5, 0.95, 'Time: '+titletime, fontsize=15,
            horizontalalignment='center', transform=plt.gcf().transFigure)
    plt.show()
    return
Пример #14
0
def test(g, alt=400, contour=True, zstr='Rho',levels=None, vector=True,
         neuion='neu', scale=500, useLT=True):
    import gitm_create_coordinate as gcc
    import matplotlib.pyplot as plt
    plt.close('all')
    fig = plt.figure(figsize=[8.38,8.12])
    # Tested parameters
    polar = [True, True, False]
    nrow = [2,2,2]
    ncol = [2,2,1]
    nax = [1,2,2]
    nlat = [90, -30, 90]
    slat = [30, -90, -90]
    dlat = [10, 10, 30]
    for k in range(3):
        ipolar = polar[k]
        pr = 'pol' if ipolar else 'rec'
        centrallon = calculate_centrallon(g, pr, useLT)
        ax, projection = gcc.create_map(
                nrow[k],ncol[k],nax[k], pr, nlat[k], slat[k], centrallon,
                coastlines=False, dlat=dlat[k],
                useLT=useLT, lonticklabel=(1, 1, 1, 1))
        ialt = np.argmin(np.abs(g['Altitude'][0,0,:]/1000-alt))
        # contour
        if contour:
            lon0, lat0, zdata0 = contour_data(zstr, g, ialt=ialt)
            fplat = (lat0[:,0]>=slat[k]) & (lat0[:,0]<=nlat[k])
            lon0, lat0, zdata0 = (k[fplat,:] for k in [lon0, lat0, zdata0])
            hc = ax.contourf(lon0, lat0, zdata0, 21 if levels is None else levels,
                    transform=ccrs.PlateCarree(),cmap='jet', extend='both')
            print(np.max(zdata0), np.min(zdata0))
        # vector
        if vector:
            lon0, lat0, ewind0, nwind0 = vector_data(g,neuion,alt=alt)
            lon0, lat0, ewind0, nwind0 = convert_vector(
                lon0, lat0, ewind0, nwind0, pr, projection)
            hq = ax.quiver(
                lon0,lat0,ewind0,nwind0,scale=scale,scale_units='inches',
                regrid_shape=20)

        # title
        plt.title(zstr+' at '+'%.2f km' % (g['Altitude'][0,0,ialt]/1000),y=1.05)
    plt.show()
    return fig, hc
Пример #15
0
def plot_den_win():
    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))
    g = g2a
    alts = [130, 400]
    for ialt, alt in enumerate(alts):
        alt_ind = np.argmin(np.abs(g['Altitude'][0, 0, 2:-2]/1000-alt))+2
        alt_str = '%6.2f' % (g['Altitude'][0, 0, alt_ind]/1000)
        ax, projection = gcc.create_map(
                1, 2, ialt+1, 'polar', nlat=nlat, slat=slat, dlat=10,
                centrallon=g3ca.calculate_centrallon(g, 'polar',  useLT=True),
                coastlines=False)
        # density
        lon0, lat0, zdata0 = g3ca.contour_data('Rho', g, alt=alt)
        fp = (lat0[:,0]>slat) & (lat0[:,0]<nlat)
        lon0, lat0, zdata0 = lon0[fp, :], lat0[fp,:], zdata0[fp,:]
        hc = ax.contourf(lon0, lat0, zdata0, 21,
                         transform=ccrs.PlateCarree(), cmap='jet',
                         extend='both')
        hc = plt.colorbar(hc, pad=0.17)
        hc.set_label(r'$\rho$ (kg/m$^3$)')
        # wind
        lon0, lat0, ewind, nwind = g3ca.vector_data(g, 'neutral', alt=alt)
        lon0, lat0, ewind, nwind = g3ca.convert_vector(
                lon0, lat0, ewind, nwind, plot_type='polar',
                projection=projection)
        hq = ax.quiver(
                lon0, lat0, ewind, nwind, scale=1500, scale_units='inches',
                regrid_shape=20)
        ax.quiverkey(hq, 0.93, -0.1, 1000, '1000 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: '+titletime, fontsize=15,
            horizontalalignment='center', transform=plt.gcf().transFigure)
    plt.show()
    return
Пример #16
0
    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)
Пример #17
0
    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)
Пример #18
0
    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
Пример #19
0
    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
Пример #20
0
#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)
    lon0, lat0, nvort0 = g3ca.contour_data('nvorticity', gdata, alt=alt)
    lon, lat, ewind, nwind = g3ca.vector_data(gdata, 'neu', alt=alt)
    lon, lat, ewind, nwind = g3ca.convert_vector(lon, lat, ewind, nwind,
                                                 'polar', projection)
    hc = ax.contourf(lon0,
                     lat0,
                     nvort0,
                     transform=ccrs.PlateCarree(),
                     cmap='seismic')
    ax.quiver(lon,
              lat,
Пример #21
0
    dglon = np.array(g2['dLon'][2:-2, 0, 0])
    zdata2, dglon1 = add_cyclic_point(zdata2[2:-2, 2:-2, alt_ind].T,
                                      coord=dglon,
                                      axis=1)
    zdata22, dglon1 = add_cyclic_point(zdata22[2:-2, 2:-2, alt_ind].T,
                                       coord=dglon,
                                       axis=1)

    dglon, dglat = np.meshgrid(dglon1, dglat)
    gt = g1['time']
    centrallon = (0 - (gt.hour + gt.minute / 60 + gt.second / 3600)) * 15
    ax1, projection = gcc.create_map(1,
                                     2,
                                     1,
                                     'polar',
                                     nlat=-40,
                                     slat=-90,
                                     centrallon=centrallon,
                                     useLT=True,
                                     dlat=10)
    ax2, projection = gcc.create_map(1,
                                     2,
                                     2,
                                     'polar',
                                     nlat=-40,
                                     slat=-90,
                                     centrallon=centrallon,
                                     useLT=True,
                                     dlat=10)
    hct = ax1.contourf(np.array(dglon),
                       np.array(dglat),
Пример #22
0
def figure5_7_refer(alt=300):
    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=(3, 9.25))
    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, lat1, alt1, T1 = \
            g1['Longitude'], g1['Latitude'], g1['Altitude'], g1['Temperature']
        lon2, lat2, alt2, T2 = \
            g2['Longitude'], g2['Latitude'], g2['Altitude'], g2['Temperature']

        alt_ind = np.argmin(np.abs(alt1[0, 0, :]/1000-alt))
        alt_str = '%6.0f' % (alt1[0, 0, alt_ind]/1000)

        lonticklabel=[0, 1, 0, 1]
        if itime == 0:
            lonticklabel[0] = 1
        if itime == 5:
            lonticklabel[2] = 1
        ax, projection = gcc.create_map(
            6, 1, itime+1, 'polar', nlat=nlat, slat=slat, dlat=10,
            centrallon=g3ca.calculate_centrallon(g1, 'polar',  useLT=True),
            coastlines=False, lonticklabel=lonticklabel)
        g1['temp'] = T1-T2
        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,:]
        hc = ax.contourf(
            lon0, lat0, zdata0, levels=np.linspace(-60, 60, 21),
            transform=ccrs.PlateCarree(), cmap='seismic', extend='both')

        # wind difference
        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)
        plt.text(
            -0.3, 0.5, ylabel[itime], rotation=90,
            transform=ax.transAxes, verticalalignment='center')
        if itime==0:
            plt.title(r'$T_d$ (K)', y=1.15)
        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(-60, 61, 20)
            hcb = plt.colorbar(
                hc, cax=cax, extendrect=True, orientation='horizontal',
                ticks=ticks)
    plt.subplots_adjust(wspace=0, hspace=0)
    plt.show()
    return
Пример #23
0
from aacgmv2 import convert
from aacgmv2 import convert_mlt
import datetime as dt
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import gitm_create_coordinate as gcc
import numpy as np

plt.figure(figsize=(6.88,6.74))
#geographic coordinates
ax1, projection1 = gcc.create_map(
        2, 2, 1, 'pol', 90, 50, 0, coastlines=False,useLT=True,
        dlat=10, lonticklabel=(1, 1, 1, 1))
ax1.plot([45,45],[50,90], 'k--',transform=ccrs.PlateCarree())
ax1.plot([225,225],[50,90], 'k--',transform=ccrs.PlateCarree())
ax1.plot([105,105],[50,90], 'k--',transform=ccrs.PlateCarree())
ax1.plot([285,285],[50,90], 'k--',transform=ccrs.PlateCarree())
ax1.scatter(0, 90, color='r', transform=ccrs.PlateCarree(), zorder=10)
ax2, projection2 = gcc.create_map(
        2, 2, 2, 'pol', -50, -90, 0, coastlines=False,useLT=True,
        dlat=10, lonticklabel=(1, 1, 1, 1))
ax2.scatter(0, -90, color='b', transform=ccrs.PlateCarree())

#geomagnetic coordinates
ax3, projection3 = gcc.create_map(
        2, 2, 3, 'pol', 90, 50, 0, coastlines=False,useLT=True,
        dlat=10, lonticklabel=(1, 1, 1, 1))
mlatn,mlonn = convert(90,0,0,date=dt.date(2002,3,21))
for k in range(24):
    mltn = convert_mlt(mlonn[0],dtime=dt.datetime(2003,3,21,k))
    ax3.scatter(mltn*15,mlatn[0],color='r',transform=ccrs.PlateCarree())
Пример #24
0
def figure2_3(run=1):
    plt.close('all')
    plt.figure(figsize=(8.28, 9.25))
    if run==1:
        g = g1
    else:
        g = g2
    rholevels = [np.linspace(8, 16, 21)*1e-10, np.linspace(1,4,21)*1e-11,
                 np.linspace(0.5, 8,21)*1e-13]
    rhoticks = [np.arange(8, 17, 2)*1e-10, np.arange(1,5,1)*1e-11,
                np.arange(1, 9, 2)*1e-13]
    templevels = [np.linspace(600, 800, 21), np.linspace(900,1500,21),
                 np.linspace(900, 1500,21)]
    tempticks = [np.arange(600, 900, 100), np.arange(900,1600,200),
                np.arange(900, 1600, 200)]
    labels =[('(a)','(b)','(c)'), ('(d)','(e)','(f)'), ('(g)','(h)','(i)')]
    qlat, qlon = convert(-90, 0, 0, date=dt.date(2003,3,22), a2g=True)
    for ialt, alt in enumerate([150, 300, 600]):
        alt_ind = np.argmin(np.abs(g['Altitude'][0, 0, 2:-2]/1000-alt))+2
        alt_str = '%6.0f' % (g['Altitude'][0, 0, alt_ind]/1000)
        ax, projection = gcc.create_map(
            3, 3, ialt+1, 'polar', nlat=nlat, slat=slat, dlat=10,
            centrallon=g3ca.calculate_centrallon(g, 'polar',  useLT=True),
            coastlines=False, lonticklabel=[1,1,1,1])

        # density
        lon0, lat0, zdata0 = g3ca.contour_data('Rho', g, alt=alt)
        fp = (lat0[:,0]>slat) & (lat0[:,0]<nlat)
        lon0, lat0, zdata0 = lon0[fp, :], lat0[fp,:], zdata0[fp,:]
        hc = ax.contourf(
            lon0, lat0, zdata0, rholevels[ialt], transform=ccrs.PlateCarree(),
            cmap='jet', extend='both')
        gcapos = ax.get_position()
        axcb = [
            gcapos.x0, gcapos.y0+0.028, gcapos.width, gcapos.height/20]
        axcb = plt.axes(axcb)
        hcb = plt.colorbar(
            hc, cax=axcb, extendrect=True, ticks=rhoticks[ialt],
            orientation='horizontal')

        # wind
        lon0, lat0, ewind, nwind = g3ca.vector_data(g, 'neutral', alt=alt)
        lon0, lat0, ewind, nwind = g3ca.convert_vector(
            lon0, lat0, ewind, nwind, plot_type='polar', projection=projection)
        hq = ax.quiver(
            lon0, lat0, ewind, nwind, scale=1000, scale_units='inches',
            regrid_shape=20)
        ax.quiverkey(hq, 0.97, 0.92, 500, '500 m/s')

        ax.scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree())
        ax.scatter(
            0, -90, color='w', s=30, transform=ccrs.PlateCarree(), zorder=1000)

        ax.set_title('%s km' % alt_str, y=1.08)

        if ialt == 0:
            plt.text(
                -0.2, 0.5, r'$\rho$ and wind', rotation=90,
                transform=ax.transAxes, verticalalignment='center')
        plt.text(0, 0.9, labels[0][ialt],transform=ax.transAxes,color='r')

        #----------------------------------------------------------------------
        ax, projection = gcc.create_map(
            3, 3, ialt+4, 'polar', nlat=nlat, slat=slat, dlat=10,
            centrallon=g3ca.calculate_centrallon(g, 'polar',  useLT=True),
            coastlines=False, lonticklabel=[1,1,1,1])
        # temperature
        lon0, lat0, zdata0 = g3ca.contour_data('Temperature', g, alt=alt)
        fp = (lat0[:,0]>slat) & (lat0[:,0]<nlat)
        lon0, lat0, zdata0 = lon0[fp, :], lat0[fp,:], zdata0[fp,:]
        hc = ax.contourf(
            lon0, lat0, zdata0, templevels[ialt], transform=ccrs.PlateCarree(),
            cmap='jet', extend='both')
        gcapos = ax.get_position()
        axcb = [
            gcapos.x0, gcapos.y0-0.017, gcapos.width, gcapos.height/20]
        axcb = plt.axes(axcb)
        hcb = plt.colorbar(
            hc, cax=axcb, extendrect=True, ticks=tempticks[ialt],
            orientation='horizontal')

        ax.scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree())
        ax.scatter(
            0, -90, color='w', s=30, transform=ccrs.PlateCarree(), zorder=1000)

        if ialt == 0:
            plt.text(
                -0.2, 0.5, 'Temperature (K)', rotation=90,
                transform=ax.transAxes, verticalalignment='center')
        plt.text(0, 0.9, labels[1][ialt],transform=ax.transAxes,color='r')
        #----------------------------------------------------------------------
        ax, projection = gcc.create_map(
            3, 3, ialt+7, 'polar', nlat=nlat, slat=slat, dlat=10,
            centrallon=g3ca.calculate_centrallon(g, 'polar',  useLT=True),
            coastlines=False, lonticklabel=[1,1,1,1])
        # ion drift
        lon0, lat0, ewind, nwind = g3ca.vector_data(g, 'ion', alt=alt)
        lon0, lat0, ewind, nwind = g3ca.convert_vector(
            lon0, lat0, ewind, nwind, plot_type='polar', projection=projection)
        if run == 2:
            ewind, nwind = 0.1*ewind, 0.1*nwind
        hq = ax.quiver(
            lon0, lat0, ewind, nwind, scale=1000, scale_units='inches',
            regrid_shape=20)
        ax.quiverkey(hq, 0.97, 0.92, 500, '500 m/s')
        ax.scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree())
        ax.scatter(
            0, -90, color='w', s=30, transform=ccrs.PlateCarree(), zorder=1000)

        if ialt == 0:
            plt.text(
                -0.2, 0.5, 'Ion Drift', rotation=90,
                transform=ax.transAxes, verticalalignment='center')
        plt.text(0, 0.9, labels[2][ialt],transform=ax.transAxes,color='r')
    plt.subplots_adjust(wspace=0.25, hspace=0.25, top=0.95, bottom=0.05)

    if run==1:
        plt.savefig(savepath+'Figure2.eps')
        plt.savefig(savepath+'Figure2.jpeg')
    else:
        plt.savefig(savepath+'Figure3.eps')
        plt.savefig(savepath+'Figure3.jpeg')
    return
Пример #25
0
from aacgmv2 import convert
from aacgmv2 import convert_mlt
import datetime as dt
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import gitm_create_coordinate as gcc
import numpy as np

plt.figure(figsize=(6.88, 6.74))
#geographic coordinates
ax1, projection1 = gcc.create_map(2,
                                  2,
                                  1,
                                  'pol',
                                  90,
                                  50,
                                  0,
                                  coastlines=False,
                                  useLT=True,
                                  dlat=10,
                                  lonticklabel=(1, 1, 1, 1))
ax1.plot([45, 45], [50, 90], 'k--', transform=ccrs.PlateCarree())
ax1.plot([225, 225], [50, 90], 'k--', transform=ccrs.PlateCarree())
ax1.plot([105, 105], [50, 90], 'k--', transform=ccrs.PlateCarree())
ax1.plot([285, 285], [50, 90], 'k--', transform=ccrs.PlateCarree())
ax1.scatter(0, 90, color='r', transform=ccrs.PlateCarree(), zorder=10)
ax2, projection2 = gcc.create_map(2,
                                  2,
                                  2,
                                  'pol',
                                  -50,
Пример #26
0
    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
Пример #27
0
    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
Пример #28
0
def plot_divrhov_rho_diff(show=True, save=True):
    # density change (shrink)
    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)
    uwind1 = np.array(g1a['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

    # density change (no shrink)
    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)
    uwind2 = np.array(g2a['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
    g1a['divrhov_diff'] = div_rhov1 - div_rhov2

    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('divrhov_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'$-\frac{\nabla\cdot(\rho\vec{u})}{\rho}$')
        # 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 + '08_divrhov_rho_diff_%s%s.pdf' %
                    (tstrday, tstring))
    return
Пример #29
0
def figure4():
    plt.close('all')
    plt.figure(figsize=(8.28, 9.25))
    labels =[('(a)','(b)','(c)'), ('(d)','(e)','(f)'), ('(g)','(h)','(i)')]
    qlat, qlon = convert(-90, 0, 0, date=dt.date(2003,3,22), a2g=True)
    ylim = [[0.6e-9,1.6e-9], [1.5e-11, 4e-11], [1e-13, 9e-13]]
    for ialt, alt in enumerate([150, 300, 600]):
        alt_ind = np.argmin(np.abs(g1['Altitude'][0, 0, 2:-2]/1000-alt))+2
        alt_str = '%6.0f' % (g1['Altitude'][0, 0, alt_ind]/1000)
        rho1, rho2 = g1['Rho'], g2['Rho']
        rhod = 100*(rho1-rho2)/rho2
        lats, lons  = g1['Latitude'], g1['Longitude']

        #----------------------------------------------------------------------
        ax, projection = gcc.create_map(
            3, 3, ialt+1, 'polar', nlat=nlat, slat=slat, dlat=10,
            centrallon=g3ca.calculate_centrallon(g1, 'polar',  useLT=True),
            coastlines=False, lonticklabel=[1,1,1,1])

        # density difference
        lon1, lat1, zdata1 = g3ca.contour_data('Rho', g1, alt=alt)
        lon2, lat2, zdata2 = g3ca.contour_data('Rho', g2, alt=alt)
        fp = (lat1[:,0]>slat) & (lat1[:,0]<nlat)
        lon0, lat0 = lon1[fp, :], lat1[fp,:]
        zdata0 = (100*(zdata1-zdata2)/zdata2)[fp, :]
        print(zdata0.min())
        hc = ax.contourf(
            lon0, lat0, zdata0, np.linspace(-30,30,21),
            transform=ccrs.PlateCarree(), cmap='seismic', extend='both')
        # colorbar
        gcapos = ax.get_position()
        axcb = [
            gcapos.x0, gcapos.y0+0.035, gcapos.width, gcapos.height/20]
        axcb = plt.axes(axcb)
        hcb = plt.colorbar(
            hc, cax=axcb, extendrect=True, ticks=np.arange(-30, 31, 15),
            orientation='horizontal')

        # wind difference
        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=1000, scale_units='inches',
                regrid_shape=20, headwidth=5)
        ax.quiverkey(hq, 0.97, 0.92, 500, '500 m/s')

        # magnetic pole
        ax.scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree())
        ax.scatter(
            0, -90, color='w', s=30, transform=ccrs.PlateCarree(), zorder=1000)

        latt1 = [-90, nlat]
        lont1 = [15*(12-ut), 15*(12-ut)]
        ax.plot(lont1, latt1, transform = ccrs.PlateCarree(), c='g')
        latt1 = [-90, nlat]
        lont1 = [15*(0-ut), 15*(0-ut)]
        ax.plot(lont1, latt1, transform = ccrs.PlateCarree(), c='g')
        ax.set_title('%s km' % alt_str, y=1.07)
        if ialt==0:
            ax.text(-0.2, 0.5, r'$\delta \rho$ (%)',
                    transform=ax.transAxes,rotation=90, fontsize=14,
                    verticalalignment='center', horizontalalignment='center')
        plt.text(
            0.05, 0.9, labels[0][ialt],transform=ax.transAxes,color='r')

        #----------------------------------------------------------------------
        # density in run1 and run2
        plt.subplot(3,3,ialt+7)
        ilat = (lats[0,:,0]/pi*180<nlat) &(lats[0,:,0]/pi*180>slat)
        lt = 12
        ilt = np.argmin(np.abs(g1['LT'][2:-2,0,0]-lt))+2
        plt.plot(
            180+lats[ilt,ilat,alt_ind]/pi*180,rho1[ilt,ilat,alt_ind], 'r',
            label = 'Run 1')
        plt.plot(
            180+lats[ilt,ilat,alt_ind]/pi*180,rho2[ilt,ilat,alt_ind], 'b',
            label = 'Run 2')
        plt.legend(loc='upper center')
        lat_1, rho_11, rho_12, rho_1d = \
            180+lats[ilt,2,alt_ind]/pi*180, rho1[ilt,2, alt_ind], \
            rho2[ilt,2, alt_ind], rhod[ilt,2,alt_ind]

        lt = 0
        ilt = np.argmin(np.abs(g1['LT'][2:-2,0,0]-lt))+2
        plt.plot(-lats[ilt,ilat,alt_ind]/pi*180,rho1[ilt,ilat,alt_ind], 'r')
        plt.plot(-lats[ilt,ilat,alt_ind]/pi*180,rho2[ilt,ilat,alt_ind], 'b')
        lat_2, rho_21, rho_22, rho_2d = \
            -lats[ilt,2,alt_ind]/pi*180, rho1[ilt,2, alt_ind], \
            rho2[ilt,2, alt_ind], rhod[ilt,2,alt_ind]

        plt.plot([lat_1,lat_2], [rho_11,rho_21], 'r')
        plt.plot([lat_1,lat_2], [rho_12,rho_22], 'b')
        plt.grid('on')

        plt.xlim([-nlat,180+nlat])
        plt.ylim(ylim[ialt])
        plt.xticks(np.arange(-nlat,181+nlat,30),
            np.concatenate(
                [np.arange(nlat,-90,-30), np.arange(-90,nlat+1,30)]))

        if ialt==0:
            plt.ylabel(r'$\rho$ (kg/m$^3$)', fontsize=14)
        plt.xlabel('Latitude')
        plt.text(
            0.05, 0.9, labels[2][ialt],transform=plt.gca().transAxes,color='r')

        #----------------------------------------------------------------------
        # density difference
        plt.subplot(3,3,ialt+4)
        lt = 12
        ilt = np.argmin(np.abs(g1['LT'][2:-2,0,0]-lt))+2
        plt.plot(
            180+lats[ilt,ilat,alt_ind]/pi*180,rhod[ilt,ilat,alt_ind], 'k')

        lt = 0
        ilt = np.argmin(np.abs(g1['LT'][2:-2,0,0]-lt))+2
        plt.plot(
            -lats[ilt,ilat,alt_ind]/pi*180,rhod[ilt,ilat,alt_ind], 'k')
        plt.plot([lat_1,lat_2], [rho_1d,rho_2d], 'k')

        plt.grid('on')

        plt.xlim([-nlat,180+nlat])
        plt.xticks(np.arange(-nlat,181+nlat,30),
            np.concatenate(
                [np.arange(nlat,-90,-30), np.arange(-90,nlat+1,30)]))
        plt.ylim(-35, 5)
        plt.yticks(np.arange(-30, 0.1, 10))
        if ialt==0:
            plt.ylabel(r'$\delta\rho$ (%)', fontsize=14)
        plt.xlabel('Latitude')
        plt.text(
            0.05, 0.9, labels[1][ialt],transform=plt.gca().transAxes,color='r')

    plt.subplots_adjust(wspace=0.25, hspace=0.25, top=0.95, bottom=0.05)
    plt.savefig(savepath+'Figure4.eps')
    plt.savefig(savepath+'Figure4.jpeg')
    return
Пример #30
0
def plot_rho_wind_ut(ns='SH', alt=150):
    path = '/home/guod/simulation_output/momentum_analysis/run_no_shrink_igrf_1_1/data'
    fn01 = path+'/3DALL_t030323_000000.bin'
    fn02 = path+'/3DALL_t030323_030000.bin'
    fn03 = path+'/3DALL_t030323_060001.bin'
    fn04 = path+'/3DALL_t030323_090002.bin'
    fn05 = path+'/3DALL_t030323_120000.bin'
    fn06 = path+'/3DALL_t030323_150001.bin'
    fn07 = path+'/3DALL_t030323_180000.bin'
    fn08 = path+'/3DALL_t030323_210002.bin'
    fn09 = path+'/3DALL_t030324_000000.bin'
    fn2 = [fn01, fn02, fn03, fn04, fn05, fn06, fn07, fn08, fn09]

    if ns=='SH':
        nlat, slat = -50, -90
    elif ns=='NH':
        nlat, slat = 90, 50
    glats, glons = convert(-90, 0, 0, date=dt.date(2003,1,1), a2g=True)
    glatn, glonn = convert(90, 0, 0, date=dt.date(2003,1,1), a2g=True)
    fig1 = plt.figure(1, figsize=(5.28,8.49))
    titf = ['(a)','(b)','(c)','(d)','(e)','(f)','(g)','(h)']
    for k in range(8):
        g2 = gitm.read(fn2[k])

        title = 'UT: '+g2['time'].strftime('%H')

        lon2, lat2, rho2 = g3ca.contour_data('Rho', g2, alt=alt)
        ilat2 = (lat2[:,0]>=slat) & (lat2[:,0]<=nlat)
        min_div_mean = \
            np.min(rho2[ilat2, :]) / \
            (np.mean(rho2[ilat2, :]*np.cos(lat2[ilat2, :]/180*np.pi)) /\
            np.mean(np.cos(lat2[ilat2,:]/180*np.pi)))
        print(ns,':  ',100*(min_div_mean-1))

        lon2, lat2, ewind2, nwind2 = g3ca.vector_data(g2,'neu',alt=alt)

        if k ==0:
            lonticklabel = [1, 0, 0, 1]
        elif k==1:
            lonticklabel = [1, 1, 0, 0]
        elif k in [2, 4]:
            lonticklabel = [0, 0, 0, 1]
        elif k in [3, 5]:
            lonticklabel = [0, 1, 0, 0]
        elif k==6:
            lonticklabel = [0, 0, 1, 1]
        elif k==7:
            lonticklabel = [0, 1, 1, 0]
        olat=False if k<7 else True

        # No shrink
        plt.figure(1)
        centrallon = g3ca.calculate_centrallon(g2, 'pol', useLT=True)
        ax, projection = gcc.create_map(
            4,2,k+1, 'pol', nlat, slat, centrallon, coastlines=False,
            dlat=10, useLT=True, lonticklabel=lonticklabel, olat=olat)
        hc1 = ax.contourf(lon2, lat2, rho2, np.linspace(0.8e-9, 1.6e-9),
            transform=ccrs.PlateCarree(),cmap='jet', extend='both')
        lon9, lat9, ewind9, nwind9 = g3ca.convert_vector(
            lon2, lat2, ewind2, nwind2, 'pol', projection)
        hq1 = ax.quiver(
            lon9,lat9,ewind9,nwind9,scale=1500,scale_units='inches',
            regrid_shape=20)
        ax.scatter(glons, glats, transform=ccrs.PlateCarree(), s=35, c='k')
        ax.scatter(glonn, glatn, transform=ccrs.PlateCarree(), s=35, c='k')
        ax.scatter(0, 90, transform=ccrs.PlateCarree(), s=35, c='w', zorder=100)
        ax.scatter(0, -90, transform=ccrs.PlateCarree(), s=35, c='w', zorder=100)
        plt.title(titf[k]+' '+title,x=0,y=0.93)

    plt.figure(1)
    plt.subplots_adjust(
        hspace=0.01, wspace=0.01, left=0.05, right=0.95, top=0.95, bottom=0.12)
    cax = plt.axes([0.25,0.07,0.5,0.02])
    hcb = plt.colorbar(
        hc1,cax=cax,orientation='horizontal',ticks=np.arange(0.8,1.7,0.2)*1e-9)
    hcb.set_label(r'$\rho$ (kg/$m^3$)')
    plt.quiverkey(hq1, 0.5,0.12, 500, '500m/s',coordinates='figure')
    plt.savefig(savepath+'1'+ns+'AllUT.eps')
    plt.savefig(savepath+'1'+ns+'AllUT.jpeg')

    return
Пример #31
0
        vort = 1.0/(Re+alt)*(
                np.gradient(-(r+alt)*nwind, axis=2)/np.gradient(alt, axis=2) +
                np.gradient(uwind, axis=1)/np.gradient(lat, axis=1))
    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)
    lon0, lat0, nvort0 = g3ca.contour_data('nvorticity', gdata, alt=alt)
    lon, lat, ewind, nwind = g3ca.vector_data(gdata, 'neu', alt=alt)
    lon, lat, ewind, nwind = g3ca.convert_vector(
            lon, lat, ewind, nwind, 'polar', projection)
    hc = ax.contourf(
            lon0, lat0, nvort0,
            transform=ccrs.PlateCarree(), cmap='seismic')
    ax.quiver(lon, lat, ewind, nwind, regrid_shape=50, scale_units='inches', scale=1000)
    plt.show()
Пример #32
0
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
Пример #33
0
    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)
Пример #34
0
def plot_divrhov_rho_diff(show=True, save=True):
    # density change (shrink)
    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)
    uwind1 = np.array(g1a['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

    # density change (no shrink)
    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)
    uwind2 = np.array(g2a['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
    g1a['divrhov_diff'] = div_rhov1-div_rhov2

    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('divrhov_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'$-\frac{\nabla\cdot(\rho\vec{u})}{\rho}$')
        # 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+'08_divrhov_rho_diff_%s%s.pdf' % (tstrday,tstring))
    return
Пример #35
0
def f4():
    plt.figure(figsize=(6.88, 6.74))
    #geographic coordinates
    ax1, projection1 = gcc.create_map(2,
                                      2,
                                      1,
                                      'pol',
                                      90,
                                      50,
                                      0,
                                      coastlines=False,
                                      useLT=True,
                                      dlat=10,
                                      lonticklabel=(1, 1, 1, 1))
    ax1.plot([45, 45], [50, 90], 'k--', transform=ccrs.PlateCarree())
    ax1.plot([225, 225], [50, 90], 'k--', transform=ccrs.PlateCarree())
    ax1.plot([105, 105], [50, 90], 'k--', transform=ccrs.PlateCarree())
    ax1.plot([285, 285], [50, 90], 'k--', transform=ccrs.PlateCarree())
    ax1.scatter(0,
                90,
                color='r',
                transform=ccrs.PlateCarree(),
                zorder=10,
                label='North Pole')
    ax1.text(0, 1, '(a)', transform=plt.gca().transAxes)
    plt.legend(loc=[0.5, 1.1])

    ax2, projection2 = gcc.create_map(2,
                                      2,
                                      2,
                                      'pol',
                                      -50,
                                      -90,
                                      0,
                                      coastlines=False,
                                      useLT=True,
                                      dlat=10,
                                      lonticklabel=(1, 1, 1, 1))
    ax2.scatter(0,
                -90,
                color='b',
                transform=ccrs.PlateCarree(),
                label='South Pole')
    ax2.text(0, 1, '(b)', transform=plt.gca().transAxes)
    plt.legend(loc=[-0.1, 1.1])

    #geomagnetic coordinates
    ax3, projection3 = gcc.create_map(2,
                                      2,
                                      3,
                                      'pol',
                                      90,
                                      50,
                                      0,
                                      coastlines=False,
                                      useLT=True,
                                      dlat=10,
                                      lonticklabel=(1, 1, 1, 1))
    mlatn, mlonn = convert(90, 0, 0, date=dt.date(2002, 3, 21))
    for k in range(24):
        mltn = convert_mlt(mlonn[0], dtime=dt.datetime(2003, 3, 21, k))
        ax3.scatter(mltn * 15,
                    mlatn[0],
                    color='r',
                    transform=ccrs.PlateCarree())
    ax3.scatter(180, 75, s=50, c='k', marker='x', transform=ccrs.PlateCarree())
    ax3.text(0, 1, '(c)', transform=plt.gca().transAxes)

    ax4, projection4 = gcc.create_map(2,
                                      2,
                                      4,
                                      'pol',
                                      -50,
                                      -90,
                                      0,
                                      coastlines=False,
                                      useLT=True,
                                      dlat=10,
                                      lonticklabel=(1, 1, 1, 1))
    mlats, mlons = convert(-90, 0, 0, date=dt.date(2002, 3, 21))
    for k in range(24):
        mlts = convert_mlt(mlons[0], dtime=dt.datetime(2003, 3, 21, k))
        ax4.scatter(mlts * 15,
                    mlats[0],
                    color='b',
                    transform=ccrs.PlateCarree())
    ax4.scatter(180,
                -75,
                s=50,
                c='k',
                marker='x',
                transform=ccrs.PlateCarree())
    ax4.text(0, 1, '(d)', transform=plt.gca().transAxes)
    plt.savefig('/Users/guod/Documents/Pole_Density_MLT_Change/Figures/'
                '000_Pole_Feature.pdf')
    return
Пример #36
0
def plot_den_win(show=True, save=True):
    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))
    g = g2a
    for ialt, alt in enumerate([130, 200, 300, 400, 500, 600]):
        alt_ind = np.argmin(np.abs(g['Altitude'][0, 0, 2:-2] / 1000 - alt)) + 2
        alt_str = '%6.2f' % (g['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(
                                            g, 'polar', useLT=True),
                                        coastlines=False)
        # density
        lon0, lat0, zdata0 = g3ca.contour_data('Rho', g, alt=alt)
        fp = (lat0[:, 0] > slat) & (lat0[:, 0] < nlat)
        lon0, lat0, zdata0 = lon0[fp, :], lat0[fp, :], zdata0[fp, :]
        hc = ax.contourf(lon0,
                         lat0,
                         zdata0,
                         21,
                         transform=ccrs.PlateCarree(),
                         cmap='jet',
                         extend='both')
        hc = plt.colorbar(hc, pad=0.17)
        hc.set_label(r'$\rho$ (kg/m$^3$)')

        # wind
        lon0, lat0, ewind, nwind = g3ca.vector_data(g, 'neutral', alt=alt)
        lon0, lat0, ewind, nwind = g3ca.convert_vector(lon0,
                                                       lat0,
                                                       ewind,
                                                       nwind,
                                                       plot_type='polar',
                                                       projection=projection)
        hq = ax.quiver(lon0,
                       lat0,
                       ewind,
                       nwind,
                       scale=1500,
                       scale_units='inches',
                       regrid_shape=20)
        ax.quiverkey(hq, 0.93, -0.1, 1000, '1000 m/s')
        ax.scatter(qlon, qlat, color='k', transform=ccrs.PlateCarree())

        # rho difference
        # lon3, lat3, zdata3 = g3ca.contour_data('Rho', g1a, alt=alt)
        # lon4, lat4, zdata4 = g3ca.contour_data('Rho', g2a, alt=alt)
        # diffrho = 100*(zdata4-zdata3)/zdata3
        # hc = ax.contour(
        #         lon4, lat4, diffrho, [-10], transform=ccrs.PlateCarree(),
        #         colors='g',linestyles='-')
        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 + '01_den_win_run2_%s%s.pdf' % (tstrday, tstring))
    return
Пример #37
0
def plot_rho_wind_ut(ns='SH', alt=150):
    path = '/home/guod/simulation_output/momentum_analysis/run_no_shrink_igrf_1_1/data'
    fn01 = path + '/3DALL_t030323_000000.bin'
    fn02 = path + '/3DALL_t030323_030000.bin'
    fn03 = path + '/3DALL_t030323_060001.bin'
    fn04 = path + '/3DALL_t030323_090002.bin'
    fn05 = path + '/3DALL_t030323_120000.bin'
    fn06 = path + '/3DALL_t030323_150001.bin'
    fn07 = path + '/3DALL_t030323_180000.bin'
    fn08 = path + '/3DALL_t030323_210002.bin'
    fn09 = path + '/3DALL_t030324_000000.bin'
    fn2 = [fn01, fn02, fn03, fn04, fn05, fn06, fn07, fn08, fn09]

    if ns == 'SH':
        nlat, slat = -50, -90
    elif ns == 'NH':
        nlat, slat = 90, 50
    glats, glons = convert(-90, 0, 0, date=dt.date(2003, 1, 1), a2g=True)
    glatn, glonn = convert(90, 0, 0, date=dt.date(2003, 1, 1), a2g=True)
    fig1 = plt.figure(1, figsize=(5.28, 8.49))
    titf = ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)']
    for k in range(8):
        g2 = gitm.read(fn2[k])

        title = 'UT: ' + g2['time'].strftime('%H')

        lon2, lat2, rho2 = g3ca.contour_data('Rho', g2, alt=alt)
        ilat2 = (lat2[:, 0] >= slat) & (lat2[:, 0] <= nlat)
        min_div_mean = \
            np.min(rho2[ilat2, :]) / \
            (np.mean(rho2[ilat2, :]*np.cos(lat2[ilat2, :]/180*np.pi)) /\
            np.mean(np.cos(lat2[ilat2,:]/180*np.pi)))
        print(ns, ':  ', 100 * (min_div_mean - 1))

        lon2, lat2, ewind2, nwind2 = g3ca.vector_data(g2, 'neu', alt=alt)

        if k == 0:
            lonticklabel = [1, 0, 0, 1]
        elif k == 1:
            lonticklabel = [1, 1, 0, 0]
        elif k in [2, 4]:
            lonticklabel = [0, 0, 0, 1]
        elif k in [3, 5]:
            lonticklabel = [0, 1, 0, 0]
        elif k == 6:
            lonticklabel = [0, 0, 1, 1]
        elif k == 7:
            lonticklabel = [0, 1, 1, 0]
        olat = False if k < 7 else True

        # No shrink
        plt.figure(1)
        centrallon = g3ca.calculate_centrallon(g2, 'pol', useLT=True)
        ax, projection = gcc.create_map(4,
                                        2,
                                        k + 1,
                                        'pol',
                                        nlat,
                                        slat,
                                        centrallon,
                                        coastlines=False,
                                        dlat=10,
                                        useLT=True,
                                        lonticklabel=lonticklabel,
                                        olat=olat)
        hc1 = ax.contourf(lon2,
                          lat2,
                          rho2,
                          np.linspace(0.8e-9, 1.6e-9),
                          transform=ccrs.PlateCarree(),
                          cmap='jet',
                          extend='both')
        lon9, lat9, ewind9, nwind9 = g3ca.convert_vector(
            lon2, lat2, ewind2, nwind2, 'pol', projection)
        hq1 = ax.quiver(lon9,
                        lat9,
                        ewind9,
                        nwind9,
                        scale=1500,
                        scale_units='inches',
                        regrid_shape=20)
        ax.scatter(glons, glats, transform=ccrs.PlateCarree(), s=35, c='k')
        ax.scatter(glonn, glatn, transform=ccrs.PlateCarree(), s=35, c='k')
        ax.scatter(0,
                   90,
                   transform=ccrs.PlateCarree(),
                   s=35,
                   c='w',
                   zorder=100)
        ax.scatter(0,
                   -90,
                   transform=ccrs.PlateCarree(),
                   s=35,
                   c='w',
                   zorder=100)
        plt.title(titf[k] + ' ' + title, x=0, y=0.93)

    plt.figure(1)
    plt.subplots_adjust(hspace=0.01,
                        wspace=0.01,
                        left=0.05,
                        right=0.95,
                        top=0.95,
                        bottom=0.12)
    cax = plt.axes([0.25, 0.07, 0.5, 0.02])
    hcb = plt.colorbar(hc1,
                       cax=cax,
                       orientation='horizontal',
                       ticks=np.arange(0.8, 1.7, 0.2) * 1e-9)
    hcb.set_label(r'$\rho$ (kg/$m^3$)')
    plt.quiverkey(hq1, 0.5, 0.12, 500, '500m/s', coordinates='figure')
    plt.savefig(savepath + '1' + ns + 'AllUT.eps')
    plt.savefig(savepath + '1' + ns + 'AllUT.jpeg')

    return
Пример #38
0
def plot_vert_divv_diff(show=True, save=True):
    velr = np.array(g1a['V!Dn!N (up)'])
    divv1 = cr.calc_div_vert(g1a['Altitude'], velr)

    velr = np.array(g2a['V!Dn!N (up)'])
    divv2 = cr.calc_div_vert(g2a['Altitude'], velr)

    g1a['vert_divv_diff'] = divv1 - divv2

    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('vert_divv_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,
                         levels=np.linspace(-1, 1, 21) * 1e-4,
                         transform=ccrs.PlateCarree(),
                         cmap='seismic',
                         extend='both')
        hcb = plt.colorbar(hc, pad=0.17)
        hcb.set_label(r'$-\nabla\cdot\vec{u}$ (up)')
        hcb.formatter.set_powerlimits((-2, 2))
        hcb.update_ticks()

        # 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 + '04_vert_divv_diff_%s%s.pdf' % (tstrday, tstring))
    return
Пример #39
0
Файл: tmp.py Проект: guodj/work
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
vadvect = uwind0*gradr0

eee = rho0*div0

plt.close('all')
plt.figure(figsize=(9, 9))
ax, projection = gcc.create_map(
        2, 2, 1, 'polar', nlat=90, slat=50,
        centrallon=g3ca.calculate_centrallon(g, 'polar', useLT=True),
        coastlines=False, dlat=30, useLT=True)
ax.contourf(lon0, lat0, -(hadvect+vadvect+eee), transform=ccrs.PlateCarree(),
            levels = np.linspace(-4e-15, 4e-15, 21), cmap='seismic')

ax, projection = gcc.create_map(
        2, 2, 2, 'polar', nlat=90, slat=50,
        centrallon=g3ca.calculate_centrallon(g, 'polar', useLT=True),
        coastlines=False, dlat=30, useLT=True)
ax.contourf(lon0, lat0, -hadvect, transform=ccrs.PlateCarree(),
            levels = np.linspace(-4e-15, 4e-15, 21), cmap='seismic')

ax, projection = gcc.create_map(
        2, 2, 3, 'polar', nlat=90, slat=50,
        centrallon=g3ca.calculate_centrallon(g, 'polar', useLT=True),
        coastlines=False, dlat=30, useLT=True)
Пример #40
0
    vele = g2['V!Dn!N (east)']+(2*np.pi)/(24*3600)*(6371*1000+alts)*np.cos(lats)
    velu = g2['V!Dn!N (up)']
    rho = g2['Rho']
    zdata2 = calc_rusanov_lats(lats,alts,veln) - np.tan(lats)*veln/(6371*1000+alts)
    zdata22 = gd.calc_divergence_north(g2,veln)
    # zdata2 = calc_rusanov_lons(lons,lats,alts,vele)
    # zdata22 = gd.calc_divergence_east(g2,vele)
    #zdata2 = calc_div_hozt(lons, lats, alts, veln, vele)
    #zdata22 = gd.calc_divergence_north(g2,veln)+gd.calc_divergence_east(g2,vele)
    dglat = np.array(g2['dLat'][0,2:-2,0])
    dglon = np.array(g2['dLon'][2:-2,0,0])
    zdata2, dglon1 = add_cyclic_point(zdata2[2:-2,2:-2,alt_ind].T, coord=dglon, axis=1)
    zdata22, dglon1 = add_cyclic_point(zdata22[2:-2,2:-2,alt_ind].T, coord=dglon, axis=1)

    dglon,dglat = np.meshgrid(dglon1, dglat)
    gt = g1['time']
    centrallon = (0-(gt.hour+gt.minute/60+gt.second/3600))*15
    ax1, projection = gcc.create_map(
            1, 2, 1, 'polar', nlat=-40, slat=-90, centrallon=centrallon,
            useLT=True, dlat=10)
    ax2, projection = gcc.create_map(
            1, 2, 2, 'polar', nlat=-40, slat=-90, centrallon=centrallon,
            useLT=True, dlat=10)
    hct= ax1.contourf(np.array(dglon), np.array(dglat), np.array(zdata22),
                levels=np.linspace(-2,2,21)*1e-4,transform=ccrs.PlateCarree(),
                cmap='seismic',extend='both')
    hct= ax2.contourf(np.array(dglon), np.array(dglat), np.array(zdata2-zdata22),
                levels=np.linspace(-2,2,21)*1e-4,transform=ccrs.PlateCarree(),
                cmap='seismic',extend='both')
    plt.show()