Beispiel #1
0
def normalize_rho(orbitfile, lat, lon, alt, rho, base_alt):
    """
    Uses the MSIS empirical model to return the helium and total mass density in an array

    Arguments:
        orbitfile:  the filename of the DE-2 orbit
        lat     :  array of latitudes  [deg]
        long    :  array of longitudes [deg]
        alt     :  array of altitudes above body surface [km]
        rho     :  array of unnormalized number density values for helium (1/cm^3)
        base_alt:  the fixed altitude to normalize density value

    Returns:
        rho_matrix  : a 2Xn matrix of normalized number densities at the fixed "base altitude" and the expected MSIS value
                      densites are first row - i.e. rho_matrix[0:all]
                      MSIS expected values are second row - i.e. rho_matrix[1:all]
    """
    species = whatplot
    rho_norm = np.zeros(len(rho))
    rho_MSIS_fixed, rho_MSIS_vary = np.zeros(len(rho)), np.zeros(len(rho))
    ratio = np.zeros(len(rho))
    date = make_date(orbitfile)

    for i in range(0, len(rho)):
        # MSIS Point objects - pt1 = fixed alt, pt2 = variable alt
        pt1 = Point(date, lat[i], lon[i], base_alt)
        pt2 = Point(date, lat[i], lon[i], alt[i])

        result1, result2 = pt1.run_msis(), pt2.run_msis(
        )  # call MSIS for these Point objects
        rho_MSIS_fixed[i] = result1.nn[species]  # particles/cm^3
        rho_MSIS_vary[i] = result2.nn[species]
        ratio[i] = rho_MSIS_fixed[i] / rho_MSIS_vary[i]
        rho_norm[i] = rho[i] * ratio[i]

    plt.subplot(211)
    plt.title(filenames[j])
    plt.plot(alt, rho_MSIS_fixed, label='MSIS rho fixed')
    plt.plot(alt, rho_MSIS_vary, label='MSIS rho vary')
    plt.plot(alt, rho, label='rho')
    plt.plot(alt, rho_norm, label='rho norm')

    plt.legend(loc=1)
    plt.ylabel(whatplot + ' Density 1/cm^3')
    plt.ticklabel_format(axis='y', style='sci', scilimits=(0, 0))
    plt.grid()

    plt.subplot(212)
    plt.plot(alt, ratio)
    plt.xlabel('Altitude')
    plt.ylabel(r'Ratio MSIS $\rho(z_0))/ \rho(z)$')
    plt.minorticks_on()
    plt.grid()
    plt.show()

    rho_matrix = np.array([rho_norm, rho_MSIS_fixed])
    return rho_matrix  # return both so you can plot
Beispiel #2
0
def main2():
    dn = datetime(2011, 3, 23, 9, 30)
    lat = 0.
    lon = -80.
    alt = 250.

    pt = Point(dn, lat, lon, alt)
    pt.run_igrf()
    pt.run_hwm93()
    pt.run_msis()
    pt.run_iri()

    print pt
    print pt.nn
    print pt.Tn_msis
Beispiel #3
0
def pyglowinput(
        latlonalt=[65.1367, -147.4472, 250.00],
        dn_list=[datetime(2015, 3, 21, 8, 00),
                 datetime(2015, 3, 21, 20, 00)],
        z=None):

    if z is None:
        z = sp.linspace(50., 1000., 200)
    dn_diff = sp.diff(dn_list)
    dn_diff_sec = dn_diff[-1].seconds
    timelist = sp.array([calendar.timegm(i.timetuple()) for i in dn_list])
    time_arr = sp.column_stack((timelist, sp.roll(timelist, -1)))
    time_arr[-1, -1] = time_arr[-1, 0] + dn_diff_sec

    v = []
    coords = sp.column_stack((sp.zeros((len(z), 2), dtype=z.dtype), z))
    all_spec = ['O+', 'NO+', 'O2+', 'H+', 'HE+']
    Param_List = sp.zeros((len(z), len(dn_list), len(all_spec), 2))
    for idn, dn in enumerate(dn_list):
        for iz, zcur in enumerate(z):
            latlonalt[2] = zcur
            pt = Point(dn, *latlonalt)
            pt.run_igrf()
            pt.run_msis()
            pt.run_iri()

            # so the zonal pt.u and meriodinal winds pt.v  will coorispond to x and y even though they are
            # supposed to be east west and north south. Pyglow does not seem to have
            # vertical winds.
            v.append([pt.u, pt.v, 0])

            for is1, ispec in enumerate(all_spec):
                Param_List[iz, idn, is1, 0] = pt.ni[ispec] * 1e6

            Param_List[iz, idn, :, 1] = pt.Ti

            Param_List[iz, idn, -1, 0] = pt.ne * 1e6
            Param_List[iz, idn, -1, 1] = pt.Te
    Param_sum = Param_List[:, :, :, 0].sum(0).sum(0)
    spec_keep = Param_sum > 0.
    species = sp.array(all_spec)[spec_keep[:-1]].tolist()
    species.append('e-')
    Param_List[:, :] = Param_List[:, :, spec_keep]
    Iono_out = IonoContainer(coords,
                             Param_List,
                             times=time_arr,
                             species=species)
    return Iono_out
