Ejemplo n.º 1
0
def test_worldgrid():
    glat, glon = latlonworldgrid(latstep=10, lonstep=20)
    assert glat[0, 0] == approx(-90.)
    assert glat[0, 0] == approx(glat[0, :])
    assert glon[0, 1] == approx(-160.)
    assert glon[0, 0] == approx(glon[:, 0])
Ejemplo n.º 2
0
    p = p.parse_args()

    if not p.simtime: #cycle through a few times for a demo
        dtime = date_range(datetime.now(),periods=24,freq='1H',tz=UTC,normalize=True).to_pydatetime()
    else:
        dtime = parse(p.simtime)
#%% altitude 1-D mode
    if p.latlon is not None:
        print('entering single location mode')
        if p.altkm is None:
            p.altkm = (60.,1000,5)
        altkm = arange(p.altkm[0],p.altkm[1],p.altkm[2])
        glat,glon=p.latlon
#%% lat/lon grid mode at constant altitude
    else:# len(p.altkm)==1:
        print('lat/lon not specified, entering auto whole-world grid mode at first altitude')
        if p.altkm is None:
            altkm = 200.
        else:
            altkm = p.altkm[0]
        glat,glon = latlonworldgrid()

    altkm = atleast_1d(altkm)
    print(f'using altitudes from {altkm[0]:.1f} to {altkm[-1]:.1f} km')

    dens,temp = rungtd7(dtime,altkm,glat,glon,p.f107a,p.f107,p.ap)
#%%
    plotgtd(dens,temp,dtime,altkm,p.ap,p.f107,glat,glon,p.odir)
    show()

Ejemplo n.º 3
0
def main():
    p = ArgumentParser(
        description='calls MSISE-00 from Python, save to NetCDF4 and/or plot')
    p.add_argument(
        '-t',
        '--time',
        help=
        'time: (single time or START STOP (1 hour time step) or list of times)',
        nargs='+',
        required=True)
    p.add_argument(
        '-a',
        '--altkm',
        help='altitude (km). scalar, or (start,stop,step) or list of alts.',
        type=float,
        nargs='+',
        required=True)
    p.add_argument('-c',
                   '--latlon',
                   help='geodetic latitude/longitude (deg)',
                   metavar=('lat', 'lon'),
                   type=float,
                   nargs=2)
    p.add_argument('-o', '--odir', help='directory to write plots to')
    p.add_argument('-w', help='NetCDF4 .nc filename to write')
    p.add_argument('-gs',
                   help='geographic grid spacing (lat, lon)',
                   nargs=2,
                   type=float,
                   default=(10, 10))
    p.add_argument('-q',
                   '--quiet',
                   help='disable plotting',
                   action='store_true')
    P = p.parse_args()

    # %% altitude
    if len(P.altkm) == 1:
        altkm = P.altkm[0]
    elif len(P.altkm) == 3:
        altkm = np.arange(*P.altkm)
    else:
        altkm = P.altkm
# %% latlon
    if P.latlon is not None:
        glat, glon = P.latlon
    else:
        glat, glon = latlonworldgrid(*P.gs)
# %% run
    atmos = msise00.run(P.time, altkm, glat, glon)
    # %% save
    if P.w:
        ncfn = Path(P.w).expanduser()
        print('saving', ncfn)
        # NOTE: .squeeze() avoids ValueError: unsupported dtype for netCDF4 variable: datetime64[ns]
        atmos.squeeze().to_netcdf(ncfn)


# %% plot
    if msplots is not None and not P.quiet:
        msplots.plotgtd(atmos, P.odir)
        show()
    else:
        print('skipped plots')