Exemplo n.º 1
0
    def trace(self, x, y, z, rlim=10., r0=1., dir=-1, maxloop=1000):
        # returns the last x,y,z and arrays xx,yy,zz along trace
        # x,y,z have to be scalar

        # we need to call recalc since common block is shared between instances
        # of geopack_2008 and T89,T96,T01,T04
        self.ps = geopack.recalc(self.dt_seconds)

        parmod = self.iopt
        #       geopack.trace(xi,yi,zi,dir,rlim=10,r0=1,parmod=2,exname='t89',inname='igrf',maxloop=1000)
        if self.use_igrf:
            return geopack.trace(x,
                                 y,
                                 z,
                                 dir,
                                 rlim,
                                 r0,
                                 parmod,
                                 't89',
                                 'igrf',
                                 maxloop=maxloop)
        else:
            return geopack.trace(x,
                                 y,
                                 z,
                                 dir,
                                 rlim,
                                 r0,
                                 parmod,
                                 't89',
                                 'dip',
                                 maxloop=maxloop)
Exemplo n.º 2
0
    def get_dataset_parameters(self, OMNI_dir: str,
                               parameters: Union[List[str], str]):
        """Loads the value of parameters for the entire period of the dataset.
        Inputs:
        OMNI_dir (str): directory where OMNI data is stored.
        paras (List[str], str): parameters that will be extracted. A full list of available parameters can be seen in
                                LoadOMNI.full_para_list. """
        if isinstance(parameters, str):
            parameters = [parameters]

        parameters = parameters.copy()

        if 'dipole' in parameters:
            dataset_date_range = pd.date_range(self.start_time,
                                               self.end_time,
                                               freq='H')
            dipoles = np.empty(dataset_date_range.shape, dtype=float)
            for i, time in enumerate(dataset_date_range):
                unix_time = (time - dt.datetime(1970, 1, 1)).total_seconds()
                dipole = 180 / np.pi * geopack.recalc(unix_time)
                dipoles[i] = dipole

            self.total['dipole'] = dipoles

            parameters.remove('dipole')

        OMNI_data_loader = LoadOMNI(self.start_time,
                                    self.end_time,
                                    data_dir=OMNI_dir)
        OMNI_data_loader.load_OMNI_data(paras_in=parameters)

        for key, val in OMNI_data_loader.paras.items():
            if key in parameters:
                val = val.flatten()
                self.total[key] = val
Exemplo n.º 3
0
def tt89(pos_var_gsm, iopt=3, suffix='', igrf_only=False):
    """
    tplot wrapper for the functional interface to Sheng Tian's implementation 
    of the Tsyganenko 96 and IGRF model:

    https://github.com/tsssss/geopack

    Input
    ------
        pos_gsm_tvar: str
            tplot variable containing the position data (km) in GSM coordinates

    Parameters
    -----------
        iopt: int
            Specifies the ground disturbance level:
                iopt= 1       2        3        4        5        6      7
                           correspond to:
                kp=  0,0+  1-,1,1+  2-,2,2+  3-,3,3+  4-,4,4+  5-,5,5+  &gt =6-

        suffix: str
            Suffix to append to the tplot output variable

    Returns
    --------
        Name of the tplot variable containing the model data
    """
    pos_data = get_data(pos_var_gsm)

    if pos_data is None:
        print('Variable not found: ' + pos_var_gsm)
        return

    b0gsm = np.zeros((len(pos_data.times), 3))
    dbgsm = np.zeros((len(pos_data.times), 3))

    # convert to Re
    pos_re = pos_data.y/6371.2

    for idx, time in enumerate(pos_data.times):
        tilt = geopack.recalc(time)

        # dipole B in GSM
        b0gsm[idx, 0], b0gsm[idx, 1], b0gsm[idx, 2] = geopack.dip(pos_re[idx, 0], pos_re[idx, 1], pos_re[idx, 2])

        # T89 dB in GSM
        dbgsm[idx, 0], dbgsm[idx, 1], dbgsm[idx, 2] = t89.t89(iopt, tilt, pos_re[idx, 0], pos_re[idx, 1], pos_re[idx, 2])

    if igrf_only:
        bgsm = b0gsm
    else:
        bgsm = b0gsm + dbgsm

    saved = store_data(pos_var_gsm + '_bt89' + suffix, data={'x': pos_data.times, 'y': bgsm})

    if saved:
        return pos_var_gsm + '_bt89' + suffix
