Exemple #1
0
    def drawHardinessMap(self, date, verbose=False):
        # get initiaized map options from config file
        map_options = self.initMapOptions(date, 'hardiness', 'temp')

        map_options['outputfile'] = \
        mapFilepath(date, self.variety, 'hardiness', 'temp')

        units = chr(176)+'F'
        map_options['title'] = \
        self.mapTitle(date, 'hardiness', units=units.decode('latin1'))

        hard_temp = self.getHardiness(date, units='F')
        drawFilledContours(hard_temp, self.lats, self.lons, **map_options)
        return map_options['outputfile']
Exemple #2
0
    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)
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)
Exemple #5
0
        map_options['title'] = title
        # date-specific map 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()
map_options['titleyoffset'] = 0.165
del map_options['contourbounds']
title = '%s\nAccumulated Chill Difference\n%s - %s' % (
    variety.description, model_1.name.title(), model_2.name.title())

# get date indepenedent attributes and grids from the stage grid manager
manager = factory.getChillGridManager(target_year, 'r', test_file)
lats = manager.lats
lons = manager.lons

date = start_date
while date < past_date:
    map_options['title'] = title
    # date-specific map options
    map_options['date'] = date
    map_options['outputfile'] = filepath_template % asAcisQueryDate(date)

    # get GDD accumulations for the date and draw the map
    chill_grid_1 = manager.getChill(model_1.name, 'accumulated', date)
    chill_grid_1[N.where(chill_grid_1 < 0.0)] = N.nan
    print 'grid 1', N.nanmin(chill_grid_1), N.nanmax(chill_grid_1)
    chill_grid_2 = manager.getChill(model_2.name, 'accumulated', date)
    chill_grid_2[N.where(chill_grid_2 < 0.0)] = N.nan
    print 'grid 2', N.nanmin(chill_grid_2), N.nanmax(chill_grid_2)

    chill_grid = chill_grid_1 - chill_grid_2
    print N.nanmin(chill_grid), N.nanmax(chill_grid)
    drawFilledContours(chill_grid, lats, lons, **map_options)

    date += ONE_DAY
Exemple #7
0
# get temp manager and lot, lon data
manager = factory.getTempGridManager(target_year, 'r', test_file)
lats = manager.lats
lons = manager.lons

map_options = { 'area':'northeast', 'titleyoffset': 0.165, #'apply_mask':False,
                'cmap':'jet', 'colorbar':True, }

temp = manager.getTemp(temp_path, start_date, end_date, units=units)

if end_date is None:
    map_options['autobounds'] = True
    map_options['date'] = start_date
    map_options['title'] = title
    map_options['outputfile'] = map_filepath % asAcisQueryDate(start_date)

    drawFilledContours(temp, lats, lons, **map_options)
else:
    map_options['contourbounds'] = plot_bound(temp, 20)

    num_days = (end_date - start_date).days + 1
    for day in range(num_days):
        date = start_date + relativedelta(days=day)
        map_options['date'] = date
        map_options['outputfile'] = map_filepath % asAcisQueryDate(date)

        day_temps = temp[day]
        map_options['title'] = title % (N.nanmin(day_temps),N.nanmax(day_temps))
        drawFilledContours(day_temps, lats, lons, **map_options)

Exemple #8
0
                                        test_file)
gdd_thresholds = manager.gddThresholds(model_1.name)
lats = manager.lats
lons = manager.lons

map_options = {
    'area': 'northeast',
    'cmap': 'jet',
    'colorbar': True,
    'titleyoffset': 0.165,
}

for lo_gdd_th, hi_gdd_th in gdd_thresholds:
    date = start_date
    while date < past_date:
        map_options['title'] = title
        # date-specific map options
        map_options['date'] = date
        map_options['outputfile'] = filepath_template % asAcisQueryDate(date)

        # get GDD accumulations for the date and draw the map
        stage_grid_1 = \
                manager.getStage(model_1.name, lo_gdd_th, hi_gdd_th, date)
        stage_grid_2 = \
                manager.getStage(model_2.name, lo_gdd_th, hi_gdd_th, date)

        stage_grid = stage_grid_1 - stage_grid_2
        drawFilledContours(stage_grid, lats, lons, **map_options)

        date += ONE_DAY
Exemple #9
0
kill_levels = variety.kill_levels
kill_temps = variety.kill_temps.attr_list

stage_names =\
tuple(fromConfig('crops.apple.variety.stage_name_map.attr_values'))

for lo_gdd_th, hi_gdd_th in gdd_thresholds:
    date = start_date
    while date <= end_date:
        map_options['date'] = date
        date_str = asAcisQueryDate(date)

        mint = temp_manager.getTemp(mint_dataset, date)
        stage_grid = \
            variety_manager.getStage(model.name, lo_gdd_th, hi_gdd_th, date)

        for stage, stage_name in enumerate(stage_names[1:], start=1):
            indexes = N.where(stage_grid == stage)
            if len(indexes[0]) > 0:
                for indx, kill_level in enumerate(kill_levels):
                    percent = '%d%%' % kill_level
                    map_options['title'] = title % (percent, stage_name)
                    map_options['outputfile'] = \
                            filepath % (date_str, stage_name, percent)

                    diff = float(kill_temps[indx]) - mint
                    drawFilledContours(diff, lats, lons, **map_options)

        date += ONE_DAY