def __init__(self, **kwargs): # initialize common configuration structure TurfThreatGridFileFactory.__init__(self, **kwargs) self.path_mode = 'default' self.riskModels = { 'anthrac': anthracRiskModel, 'bpatch': bpatchRiskModel, 'dspot': dspotRiskModel, 'hstress': hstressRiskModel, 'pblight': pblightRiskModel, } self.weatherDataReaders = { 'anthrac': getAnthracWeatherData, 'bpatch': getBpatchWeatherData, 'dspot': getDspotWeatherData, 'hstress': getHstressWeatherData, 'pblight': getPblightWeatherData, }
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # date_to_fix = options.date_to_fix debug = options.debug dev_mode = options.dev_mode period = options.period region_key = options.grid_region verbose = options.verbose or debug threat_key = args[0] num_args = len(args) if num_args == 2: target_year = int(args[1]) # create a factory for disease file access factory = TurfThreatGridFileFactory(CONFIG) if dev_mode: factory.useDirpathsForMode('dev') region = factory.regionConfig(region_key) threat = factory.threatConfig(threat_key) # filter annoying numpy warnings warnings.filterwarnings('ignore', "All-NaN axis encountered") warnings.filterwarnings('ignore', "All-NaN slice encountered") warnings.filterwarnings('ignore', "invalid value encountered in greater") warnings.filterwarnings('ignore', "invalid value encountered in less") warnings.filterwarnings('ignore', "Mean of empty slice") # MUST ALSO TURN OFF WARNING FILTERS AT END OF SCRIPT !!!!! # get grid file builder manager = factory.threatFileManager(threat_key, period, target_year, region) msg = '\nAttempting to repair first_valid date in %s threat/risk file :\n%s'
forecast = options.forecast debug = options.debug dev_mode = options.dev_mode region_key = options.region verbose = options.verbose or debug threat_key = args[0] period_key = args[1] # assume forecast starts today fcast_start = TODAY # assume last obs was yesterday previous_obs = TODAY - ONE_DAY # factory for accessing threat data files data_factory = TurfThreatGridFileFactory() if dev_mode: data_factory.useDirpathsForMode('dev') region = data_factory.regionConfig(region_key) def findLastMap(map_factory, previous_obs, threat_key, period_key): map_factory.turfMapFilename(threat_key, None, region) if start_date is None: reader = data_factory.threatFileReader(threat_key, period_key, TODAY.year) else: reader = data_factory.threatFileReader(threat_key, period_key, start_date.year) if verbose: print 'reading data from :\n', reader.filepath
else: # a single period was passed periods = (args[1], ) # get reguired information from static file factory = SeasonalStaticFileFactory() if dev_mode: factory.useDirpathsForMode('dev') region = factory.regionConfig(region_key) source = factory.sourceConfig(source_key) reader = factory.staticFileReader(source, region) lats = reader.getData('lat') lons = reader.getData('lon') reader.close() del reader, factory # create a factory for disease file access factory = TurfThreatGridFileFactory(CONFIG) if dev_mode: factory.useDirpathsForMode('dev') region = factory.regionConfig(region_key) source = factory.sourceConfig(source_key) threat = factory.threatConfig(threat_key) # filter annoying numpy warnings warnings.filterwarnings('ignore', "All-NaN axis encountered") warnings.filterwarnings('ignore', "All-NaN slice encountered") warnings.filterwarnings('ignore', "invalid value encountered in greater") warnings.filterwarnings('ignore', "invalid value encountered in less") warnings.filterwarnings('ignore', "Mean of empty slice") # MUST ALSO TURN OFF WARNING FILTERS AT END OF SCRIPT !!!!! for period_key in periods: # get grid file builder
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # debug = options.debug dev_mode = options.dev_mode sub_region = options.sub_region verbose = options.verbose or debug threat = args[0] path_key = 'threats.%s' % threat include_avg = threat != 'hstress' if num_args == 1: target_year = datetime.date.today().year elif num_args == 2: target_year = int(args[1]) # create a factory for access to the threat file factory = TurfThreatGridFileFactory() if dev_mode: factory.useDirpathsForMode('dev') region = factory.regionConfig(factory.project.region) if include_avg: # open average data file and extract lat, lon, data and it's dates avg_reader = factory.threatFileReader(threat, 'average', target_year) avg_dates = avg_reader.dateAttributes('risk', True) avg_reader.close() # open daily data file and extract lat, lon, data and it's dates daily_reader = factory.threatFileReader(threat, 'daily', target_year) daily_dates = daily_reader.dateAttributes('risk', True) daily_reader.close() # extract the dates needed for the json files and create the common json template
debug = options.debug dev_mode = options.dev_mode region_key = options.grid_region verbose = options.verbose or debug threat_key = args[0] period = args[1] new_date = datetime.date(*[int(arg) for arg in args[2:]]) if threat_key == 'hstess': datasets = ('stress', 'risk') else: datasets = ('threat', 'risk') # create a factory for disease file access factory = TurfThreatGridFileFactory(CONFIG) if dev_mode: factory.useDirpathsForMode('dev') threat_name = factory.threatName(threat_key) # get grid file builder manager = factory.threatFileManager(threat_key, period, new_date.year) manager.close() msg = '\nAttempting to repair obs dates in %s %s threat/risk file :\n%s' print msg % (threat_name, period.title(), manager.filepath) for dataset in datasets: manager.open('r') fcast_start_date = manager.dateAttribute(dataset, 'fcast_start_date', None) last_valid_date = manager.dateAttribute(dataset, 'last_valid_date', None) last_obs_date = manager.dateAttribute(dataset, 'last_obs_date', None) print '\nBefore repairs to %s dataset:' % dataset
month = int(args[2]) start_date = datetime.date(year,month,int(args[3])) if num_date_args == 3: # single day end_date = start_date elif num_date_args == 4: # end on different day end_date = datetime.date(year,month,int(args[4])) elif num_date_args == 5: # end at different month and day end_date = datetime.date(year,int(args[4]),int(args[5])) else: errmsg = 'Invalid number of date arguments (%d).' % num_date_args raise ValueError, errmsg target_year = start_date.year # factory for accessing threat data files grid_factory = TurfThreatGridFileFactory() if dev_mode: grid_factory.useDirpathsForMode('dev') region = grid_factory.regionConfig(region_key) reader = grid_factory.gridFileReader(threat_key, 'daily', target_year, region) if verbose: print 'reading data from :\n', reader.filepath date_attrs = reader.dateAttributes('risk') last_valid_date = date_attrs['last_valid_date'] data_start_date = date_attrs['start_date'] # factory for building and accessing map files map_factory = TurfMapFileFactory() if dev_mode: map_factory.useDirpathsForMode('dev') map_options = map_factory.mapOptions(threat_key, region).attrs threat = map_factory.configForThreat(threat_key)
def useDirpathsForMode(self, mode): TurfThreatGridFileFactory.useDirpathsForMode(self, mode) self.path_mode = mode
if arg_2 > 99: month = int(args[3]) start_date = datetime.date(arg_2, month, int(args[4])) end_date = datetime.date(arg_2, month, int(args[5])) else: year = today.year start_date = datetime.date(year, arg_2, int(args[3])) end_date = datetime.date(year, int(args[4]), int(args[5])) elif num_date_args == 5: start_date = datetime.date(arg_2, int(args[3]), int(args[4])) end_date = datetime.date(arg_2, int(args[5]), int(args[6])) target_year = end_date.year threat_factory = TurfThreatGridFileFactory() region = threat_factory.regionConfig(region_key) period = threat_factory.threatConfig(threat).periods[period_key] weather_reader = SmartThreatWeatherReader(region) if dev_mode: threat_factory.useDirpathsForMode('dev') weather_reader.useDirpathsForMode('dev') if start_date is None: start_date = end_date end_date += datetime.timedelta(days=period.num_days) print '\nrequested :' print ' today =', today