Exemplo n.º 4
0
    def __init__(self, year, month, day, hour, minute, use_igrf, *args,
                 **kwargs):
        from geopack import t01
        # epoch time since Jan. 1 1970 00:00 UT
        # datetime.timedelta
        dt = datetime.datetime(year, month, day, hour,
                               minute) - datetime.datetime(1970, 1, 1)
        # seconds from 1970/1/1 00:00 UT
        self.dt_seconds = dt.total_seconds()

        self.ps = geopack.recalc(self.dt_seconds)
        self.use_igrf = use_igrf

        from geospacepy import omnireader
        sTimeIMF = datetime.datetime(year, month, day, hour, minute)
        eTimeIMF = datetime.datetime(year, month, day, hour,
                                     minute) + datetime.timedelta(
                                         0, 0, 0, 0, 1, 0)
        omniInt = omnireader.omni_interval(sTimeIMF, eTimeIMF, '1min')
        t = omniInt['Epoch']  #datetime timestamps
        By = omniInt['BY_GSM']
        Bz = omniInt['BZ_GSM']
        Pdyn = omniInt['Pressure']
        SYM_H = omniInt['SYM_H']

        self.parmod = np.array([Pdyn, SYM_H, By, Bz, 0., 0., 0., 0., 0., 0.],
                               dtype=float)

        super(T01, self).__init__(*args, **kwargs)
        #        parmod=np.zeros(10,dtype=float)
        #        t89.tsyganenko.init_t89(year,month,day,hour,minute,use_igrf,0,parmod)
        #        t89.tsyganenko.init_t89(int(year),int(month),int(day),int(hour),int(minute),int(use_igrf))
        bounds_error = kwargs.get('bounds_error', False)
        fill_value = kwargs.get('missing_value', np.nan)

        self.citation = 'Kamodo.T01 by Lutz Rastaetter (2020), Geopack/Tsyganenko by Sheng Tian (2019) and geospacepy-lite by Liam Kilkommons (2019)'

        self.x = np.linspace(-30., 10., 40)  # make sure to avoid (0,0,0)
        self.y = np.linspace(-10., 10., 20)
        self.z = np.linspace(-10., 10., 20)

        self.variables = dict(b_x=dict(units='nT', data=None),
                              b_y=dict(units='nT', data=None),
                              b_z=dict(units='nT', data=None),
                              bvec=dict(units='nT', data=None))

        for varname in self.variables:
            units = self.variables[varname]['units']
            self.register_variable(varname, units)
Exemplo n.º 5
0
    def __init__(self, year, month, day, hour, minute, use_igrf, *args,
                 **kwargs):
        from geopack import t89
        super(T89, self).__init__(*args, **kwargs)
        # time since Jan. 1 1970 00:00 UT as datetime.timedelta
        dt = datetime.datetime(year, month, day, hour,
                               minute) - datetime.datetime(1970, 1, 1)
        # seconds from 1970/1/1 00:00 UT
        self.dt_seconds = dt.total_seconds()

        self.ps = geopack.recalc(self.dt_seconds)
        self.use_igrf = use_igrf

        from geospacepy import omnireader
        sTimeIMF = datetime.datetime(year, month, day, hour)
        eTimeIMF = datetime.datetime(
            year, month, day, hour) + datetime.timedelta(0, 0, 0, 1, 0, 0)
        omniInt = omnireader.omni_interval(sTimeIMF, eTimeIMF, 'hourly')
        t = omniInt['Epoch']  #datetime timestamps
        By, Bz = omniInt['BY_GSM'], omniInt['BZ_GSM']

        kp = omniInt['KP']
        self.iopt = int(kp[0]) + 1
        if self.iopt > 7: self.iopt = 7

        bounds_error = kwargs.get('bounds_error', False)
        fill_value = kwargs.get('missing_value', np.nan)

        self.citation = 'Kamodo.T89 by Lutz Rastaetter (2020), Geopack/Tsyganenko by Sheng Tian (2019) and geospacepy-lite by Liam Kilkommons (2019)'
        self.unit = 'nT'

        self.x = np.linspace(-30., 10., 20)
        self.y = np.linspace(-10., 10., 10)
        self.z = np.linspace(-10., 10., 10)

        self.variables = dict(b_x=dict(units='nT', data=None),
                              b_y=dict(units='nT', data=None),
                              b_z=dict(units='nT', data=None),
                              bvec=dict(units='nT', data=None))

        for varname in self.variables:
            units = self.variables[varname]['units']
            self.register_variable(varname, units)
