예제 #1
0
def ne2xy_converter(stn, dt, nan=True, elevation=None):
    """ ??? """
    station_info = STATION_MAP[stn.upper()]
    lat = station_info.glat
    lon = station_info.glon
    point = Point(dt, lat, lon, elevation / 1e3 if elevation else 0)
    point.run_igrf()
    dec_deg = point.dec
    logger.info('using declination angle {:f} (deg) for {}'.format(
        dec_deg, stn))
    dec_rad = math.radians(dec_deg)
    cos_dec = math.cos(dec_rad)
    sin_dec = math.sin(dec_rad)

    def ne2xy(n, e):
        if n in [88888, 99999] or e in [88888, 99999]:
            if nan:
                return NP.nan, NP.nan
            else:
                return 88888, 88888
        x = cos_dec * n - sin_dec * e
        y = sin_dec * n + cos_dec * e
        return x, y

    return ne2xy
예제 #2
0
파일: boris_mover.py 프로젝트: jvierine/isr
def get_B(pos):
    """
    Use pyglow to get IGRF magnetic field
    in ECEF coordinates
    """
    lat_lon_h = jcoord.ecef2geodetic(pos[0], pos[1], pos[2])
    pt = Point(datetime.datetime(2000, 1, 1, 1, 0), lat_lon_h[0], lat_lon_h[1],
               lat_lon_h[2] / 1e3)
    pt.run_igrf()
    Bxyz = jcoord.enu2ecef(lat_lon_h[0], lat_lon_h[1], lat_lon_h[2], pt.Bx,
                           pt.By, pt.Bz)
    return (Bxyz)
예제 #3
0
파일: test.py 프로젝트: hiyoku/modeloBubble
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
예제 #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
예제 #5
0
파일: iaga2hdf.py 프로젝트: mfkiwl/pyrsss
def get_dec_tenths_arcminute(header, date):
    """
    Return the local magnetic declination angle associated with a
    sensor at the location given in *header* and *date*. The returned
    angle is in tenths of arcminutes (there are 360 * 60 * 10 tenths
    of arcminnutes in one circle).
    """
    point = Point(date, header['Geodetic Latitude'],
                  header['Geodetic Longitude'], header['Elevation'])
    point.run_igrf()
    dec_deg = point.dec
    if 'IAGA CODE' in header:
        logger.info('using declination angle {:f} (deg) for {}'.format(
            dec_deg, header['IAGA CODE']))
    else:
        logger.info('using declination angle {:f} (deg)'.format(dec_deg))
    return fix_sign(deg2tenths_of_arcminute(dec_deg))
예제 #6
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
예제 #7
0
파일: sm2iaga.py 프로젝트: butala/pyrsss
def ne2xy_converter(stn, dt, nan=True, elevation=None):
    """ ??? """
    station_info = STATION_MAP[stn.upper()]
    lat = station_info.glat
    lon = station_info.glon
    point = Point(dt, lat, lon, elevation / 1e3 if elevation else 0)
    point.run_igrf()
    dec_deg = point.dec
    dec_rad = math.radians(dec_deg)
    cos_dec = math.cos(dec_rad)
    sin_dec = math.sin(dec_rad)

    def ne2xy(n, e):
        if n in [88888, 99999] or e in [88888, 99999]:
            if nan:
                return NP.nan, NP.nan
            else:
                return 88888, 88888
        x = cos_dec * n - sin_dec * e
        y = sin_dec * n + cos_dec * e
        return x, y

    return ne2xy
예제 #8
0
파일: test.py 프로젝트: hiyoku/modeloBubble
    # 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
예제 #9
0
def add_igrf(inst, glat_label='glat', glong_label='glong', alt_label='alt'):
    """ 
    Uses International Geomagnetic Reference Field (IGRF) model to obtain geomagnetic field values.
    
    Uses pyglow module to run IGRF. 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_igrf, '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 HWM winds.
        'B' total geomagnetic field
        'B_east' Geomagnetic field component along east/west directions (+ east)
        'B_north' Geomagnetic field component along north/south directions (+ north)
        'B_up' Geomagnetic field component along up/down directions (+ up)
        'B_ecef_x' Geomagnetic field component along ECEF x
        'B_ecef_y' Geomagnetic field component along ECEF y
        'B_ecef_z' Geomagnetic field component along ECEF z
        
    """

    import pyglow
    from pyglow.pyglow import Point
    import pysatMagVect

    igrf_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_igrf()
        igrf = {}
        igrf['B'] = pt.B
        igrf['B_east'] = pt.Bx
        igrf['B_north'] = pt.By
        igrf['B_up'] = pt.Bz
        igrf_params.append(igrf)
    # print 'Complete.'
    igrf = pds.DataFrame(igrf_params)
    igrf.index = inst.data.index
    inst[igrf.keys()] = igrf

    # convert magnetic field in East/north/up to ECEF basis
    x, y, z = pysatMagVect.enu_to_ecef_vector(inst['B_east'], inst['B_north'],
                                              inst['B_up'], inst[glat_label],
                                              inst[glong_label])
    inst['B_ecef_x'] = x
    inst['B_ecef_y'] = y
    inst['B_ecef_z'] = z

    # metadata
    inst.meta['B'] = {
        'units': 'nT',
        'desc': 'Total geomagnetic field from IGRF.'
    }
    inst.meta['B_east'] = {
        'units':
        'nT',
        'desc':
        'Geomagnetic field from IGRF expressed using the East/North/Up (ENU) basis.'
    }
    inst.meta['B_north'] = {
        'units':
        'nT',
        'desc':
        'Geomagnetic field from IGRF expressed using the East/North/Up (ENU) basis.'
    }
    inst.meta['B_up'] = {
        'units':
        'nT',
        'desc':
        'Geomagnetic field from IGRF expressed using the East/North/Up (ENU) basis.'
    }

    inst.meta['B_ecef_x'] = {
        'units':
        'nT',
        'desc':
        'Geomagnetic field from IGRF expressed using the Earth Centered Earth Fixed (ECEF) basis.'
    }
    inst.meta['B_ecef_y'] = {
        'units':
        'nT',
        'desc':
        'Geomagnetic field from IGRF expressed using the Earth Centered Earth Fixed (ECEF) basis.'
    }
    inst.meta['B_ecef_z'] = {
        'units':
        'nT',
        'desc':
        'Geomagnetic field from IGRF expressed using the Earth Centered Earth Fixed (ECEF) basis.'
    }
    return
예제 #10
0
파일: testglow.py 프로젝트: jswoboda/pyglow
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
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)