def weatherFileTimespan(self, year, month, timezone='UTC'): """ Returns tuple with start hour and end hour for the monthly file. If timezone is specified, times will be adjust to that timezone. Otherwise, times are in UTC timezones (same as times in file). """ start_time = datetime.datetime(year, month, 1, 0) start_time = tzutils.tzaDatetime(start_time, 'UTC') last_day = lastDayOfMonth(year, month) end_time = datetime.datetime(year, month, last_day, 23) end_time = tzutils.tzaDatetime(end_time, 'UTC') if timezone != 'UTC': start_time = tzutils.asLocalTime(start_time, timezone) end_time = tzutils.asLocalTime(end_time, timezone) return start_time, end_time
elif num_args == 5: variable_name = args[0].upper() time_tuple = (int(args[1]), int(args[2]), int(args[3]), target_hour) 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:
def obsTimeForDate(self, date, hour, timezone): obs_time = datetime.datetime.combine(date, datetime.time(hour)) return tzutils.asLocalTime(obs_time, timezone)
grib_time += ONE_HOUR continue else: break grib_time += ONE_HOUR # turn annoying numpy warnings back on warnings.resetwarnings() if len(downloaded) > 0: msg = '\n"RHUM" grib data updated for %d hours :' print msg % len(downloaded) * 6 if verbose: for hour, end_hour in downloaded: start = tzutils.asLocalTime(hour, local_timezone) start_local = tzutils.hourAsString(start) end = tzutils.asLocalTime(end_hour, local_timezone) end_local = tzutils.hourAsString(end) local = '%s to %s %s' % (start_local, end_local, local_timezone) start_utc = tzutils.hourAsString(hour) end_utc = tzutils.hourAsString(end_hour) print ' %s (%s to %s UTC)' % local, start_utc, end_utc else: start, end = downloaded[0] local_time = tzutils.asLocalTime(start, local_timezone) local_str = tzutils.hourAsString(local_time, True) utc_str = tzutils.hourAsString(start, True) print '%s >> %s' % (local_str, utc_str)
temps) diffs = temps - dewpt print ' diffs', N.nanmin(diffs), N.nanmean(diffs), N.nanmax( diffs) print ' rhum', N.nanmin(rhum), N.nanmean(rhum), N.nanmax(rhum) builder.open('a') builder.updateDataset(file_var_name, start_time, rhum, units='%', source='urma', update_provenance=True) builder.close() start_time = end_time + ONE_HOUR # turn annoying numpy warnings back on warnings.resetwarnings() elapsed_time = elapsedTime(BUILD_START_TIME, True) msg = '\nCompleted build for "%s" file in %s. Data entered for :' print msg % (file_var_name, elapsed_time) local_time = tzutils.asLocalTime(file_start_time, local_timezone) local_str = tzutils.hourAsString(local_time, True) utc_str = tzutils.hourAsString(file_start_time, True) print ' %s >> %s' % (local_str, utc_str) local_time = tzutils.asLocalTime(end_time, local_timezone) local_str = tzutils.hourAsString(local_time, True) utc_str = tzutils.hourAsString(end_time, True) print ' thru\n %s >> %s' % (local_str, utc_str)