Exemplo n.º 6
0
    def b(self, xvec):
        # x,y,z can be an array or list
        try:
            x, y, z = xvec
        except:
            x, y, z = xvec.T
# we need to call recalc since common block may be shared between instances
# of geopack-2008 and T89,T96,T01,T04
        self.ps = geopack.recalc(self.dt_seconds)

        x = np.array([x])
        y = np.array([y])
        z = np.array([z])
        x = x.flatten()
        y = y.flatten()
        z = z.flatten()
        nx = len(x)
        ny = len(y)
        nz = len(z)
        nn = min([nx, ny, nz])
        bx_out = np.zeros(nn, dtype=float)
        by_out = np.zeros(nn, dtype=float)
        bz_out = np.zeros(nn, dtype=float)

        for ix in range(nn):
            rr = np.sqrt(x[ix]**2 + y[ix]**2 + z[ix]**2)
            if (rr > 0.000001):
                bx_, by_, bz_ = geopack.t04.t04(self.parmod, self.ps, x[ix],
                                                y[ix], z[ix])
                if self.use_igrf:
                    bx0, by0, bz0 = geopack.igrf_gsm(x[ix], y[ix], z[ix])
                else:
                    bx0, by0, bz0 = geopack.dip(x[ix], y[ix], z[ix])
                bx_out[ix] = bx_ + bx0
                by_out[ix] = by_ + by0
                bz_out[ix] = bz_ + bz0
            else:
                bx_out[ix] = np.nan
                by_out[ix] = np.nan
                bz_out[ix] = np.nan

        return (np.column_stack((bx_out, by_out, bz_out)))
Exemplo n.º 7
0
def tt01(pos_var_gsm, parmod=None, suffix=''):
    """
    tplot wrapper for the functional interface to Sheng Tian's implementation of the Tsyganenko 2001 and IGRF model:

    https://github.com/tsssss/geopack

    Input
    ------
        pos_gsm_tvar: str
            tplot variable containing the position data (km) in GSM coordinates

    Parameters
    -----------
        parmod: ndarray
            10-element array (vs. time), but only the first 6 elements are used
                (1) solar wind pressure pdyn (nanopascals),
                (2) dst (nanotesla)
                (3) byimf (nanotesla)
                (4) bzimf (nanotesla)
                (5) g1-index
                (6) g2-index  (see Tsyganenko [2001] for an exact definition of these two indices)

        suffix: str
            Suffix to append to the tplot output variable

    Returns
    --------
        Name of the tplot variable containing the model data
    """
    pos_data = get_data(pos_var_gsm)

    if pos_data is None:
        print('Variable not found: ' + pos_var_gsm)
        return

    b0gsm = np.zeros((len(pos_data.times), 3))
    dbgsm = np.zeros((len(pos_data.times), 3))

    # convert to Re
    pos_re = pos_data.y/6371.2

    if parmod is not None:
        par = get_data(parmod)

        if par is not None:
            par = par.y
    else:
        print('parmod keyword required.')
        return

    for idx, time in enumerate(pos_data.times):
        tilt = geopack.recalc(time)

        # dipole B in GSM
        b0gsm[idx, 0], b0gsm[idx, 1], b0gsm[idx, 2] = geopack.dip(pos_re[idx, 0], pos_re[idx, 1], pos_re[idx, 2])

        # T96 dB in GSM
        dbgsm[idx, 0], dbgsm[idx, 1], dbgsm[idx, 2] = t01.t01(par[idx, :], tilt, pos_re[idx, 0], pos_re[idx, 1], pos_re[idx, 2])

    bgsm = b0gsm + dbgsm

    saved = store_data(pos_var_gsm + '_bt01' + suffix, data={'x': pos_data.times, 'y': bgsm})

    if saved:
        return pos_var_gsm + '_bt01' + suffix
Exemplo n.º 8
0
#Test of Sheng's geopack for Python 
from geopack import geopack
import matplotlib as plt
import math
import datetime
from dateutil import parser
import numpy as np 

# From date and time
t1 = datetime.datetime(2017,11,28,11,42,0)
tref = datetime.datetime(1970,1,1)
ut = (t1-tref).total_seconds()
#print(ut)
#978404645.0   #Correct. Tested against IDL
ps = geopack.recalc(ut)


#RBSPa test (2017-11-28 at 11 UT) from SSCWeb 
       Time                   GEO (RE)                         GSE (RE)                         GSM (RE)                          SM (RE)            
yy/mm/dd hh:mm:ss      X          Y          Z          X          Y          Z          X          Y          Z          X          Y          Z    
17/11/28 11:00:00       4.16      -2.74       0.86       2.95      -3.85       1.44       2.95      -3.12       2.67       3.69      -3.12       1.49