Beispiel #4
0
def pyglowinput(latlonalt=[65.1367, -147.4472, 250.00], dn_list=[datetime(2015, 3, 21, 8, 00), datetime(2015, 3, 21, 20, 00)], z=None):


    if z is None:
        z = sp.linspace(50., 1000., 200)
    dn_diff = sp.diff(dn_list)
    dn_diff_sec = dn_diff[-1].seconds
    timelist = sp.array([calendar.timegm(i.timetuple()) for i in dn_list])
    time_arr = sp.column_stack((timelist, sp.roll(timelist, -1)))
    time_arr[-1, -1] = time_arr[-1, 0]+dn_diff_sec

    v=[]
    coords = sp.column_stack((sp.zeros((len(z), 2), dtype=z.dtype), z))
    all_spec = ['O+', 'NO+', 'O2+', 'H+', 'HE+']
    Param_List = sp.zeros((len(z), len(dn_list),len(all_spec),2))
    for idn, dn in enumerate(dn_list):
        for iz, zcur in enumerate(z):
            latlonalt[2] = zcur
            pt = Point(dn, *latlonalt)
            pt.run_igrf()
            pt.run_msis()
            pt.run_iri()

            # so the zonal pt.u and meriodinal winds pt.v  will coorispond to x and y even though they are
            # supposed to be east west and north south. Pyglow does not seem to have
            # vertical winds.
            v.append([pt.u, pt.v, 0])

            for is1, ispec in enumerate(all_spec):
                Param_List[iz, idn, is1, 0] = pt.ni[ispec]*1e6

            Param_List[iz, idn, :, 1] = pt.Ti

            Param_List[iz, idn, -1, 0] = pt.ne*1e6
            Param_List[iz, idn, -1, 1] = pt.Te
    Param_sum = Param_List[:, :, :, 0].sum(0).sum(0)
    spec_keep = Param_sum > 0.
    species = sp.array(all_spec)[spec_keep[:-1]].tolist()
    species.append('e-')
    Param_List[:, :] = Param_List[:, :, spec_keep]
    Iono_out = IonoContainer(coords, Param_List, times = time_arr, species=species)
    return Iono_out
Beispiel #5
0
Hp_mbar = np.zeros(len(m))
Hp_he = np.zeros(len(m))
Hp_n2 = np.zeros(len(m))
Hp_o1 = np.zeros(len(m))

k = 1.3806 * 10**(-23)  #Boltzmann's constant
g0 = 9.81  #m/s^2
R = 6373  #Radius of earth in km
Av = 6.022141 * 10**23  #Avogadro's Constant
n = 0
rho = np.zeros(len(m))

#Iterate through altitudes in range m
for x in m:
    pt = Point(dn, lat, lon, x)
    result = pt.run_msis()
    #Knudsen number estimate
    n_dens_tot = result.nn['HE']+result.nn['N2']+result.nn['O2'] \
        +result.nn['AR']+result.nn['H']+result.nn['O']+result.nn['N']# number density per cm^3

    g = g0 * R**2 / (R + x)**2
    m_dens1 = (result.nn['HE']*.004003/Av+result.nn['N2']*.0280134/Av\
    +result.nn['O2']*.032/Av+result.nn['AR']*.039948/Av+result.nn['N']\
    *.01401/Av+result.nn['H']*.001/Av+result.nn['O']*.016/Av)#kg/cm^3

    Mbar[n] = m_dens1 * Av * 1000 / (n_dens_tot)  #kg/kmol
    Tn[n] = result.Tn_msis

    #Follows form of kT/mg for pressure scale height
    Hp_mbar[n] = k * Tn[n] / (Mbar[n] * g) * Av
    Hp_he[n] = k * Tn[n] / (.004003 / Av * g) / 1000
