Ejemplo n.º 1
0
def load_amb_l1a(sc='mms1', mode='fast', level='l1a', optdesc='amb',
                 start_date=None, end_date=None, rename_vars=True,
                 **kwargs):
    """
    Load EDI data.
    
    CDF variable names are renamed to something easier to remember and
    use. Original CDF variable names are kept as an attribute "cdf_name"
    in each individual variable.
    
    Parameters
    ----------
    sc : str
        Spacecraft ID: ('mms1', 'mms2', 'mms3', 'mms4')
    mode : str
        Instrument mode: ('slow', 'srvy', 'fast', 'brst').
    level : str
        Data quality level ('l1a', 'l2pre', 'l2')
    optdesc : str
        Optional descriptor. Options are: {'efield' | 'amb' | 'amb-pm2' |
        'amb-alt-cc', 'amb-alt-oc', 'amb-alt-oob', 'amb-perp-c',
        'amb-perp-ob'}
    start_date, end_date : `datetime.datetime`
        Start and end of the data interval.
    rename_vars : bool
        If true (default), rename the standard MMS variable names
        to something more memorable and easier to use.
    \*\*kwargs : dict
    	Any keyword accepted by *pymms.data.util.load_data*
    
    Returns
    -------
    dist : `xarray.Dataset`
        EDI data.
    """
    
    # Download the data
    sdc = api.MrMMS_SDC_API(sc, 'edi', mode, level,
                            optdesc=optdesc,
                            start_date=start_date,
                            end_date=end_date,
                            **kwargs)
    
    files = sdc.download_files()
    try:
        files = api.sort_files(files)[0]
    except IndexError:
        raise IndexError('No files found: {0}'.format(sdc))
    
    # Read all of the data files. Skip empty files unless all files are empty
    data = []
    for file in files:
        data.append(util.cdf_to_ds(file, **kwargs))
    
    # Variables must be concatenated based on their DEPEND_0 variable
    rec_vnames = ['Epoch', 'epoch_angle', 'epoch_timetag']
    out_data = []
    for recname in rec_vnames:
        # Remove all data not associated with the current record name
        drop_vars = [varname
                     for varname in data[0]
                     if recname not in data[0][varname].coords]
        drop_coords = [coord
                       for coord in data[0].coords
                       if coord != recname]
        rec_data = [ds.drop(drop_vars + drop_coords) for ds in data]
        
        # Concatenate remaining variables together
        out = xr.concat(rec_data, dim=recname)
        
        # Select the desired time range
        out = out.sel(indexers={recname: slice(start_date, end_date)})
        
        # All datasets will be merged back together, so keep track of them
        out_data.append(out)
    
    # Combine the datasets back together
    data = xr.merge(out_data)
    
    # Rename data variables to something simpler
    if rename_vars:
        data = rename(data, sc, mode, level, optdesc)
    
    # Add data descriptors to attributes
    data.attrs['sc'] = sc
    data.attrs['instr'] = 'edi'
    data.attrs['mode'] = mode
    data.attrs['level'] = level
    data.attrs['optdesc'] = optdesc
    
    return data
Ejemplo n.º 2
0
r_gse_vname = '_'.join((sc, 'mec', 'r', 'gse'))
r_lbl_vname = '_'.join((sc, 'mec', 'r', 'gse', 'label'))

v_gse_vname = '_'.join((sc, 'mec', 'v', 'gse'))
v_lbl_vname = '_'.join((sc, 'mec', 'v', 'gse', 'label'))

mlt_vname = '_'.join((sc, 'mec', 'mlat'))
l_dip_vname = '_'.join((sc, 'mec', 'l', 'dipole'))

sdc.instr = 'mec'
sdc.mode = mode
sdc.optdesc = 'epht89d'
files = sdc.download()

mec_data = util.cdf_to_ds(files[0], [r_gse_vname, v_gse_vname, mlt_vname, l_dip_vname])
mec_data = mec_data.rename({r_gse_vname: 'R_sc',  # convert R to polar
                            r_lbl_vname: 'R_sc_index',
                            v_gse_vname: 'V_sc',
                            v_lbl_vname: 'V_sc_index',
                            mlt_vname: 'MLT_sc',
                            l_dip_vname: 'L_sc',
                            'Epoch': 'time',
                            })
# Interpolate to EDP times
#   - MEC velocity is smoothly and slowly varying so can be up sampled
#   - FGM data is sampled the same or faster so can be sychronized/down sampled
mec_data = mec_data.interp_like(edi_data)

# Combine all into one data set
data = xr.merge([mec_data, edi_data])
Ejemplo n.º 3
0
                        optdesc='dce',
                        start_date=t0,
                        end_date=t1)

r_gse_vname = '_'.join((sc, 'mec', 'r', 'gse'))
r_lbl_vname = '_'.join((sc, 'mec', 'r', 'gse', 'label'))

v_gse_vname = '_'.join((sc, 'mec', 'v', 'gse'))
v_lbl_vname = '_'.join((sc, 'mec', 'v', 'gse', 'label'))

sdc.instr = 'mec'
sdc.mode = mode
sdc.optdesc = 'epht89d'
files = sdc.download()

mec_data = util.cdf_to_ds(files[0], [r_gse_vname, v_gse_vname])
mec_data = mec_data.rename({
    r_gse_vname: 'R_sc',
    r_lbl_vname: 'R_sc_index',
    v_gse_vname: 'V_sc',
    v_lbl_vname: 'V_sc_index',
    'Epoch': 'time'
})

mec_data = mec_data.assign_coords(R_sc_index=['Rx', 'Ry', 'Rz'],
                                  V_sc_index=['Vx', 'Vy', 'Vz'])

# EDP Fast Data
t_vname = '_'.join((sc, 'edp', 'epoch', 'fast', level))
e_fast_vname = '_'.join((sc, 'edp', 'dce', 'gse', 'fast', level))
e_labl_vname = '_'.join((sc, 'edp', 'label1', 'fast', level))
Ejemplo n.º 4
0
            if tdelta.astype(int) < 5e8
            else (t + np.timedelta64(1, 's') - tdelta)
            for t, tdelta in zip(edi_time.data, edi_time.data - edi_time.data.astype('datetime64[s]'))
           ]
edi_data['time'] = edi_time

# FGM Data
fgm_data = fgm.load_data('mms1', 'fgm', 'srvy', 'l2', t0, t1)

# EDP Fast Data
t_vname = '_'.join((sc, 'edp', 'epoch', 'fast', level))
e_fast_vname = '_'.join((sc, 'edp', 'dce', 'gse', 'fast', level))
e_labl_vname = '_'.join((sc, 'edp', 'label1', 'fast', level))
sdc = api.MrMMS_SDC_API(sc, 'edp', 'fast', level, optdesc='dce', start_date=t0, end_date=t1)
files = sdc.download()
edp_fast_data = util.cdf_to_ds(files[0], e_fast_vname)
edp_fast_data = edp_fast_data.rename({t_vname: 'time',
                                      e_fast_vname: 'E',
                                      e_labl_vname: 'E_index'})

# EDP Slow Data
t_vname = '_'.join((sc, 'edp', 'epoch', 'slow', level))
e_slow_vname = '_'.join((sc, 'edp', 'dce', 'gse', 'slow', level))
e_labl_vname = '_'.join((sc, 'edp', 'label1', 'slow', level))
sdc.mode = 'slow'
files = sdc.download()
edp_slow_data = util.cdf_to_ds(files[0], e_slow_vname)
edp_slow_data = edp_slow_data.rename({t_vname: 'time',
                                      e_slow_vname: 'E',
                                      e_labl_vname: 'E_index'})