17/11/28 11:42:00       4.44      -3.12       0.94       3.71      -3.60       1.88 09:03:18       3.71      -2.77       2.97       4.46      -2.77       1.64 09:52:35    6.0



xgse = 3.71*6370. 
ygse = -3.60*6370.
zgse = 1.88*6370.

Exemplo n.º 9
0
def tts04(pos_var_gsm, parmod=None, suffix=''):
    """
    tplot wrapper for the functional interface to Sheng Tian's implementation of the 
    Tsyganenko-Sitnov (2004) storm-time geomagnetic field model

    https://github.com/tsssss/geopack

    Input
    ------
        pos_gsm_tvar: str
            tplot variable containing the position data (km) in GSM coordinates

    Parameters
    -----------
        parmod: ndarray
            10-element array (vs. time):
                (1) solar wind pressure pdyn (nanopascals),
                (2) dst (nanotesla),
                (3) byimf,
                (4) bzimf (nanotesla)
                (5-10) indices w1 - w6, calculated as time integrals from the beginning of a storm
                    see the reference (3) below, for a detailed definition of those variables

        suffix: str
            Suffix to append to the tplot output variable

    Returns
    --------
        Name of the tplot variable containing the model data
    """
    pos_data = get_data(pos_var_gsm)

    if pos_data is None:
        print('Variable not found: ' + pos_var_gsm)
        return

    b0gsm = np.zeros((len(pos_data.times), 3))
    dbgsm = np.zeros((len(pos_data.times), 3))

    # convert to Re
    pos_re = pos_data.y / 6371.2

    if parmod is not None:
        par = get_data(parmod)

        if par is not None:
            par = par.y
    else:
        print('parmod keyword required.')
        return

    for idx, time in enumerate(pos_data.times):
        tilt = geopack.recalc(time)

        if not np.isfinite(par[idx, :]).all():
            # skip if there are any NaNs in the input
            continue

        # dipole B in GSM
        b0gsm[idx,
              0], b0gsm[idx,
                        1], b0gsm[idx,
                                  2] = geopack.dip(pos_re[idx, 0],
                                                   pos_re[idx, 1], pos_re[idx,
                                                                          2])

        # T96 dB in GSM
        dbgsm[idx,
              0], dbgsm[idx,
                        1], dbgsm[idx,
                                  2] = t04.t04(par[idx, :], tilt, pos_re[idx,
                                                                         0],
                                               pos_re[idx, 1], pos_re[idx, 2])

    bgsm = b0gsm + dbgsm

    saved = store_data(pos_var_gsm + '_bts04' + suffix,
                       data={
                           'x': pos_data.times,
                           'y': bgsm
                       })

    if saved:
        return pos_var_gsm + '_bts04' + suffix
