コード例 #1
0
    def _resolveHourlyAttributes(self, object_config, kwarg_dict):
        attrs = {
            'period':
            kwarg_dict.get('period', object_config.get('period', 'hour')),
        }
        attrs['frequency'] = frequency = \
             kwarg_dict.get('frequency',object_config.get('frequency',1))
        # dataset timezone attribute must be a string
        timezone = str(
            kwarg_dict.get('timezone',
                           object_config.get('timezone', self.timezone)))
        attrs['timezone'] = timezone

        # add object's time span
        start_time = kwarg_dict.get('start_time', self.start_time)
        start_time = tzutils.asHourInTimezone(start_time, timezone)
        attrs['start_time'] = tzutils.hourAsString(start_time)

        end_time = kwarg_dict.get('end_time', self.end_time)
        end_time = tzutils.asHourInTimezone(end_time, timezone)
        attrs['end_time'] = tzutils.hourAsString(end_time)

        num_hours = tzutils.hoursInTimespan(start_time, end_time)
        attrs['num_hours'] = (num_hours / frequency) + 1

        # object may or may not have a reference time
        reference_time = kwarg_dict.get('reference_time', None)
        if reference_time is not None:  # and reference_time != start_time:
            reference_time = tzutils.asHourInTimezone(reference_time, timezone)
            attrs['reference_time'] = tzutils.hourAsString(reference_time)

        return attrs
コード例 #2
0
 def setTimeAttribute(self, dataset_path, attribute_name, hour, **kwargs):
     if isinstance(hour, basestring):
         if ':' not in hour:
             errmsg = '"%s" is an invalid value for "%s"'
             raise ValueError, errmsg % (hour, attribute_name)
         self.setObjectAttribute(dataset_path, attribute_name, hour)
     else:
         include_timezone = kwargs.get('include_timezone', False)
         if not tzutils.isInTimezone(hour, self.tzinfo):
             tzhour = tzutils.asHourInTimezone(hour, self.tzinfo)
             hour_str = tzutils.hourAsString(tzhour, include_timezone)
         else: hour_str = tzutils.hourAsString(hour, include_timezone)
         self.setObjectAttribute(dataset_path, attribute_name, hour_str)
コード例 #3
0
 def additionalFileAttributes(self, **kwargs):
     """
     Returns timezone, start_time & end_time attributes based on values
     specified in preInitBuilder().
     Also adds any attributes returned from a subclass' implementation
     or _initMyFileAttributes()
     """
     attr_dict = {
         'end_time': tzutils.hourAsString(self.end_time),
         'num_hours': self.num_hours,
         'start_time': tzutils.hourAsString(self.start_time),
         'timezone': self.timezone,
     }
     return attr_dict
コード例 #4
0
def timeAccumStatsProvenanceGenerator(source, hour, timestamp, hourly,
                                      accumulated):
    return (tzutils.hourAsString(hour), N.nanmin(hourly), N.nanmax(hourly),
            N.nanmean(hourly), nanMedian(hourly,
                                         axis=None), N.nanmin(accumulated),
            N.nanmax(accumulated), N.nanmean(accumulated),
            nanMedian(accumulated, axis=None), timestamp, source)
コード例 #5
0
    def generateEmptyProvenance(self, prov_type, attrs):
        start_time = attrs.get('start_time', self.start_time)
        end_time = attrs.get('end_time', self.end_time)
        timezone = attrs.get('timezone', self.fileAttribute('timezone'))
        hour = tzutils.asHourInTimezone(start_time, timezone)
        end_time = tzutils.asHourInTimezone(end_time, timezone)
        time_increment = datetime.timedelta(
            hours=prov_type.get('frequency', 1))

        records = []
        record_tail = prov_type.empty[1:]
        while hour <= end_time:
            record = (tzutils.hourAsString(hour), ) + record_tail
            records.append(record)
            hour += time_increment
        return records
コード例 #6
0
def timeStatsProvenanceGenerator(source, hour, timestamp, data):
    return (tzutils.hourAsString(hour), N.nanmin(data), N.nanmax(data),
            N.nanmean(data), nanMedian(data, axis=None), timestamp, source)
コード例 #7
0
def timeStampProvenanceGenerator(source, hour, timestamp, data):
    return (tzutils.hourAsString(hour), timestamp, source)
コード例 #8
0
                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)
コード例 #9
0
            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)