def drawGDDMap(self, date, verbose=False): min_gdd = fromConfig('crops.grape.maps.min_gdd_to_post') min_percent = fromConfig('crops.grape.maps.min_percent_nodes') lats = self.lats lons = self.lons # get initiaized map options from config file map_options = self.initMapOptions(date, 'variety', 'gdd', 'gdd') # get GDD accumulations for the date and draw the map gdd_grid = self.getGdd(model.name, date) gdd_grid[N.where(gdd_grid < 0.99)] = N.nan finite = N.where(N.isfinite(gdd_grid)) num_finite = len(finite[0]) if num_finite > 0: num_ge_min = float(len(N.where(gdd_grid[finite] >= min_gdd)[0])) draw_contours = (num_ge_min / num_finite) > min_percent else: draw_contours = False if draw_contours: map_options['finish'] = False options, _map_, fig, axes, fig1, xy_extremes = \ drawFilledContours(gdd_grid, lats, lons, **map_options) addModelText(fig, **map_options) finishMap(fig, axes, fig1, **options) return options['outputfile'] else: config = fromConfig('crops.grape.maps.no_data.gdd.attrs') return drawNoDataMap(lons, lats, config=config, model=model, **map_options)
def drawStageContourMap(self, date, model, lo_gdd_th, hi_gdd_th, verbose=False): lats = self.lats lons = self.lons # get initiaized map options from config file map_options = self.initMapOptions(date, model, lo_gdd_th, lo_gdd_th, 'variety', 'stage', 'stage') # get stage index for date and draw the map stage_grid = self.getStage(model.name, lo_gdd_th, hi_gdd_th, date) isfinite = N.where(N.isfinite(stage_grid)) if len(N.where(stage_grid[isfinite] > 0)[0]) > 0: map_options['finish'] = False options, _map_, fig, axes, fig1, xy_extremes = \ drawFilledContours(stage_grid, lats, lons, **map_options) addModelText(fig, model, **map_options) finishMap(fig, axes, fig1, **options) return options['outputfile'] else: config = fromConfig('crops.apple.variety.maps.no_data.stage.attrs') return drawNoDataMap(lons, lats, config=config, model=model, **map_options)
def drawNoDataMap(self, map_key, **options): from frost.visual.maps import mapSetup no_data = fromConfig('crops.grape.maps.no_data.%s.attrs' % map_key) options.update(no_data) map_options, _basemap_, map_fig, axes, xy_extremes = \ mapSetup(options, self.lats, self.lons) if 'contourbounds' in options: from frost.visual import resolveColorMapOptions x_min = xy_extremes[0] x = N.array( [ [x_min, x_min+1.0], [x_min, x_min+1.0 ] ] ) y_min = xy_extremes[2] y = N.array( [ [y_min, y_min], [y_min+1.0, y_min+1.0 ] ] ) zero = N.array( [ [0.0, 0.0], [0.0, 0.0] ] ) cmap_options = resolveColorMapOptions(**map_options) fig1 = _basemap_.contourf(x, y, zero, options['contourbounds'], **cmap_options) finishMap(map_fig, axes, fig1, **map_options) else: finishMap(map_fig, axes, map_fig, **map_options) return map_options['outputfile']
def drawNoDataMap(lons, lats, **options): model = options['model'] del options['model'] map_options = resolveMapOptions(**options) no_data_config = options.get('config', None) if no_data_config is not None: map_options.update(no_data_config) _basemap_, map_fig, axes, xy_extremes = mapInit(lats, lons, **map_options) if 'contourbounds' in map_options: x_min = xy_extremes[0] x = N.array([[x_min, x_min + 1.0], [x_min, x_min + 1.0]]) y_min = xy_extremes[2] y = N.array([[y_min, y_min], [y_min + 1.0, y_min + 1.0]]) zero = N.array([[0.0, 0.0], [0.0, 0.0]]) cmap_options = resolveColorMapOptions(**map_options) fig1 = _basemap_.contourf(x, y, zero, options['contourbounds'], **cmap_options) else: fig1 = map_fig addModelText(map_fig, model, **map_options) finishMap(map_fig, axes, fig1, **map_options) return map_options['outputfile']
def drawKillMap(self, date, mint, verbose=False): if self.temp_reader is None: from frost.functions import tempGridReader self.temp_reader = tempGridReader(date) lats = self.lats lons = self.lons # get initiaized map options from config file map_options = self.initMapOptions(date, 'kill', 'potential') map_options['title'] = self.mapTitle(date, 'kill') # extract options required for plotting markers marker_colors = map_options['markercolors'] # get hardines temp and min temp for the date hardiness = self.getHardiness(date, units='F') mint = self.temp_reader.getTemp('reported.mint', date, units='F') # we need number of degrees mint is below hardiness temp. # In order to guarantee that we don't have one negative value # and one positive value, we need to adjust the grids so that # all values in each of them are above zero # using 1000. might be overkill, but it is guaranteed safe hardiness += 1000. mint += 1000. diff = hardiness - mint indexes = N.where(diff >= 0) # there is potential kill at one or more grid nodes if len(indexes[0]) > 0: options, _map_, map_fig, axes, xy_extremes, x, y, _grid_ = \ hiResMap(diff, lats, lons, **map_options) del x, y, _grid_ diff = diff[indexes].flatten() _lats_ = lats[indexes].flatten() _lons_ = lons[indexes].flatten() # draw a separate map layer for each potential for indx, where_clause in enumerate(map_options['where_potential']): prob_indexes = eval('N.where(%s)' % where_clause) if len(prob_indexes[0]) > 0: diff[prob_indexes] = indx fig = addScatterToMap(options, _map_, map_fig, diff[prob_indexes], _lats_[prob_indexes], _lons_[prob_indexes], markercolor=marker_colors[indx]) finishMap(map_fig, axes, map_fig, **options) return options['outputfile'] # no kill events - draw a blank map else: return self.drawNoDataMap('kill', **map_options)
def drawKillMap(self, date, model, lo_gdd_th, hi_gdd_th, verbose=False): lats = self.lats lons = self.lons # get initiaized map options from config file map_options = self.initMapOptions(date, model, None, None, 'variety', 'kill', 'kill') var_config = fromConfig('crops.apple.variety') # extract options required for plotting markers marker_colors = map_options['markercolors'] kill_probabilities = var_config.kill_probabilities # get stage index for date and draw the map kill = self.getKill(model.name, lo_gdd_th, hi_gdd_th, date) indexes = N.where(kill > 0) # kill is probable at one or more grid nodes if len(indexes[0]) > 0: options, _map_, map_fig, axes, xy_extremes, x, y, _grid_ = \ hiResMap(kill, lats, lons, **map_options) del x, y, _grid_ kill = kill[indexes].flatten() _lats_ = lats[indexes].flatten() _lons_ = lons[indexes].flatten() # draw a separate map layer for each probability for indx, probability in enumerate(kill_probabilities, start=1): prob_indexes = N.where(kill == probability) if len(prob_indexes[0]) > 0: kill[prob_indexes] = indx fig = addScatterToMap(options, _map_, map_fig, kill[prob_indexes], _lats_[prob_indexes], _lons_[prob_indexes], markercolor=marker_colors[indx - 1]) addModelText(map_fig, model, **map_options) finishMap(map_fig, axes, map_fig, **options) return options['outputfile'] # no kill events - draw a blank map else: config = fromConfig('crops.apple.variety.maps.no_data.kill.attrs') return drawNoDataMap(lons, lats, config=config, model=model, **map_options)
def drawStageMap(self, date, model, lo_gdd_th, hi_gdd_th, verbose=False): lats = self.lats lons = self.lons # get initiaized map options from config file map_options = self.initMapOptions(date, model, lo_gdd_th, lo_gdd_th, 'variety', 'stage', 'stage') var_config = fromConfig('crops.apple.variety') # extract options required for plotting markers marker_colors = map_options['markercolors'] stage_name_map = var_config.stage_name_map # get stage index for date and draw the map stage_data = self.getStage(model.name, lo_gdd_th, hi_gdd_th, date) isfinite = N.where(N.isfinite(stage_data)) if len(N.where(stage_data[isfinite] > 0)[0]) > 0: options, _map_, map_fig, axes, xy_extremes, x, y, _grid_ = \ hiResMap(stage_data, lats, lons, **map_options) del x, y, _grid_ _lats_ = lats[isfinite].flatten() _lons_ = lons[isfinite].flatten() stage_data = stage_data[isfinite].flatten() for stage in range(len(stage_name_map.attrs)): indexes = N.where(stage_data == stage) if len(indexes[0]) > 0: fig = addScatterToMap(map_options, _map_, map_fig, stage_data[indexes], _lats_[indexes], _lons_[indexes], markercolor=marker_colors[stage]) addModelText(map_fig, model, **map_options) finishMap(map_fig, axes, map_fig, **options) return options['outputfile'] else: config = fromConfig('crops.apple.variety.maps.no_data.stage.attrs') return drawNoDataMap(lons, lats, config=config, model=model, **map_options)
def drawChillMaskMap(self, date, model, lo_gdd_th, hi_gdd_th, verbose=False): lats = self.lats lons = self.lons # get initiaized map options from config file map_options = self.initMapOptions(date, model, None, None, 'variety', 'mask', 'mask') var_config = fromConfig('crops.apple.variety') # get stage index for date and draw the map mask = self.getChillMask(model.name, lo_gdd_th, hi_gdd_th, date) indexes = N.where(mask == True) # kill is probable at one or more grid nodes if len(indexes[0]) > 0: options, _map_, map_fig, axes, xy_extremes, x, y, _grid_ = \ hiResMap(mask, lats, lons, **map_options) del x, y, _grid_ x, y = _map_(lons[indexes].flatten(), lats[indexes].flatten()) fig1 = _map_.scatter(x, y, c='r', s=3, marker='^', linewidths=0) addModelText(map_fig, model, **map_options) finishMap(map_fig, axes, map_fig, **options) return options['outputfile'] # no kill events - draw a blank map else: config = fromConfig('crops.apple.variety.maps.no_data.kill.attrs') return drawNoDataMap(lons, lats, config=config, model=model, **map_options)
map_options = map_config.options[map_type].attrs map_options = setupMap(map_options) map_options['title'] = None map_options['title2'] = None map_options['area_template'] = map_config.no_data[map_type].create_with if 'grid' in map_options: del map_options['grid'] dirpath = os.path.split(output_file)[0] if dirpath: if not os.path.exists(dirpath): os.makedirs(dirpath) map_options['outputfile'] = output_file else: dirpath = map_options['shapelocation'] map_options['outputfile'] = os.path.join(dirpath, output_file) factory = AppleGridFactory() target_year = factory.getTargetYear(datetime.now()) reader = factory.getTempGridReader(target_year) _map_ = hiResMap(reader.getTemp('reported.maxt', reader.start_date), reader.lats, reader.lons, **map_options) options = _map_[0] fig1 = fig = _map_[2] if map_type in ('gdd', 'accumulated'): grid = N.empty(reader.lons.shape, dtype=float) grid.fill(N.nan) drawFilledContours(grid, reader.lats, reader.lons, **map_options) else: finishMap(fig, fig, options)
map_options['date'] = date map_options['outputfile'] = filepath_template % asAcisQueryDate(date) # get GDD accumulations for the date and draw the map chill_grid = manager.getChill(model.name, 'accumulated', date) finite = N.where(N.isfinite(chill_grid)) num_finite = float(len(finite[0])) if num_finite > 0: num_ge_min = float(len(N.where(chill_grid[finite] >= min_chill)[0])) if num_ge_min > 0 and (num_ge_min / num_finite) > min_percent: chill_grid[chill_grid < 100.] = N.nan options, _map_, fig, axes, fig1, xy_extremes = \ drawFilledContours(chill_grid, lats, lons, finish=False, **map_options) addModelText(fig, model, **map_options) finishMap(fig, axes, fig1, **options) path = options['outputfile'] else: path = drawNoDataMap(lons, lats, config=no_data, model=model, **map_options) print 'completed', path else: print 'All data missing for', date.strftime('%Y-%m-%d') date += ONE_DAY # turn annoying numpy warnings back on warnings.resetwarnings()