def _load(probe, starttime, endtime, instrument, product_id, cdfkeys):
daylist = helper._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 = os.path.join(cluster_dir,
'c' + probe,
instrument,
year)
local_fname = 'C' + probe + '_' + product_id + '__' +\
year + month + day + '.cdf'
# If we don't have local file download it
if not os.path.exists(os.path.join(local_dir, local_fname)):
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(helper.cdf2df(cdf, index_key, cdfkeys))
if len(data) == 0:
raise RuntimeError('No data available to download during requested '
'times')
return helper.timefilter(data, starttime, endtime)
评论列表
文章目录