コード例 #1
0
ファイル: legacy.py プロジェクト: climatepals/iri2016
def IRI(time, altkmrange, glat, glon, ap=None, f107=None, ssn=None, var=None):

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

    assert len(altkmrange) == 3, "altitude (km) min, max, step"

    #        doy = squeeze(TimeUtilities().CalcDOY(year, month, dom))

    # IRI options
    jf = Switches()

    # additional "input parameters" (necessary to scale the empirical model results
    # to measurements)
    #    addinp = -np.ones(12)

    # ------------------------------------------------------------------------------
    #
    #    if time.year < 1958:
    #
    #        addinp[10 - 1] = ssn  # RZ12  (This switches 'jf[17 - 1]' to '0' and
    #                            # uses correlation function to estimate IG12)
    #
    #        jf[25 - 1] = 1        #   25    F107D from APF107.DAT  F107D user input (oarr(41))         1
    #        jf[27 - 1] = 1        #   27    IG12 from file         IG12 - user                         1
    #        jf[32 - 1] = 1        #   32    F10.7_81 from file     PF10.7_81 - user input (oarr(46))   1
    #
    #    else:  # case for solar and geomagnetic indices from files
    #
    #        jf[17 - 1] = 1        #   17    Rz12 from file         Rz12 - user input                   1
    #        jf[26 - 1] = 1        #   26    foF2 storm model       no storm updating                   1
    #        jf[35 - 1] = 1        #   35    foE storm model        no foE storm updating               0
    #     #
    #     #------------------------------------------------------------------------------

    mmdd = 100 * time.month + time.day  # month and dom (MMDD)
    # hour + 25 denotes UTC time
    dhour = (time.hour + 25) + time.minute / 60.0
    # %% more inputs
    jmag = 0  # 0: geographic; 1: geomagnetic
    # iut = 0             #  0: for LT;     1: for UT
    # height = 300.       #  in km
    # h_tec_max = 2000    #  0: no TEC; otherwise: upper boundary for integral
    # ivar = var          #  1: altitude; 2: latitude; 3: longitude; ...

    # Ionosphere (IRI)
    #        a, b = iriwebg(jmag, jf, glat, glon, int(time.year), mmdd, iut, time.hour,
    #            height, h_tec_max, ivar, ivbeg, ivend, ivstp, addinp, self.iriDataFolder)

    altkm = np.arange(*altkmrange)
    if altkm.size < 10:
        raise ValueError(
            "Altitude grid must have enough points to compute quantities of interest"
        )

    outf, oarr = iri16.iri_sub(jf, jmag, glat, glon, time.year, mmdd, dhour,
                               altkmrange[0], altkmrange[1], altkmrange[2],
                               str(proot / "data/"))

    outf = outf[:, :altkm.size]
    # %% collect output
    dsf = {
        k:
        (("time", "alt_km", "lat", "lon"), np.atleast_2d(v[None, :, None,
                                                           None]))
        for (k, v) in zip(simout, outf[:11, :])
    }

    dsf.update({"NmF2": (("time", "lat", "lon"), np.atleast_3d(oarr[0]))})
    dsf.update({"hmF2": (("time", "lat", "lon"), np.atleast_3d(oarr[1]))})
    dsf.update({"NmF1": (("time", "lat", "lon"), np.atleast_3d(oarr[2]))})
    dsf.update({"hmF1": (("time", "lat", "lon"), np.atleast_3d(oarr[3]))})
    dsf.update({"NmE": (("time", "lat", "lon"), np.atleast_3d(oarr[4]))})
    dsf.update({"hmE": (("time", "lat", "lon"), np.atleast_3d(oarr[5]))})
    dsf.update({"B0": (("time", "lat", "lon"), np.atleast_3d(oarr[9]))})

    iri = xarray.Dataset(
        dsf,
        coords={
            "time": [time],
            "alt_km": altkm,
            "lat": [glat],
            "lon": [glon]
        },
        attrs={
            "f107": oarr[40],
            "ap": oarr[50],
            "glat": glat,
            "glon": glon,
            "time": time
        },
    )

    return iri
コード例 #2
0
def IRI(time, altkm, glat, glon, ap=None, f107=None, ssn=None, var=None):

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

    altkm = np.atleast_1d(altkm)

