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)