Beispiel #6
0
    # run_parallel()

    # JMAX = 121
    # DEN_I = np.zeros((JMAX))

    dn = datetime(2015, 10, 23, 21, 0)
    msis_alt = 335.
    msis_lat = 0.
    msis_lon = -40.

    # dn = datetime(2011, 3, 23, 9, 30)
    # msis_lat = 0.
    # msis_lon = -80.
    # msis_alt = 250.

    # Criando o Point do PyGlow
    # Criando o Point do PyGlow
    print('criando ponto')
    ponto = Point(dn, msis_lat, msis_lon, msis_alt)
    print('rodando igrf')
    ponto.run_igrf()
    print('rodando hwm')
    ponto.run_hwm93()
    print(ponto.u, ponto.v)
    print('rodando msis')
    ponto.run_msis()
    print(ponto.Tn_msis, np.float64(ponto.nn['O']), np.float64(ponto.nn['O2']), np.float64(ponto.nn['N2']))

    # from pyglow.pyglow import update_indices
    # update_indices([2012, 2016])  # grabs indices for 2012 and 2013
Beispiel #7
0
def add_msis(inst, glat_label='glat', glong_label='glong', alt_label='alt'):
    """ 
    Uses MSIS model to obtain thermospheric values.
    
    Uses pyglow module to run MSIS. Configured to use actual solar parameters to run 
    model.
    
    Example
    -------
        # function added velow modifies the inst object upon every inst.load call
        inst.custom.add(add_msis, 'modify', glat_label='custom_label')
    
    Parameters
    ----------
    inst : pysat.Instrument
        Designed with pysat_sgp4 in mind
    glat_label : string
        label used in inst to identify WGS84 geodetic latitude (degrees)
    glong_label : string
        label used in inst to identify WGS84 geodetic longitude (degrees)
    alt_label : string
        label used in inst to identify WGS84 geodetic altitude (km, height above surface)
        
    Returns
    -------
    inst
        Input pysat.Instrument object modified to include MSIS values winds.
        'Nn' total neutral density particles/cm^3
        'Nn_N' Nitrogen number density (particles/cm^3)
        'Nn_N2' N2 number density (particles/cm^3)
        'Nn_O' Oxygen number density (particles/cm^3)
        'Nn_O2' O2 number density (particles/cm^3)
        'Tn_msis' Temperature from MSIS (Kelvin)
        
    """

    import pyglow
    from pyglow.pyglow import Point

    msis_params = []
    # print 'IRI Simulations'
    for time, lat, lon, alt in zip(inst.data.index, inst[glat_label],
                                   inst[glong_label], inst[alt_label]):
        pt = Point(time, lat, lon, alt)
        pt.run_msis()
        msis = {}
        total = 0
        for key in pt.nn.keys():
            total += pt.nn[key]
        msis['Nn'] = total
        msis['Nn_N'] = pt.nn['N']
        msis['Nn_N2'] = pt.nn['N2']
        msis['Nn_O'] = pt.nn['O']
        msis['Nn_O2'] = pt.nn['O2']
        msis['Tn_msis'] = pt.Tn_msis
        msis_params.append(msis)
    # print 'Complete.'
    msis = pds.DataFrame(msis_params)
    msis.index = inst.data.index
    inst[msis.keys()] = msis

    # metadata
    inst.meta['Nn'] = {
        'units': 'cm^-3',
        'desc': 'Total neutral number particle density from MSIS.'
    }
    inst.meta['Nn_N'] = {
        'units': 'cm^-3',
        'desc': 'Total nitrogen number particle density from MSIS.'
    }
    inst.meta['Nn_N2'] = {
        'units': 'cm^-3',
        'desc': 'Total N2 number particle density from MSIS.'
    }
    inst.meta['Nn_O'] = {
        'units': 'cm^-3',
        'desc': 'Total oxygen number particle density from MSIS.'
    }
    inst.meta['Nn_O2'] = {
        'units': 'cm^-3',
        'desc': 'Total O2 number particle density from MSIS.'
    }
    inst.meta['Tn_msis'] = {
        'units': 'K',
        'desc': 'Neutral temperature from MSIS.'
    }

    return
Kn1 = np.zeros(len(m))  #Knudsen number for characteristic length
Kn2 = np.zeros(len(m))
Kn1At = np.zeros(len(m))  #Atmospheric knudsen number
Kn2At = np.zeros(len(m))
k = 1.3806 * 10**(-23)  #Boltzmann's constant
g0 = 9.81  #m/s^2
R = 6373  #Radius of earth in km
Av = 6.022141 * 10**23  #Avogadro's Constant
n = 0
rho = np.zeros(len(m))

