예제 #1
0
def plot_vert_divv_diff(show=True, save=False):
    plt.close('all')
    plt.figure()

    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)

    ilt = np.argmin(np.abs(g1a['LT'][2:-2, 0, 0]-whichlt))+2
    divv1 = divv1[ilt,2:-2,2:-2]
    divv2 = divv2[ilt,2:-2,2:-2]
    ddivv = np.array(divv1-divv2).T
    lat = np.array(g1a['dLat'][ilt, 2:-2, 2:-2]).T
    alt = np.array(g1a['Altitude'][ilt, 2:-2, 2:-2]/1000).T
    plt.contourf(lat, alt, ddivv, levels=np.linspace(-1, 1, 21)*1e-4,
                 cmap='seismic', extend='both')
    plt.xlim(-90, -40)
    plt.xlabel('Latitude')
    plt.ylabel('Altitude')
    plt.text(0.5, 0.95, 'Time: '+tstring, fontsize=15,
            horizontalalignment='center', transform=plt.gcf().transFigure)
    if show:
        plt.show()
    if save:
        plt.savefig(spath+'04_vert_divv_diff%s.pdf' % tstring)
    return
예제 #2
0
def plot_divrhov_rho(read=True):
    if read:
        divrhov = []
        for fn1, fn2 in zip(fns1,fns2):
            g1, g2 = gitm.read(fn1), gitm.read(fn2)
            # density change (shrink)
            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

            # density change (no shrink)
            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
            div_rhov = div_rhov1 - div_rhov2

            divrhov1 = []
            for alt in alts:
                ialt = np.argmin(np.abs(g1['Altitude'][0, 0, 2:-2]-alt*1000))+2
                divrhov2 = []
                for lt in lts:
                    ilt = np.argmin(np.abs(g1['LT'][2:-2, 0, 0]-lt))+2
                    divrhov2.append(
                        np.array(div_rhov[ilt, 2:-2, ialt]).reshape(1,1,1,-1))
                divrhov2 = np.concatenate(divrhov2, axis=2)
                divrhov1.append(divrhov2)
            divrhov1 = np.concatenate(divrhov1, axis=1)
            divrhov.append(divrhov1)
        divrhov = np.concatenate(divrhov, axis=0)
        lat = g1['dLat'][0, 2:-2, 0]
        np.savez('/home/guod/tmp/divrhov_rho', divrhov=divrhov, lat=lat)
    ldf = np.load('/home/guod/tmp/divrhov_rho.npz')
    divrhov, lat = ldf['divrhov'], ldf['lat']
    plt.close()
    plt.contourf(
        timeidx, lat, divrhov[:,3, 1, :].T, levels=np.linspace(-1,1,21)*1e-4,
        cmap='seismic')
    plt.ylim(-90, -40)
    plt.show()
    return
예제 #3
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)
예제 #4
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
예제 #5
0
def plot_divrhov_rho_diff(show=True, save=False):
    plt.close('all')
    plt.figure()
    # 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

    ilt = np.argmin(np.abs(g1a['LT'][2:-2, 0, 0]-whichlt))+2
    divrhov1 = div_rhov1[ilt,2:-2,2:-2]
    divrhov2 = div_rhov2[ilt,2:-2,2:-2]
    ddivrhov = np.array(divrhov1-divrhov2).T
    lat = np.array(g1a['dLat'][ilt, 2:-2, 2:-2]).T
    alt = np.array(g1a['Altitude'][ilt, 2:-2, 2:-2]/1000).T
    plt.contourf(lat, alt, ddivrhov, levels=np.linspace(-1, 1, 21)*1e-4,
                 cmap='seismic', extend='both')
    plt.xlim(-90, -40)
    plt.xlabel('Latitude')
    plt.ylabel('Altitude')
    plt.text(0.5, 0.95, 'Time: '+tstring, fontsize=15,
            horizontalalignment='center', transform=plt.gcf().transFigure)
    if show:
        plt.show()
    if save:
        plt.savefig(spath+'03_divrhov_rho_diff_%s.pdf' % tstring)
    return
예제 #6
0
def plot_vert_divv(read=True):
    if read:
        divv = []
        for fn1, fn2 in zip(fns1,fns2):
            g1, g2 = gitm.read(fn1), gitm.read(fn2)
            velr = np.array(g1['V!Dn!N (up)'])
            div_v1 = cr.calc_div_vert(g1['Altitude'], velr)

            velr = np.array(g2['V!Dn!N (up)'])
            div_v2 = cr.calc_div_vert(g2['Altitude'], velr)
            div_v = div_v1 - div_v2

            divv1 = []
            for alt in alts:
                ialt = np.argmin(np.abs(g1['Altitude'][0, 0, 2:-2]-alt*1000))+2
                divv2 = []
                for lt in lts:
                    ilt = np.argmin(np.abs(g1['LT'][2:-2, 0, 0]-lt))+2
                    divv2.append(
                        np.array(div_v[ilt, 2:-2, ialt]).reshape(1,1,1,-1))
                divv2 = np.concatenate(divv2, axis=2)
                divv1.append(divv2)
            divv1 = np.concatenate(divv1, axis=1)
            divv.append(divv1)
        divv = np.concatenate(divv, axis=0)
        lat = g1['dLat'][0, 2:-2, 0]
        np.savez('/home/guod/tmp/vert_divv', divv=divv, lat=lat)
    ldf = np.load('/home/guod/tmp/vert_divv.npz')
    divv, lat = ldf['divv'], ldf['lat']
    plt.close()
    plt.contourf(
        timeidx, lat, divv[:,3, 1, :].T, levels=np.linspace(-1,1,21)*1e-4,
        cmap='seismic')
    plt.ylim(-90, -40)
    plt.show()
    return
