예제 #1
0
def omni_load(dates, level, downloadonly=False, varformat=None,
              get_support_data=False, prefix='', suffix=''):
    """Loads OMNI data into pytplot variables"""

    file_list = omni_filename(dates, level)

    # 1. Download files
    count = 0
    downloaded_files = []
    for remotef, localf in file_list:
        count += 1
        resp, err, localfile = pyspedas.download_files(remotef, localf)
        if resp:
            print(str(count) + '. File was downloaded. Location: ' + localfile)
            downloaded_files.append(localfile)
        else:
            print(str(count) + '. Error: Could not download file: ' + remotef)
            print(err)
    print('Downloaded ' + str(len(downloaded_files)) + ' files.')

    # 2. Load files into tplot
    downloaded_vars = []
    if not downloadonly:
        try:
            downloaded_vars = pytplot.cdf_to_tplot(downloaded_files, varformat,
                                                   get_support_data, prefix,
                                                   suffix, False, True)
        except TypeError as e:
            msg = "cdf_to_tplot could not load all data.\nError:\n" + str(e)
            print(msg)
    print('Loaded ' + str(len(downloaded_vars)) + ' variables.')

    # 3. Time clip
    if len(downloaded_vars) > 0:
        pyspedas.time_clip(downloaded_vars, dates[0], dates[1], '')
예제 #2
0
def themis_load(dates,
                probes,
                instruments,
                level,
                downloadonly=False,
                varformat=None,
                get_support_data=False,
                prefix='',
                suffix=''):
    """Loads themis data into pytplot variables"""

    file_list = themis_filename(dates, probes, instruments, level)
    # print(file_list)
    count = 0
    dcount = 0

    for remotef, localf in file_list:
        count += 1
        resp, err, localfile = pyspedas.download_files(remotef, localf)
        if resp:
            print(str(count) + '. File was downloaded. Location: ' + localfile)
            dcount += 1
            if not downloadonly:
                try:
                    cdfvars = pyspedas.cdf_to_tplot(localfile, varformat,
                                                    get_support_data, prefix,
                                                    suffix, False, True)

                except TypeError as e:
                    msg = "cdf_to_tplot could not load " + localfile
                    + "\nError:\n" + str(e)
                    print(msg)

        else:
            print(
                str(count) + '. There was a problem. Could not download \
                  file: ' + remotef)
            print(err)

    if len(dates) == 2:
        pyspedas.time_clip(cdfvars, dates[0], dates[1], cdfvars)

    print('Downloaded ' + str(dcount) + ' files.')
    print('tplot variables:')
    print(pyspedas.tplot_names())
예제 #3
0
from pyspedas import subtract_median

subtract_median('mms4_fgm_b_gsm_brst_l2')

tplot([
    'mms4_fgm_b_gsm_brst_l2', 'mms4_fgm_b_gsm_brst_l2-d',
    'mms4_fgm_b_gsm_brst_l2-m'
])

# time clip
from pyspedas import time_clip

time_clip([
    'mms4_fgm_b_gsm_brst_l2', 'mms4_fgm_b_gsm_brst_l2-d',
    'mms4_fgm_b_gsm_brst_l2-m'
],
          '2015-10-16/13:06:45',
          '2015-10-16/13:07',
          suffix='')

tplot([
    'mms4_fgm_b_gsm_brst_l2', 'mms4_fgm_b_gsm_brst_l2-d',
    'mms4_fgm_b_gsm_brst_l2-m'
])

# clip the data
from pyspedas import tclip

tclip([
    'mms4_fgm_b_gsm_brst_l2', 'mms4_fgm_b_gsm_brst_l2-d',
    'mms4_fgm_b_gsm_brst_l2-m'
예제 #4
0
 def test_timeclip(self):
     """Test time_clip."""
     time_clip('aaabbbccc', 1577308800, 1577598800)  # Test non-existent
     tn = [
         1577112800, 1577308800, 1577598800, 1577608800, 1577998800,
         1587998800
     ]
     dn = [3., 5., 8., 15., 20., 1.]
     store_data('test1', data={'x': tn, 'y': dn})
     time_clip('aaabbb', 1577308800, 1577598800)
     time_clip('test1', 1577112800, 1577608800)
     d = get_data('test1-tclip')
     dd = d[1]
     time_clip('test', 1577308800, 1577598800, new_names='name-clip')
     time_clip(['test', 'name-clip'],
               1577308800,
               1577598800,
               new_names='name1-ci')
     time_clip('test', 1577308800, 1577598800, overwrite=1)
     time_clip('test', 1577308800, 1577598800, new_names="testtest")
     time_clip(['test', 'test1'],
               1577308800,
               1577598800,
               new_names="testtest2")
     time_clip('test1', 1677112800, 1577608800)
     self.assertTrue((dd == [3., 5., 8., 15.]).all())