def hirs_to_time_interval(filename): begin_time = datetime.strptime(filename[12:24], 'D%y%j.S%H%M') end_time = datetime.strptime(filename[12:19]+filename[25:30], 'D%y%j.E%H%M') if end_time < begin_time: end_time += timedelta(days=1) return TimeInterval(begin_time, end_time)
def print_contexts(platform, dt_left, dt_right, granule_length): interval = TimeInterval(dt_left, dt_right) contexts = comp.find_contexts(platform, hirs_version, collo_version, csrb_version, ctp_version, tpw_version, interval) contexts.sort() for context in contexts: print context return contexts
def build_task(self, context, task): num_days = monthrange(context['granule'].year, context['granule'].month)[1] interval = TimeInterval(context['granule'], context['granule'] + timedelta(num_days), False, True) daily_contexts = HIRS_TPW_DAILY().find_contexts( context['sat'], context['hirs_version'], context['collo_version'], context['csrb_version'], context['ctp_version'], context['tpw_version'], interval) for (i, c) in enumerate(daily_contexts): task.input('TPWD-{}'.format(i), HIRS_TPW_DAILY().dataset('out').product(c), True)
SPC = StoredProductCatalog() for context in contexts: if SPC.exists(c.dataset(output).product(context)): s_path = os.path.join( config.get()['product_dir'], SPC.file(c.dataset(output).product(context)).path) d_path = os.path.join(config.get()['results_dir'], c.context_path(context, output)) file_name = os.path.basename(s_path) if not os.path.exists(d_path): os.makedirs(d_path) if not os.path.isfile(os.path.join(d_path, file_name)): os.symlink(s_path, os.path.join(d_path, file_name)) output = 'out' sat = 'metop-a' hirs_version = 'v20151014' collo_version = 'v20140204' csrb_version = 'v20150915' ctp_version = 'v20150915' interval = TimeInterval(datetime(2009, 1, 1), datetime(2009, 2, 1)) c = HIRS_CTP_ORBITAL() contexts = c.find_contexts(sat, hirs_version, collo_version, csrb_version, ctp_version, interval) symlink(c, output, contexts)
#TimeInterval(datetime(2016, 8, 1), datetime(2016, 9, 1) - wedge), #TimeInterval(datetime(2016, 9, 1), datetime(2016, 10, 1) - wedge), #TimeInterval(datetime(2016, 10, 1),datetime(2016, 11, 1) - wedge), #TimeInterval(datetime(2016, 11, 1),datetime(2016, 12, 1) - wedge), #TimeInterval(datetime(2016, 12, 1),datetime(2017, 1, 1) - wedge), #] # Examine how many of the defined contexts are populated intervals = [] year, month = 2016, 5 months = range(1, 12 + 1) for month in months: days_in_month = monthrange(year, month)[1] dt_start = datetime(year, month, 1) dt_end = datetime(year, month, 1) + timedelta(days=days_in_month) interval = TimeInterval(dt_start, dt_end - wedge) contexts = comp.find_contexts(platform, hirs_version, collo_version, csrb_version, ctp_version, tpw_version, interval) num_contexts_exist = 0 for context in contexts: num_contexts_exist += SPC.exists(comp.dataset('out').product(context)) LOG.info("Interval {} has {}/{} contexts existing".format( interval, num_contexts_exist, len(contexts))) missing_contexts = len(contexts) - num_contexts_exist if missing_contexts == 1: intervals.append(interval) LOG.info("Submitting intervals...") for interval in intervals: LOG.info("Submitting interval {} -> {}".format(interval.left,