#        doy = squeeze(TimeUtilities().CalcDOY(year, month, dom))

    # IRI options
    jf = Switches()

    # additional "input parameters" (necessary to scale the empirical model results
    # to measurements)
#    addinp = -np.ones(12)

    # ------------------------------------------------------------------------------
    #
#    if time.year < 1958:
#
#        addinp[10 - 1] = ssn  # RZ12  (This switches 'jf[17 - 1]' to '0' and
#                            # uses correlation function to estimate IG12)
#
#        jf[25 - 1] = 1        #   25    F107D from APF107.DAT  F107D user input (oarr(41))         1
#        jf[27 - 1] = 1        #   27    IG12 from file         IG12 - user                         1
#        jf[32 - 1] = 1        #   32    F10.7_81 from file     PF10.7_81 - user input (oarr(46))   1
#
#    else:  # case for solar and geomagnetic indices from files
#
#        jf[17 - 1] = 1        #   17    Rz12 from file         Rz12 - user input                   1
#        jf[26 - 1] = 1        #   26    foF2 storm model       no storm updating                   1
#        jf[35 - 1] = 1        #   35    foE storm model        no foE storm updating               0
#     #
#     #------------------------------------------------------------------------------

    mmdd = 100*time.month + time.day               # month and dom (MMDD)
    # hour + 25 denotes UTC time
    dhour = (time.hour + 25) + time.minute/60.
# %% more inputs
    jmag = 0  # 0: geographic; 1: geomagnetic
    # iut = 0             #  0: for LT;     1: for UT
    # height = 300.       #  in km
    # h_tec_max = 2000    #  0: no TEC; otherwise: upper boundary for integral
    # ivar = var          #  1: altitude; 2: latitude; 3: longitude; ...

    # Ionosphere (IRI)
#        a, b = iriwebg(jmag, jf, glat, glon, int(time.year), mmdd, iut, time.hour,
#            height, h_tec_max, ivar, ivbeg, ivend, ivstp, addinp, self.iriDataFolder)

    outf, oarr = iri16.iri_sub(jf, jmag, glat, glon,
                               time.year, mmdd, dhour, altkm,
                               proot/'data/')

# %% collect output
    dsf = {k: (('time', 'alt_km', 'lat', 'lon'), np.atleast_2d(v[None, :, None, None])) for (k, v) in zip(simout, outf[:9, :])}

    dsf.update({'NmF2': (('time', 'lat', 'lon'), np.atleast_3d(oarr[0]))})
    dsf.update({'hmF2': (('time', 'lat', 'lon'), np.atleast_3d(oarr[1]))})
    dsf.update({'NmF1': (('time', 'lat', 'lon'), np.atleast_3d(oarr[2]))})
    dsf.update({'hmF1': (('time', 'lat', 'lon'), np.atleast_3d(oarr[3]))})
    dsf.update({'NmE': (('time', 'lat', 'lon'), np.atleast_3d(oarr[4]))})
    dsf.update({'hmE': (('time', 'lat', 'lon'), np.atleast_3d(oarr[5]))})
    dsf.update({'B0': (('time', 'lat', 'lon'), np.atleast_3d(oarr[9]))})

    iri = xarray.Dataset(dsf,
                         coords={'time': [time], 'alt_km': altkm, 'lat': [glat], 'lon': [glon]},
                         attrs={'f107': oarr[40], 'ap': oarr[50],
                                'glat': glat, 'glon': glon, 'time': time,
                                })

# FIRI Ne (in m-3)
#        iri_ne_firi = self._RmNeg(a[13 - 1, :])[0]

# Ionic density (NO+, O2+, O+, H+, He+, N+, Cluster Ions)

#        iri = {'ne' : neIRI, 'te' : teIRI, 'ti' : tiIRI, 'neFIRI' : iri_ne_firi,
#            'oplus' : oplusIRI, 'o2plus' : o2plusIRI, 'noplus' : noplusIRI,
#            'hplus' : hplusIRI, 'heplus' : heplusIRI, 'nplus' : nplusIRI}

#        iriadd = { 'NmF2' : b[1 - 1, :][0], 'hmF2' : b[2 - 1, :][0],
#                'B0' : b[10 - 1, :][0] }

    return iri