Exemplo n.º 10
0
    def test_to_known_values(self):
        """geopack should give known result with known input"""

        # test recalc, which returns dipole tilt angle in rad.
        self.assertEqual(self.test['recalc'],
                         geopack.recalc(self.test['ut'], *self.test['v_gse']))

        # test sun, which returns 5 angles in rad.
        self.assertEqual(self.test['sun'], geopack.sun(self.test['ut']))

        # test internal models.
        self.assertTrue(
            approx_eq(self.test['igrf'],
                      geopack.igrf_gsm(*self.test['r_gsm'])))
        self.assertTrue(
            approx_eq(self.test['dip'], geopack.dip(*self.test['r_gsm'])))
        self.assertTrue(
            approx_eq(self.test['igrf_gsw'],
                      geopack.igrf_gsw(*self.test['r_gsw']), 1e-3))
        self.assertTrue(
            approx_eq(self.test['dip_gsw'],
                      geopack.dip_gsw(*self.test['r_gsw']), 1e-3))

        # test external models.
        self.assertTrue(
            approx_eq(self.test['t89'], t89.t89(*self.test['par1'])))
        self.assertTrue(
            approx_eq(self.test['t96'], t96.t96(*self.test['par2'])))
        self.assertTrue(
            approx_eq(self.test['t01'], t01.t01(*self.test['par2'])))
        self.assertTrue(
            approx_eq(self.test['t04'], t04.t04(*self.test['par2'])))

        # test coord transform, which returns B in nT.
        self.assertTrue(
            approx_eq(self.test['r_mag'],
                      geopack.geomag(*self.test['r_geo'], 1)))
        self.assertTrue(
            approx_eq(self.test['r_geo'],
                      geopack.geomag(*self.test['r_mag'], -1)))

        self.assertTrue(
            approx_eq(self.test['r_geo'],
                      geopack.geigeo(*self.test['r_gei'], 1)))
        self.assertTrue(
            approx_eq(self.test['r_gei'],
                      geopack.geigeo(*self.test['r_geo'], -1)))

        self.assertTrue(
            approx_eq(self.test['r_sm'], geopack.magsm(*self.test['r_mag'],
                                                       1)))
        self.assertTrue(
            approx_eq(self.test['r_mag'],
                      geopack.magsm(*self.test['r_sm'], -1)))

        self.assertTrue(
            approx_eq(self.test['r_gse'],
                      geopack.gsmgse(*self.test['r_gsm'], 1)))
        self.assertTrue(
            approx_eq(self.test['r_gsm'],
                      geopack.gsmgse(*self.test['r_gse'], -1)))

        self.assertTrue(
            approx_eq(self.test['r_gsm'], geopack.smgsm(*self.test['r_sm'],
                                                        1)))
        self.assertTrue(
            approx_eq(self.test['r_sm'], geopack.smgsm(*self.test['r_gsm'],
                                                       -1)))

        self.assertTrue(
            approx_eq(self.test['r_gsm'],
                      geopack.geogsm(*self.test['r_geo'], 1)))
        self.assertTrue(
            approx_eq(self.test['r_geo'],
                      geopack.geogsm(*self.test['r_gsm'], -1)))

        self.assertTrue(
            approx_eq(self.test['r_gsw'],
                      geopack.gswgsm(*self.test['r_gsm'], -1)))
        self.assertTrue(
            approx_eq(self.test['r_gsm'],
                      geopack.gswgsm(*self.test['r_gsw'], 1)))

        self.assertTrue(
            approx_eq(self.test['geo'], geopack.geodgeo(*self.test['geod'], 1),
                      1e-3))
        self.assertTrue(
            approx_eq(self.test['geod2'],
                      geopack.geodgeo(*self.test['geo2'], -1), 1e-3))

        # test trace.
        self.assertTrue(
            approx_eq(
                self.test['trace_t89_igrf'],
                geopack.trace(*self.test['r_gsm'], *self.test['trace_setting'],
                              self.test['par1'][0], 't89', 'igrf')))
        self.assertTrue(
            approx_eq(
                self.test['trace_t96_igrf'],
                geopack.trace(*self.test['r_gsm'], *self.test['trace_setting'],
                              self.test['par2'][0], 't96', 'igrf')))
        self.assertTrue(
            approx_eq(
                self.test['trace_t01_igrf'],
                geopack.trace(*self.test['r_gsm'], *self.test['trace_setting'],
                              self.test['par2'][0], 't01', 'igrf')))
        self.assertTrue(
            approx_eq(
                self.test['trace_t04_igrf'],
                geopack.trace(*self.test['r_gsm'], *self.test['trace_setting'],
                              self.test['par2'][0], 't04', 'igrf')))

        # test magnetopaus model.
        self.assertTrue(
            approx_eq(
                self.test['mgnp_t96'],
                geopack.t96_mgnp(*self.test['mgnp_t96_par'],
                                 *self.test['r_gsm'])))
        self.assertTrue(
            approx_eq(
                self.test['mgnp_shu'],
                geopack.shuetal_mgnp(*self.test['mgnp_shu_par'],
                                     *self.test['r_gsm'])))
Exemplo n.º 11
0
def cocochan(ifile):
    """
    convert Chandra ECI linear coords to GSE, GSM coords
    input: ifile    --- a data file name with:
                        t, x, y, z, vx, vy, vz, fy, mon, day, hh, mm, ss, kp
    output: line    --- data line with:
                        t, x, y, z, xsm, ysm, zsm, lid
                            lid = 1 if spacecraft is in solar wind
                            lid = 2 if spacecraft is in magnetosheath
                            lid = 3 if spacecraft is in magnetosphere

    Note: this python script is converted from Robert Cameron (2001) f77 program
          cocochan.f and crmflx_**.f which came with geopack.f

    python version of geopack: https://pypi.org/project/geopack/
    """
    #
    #--- read data
    #
    out = mcf.read_data_file(ifile)
    #
    #--- separate data and convert into column data
    #
    try:
        [t, x, y, z, vx, vy, vz, fy, mon, day, hh, mm, ss,
         kp] = mcf.separate_data_to_arrays(out)
    except:
        [t, x, y, z, vx, vy, vz, fy, mon, day, hh, mm,
         ss] = mcf.separate_data_to_arrays(out)
        kp = [1] * len(t)
