Пример #1
0
def _load(probe, starttime, endtime, instrument, product_id, cdfkeys):
    daylist = util._daysplitinterval(starttime, endtime)
    data = []
    for day in daylist:
        date = day[0]
        year = str(date.year)
        month = str(date.month).zfill(2)
        day = str(date.day).zfill(2)

        local_dir = cluster_dir / ('c' + probe) / instrument / year
        local_fname = 'C' + probe + '_' + product_id + '__' +\
            year + month + day + '.cdf'
        local_file = local_dir / local_fname
        # If we don't have local file download it
        if not local_file.exists():
            thisstart = datetime.combine(date, time.min)
            thisend = datetime.combine(date, time.max)
            try:
                _download(probe, thisstart, thisend, instrument, product_id)
            except Exception as err:
                print(str(err), '\n')
                continue

        from pycdf import pycdf
        cdf = pycdf.CDF(os.path.join(local_dir, local_fname))
        for key, value in cdfkeys.items():
            if value == 'Time':
                index_key = key
                break
        data.append(util.cdf2df(cdf, index_key, cdfkeys))
    if len(data) == 0:
        raise RuntimeError('No data available to download during requested '
                           'times')
    return util.timefilter(data, starttime, endtime)
Пример #2
0
def _load_local(local_dir, filename, filetype):
    # Import local file
    if filetype == 'cdf':
        cdf = pycdf.CDF(os.path.join(local_dir, filename))
        return cdf
    elif filetype == 'ascii':
        f = open(os.path.join(local_dir, filename))
        return f
Пример #3
0
def cdfpeek(cdf_loc):
    """
    List all the variables present in a CDF file, along with their size.

    Parameters
    ----------
    cdf_loc : string
        Local location of the cdf file.
    """
    from pycdf import pycdf
    cdf = pycdf.CDF(cdf_loc)
    print(cdf)
Пример #4
0
def _load_cdf(file_path):
    '''
    A function to handle loading pycdf, and printing a nice error if things
    go wrong.
    '''
    from pycdf import pycdf
    try:
        cdf = pycdf.CDF(str(file_path))
    except Exception as err:
        print('Error whilst trying to load {}\n'.format(file_path))
        raise err
    return cdf
Пример #5
0
def _load_local(local_dir, filename, filetype):
    # Import local file
    if filetype == 'cdf':
        from pycdf import pycdf
        try:
            cdf = pycdf.CDF(os.path.join(local_dir, filename))
        except Exception as err:
            print('Error whilst trying to load {}\n'.format(
                os.path.join(local_dir, filename)))
            raise err
        return cdf
    elif filetype == 'ascii':
        f = open(os.path.join(local_dir, filename))
        return f