#Iterate through altitudes in range m
for x in m:
    pt = Point(dn, lat, lon, x)
    pt2 = Point(dn2, lat, lon, x)
    result = pt.run_msis()
    result2 = pt2.run_msis()

    #Knudsen number estimate
    n_dens_tot = result.nn['HE']+result.nn['N2']+result.nn['O2'] \
        +result.nn['AR']+result.nn['H']+result.nn['O']+result.nn['N']# number density per cm^3

    d_avg = (result.nn['HE']/n_dens_tot*260+result.nn['N2']/n_dens_tot*364\
        +result.nn['O2']/n_dens_tot*346+result.nn['AR']/n_dens_tot*340)\
        *10**(-12)+(result.nn['H']+result.nn['O']+result.nn['N'])/n_dens_tot*5.046*10**(-10)# average kinetic diameter of
    # molecules in atmosphere. Note H and O are ignored due to no data on
    # their kinetic diameters and the breakdown of the model with ions
    # (hard sphere collisions of molecules)
    lam = 1 / (math.sqrt(2) * math.pi * d_avg**2 * n_dens_tot * 10**(6))
    # lam = 1/(pi*Nv*D^2*sqrt(2))
    L = 1  #in meters. Chosen characteristic length
Beispiel #9
0
from pyglow.pyglow import Point
from datetime import datetime

dn = datetime(2011, 3, 23, 9, 30)
lat = 0.
lon = -80.
alt = 250.

pt = Point(dn, lat, lon, alt)

print "Before running any models:"
print pt

pt.run_igrf()
pt.run_hwm93()
pt.run_msis()
pt.run_iri()

print "After running models:"
print pt
Beispiel #10
0
date = datetime(2000, 1, 1, 0, 0)               # (yr, month, day, hour, minute) - refer to datetime module online
latitude = 45
longitude = 90
altitude = 400

#--------------------------------------------------

# for now we will not deal with inputting our out geophys indices, so we let the Point obj do this for us.
# Now make the Point object!

new_pt = Point(date, latitude, longitude, altitude)

# from this new_pt Point object, we can run MSIS (or anything else in the Point class).

result = new_pt.run_msis()          # result now contains the neutral temp, number densities (given in the run_msis fuction)
                                    # and total number density for the specific variables given above
'''
check them out...
which neutral species do you what to look at? 
Can be: 
HE, O, N2, O2, AR, H, N, O_anomalous, or rho (total number density) 

Or:
Tn_msis (neutral temperature [K])
'''

species = 'HE'      # <---- change this to whatever species you want!

density = result.nn[species]
total_density = result.rho
Beispiel #11
0
                elif i == 5:
                    long[k] = float(line.split(delimiter)[i])
                elif i == 6:
                    LST[k] = float(line.split(delimiter)[i])
                else:
                    continue
            k += 1  # only increment k once per two lines
        counter += 1
    fread.close()

    # Get MSIS temperature data
    if add_MSIS:
        date = make_date(filenames[j])
        for i in range(0, len(temp)):
            pt = Point(date, lat[i], long[i], alt[i])
            result = pt.run_msis()  # call MSIS for these Point objects
            temp_MSIS[i] = result.Tn_msis

    # plt the data....

    print('Done reading files. Plotting...')

    plt.title('DE2 Orbit 1614 - LT 19.0')
    plt.scatter(lat, temp, marker='.', label='DE-2')
    if add_MSIS:
        plt.scatter(lat, temp_MSIS, marker='.', label='MSIS')
    plt.ylabel('Neutral Temperature [K]')
    plt.xlabel('Latitude [deg]')
    plt.legend()
    #plt.ylim([850, 1425])
    #plt.xlim([40, -40])
dn = datetime(2010, 3, 23, 15, 30)
lat = 40.
lon = -80.
alt = 250.

pt = Point(dn, lat, lon, alt)

pt.run_hwm93()
pt.run_hwm07()
pt.run_hwm14()

pt.run_hwm(version=1993)
pt.run_hwm(version=2007)
pt.run_hwm(version=2014)
pt.run_hwm()

pt.run_msis()
pt.run_msis(version=2000)

pt.run_igrf()
pt.run_igrf(version=2011)

pt.run_iri()
pt.run_iri(version=2016)
pt.run_iri(version=2012)

try:
    pt.run_iri(version=2020)  # should fail
except ValueError as e:
    print("Caught an exception: %s" % e)