Example #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], '')
Example #2
0
def download_and_load(remote_files,
                      local_dir,
                      download_only=False,
                      varformat=None,
                      get_support_data=False,
                      prefix='',
                      suffix=''):
    """ Download cdf files.
        Load cdf files into pytplot variables.
        TODO: Loading files into pytplot has problems.
    """

    result = []
    """ # For debug only
    msg = local_dir + str(download_only) + " ... " + '==='.join(remote_files)
    title = 'Download Files'
    show_my_message(title, msg)
    print(msg)
    """

    remotehttp = "https://cdaweb.sci.gsfc.nasa.gov/sp_phys/data"
    count = 0
    dcount = 0
    for remotef in remote_files:
        f = remotef.strip().replace(remotehttp, '', 1)
        localf = local_dir + os.path.sep + f

        resp, err, locafile = pyspedas.download_files(remotef, localf)
        count += 1
        if resp:
            print(str(count) + '. File was downloaded. Location: ' + locafile)
            dcount += 1
            result.append(localf)
            if not download_only:
                try:
                    pytplot.cdf_to_tplot(locafile, varformat, get_support_data,
                                         prefix, suffix, False, True)
                except ValueError as err:
                    msg = "cdf_to_tplot could not load " + locafile
                    msg += "\n\n"
                    msg += "Error from pytplot: " + str(err)
                    print(msg)
                    show_my_message("Error!", msg)

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

    print('Downloaded ' + str(dcount) + ' files.')
    print('tplot variables:')
    print(pyspedas.tplot_names())

    return result
Example #3
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())
Example #4
0
def gmag_load(dates,
              stations,
              group=None,
              downloadonly=False,
              varformat=None,
              get_support_data=False,
              prefix='',
              suffix=''):
    """Loads themis data into pytplot variables"""

    if group is not None:
        stations = gmag_list(group)

    file_list = gmag_filename(dates, stations)

    count = 0
    dcount = 0
    for remotef, localf in file_list:
        count += 1
        resp, err, locafile = pyspedas.download_files(remotef, localf)
        if resp:
            print(str(count) + '. File was downloaded. Location: ' + locafile)
            dcount += 1
            if not downloadonly:
                try:
                    testcdf = pyspedas.cdf_to_tplot(locafile, varformat,
                                                    get_support_data, prefix,
                                                    suffix, False, True)
                    print(testcdf)
                except TypeError as e:
                    msg = "cdf_to_tplot could not load " + locafile
                    + "\nError:\n" + str(e)
                    print(msg)

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

    print('Downloaded ' + str(dcount) + ' files.')
    print('tplot variables:')
    print(pyspedas.tplot_names())