# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # procmsg = '\nProcessing station %d of %d : %d : %s (%s)' skipmsg = '\nSkipping station %d of %d : %d : %s (%s)' debug = options.debug replace_existing = options.replace_existing report_missing = options.report_missing seq_count_cutoff = options.sequence_count_cutoff if options.datasets != 'all': datasets = list(stringToTuple(options.datasets)) else: datasets = None factory = ObsnetDataFactory(options) stations = factory.argsToStationData(args, options) total_stations = len(stations) buddy_locator = BuddyLocator(factory, options.min_buddy_years, options.max_buddies, options.max_buddy_distance) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - exceptions_encountered = [] station_num = 0 for station in stations: ucanid = station['ucanid'] station_id = station['sid'] station_name = station['name'] if options.datasets == 'all': datasets = station['datasets']
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # search_keys = ('active','bbox','county','network','state') metadata = stringToTuple(options.metadata) sort_by = stringToTuple(options.sort_by) index_metadata = tuple(set(metadata) | set(sort_by)) sort_by_template = getSortBy(*sort_by) def sortBy(station): return sort_by_template % station if len(args) > 0: filepath = os.path.abspath(os.path.normpath(args[0])) path, ext = os.path.splitext(filepath) output_format = ext[1:] if output_format == 'py': output_format = 'dump' else: output_format = options.output_format fileroot = 'indexed_metadata_summary' filepath = os.path.abspath('%s.%s' % (fileroot,output_format)) factory = ObsnetDataFactory(options) stations = factory.argsToStationData(( ), options, index_metadata, 'index', search_keys) stations = sorted(stations, key=sortBy) writeStationsToFile(stations, filepath, output_format, mode='w') msg = " metadata summary for %d stations written to file" % len(stations) print msg, filepath
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 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))
today = datetime.now() base_time = today - ONE_DAY # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - metadata = ['sid', 'name', 'active', 'network', 'last_report'] if options.bbox is not None: metadata.append('lat') metadata.append('lon') if options.county is not None: metadata.append('county') if options.state is not None: metadata.append('state') factory = ObsnetDataFactory(options) stations = factory.argsToStationData((), options, tuple(metadata)) stations = sorted(stations, key=lambda station: station['name']) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - verified_stations = [] print '\n Active Stations\n%s' % separator for station in stations: last_hour = asDatetime(station['last_report'], True) station['last_hour'] = last_hour.strftime('%b %d, %Y at %I %p') delta = base_time - last_hour station['num_days'] = delta.days verified_stations.append(station) stations = sorted(verified_stations, key=lambda station: station['num_days'])
if len(args) > 0 and args[0].isdigit(): end_date = (int(args[0]), int(args[1]), int(args[2])) if len(args) > 3: args = args[4:] else: args = () else: end_date = None search_keys = ('bbox', 'county', 'network', 'sid', 'state') if options.elements == 'all': all_elements = list(ELEMENTS.keys()) else: all_elements = list(stringToTuple(options.elements)) all_elements.sort() factory = ObsnetDataFactory(options) stations = factory.argsToStationData(args, options, search_keys=search_keys) stations.sort(key=lambda x: x['ucanid']) total_stations = len(stations) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - badmsg = 'encountered known bad station %s : %s (%s)' procmsg = '\nprocessing station %d of %d : %d : %s (%s)' skipmsg = 'skipping station %d of %d : %d : %s (%s)' days_per_request = options.days_per_request replace_existing = options.replace_existing test_run = options.test if test_run: debug = True else: debug = options.debug