if len(args) > 0:
    year = int(args[0])
    month = int(args[1])
    day = int(args[2])
    if len(args) > 3: newa_base_time = datetime(year, month, day, int(args[3]))
    else: newa_base_time = datetime(year, month, day, 23)
# otherwise, latest_possible report date is yesterday
else:
    newa_base_time = today - ONE_DAY
test_last_day = dateAsInt(newa_base_time)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

criteria = ('bbox', 'county', 'name', 'network', 'sid', 'state')
factory = ObsnetDataFactory(options)
criteria = factory._validCriteria(options, criteria)
metadata = list(factory._parseMetadata(options.metadata))
if 'datasets' not in metadata: metadata.append('datasets')
if 'first_hour' not in metadata: metadata.append('first_hour')
if 'last_report' not in metadata: metadata.append('last_report')
if 'name' not in metadata: metadata.append('name')
if 'sid' not in metadata: metadata.append('sid')
if 'state' not in metadata: metadata.append('state')
if 'ucanid' not in metadata: metadata.append('ucanid')

for station in factory.getIndexedStations(metadata, criteria, options.sort_by):
    if test_index:
        prev_last_report = station['last_report']
        prev_last_day = prev_last_report / 100
        if prev_last_day != test_last_day:
            print test_msg % station
예제 #2
0
datasets_as_tuple = options.datasets_as_tuple
sort_by = options.sort_by

if len(args) > 0:
    dump_filepath = os.path.normpath(args[0])
    filepath, ext = os.path.splitext(dump_filepath)
    if ext in ('.txt', '.tsv'): as_tsv_file = True
    else: as_tsv_file = False
else:
    as_tsv_file = options.as_tsv_file
    dump_filepath = 'station_index_dump'
    if as_tsv_file: dump_filepath += '.tsv'
    else: dump_filepath += '.py'

factory = ObsnetDataFactory(options)
criteria = factory._validCriteria(options, ('network', 'state'))
metadata = factory._parseMetadata(options.metadata)

dump_file = open(dump_filepath, 'w')
# tab separated values file
if as_tsv_file:
    dump_file.write('\t'.join(metadata))
    for station in factory.getIndexedStations(metadata, criteria, sort_by):
        line = '\t'.join([str(station[key]) for key in metadata])
        dump_file.write('\n%s' % line)
# importable python object file
else:
    dump_file.write('(')
    for station in factory.getIndexedStations(metadata, criteria, sort_by):
        if datasets_as_tuple:
            station['datasets'] = tuple([
    elements = stringToTuple(options.elements)
min_year_span = options.min_year_span
percent_missing = options.percent_missing
report_rate = options.report_rate
replace_existing = options.replace_existing

max_sample_size = durtions_days * durations_hours
min_sample_size = int(max_sample_size * (1.0 - (percent_missing / 100.)))
rel_hours_cushion = relativedelta(hours=hours_cushion)

# create a factory, then use it to get the list of stations
factory = ObsnetDataFactory(options)
if len(args) > 0:
    ucanids = [int(arg) for arg in args]
else:
    criteria = factory._validCriteria(options, SEARCH_KEYS)
    ucanids = factory.getStationIdsFromArgs(args, criteria)

# apply rule to replace existing data files
if replace_existing:
    for ucanid in ucanids:
        filepath = factory.getFilepathForUcanid(ucanid,'hour-stats')
        if os.path.exists(filepath): os.remove(filepath)
else:
    ucanids = [uid for uid in ucanids
              if not os.path.exists(factory.getFilepathForUcanid(uid,'hour-stats'))]

# process each station in the list
for ucanid in ucanids:

    hours_manager = factory.getStationFileManager((ucanid,'hours'), 'r')
예제 #4
0
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

if options.sid is None and options.name is None and options.ucanid is None:
    print 'You must se one of the following options : --sid, --name or --ucanid'
    os.exit(99)

dataset_name = args[0]
year = int(args[1])
month = int(args[2])
day = int(args[3])
date = datetime(year, month, day)
print date.strftime('Retrieving data for %B %d, %Y')

factory = ObsnetDataFactory(options)
station = factory.argsToStationData((), options)[0]

criteria = factory._validCriteria(options, ('sid', 'name', 'ucanid'))
metadata = ('lat', 'lon', 'name', 'network', 'sid', 'state', 'ucanid')
station = factory.getIndexedStations(metadata, criteria)[0]
print STATION_INFO % station

start, end, stn_data = getStationData(factory, station, date, dataset_name)
print STN_DATA_MSG % (start.strftime('%Y-%m-%d:%H'),
                      end.strftime('%Y-%m-%d:%H'), arrayToString(stn_data))

grid_data = getGridData(factory, station, date, dataset_name)
print GRID_DATA_MSG % (date.strftime('%Y-%m-%d'), arrayToString(grid_data))

print COMPARE_MSG % (N.nansum(stn_data), N.nanmin(grid_data),
                     N.nanmax(grid_data))