end_time = tzutils.asUTCTime(datetime.datetime(year, month, int(args[2]), int(args[3]))) elif num_time_args == 5: month = int(args[0]) start_time = tzutils.asUTCTime(datetime.datetime(year, month, int(args[1]), int(args[2]))) end_time = tzutils.asUTCTime(datetime.datetime(year, month, int(args[3]), int(args[4]))) # create a factory for access to reanalysis files turf_factory = TurfWeatherFileFactory() if dev_mode: turf_factory.useDirpathsForMode('dev') region = turf_factory.regionConfig(region_key) source = turf_factory.sourceConfig(source_key) # get a factory for access to forecast files anal_factory = ReanalysisGridFileFactory() if dev_mode: anal_factory.useDirpathsForMode('dev') # get a data manager for the weather file components manager = turf_factory.weatherFileManager(weather_key, year, month, region, mode='r') manager.close() completed = 0 # update reanalysis temperatures success, actual_end_time = updateReanalysis(anal_factory, manager, 'TMP', start_time, end_time, debug) if end_time is None and actual_end_time == last_day_end: next_start = last_day_end + ONE_HOUR next_manager = turf_factory.weatherFileManager(weather_key, next_start.year, next_start.month, region, mode='r') ok, next_end_time = updateReanalysis(anal_factory, next_manager, 'TMP', next_start, None, debug) if success: completed += 1
data_start_time = hourInTimezone(now.year, arg_2, int(args[3]), int(args[4]), file_tzinfo) data_end_time = hourInTimezone(now.year, int(args[5]), int(args[6]), int(args[7]), file_tzinfo) elif num_time_args == 7: # multiple days in different month of the same year # args ... 2 = year, 3 = first month, 4 = 1st day, 5 = 1st hour, # 6 = last month 7 = last day, 8 = last hour year = int(args[2]) update_start_time = hourInTimezone(year, int(args[3]), int(args[4]), int(args[5]), file_tzinfo) update_end_time = hourInTimezone(year, int(args[6]), int(args[7]), int(args[8]), file_tzinfo) # create a factory for access to grid files grid_factory = ReanalysisGridFileFactory() if dev_mode: grid_factory.useDirpathsForMode('dev') # get all available data since last reanalysis update if data_start_time is None: time_attr_key = '%s_end_time' % analysis.lower() filepath = grid_factory.analysisGridFilepath(now, grid_variable, grid_region) if not os.path.exists(filepath): # look in previous month to make sure it was completed if now.month >= 2: prev_month = now.month - 1 last_day = lastDayOfMonth(now.year, prev_month) btimeSliceefore = datetime.datetime(now.year, prev_month, last_day, 23)
update_end_time = hourInTimezone(arg_0, month, int(args[4]), arg_5, file_tzinfo) else: # specific months/days/hours (UTC time) in current year # args ... 0 = first month, 1 = 1st day, 2 = 1st hour, # 3 = last month, 4 = last day, 5 = last hour update_start_time = hourInTimezone(now.year, arg_0, int(args[1]), int(args[2]), file_tzinfo) update_end_time = hourInTimezone(now.year, int(args[3]), int(args[4]), int(args[5]), file_tzinfo) elif num_time_args == 7: # multiple days in different month of the same year # args ... 0 = year, 1 = first month, 2 = 1st day, 3 = 1st hour, # 4 = last month, 5 = last day, 6 = last hour year = int(args[0]) update_start_time = hourInTimezone(year, int(args[1]), int(args[2]), int(args[3]), file_tzinfo) update_end_time = hourInTimezone(year, int(args[4]), int(args[5]), int(args[6]), file_tzinfo) # create a factory for access to grid files grid_factory = ReanalysisGridFileFactory(analysis, grib_source) if dev_mode: grid_factory.useDirpathsForMode('dev') # create a smart grib file reader to retrieve the gribs grib_reader = SmartReanalysisGribReader(analysis_source) if dev_mode: grib_reader.useDirpathsForMode('dev') kwargs = { 'debug':debug, 'verbose':verbose } # update all grids except RHUM for grib_variable in grib_variables: VARIABLE_START_TIME = datetime.datetime.now() grid_variable = grib_reader.gridVariableName(grib_variable)
now = datetime.date.today() if num_time_args == 0: errmsg = 'No time arguments passed to script. You must at least specify' raise RuntimeError, '%s an hour on the current day.' % errmsg elif num_time_args == 1: new_obs_time = datetime.datetime(now.year, now.month, now.day, int(args[1]) elif num_time_args == 2: new_obs_time = datetime.datetime(now.year, now.month, int(args[1]), int(args[1])) elif num_time_args == 3: new_obs_time = datetime.datetime(now.year, int(args[1]), int(args[2]), int(args[3])) else: errmsg = 'Too many time arguments (%d) passed to script. Up to 3 are supported.' raise RuntimeError, errmsg % num_time_args # create a factory for access to grid files factory = ReanalysisGridFileFactory(analysis, grib_source, grib_server) if dev_mode: factory.useDirpathsForMode('dev') region = factory.regionConfig(grid_region) manager = factory.gridFileManager(new_obs_time, variable, grid_region, mode='r') print '\nBefore repairs to %s variable:' % variable print ' last_obs_time :', manager.dateAttribute(variable, 'last_obs_time', None) print ' rtma_end_time :', manager.dateAttribute(variable, 'rtma_end_time') print ' last_valid_time :', manager.dateAttribute(variable, 'last_valid_time', None) manager.close() manager.open(mode='a') manager.setTimeAttribute(variable, 'last_obs_time', new_obs_time) manager.setTimeAttribute(variable, 'rtma_end_time', new_obs_time) manager.setTimeAttribute(variable, 'last_valid_time', new_obs_time) manager.close()
num_hours = int(args[4]) else: allowed_args = 'You may pass 2 arguments (variable name, number of hours)' allowed_args += ' or 5 arguments (variable name, year, month, day, number' allowed_args += ' of hours).' if num_args == 0: errmsg = 'No arguments passed to script. %s' % allowed_args else: errmsg = 'Incorrect number of argumets. %s' % allowed_args raise RuntimeError, errmsg reference_time = \ tzutils.asLocalTime(datetime.datetime(*time_tuple), local_timezone) # create a factory for access to grid files grid_factory = \ ReanalysisGridFileFactory('reanalysis', timezone=local_timezone) if dev_mode: grid_factory.useDirpathsForMode('dev') region = grid_factory.regionConfig(region_key) # get manager for the reference time span manager = grid_factory.gridFileManager(reference_time, variable_name, region_key, num_hours=num_hours, use_time_in_path=use_time_in_path) time_attrs = manager.timeAttributes(variable_name) if debug: print 'updating file for ...' print ' variable :', variable_name print ' file date :', reference_time.date() print ' ', manager.filepath
update_start_time = hourInTimezone(arg_0, month, int(args[2]), int(args[3]), file_tzinfo) update_end_time = hourInTimezone(arg_0, month, int(args[4]), int(args[5]), file_tzinfo) else: # specific months/days/hours (UTC time) in current year update_start_time = hourInTimezone(now.year, arg_0, int(args[1]), int(args[2]), file_tzinfo) update_end_time = hourInTimezone(now.year, int(args[3]), int(args[4]), int(args[5]), file_tzinfo) elif num_time_args == 7: # multiple days in different month of the same year # args ... 1 = year, 2 = first month, 3 = 1st day, 4 = 1st hour, # 5 = last month 6 = last day, 7 = last hour year = int(args[0]) update_start_time = hourInTimezone(year, int(args[1]), int(args[2]), int(args[3]), file_tzinfo) update_end_time = hourInTimezone(year, int(args[4]), int(args[5]), int(args[6]), file_tzinfo) # create a factory for access to grid files grid_factory = ReanalysisGridFileFactory() if dev_mode: grid_factory.useDirpathsForMode('dev') if update_start_time is None: filepath = grid_factory.analysisGridFilepath(now, 'RHUM', grid_region) if not os.path.exists(filepath): grid_factory.buildReanalysisGridFile(now, 'RHUM', grid_region, 'UTC') reader = grid_factory.gridFileManager(now, 'RHUM', grid_region) time_attr_key = '%s_end_time' % analysis.lower() last_anal_time = reader.timeAttribute('RHUM', time_attr_key, None) if last_anal_time is None: # file never updated before update_start_time = reader.timeAttribute('RHUM', 'start_time') else: # starting 1 hour after last valid time in file update_start_time = last_anal_time + datetime.timedelta(hours=1)
def __init__(self, num_hours, region, config_object=CONFIG, **kwargs): ReanalysisGridFileFactory.__init__(self, 'urma.%s' % grib_source, CONFIG) self._initUrmaGridFactory_(num_hours, region, **kwargs)
def __init__(self, region, **kwargs): ReanalysisGridFileFactory.__init__(self, MAP_CONFIG, **kwargs) self.region = region dims = self.source.dimensions[region] self.grid_dimensions = (dims.lat, dims.lon) self.map_config = self.config.mapper
def __init__(self, region, **kwargs): ReanalysisGridFileFactory.__init__(self, **kwargs) self.region = region dims = self.source.dimensions[region] self.grid_dimensions = (dims.lat, dims.lon)
elif num_date_args == 1: reference_date = datetime.date(today.year, int(args[1]), 1) elif num_date_args > 1: reference_date = datetime.date(int(args[1]), int(args[2]), 1) else: errmsg = 'No arguments passed to script. You must at least specify' raise RuntimeError, '%s the grib variable name.' % errmsg if verbose: print 'requesting ...' print ' variable :', grib_var_name print ' ref date :', reference_date print ' timezone :', file_timezone # create a factory for access to grid files factory = ReanalysisGridFileFactory(timezone=file_timezone) if dev_mode: factory.useDirpathsForMode('dev') # look for overrides of the default timespan parameters kwargs = { 'timezone': file_timezone, } if target_hour is not None: kwargs['target_hour'] = target_hour timespan = factory.fileTimespan(reference_date, **kwargs) if verbose: grid_start_time, reference_time, grid_end_time, num_hours = timespan print ' grid file timespan in %s timeszone :' % file_timezone print ' start hour :', grid_start_time print ' ref hour :', reference_time print ' end hour :', grid_end_time
elif num_args == 3: date_tuple = tuple([int(n) for n in args]) else: errmsg = 'No arguments passed to script. You must at least specify' raise RuntimeError, '%s the grib variable name.' % errmsg reference_date = datetime.date(*date_tuple) if debug: print 'requesting ...' print ' file var :', file_var_name print ' grib var :', grib_var_name print ' ref date :', reference_date # create a factory for access to grid files grid_factory = ReanalysisGridFileFactory('reanalysis', CONFIG) if dev_mode: grid_factory.useDirpathsForMode('dev') region = grid_factory.regionConfig(region_key) timespan = grid_factory.fileTimespan(reference_date, obs_days, fcast_days, target_hour, local_timezone) start_time, reference_time, end_time = timespan if debug: print 'timespan in local timezone...' print ' start hour :', start_time print ' ref hour :', reference_time print ' end hour :', end_time # create a factory for access to grib & static files grib_factory = ReanalysisGribFileFactory(grib_source, CONFIG) if dev_mode: grib_factory.useDirpathsForMode('dev')