Example #1
0
def test_gtd():

    iyd, utsec, stl = sd.datetime2gtd(T, glon=42)

    assert_allclose(iyd, 183)
    assert_allclose(utsec, (43200, 0, 43200))
    assert_allclose(stl, (14.8, 2.8, 14.8))
Example #2
0
def test_list():

    iyd, utsec, stl = sd.datetime2gtd(T, glon=42)

    assert (iyd == 183).all()
    assert_allclose(utsec, (43200, 0, 43200, 43200))
    assert_allclose(stl, (14.8, 2.8, 14.8, 14.8))
Example #3
0
def run(time: datetime, altkm: np.ndarray, glat: float, glon: float,
        f107a: float, f107: float, ap: int) -> xarray.Dataset:
    altkm = np.atleast_1d(altkm).astype(float)

    if isinstance(time, str):
        time = parse(time)

    iyd, utsec, stl = datetime2gtd(time, glon)

    merid = np.empty(altkm.size, dtype=float)
    zonal = np.empty(altkm.size, dtype=float)

    for i, a in enumerate(altkm):
        w = hwm93fort.gws5(iyd, utsec, a, glat, glon, stl, f107a, f107,
                           (ap, ap))
        merid[i] = w[0]
        zonal[i] = w[1]

    # %% assemble output
    winds = xarray.Dataset(
        {
            "meridional": ("alt_km", merid),
            "zonal": ("alt_km", zonal)
        },
        coords={"alt_km": altkm},
        attrs={
            "time": time.isoformat(),
            "glat": glat,
            "glon": glon
        },
    )

    return winds
Example #4
0
def test_list():

    iyd, utsec, stl = sd.datetime2gtd(T, glon=42)

    assert (iyd == 183).all()
    assert utsec == approx((43200, 0, 43200, 43200))
    assert stl == approx((14.8, 2.8, 14.8, 14.8))
Example #5
0
def rungtdGLOW(dtime, altkm, glat, glon, f107a, f107, ap, mass, tselecopts):
    chdir(str(glowpath))
    ap = atleast_1d(ap)
    if ap.size == 1: ap = repeat(ap, 7)
    species = ['He', 'O', 'N2', 'O2', 'Ar', 'Total', 'H', 'N', 'AnomalousO']
    ttypes = ['exotemp', 'heretemp']

    tselec(tselecopts)  #like the msis_driver example
    logging.debug('tselec options used:   {}'.format(
        csw.sw))  #don't use tretrv, it doesn't work

    iyd, utsec, stl = datetime2gtd(dtime, glon)

    altkm = atleast_1d(altkm)
    dens = empty((altkm.size, 9))
    temp = empty((altkm.size, 2))

    meters(1)  # makes output in m^-3 and kg/m^-3
    for i, a in enumerate(altkm):
        dens[i, :], temp[i, :] = gtd7(iyd, utsec, a, glat, glon, stl, f107a,
                                      f107, ap, mass)

    densd = DataArray(dens,
                      dims=['z_km', 'species'],
                      coords={
                          'z_km': altkm,
                          'species': species
                      })
    tempd = DataArray(temp,
                      dims=['z_km', 'temperature'],
                      coords={
                          'z_km': altkm,
                          'temperature': ttypes
                      })
    return densd, tempd
Example #6
0
def test_datetime():
    t = T[0]
    assert isinstance(t, datetime.datetime)

    iyd, utsec, stl = sd.datetime2gtd(t, glon=42)

    assert iyd == 183
    assert utsec == 43200
    assert_allclose(stl, 14.8)
Example #7
0
def test_dt64():
    t = T[2]
    assert isinstance(t, np.datetime64)

    iyd, utsec, stl = sd.datetime2gtd(t, glon=42)

    assert iyd == 183
    assert utsec == 43200
    assert_allclose(stl, 14.8)
Example #8
0
def test_datetime():
    t = T[0]
    assert isinstance(t, datetime.datetime)

    iyd, utsec, stl = sd.datetime2gtd(t, glon=42)

    assert iyd == 183
    assert utsec == 43200
    assert stl == approx(14.8)
Example #9
0
def test_glon():
    glon = range(-180, 180 + 45, 45)

    iyd, utsec, stl = sd.datetime2gtd(T, glon)

    Estl = np.array([
        np.arange(0, 24 + 3, 3),
        np.arange(-12, 12 + 3, 3),
        np.arange(0, 24 + 3, 3),
        np.arange(0, 24 + 3, 3)
    ])

    assert_allclose(utsec, (43200, 0, 43200, 43200))
    assert_allclose(stl, Estl)
Example #10
0
def test_glon():
    glon = range(-180, 180 + 45, 45)

    iyd, utsec, stl = sd.datetime2gtd(T, glon)

    Estl = np.array([
        np.arange(0, 24 + 3, 3),
        np.arange(-12, 12 + 3, 3),
        np.arange(0, 24 + 3, 3),
        np.arange(0, 24 + 3, 3),
    ])

    assert utsec == approx((43200, 0, 43200, 43200))
    assert stl == approx(Estl)
Example #11
0
def rungtd1d(time, altkm:float, glat:float, glon:float) -> xarray.Dataset:
    """
    This is the "atomic" function looped by other functions
    """
    # %% get solar parameters for date
    f107Ap = readmonthlyApF107(time)
    f107a = f107Ap['f107s'].item()
    f107  = f107Ap['f107o'].item()
    Ap    = (f107Ap['Apo'].item(),)*7
#%%
    altkm= np.atleast_1d(altkm)
    glon = np.atleast_1d(glon).squeeze()
    glat = np.atleast_1d(glat).squeeze()

    assert isinstance(time,(np.datetime64,datetime,str)),'if you have multiple times, for loop over them'

