Ejemplo n.º 1
0
    def forecast_times(self,cycle_start, from_utc, to_utc):  
        """
        Compute the span of hours to be used in a forecast cycle
        This should be common to all forecast data sources

        :param cycle_start: UTC time of cycle start
        :param from_utc: forecast start time
        :param to_utc: forecast end time
        :return fc_start, fc_hours: first and last hour in the forecast to be used
        """

        logging.info('%s cycle %s forecast from %s to %s UTC' % (self.id, str( cycle_start), str( from_utc), str( to_utc)))

        # check if the request is even satisfiable
        if (from_utc - cycle_start).total_seconds() < 0:
            raise GribError('cycle start %s is after forecast start %s' % (str(cycle_start), str(from_utc)))
        if (to_utc - from_utc).total_seconds() < 3600:
            raise GribError('forecast from %s to %s is less than one hour' % (str(from_utc), str(to_utc)))

        fc_hours = timedelta_hours(to_utc - cycle_start)

        if fc_hours > self.max_forecast_hours :
            logging.error('cycle start %s to forecast end %s is more than %s hours' % (str(cycle_start), str(to_utc),self.max_forecast_hours))
            raise GribError('Unsatisfiable: %s forecast is only available for %s hours.' % (self.id, self.max_forecast_hours))

        fc_start = timedelta_hours(from_utc - cycle_start, False) # rounding down

        logging.info('%s using cycle %s hours %d to %d' % (self.id, str(cycle_start), fc_start, fc_hours))

        return fc_start, fc_hours
Ejemplo n.º 2
0
def test_time():

    cfg = load_sys_cfg()

    g = NAM218(cfg)

    cycle_start_esmf = "2005-01-05_00:00:00"
    cycle_start = esmf_to_utc(cycle_start_esmf)
    from_utc = esmf_to_utc("2005-01-05_00:00:00")
    to_utc = esmf_to_utc("2005-01-06_22:00:0")

    print(cycle_start.year, cycle_start.month, cycle_start.day,
          cycle_start.hour)

    fc_hours = int((to_utc - cycle_start).total_seconds()) / 3600

    delta = from_utc - cycle_start
    print(str(delta))
    print(delta.days, delta.seconds, delta.total_seconds())
    print((to_utc - cycle_start).total_seconds())
    print(timedelta_hours(to_utc - cycle_start))
    print(timedelta_hours(to_utc - cycle_start, False))

    fc_start, fc_hours = g.forecast_times(cycle_start, from_utc, to_utc)
    print('fc_start = ', fc_start)
    print('fc_hours = ', fc_hours)
    fc_list, colmet_list_utc = g.file_times(cycle_start, fc_start, fc_hours)
    grib_files, colmet_prefix, colmet_files = g.file_names(
        cycle_start, fc_list, colmet_list_utc)
    print('fc_list = ', fc_list)
    print('colmet_list_utc = ')
    for x in colmet_list_utc:
        print(x)
    print('grib_files = ')
    for x in grib_files:
        print(x)
    print('colmet_files = ')
    for x in colmet_files:
        print(colmet_prefix + '/' + x)
Ejemplo n.º 3
0
    def __init__(self, args):
        """
        Initialize the job state from the arguments dictionary.

        :param args: the forecast job arguments
        """
        super(JobState, self).__init__(args)
        #self.grib_source = [self.grib_source] if isinstance(self.grib_source, basestring) else self.grib_source
        #self.grib_source = [self.resolve_grib_source(g, args) for g in self.grib_source]
        self.grib_source = self.resolve_grib_source(self.grib_source, args)
        logging.info('Simulation requested from %s to %s' %
                     (str(self.start_utc), str(self.end_utc)))
        self.start_utc = round_time_to_hour(
            self.start_utc,
            up=False,
            period_hours=self.grib_source[0].period_hours)
        self.end_utc = round_time_to_hour(
            self.end_utc,
            up=True,
            period_hours=self.grib_source[0].period_hours)
        self.cycle_start_utc = round_time_to_hour(
            self.get('cycle_start_utc', None),
            period_hours=self.grib_source[0].cycle_hours)
        logging.info('Simulation times rounded  %s to %s' %
                     (str(self.start_utc), str(self.end_utc)))
        #self.start_utc = round_time_to_hour(self.start_utc, up=False, period_hours=self.grib_source.period_hours);
        #self.end_utc = round_time_to_hour(self.end_utc, up=True, period_hours=self.grib_source.period_hours);
        self.fc_hrs = timedelta_hours(self.end_utc - self.start_utc)
        if 'job_id' in args:
            logging.info('job_id %s given in the job description' %
                         args['job_id'])
            self.job_id = args['job_id']
        else:
            logging.warning('job_id not given, creating.')
            self.job_id = 'wfc-' + self.grid_code + '-' + utc_to_esmf(
                self.start_utc) + '-{0:02d}'.format(self.fc_hrs)
        self.emails = self.parse_emails(args)
        self.domains = args['domains']
        self.ignitions = args.get('ignitions', None)
        self.fmda = self.parse_fmda(args)
        self.postproc = args['postproc']
        self.wrfxpy_dir = args['sys_install_path']
        self.args = args
        logging.debug('JobState initialized: ' + str(self))