#
#--- compute ut in seconds from 1970.1.1
#
    uts = ut_in_secs(fy[0], mon[0], day[0], hh[0], mm[0], ss[0])
    #
    #--- usually this need to be run only once but it seems better to run every time;
    #--- value is kept to be used by other geopack functions
    #
    psi = geopack.recalc(uts)

    line1 = ''
    line2 = ''
    line3 = ''
    for k in range(0, len(t)):
        #
        #--- convert position to km
        #
        xs = x[k] / 1.0e3
        ys = y[k] / 1.0e3
        zs = z[k] / 1.0e3
        r = math.sqrt(xs * xs + ys * ys + zs * zs)

        uts = ut_in_secs(fy[k], mon[k], day[k], hh[k], mm[k], ss[k])
        psi = geopack.recalc(uts)
        #
        #--- convert the coordinates into gsm and gse
        #
        [xgsm, ygsm, zgsm, xgm, ygm, zgm, xge, yge, zge,
         lid] = compute_gsm(xs, ys, zs, kp[k])
        #
        #--- convert to special coordinates
        #
        #        [mr, mt, mp] = convert_to_special_coords(xgsm, ygsm, zgsm)
        #        [er, et, ep] = convert_to_special_coords(xge, yge, zge)

        line1 = line1 + '%11.1f' % t[k]
        line1 = line1 + '\t%10.2f' % r
        line1 = line1 + '\t%10.2f' % xs
        line1 = line1 + '\t%10.2f' % ys
        line1 = line1 + '\t%10.2f' % zs
        line1 = line1 + '\t%10.2f' % xgsm
        line1 = line1 + '\t%10.2f' % ygsm
        line1 = line1 + '\t%10.2f' % zgsm
        line1 = line1 + '\t\t%1d' % lid
        line1 = line1 + '\n'

    return line1
Exemplo n.º 12
0
    def __init__(self, year, month, day, hour, minute, use_igrf, *args,
                 **kwargs):
        from geopack import t04
        # epoch time since Jan. 1 1970 00:00 UT
        # datetime.timedelta
        dt = datetime.datetime(year, month, day, hour,
                               minute) - datetime.datetime(1970, 1, 1)
        # seconds from 1970/1/1 00:00 UT
        self.dt_seconds = dt.total_seconds()
        qin_denton_url = 'https://rbsp-ect.newmexicoconsortium.org/data_pub/QinDenton/%d/' % (
            year)
        qin_denton_file = 'QinDenton_%d%d%d_1min.txt' % (year, month, day)
        # fetch file
        qin_denton_local_file = './data/QinDenton/%d/%s' % (year,
                                                            qin_denton_file)

        #        import requests
        #        response=requests.get(qin_denton_url+qin-denton_file
        import pandas as pd
        qindenton_frame = pd.read_json(qin_denton_local_file)

        self.ps = geopack.recalc(self.dt_seconds)
        self.use_igrf = use_igrf

        from geospacepy import omnireader
        sTimeIMF = datetime.datetime(year, month, day, hour, minute)
        eTimeIMF = datetime.datetime(year, month, day, hour,
                                     minute) + datetime.timedelta(
                                         0, 0, 0, 0, 1, 0)
        omniInt = omnireader.omni_interval(sTimeIMF, eTimeIMF, '1min')
        t = omniInt['Epoch']  #datetime timestamps
        By = omniInt['BY_GSM']
        Bz = omniInt['BZ_GSM']
        Pdyn = omniInt['Pressure']
        SYM_H = omniInt['SYM_H']
        # need Qin-Denton parameters
        w1, w2, w3, w4, w5, w6 = np.zeros(6, dtype=float)

        #        import pandas as pd
        #        pd.read_json(qin_denton_path
        # end Qin-Dention acquisition

        self.parmod = np.array([Pdyn, SYM_H, By, Bz, w1, w2, w3, w4, w5, w6],
                               dtype=float)

        super(T04, self).__init__(*args, **kwargs)
        #        parmod=np.zeros(10,dtype=float)
        #        t89.tsyganenko.init_t89(year,month,day,hour,minute,use_igrf,0,parmod)
        #        t89.tsyganenko.init_t89(int(year),int(month),int(day),int(hour),int(minute),int(use_igrf))
        bounds_error = kwargs.get('bounds_error', False)
        fill_value = kwargs.get('missing_value', np.nan)

        self.units = 'nT'
        self.citation = 'Kamodo.T89 by Lutz Rastaetter (2020), Geopack/Tsyganenko by Sheng Tian (2019) and geospacepy-lite by Liam Kilkommons (2019)'

        self.x = np.linspace(-30., 10., 40)  # make sure to avoid (0,0,0)
        self.y = np.linspace(-10., 10., 20)
        self.z = np.linspace(-10., 10., 20)

        self.variables = dict(b_x=dict(units='nT', data=None),
                              b_y=dict(units='nT', data=None),
                              b_z=dict(units='nT', data=None),
                              bvec=dict(units='nT', data=None))

        for varname in self.variables:
            units = self.variables[varname]['units']
            self.register_variable(varname, units)