gallfn = '/Users/guod/data/GITMOutput/run_shrink_notides_tmp/UA/data/3DALL_t030323_000004.bin'
gthmfn = '/Users/guod/data/GITMOutput/run_shrink_notides_tmp/UA/data/3DTHM_t030323_000004.bin'
gall = gitm.read(gallfn)
lontp = gall['Longitude']
lattp = gall['Latitude']
alttp = gall['Altitude']
Re = 6371 * 1000  # Earth radius, unit: m
RR = Re + alttp
omega = 2 * np.pi / (24 * 3600)
rhotp = gall['Rho']
nwindtp = gall['V!Dn!N (north)']
ewindtp = gall['V!Dn!N (east)'] + omega * RR * np.cos(lattp)
uwindtp = gall['V!Dn!N (up)']
gall['div_rhov'] = \
    -(cr.calc_div_hozt(lontp, lattp, alttp, rhotp*nwindtp, rhotp*ewindtp)\
    +cr.calc_div_vert(alttp, rhotp*uwindtp))/rhotp
gall['vert_divv'] = -cr.calc_div_vert(alttp, uwindtp)
gall['hozt_divv'] = -cr.calc_div_hozt(lontp, lattp, alttp, nwindtp, ewindtp)
gall['vert_vgradrho'] = -uwindtp * cr.calc_rusanov_alts_ausm(alttp,
                                                             rhotp) / rhotp
gall['hozt_vgradrho'] = \
    -(nwindtp*cr.calc_rusanov_lats(lattp,alttp,rhotp)\
    +ewindtp*cr.calc_rusanov_lons(lontp,lattp,alttp,rhotp))/rhotp
gp.calc_pressure(gall)
gthm = gitm.read(gthmfn)
gthm['total energy'] =\
    gthm['EUV Heating'] + gthm['Conduction'] + \
    gthm['Chemical Heating'] + gthm['Auroral Heating'] + \
    gthm['Joule Heating'] - gthm['NO Cooling'] - gthm['O Cooling']
savepath = '/Users/guod/tmp/'
예제 #8
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)
예제 #9
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
예제 #10
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
예제 #11
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
gallfn = '/Users/guod/data/GITMOutput/run_shrink_notides_tmp/UA/data/3DALL_t030323_000004.bin'
gthmfn = '/Users/guod/data/GITMOutput/run_shrink_notides_tmp/UA/data/3DTHM_t030323_000004.bin'
gall = gitm.read(gallfn)
lontp = gall['Longitude']
lattp = gall['Latitude']
alttp = gall['Altitude']
Re = 6371*1000 # Earth radius, unit: m
RR = Re+alttp
omega = 2*np.pi/(24*3600)
rhotp = gall['Rho']
nwindtp = gall['V!Dn!N (north)']
ewindtp = gall['V!Dn!N (east)'] + omega*RR*np.cos(lattp)
uwindtp = gall['V!Dn!N (up)']
gall['div_rhov'] = \
    -(cr.calc_div_hozt(lontp, lattp, alttp, rhotp*nwindtp, rhotp*ewindtp)\
    +cr.calc_div_vert(alttp, rhotp*uwindtp))/rhotp
gall['vert_divv'] = -cr.calc_div_vert(alttp, uwindtp)
gall['hozt_divv'] = -cr.calc_div_hozt(lontp, lattp, alttp, nwindtp, ewindtp)
gall['vert_vgradrho'] = -uwindtp*cr.calc_rusanov_alts_ausm(alttp,rhotp)/rhotp
gall['hozt_vgradrho'] = \
    -(nwindtp*cr.calc_rusanov_lats(lattp,alttp,rhotp)\
    +ewindtp*cr.calc_rusanov_lons(lontp,lattp,alttp,rhotp))/rhotp
gp.calc_pressure(gall)
gthm = gitm.read(gthmfn)
gthm['total energy'] =\
    gthm['EUV Heating'] + gthm['Conduction'] + \
    gthm['Chemical Heating'] + gthm['Auroral Heating'] + \
    gthm['Joule Heating'] - gthm['NO Cooling'] - gthm['O Cooling']
savepath='/Users/guod/tmp/'

def multiple_alts_const_alt():
예제 #13
0
파일: work3_final1.py 프로젝트: guodj/work
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