# don't check ap, too complicated
    assert isinstance(MASS,(float,int))
    assert len(TSELECOPS)==25
#%%
    Ap = np.atleast_1d(Ap)
    if Ap.size==1:
        Ap = np.repeat(Ap,7)

    gtd7.tselec(TSELECOPS) #like the msis_driver example

    iyd,utsec,stl = datetime2gtd(time, glon)
    altkm         = np.atleast_1d(altkm)

    gtd7.meters(1) # makes output in m^-3 and kg/m^-3

    dens = np.empty((altkm.size, len(species)))
    temp = np.empty((altkm.size, len(ttypes)))
    for i,a in enumerate(altkm):
        dens[i,:], temp[i,:] = gtd7.gtd7(iyd, utsec, a, glat,glon, stl, f107a, f107, Ap,MASS)


    dsf = {k: (('time','alt_km','lat','lon'),v[None,:,None,None]) for (k,v) in zip(species, dens.T)}
    dsf.update({'Tn':  (('time','alt_km','lat','lon'), temp[:,1][None,:,None,None]),
                'Texo':(('time','alt_km','lat','lon'), temp[:,0][None,:,None,None])})

    atmos = xarray.Dataset(dsf,
                           coords={'time':[time], 'alt_km':altkm, 'lat':[glat],'lon':[glon],},
                           attrs={'Ap':Ap,'f107':f107,'f107a':f107a,
                                  'species':species})

    return atmos
Example #12
0
def rungtd1d(t,altkm,glat,glon,f107a,f107,ap):
    """
    This is the "atomic" function looped by other functions
    """
#%%
    altkm= atleast_1d(altkm)
    glon = atleast_1d(glon).squeeze()
    glat = atleast_1d(glat).squeeze()

    assert isinstance(t,(datetime,str)),'if you have multiple times, for loop over them'

    assert isinstance(f107a,(float,int))
    assert isinstance(f107,(float,int))
# don't check ap, too complicated
    assert isinstance(MASS,(float,int))
    assert len(TSELECOPS)==25
#%%
    ap = atleast_1d(ap)
    if ap.size==1:
        ap = repeat(ap,7)

    gtd7.tselec(TSELECOPS) #like the msis_driver example

    iyd,utsec,stl = datetime2gtd(t,glon)
    altkm         = atleast_1d(altkm)

    dens = DataArray(data=empty((altkm.size, len(species))),
                     coords=[altkm, species],dims=['alt_km','species'])
    temp = DataArray(data=empty((altkm.size, len(ttypes))),
                      coords=[altkm, ttypes],dims=['alt_km','temp'])

    gtd7.meters(1) # makes output in m^-3 and kg/m^-3
    for i,a in enumerate(altkm):
        dens[i,:],temp[i,:] = gtd7.gtd7(iyd,utsec,a, glat,glon,stl, f107a,f107, ap,MASS)

    return dens,temp
Example #13
0
def test_snoem():
    doy = datetime2gtd(dtime)[0]
    zno, maglat, nozm = glowfort.snoem(doy, 1.75 * log(0.4 * ap), f107)
    assert_allclose((nozm[12, 15], nozm[-2, -1]), (35077728.0, 1.118755e+08))
    return nozm
Example #14
0
def rungtd1d(time: Union[datetime, str, np.ndarray], altkm: np.ndarray,
             glat: float, glon: float) -> xarray.Dataset:
    """
    This is the "atomic" function looped by other functions
    """
    time = todt64(time)
    # %% get solar parameters for date
    f107Ap = ga.getApF107(time, smoothdays=81)
    f107a = f107Ap['f107s'].item()
    f107 = f107Ap['f107'].item()
    Ap = f107Ap['Ap'].item()
    # %% dimensions
    altkm = np.atleast_1d(altkm)
    assert altkm.ndim == 1
    assert isinstance(glon, (int, float))
    assert isinstance(glat, (int, float))
    assert isinstance(time, np.datetime64) or (time.size == 1 and isinstance(
        time[0],
        np.datetime64)), 'if you have multiple times, for loop over them'

    # don't check ap, too complicated
    assert isinstance(MASS, (float, int))
    assert len(TSELECOPS) == 25
    # %%
    gtd7.tselec(TSELECOPS)  # like the msis_driver example

    iyd, utsec, stl = datetime2gtd(time, glon)
    altkm = np.atleast_1d(altkm)

    gtd7.meters(1)  # makes output in m^-3 and kg/m^-3
    # %%
    if isinstance(Ap, (float, int)):
        Ap = [Ap] * 7  # even if SW(9) == 1 due to f2py needs for array

    dens = np.empty((altkm.size, len(species)))
    temp = np.empty((altkm.size, len(ttypes)))
    for i, a in enumerate(altkm):
        dens[i, :], temp[i, :] = gtd7.gtd7(iyd, utsec, a, glat, glon, stl,
                                           f107a, f107, Ap, MASS)

    dsf = {
        k: (('time', 'alt_km', 'lat', 'lon'), v[None, :, None, None])
        for (k, v) in zip(species, dens.T)
    }
    dsf.update({
        'Tn': (('time', 'alt_km', 'lat', 'lon'), temp[:, 1][None, :, None,
                                                            None]),
        'Texo': (('time', 'alt_km', 'lat', 'lon'), temp[:, 0][None, :, None,
                                                              None])
    })

    atmos = xarray.Dataset(dsf,
                           coords={
                               'time': time.astype(datetime),
                               'alt_km': altkm,
                               'lat': [glat],
                               'lon': [glon],
                           },
                           attrs={
                               'Ap': Ap,
                               'f107': f107,
                               'f107a': f107a,
                               'species': species
                           })

    return atmos