Exemplo n.º 13
0
 def get_dipole_tilt(minute):
     t = (self.date - dt.datetime(1970, 1, 1) -
          dt.timedelta(minutes=int(minute))).total_seconds()
     return 180 / np.pi * geopack.recalc(t)
Exemplo n.º 14
0
def transform(
        Xvec=np.array([[0., 0., 1.]]),
        Time=np.array([datetime(2000, 1, 1, 0, 0, 0, tzinfo=timezone.utc)]),
        coord_in='GSE',
        coord_out='GEO',
        debug=False,
        **kwargs):
    # no operation for same input and output coordinates
    if coord_in == coord_out:
        return Xvec
    Xvec = np.array(Xvec)
    Xvec_out = []
    #        print(Xvec.shape)

    # show whether we are using the correct time
    if debug:
        print(Time[0])
        print(seconds_from_19700101(Time[0]))
        psi = geopack.recalc(seconds_from_19700101(Time[0]))
        print('psi=', psi)

    if coord_in == "GSE":
        if coord_out == "GSM":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.gsmgse(x_, y_, z_, -1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "SM":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.gsmgse(x_, y_, z_, -1)
                (x_out2, y_out2,
                 z_out2) = geopack.smgsm(x_out, y_out, z_out, -1)
                Xvec_out.append([x_out2, y_out2, z_out2])
            return Xvec_out

        if coord_out == "GEO":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.gsmgse(x_, y_, z_, -1)
                (x_out2, y_out2,
                 z_out2) = geopack.geogsm(x_out, y_out, z_out, -1)
                Xvec_out.append([x_out2, y_out2, z_out2])
            return Xvec_out

        if coord_out == "GEI":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.gsmgse(x_, y_, z_, -1)
                (x_out2, y_out2,
                 z_out2) = geopack.geogsm(x_out, y_out, z_out, -1)
                (x_out3, y_out3,
                 z_out3) = geopack.geigeo(x_out2, y_out2, z_out2, -1)
                Xvec_out.append([x_out3, y_out3, z_out3])
            return Xvec_out

        if coord_out == "MAG":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.gsmgse(x_, y_, z_, -1)
                (x_out2, y_out2,
                 z_out2) = geopack.geogsm(x_out, y_out, z_out, -1)
                (x_out3, y_out3,
                 z_out3) = geopack.geomag(x_out2, y_out2, z_out2, 1)
                Xvec_out.append([x_out3, y_out3, z_out3])
            return Xvec_out

        print("target coordinate system not supported")
        return False

    if coord_in == "GSM":
        if coord_out == "GSE":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.gsmgse(x_, y_, z_, 1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "SM":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.smgsm(x_, y_, z_, -1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "GEO":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geogsm(x_, y_, z_, -1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "GEI":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geogsm(x_, y_, z_, -1)
                (x_out2, y_out2,
                 z_out2) = geopack.geigeo(x_out, y_out, z_out, -1)
                Xvec_out.append([x_out2, y_out2, z_out2])
            return Xvec_out

        if coord_out == "MAG":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.gsmgse(x_, y_, z_, 1)
                (x_out2, y_out2,
                 z_out2) = geopack.geomag(x_out, y_out, z_out, 1)
                Xvec_out.append([x_out2, y_out2, z_out2])
            return Xvec_out

        print("target coordinate system not supported")
        return False

    if coord_in == "SM":
        if coord_out == "GSM":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.smgsm(x_, y_, z_, 1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "GSE":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.smgsm(x_, y_, z_, 1)
                (x_out2, y_out2,
                 z_out2) = geopack.gsmgse(x_out, y_out, z_out, 1)
                Xvec_out.append([x_out2, y_out2, z_out2])
            return Xvec_out

        if coord_out == "MAG":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.magsm(x_, y_, z_, -1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "GEO":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.magsm(x_, y_, z_, -1)
                (x_out2, y_out2,
                 z_out2) = geopack.geomag(x_out, y_out, z_out, -1)
                Xvec_out.append([x_out2, y_out2, z_out2])
            return Xvec_out

        if coord_out == "GEI":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.magsm(x_, y_, z_, -1)
                (x_out2, y_out2,
                 z_out2) = geopack.geomag(x_out, y_out, z_out, -1)
                (x_out3, y_out3,
                 z_out3) = geopack.geigeo(x_out2, y_out2, z_out2, -1)
                Xvec_out.append([x_out3, y_out3, z_out3])
            return Xvec_out

        print("target coordinate system not supported")
        return False

    if coord_in == "MAG":
        if coord_out == "SM":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.magsm(x_, y_, z_, -1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "GEO":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geomag(x_, y_, z_, -1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "GSM":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geomag(x_, y_, z_, -1)
                (x_out2, y_out2,
                 z_out2) = geopack.geogsm(x_out, y_out, z_out, 1)
                Xvec_out.append([x_out2, y_out2, z_out2])
            return Xvec_out

        if coord_out == "GSE":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geomag(x_, y_, z_, -1)
                (x_out2, y_out2,
                 z_out2) = geopack.geogsm(x_out, y_out, z_out, 1)
                (x_out3, y_out3,
                 z_out3) = geopack.gsmgse(x_out2, y_out2, z_out2, 1)
                Xvec_out.append([x_out3, y_out3, z_out3])
            return Xvec_out

        if coord_out == "GEI":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geomag(x_, y_, z_, -1)
                (x_out2, y_out2,
                 z_out2) = geopack.geigeo(x_out, y_out, z_out, -1)
                Xvec_out.append([x_out2, y_out2, z_out2])
            return Xvec_out

        print("target coordinate system not supported")
        return False

    if coord_in == "GEO":
        if coord_out == "GEI":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geigeo(x_, y_, z_, -1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "MAG":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geomag(x_, y_, z_, 1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "SM":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geomag(x_, y_, z_, 1)
                (x_out2, y_out2,
                 z_out2) = geopack.magsm(x_out, y_out, z_out, 1)
                Xvec_out.append([x_out2, y_out2, z_out2])
            return Xvec_out

        if coord_out == "GSM":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geogsm(x_, y_, z_, 1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "GSE":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geogsm(x_, y_, z_, 1)
                (x_out2, y_out2,
                 z_out2) = geopack.gsmgse(x_out, y_out, z_out, 1)
                Xvec_out.append([x_out2, y_out2, z_out2])
            return Xvec_out

        print("target coordinate system not supported")
        return False

    if coord_in == "GEI":
        if coord_out == "GEO":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geigeo(x_, y_, z_, 1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "MAG":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geigeo(x_, y_, z_, 1)
                (x_out2, y_out2,
                 z_out2) = geopack.geomag(x_out, y_out, z_out, 1)
                Xvec_out.append([x_out, y_out, z_out])
            return Xvec_out

        if coord_out == "SM":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geigeo(x_, y_, z_, 1)
                (x_out2, y_out2, z_out2) = geopack.geomag(x_, y_, z_, 1)
                (x_out3, y_out3,
                 z_out3) = geopack.magsm(x_out2, y_out2, z_out2, 1)
                Xvec_out.append([x_out3, y_out3, z_out3])
            return Xvec_out

        if coord_out == "GSM":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geigeo(x_, y_, z_, 1)
                (x_out2, y_out2,
                 z_out2) = geopack.geogsm(x_out, y_out, z_out, 1)
                Xvec_out.append([x_out2, y_out2, z_out2])
            return Xvec_out

        if coord_out == "GSE":
            for i in range(len(Xvec[:, 0])):
                if i < len(Time):
                    psi = geopack.recalc(seconds_from_19700101(Time[i]))
                x_ = Xvec[i, 0]
                y_ = Xvec[i, 1]
                z_ = Xvec[i, 2]
                (x_out, y_out, z_out) = geopack.geigeo(x_, y_, z_, 1)
                (x_out2, y_out2,
                 z_out2) = geopack.geogsm(x_out, y_out, z_out, 1)
                (x_out3, y_out3,
                 z_out3) = geopack.gsmgse(x_out2, y_out2, z_out2, 1)
                Xvec_out.append([x_out3, y_out3, z_out3])
            return Xvec_out

        print("target coordinate system not supported")
        return False

    print("origin coordinate system not supported")
    return False