temp_reader = factory.getTempGridReader(target_year, test_file)
if forecast:
    mint = temp_reader.getTemp('forecast.mint', start_date, end_date)
else:
    temp_start = start_date + ONE_DAY
    if end_date is None:
        mint = temp_reader.getTemp('reported.mint', temp_start, None)
    else:
        temp_end = end_date + ONE_DAY
        mint = temp_reader.getTemp('reported.mint', temp_start, temp_end)
temp_reader.close()
del temp_reader

# get a Variety grid manager for the target year
variety_manager = \
    factory.getVarietyGridManager(target_year, variety, 'a', test_file)
models = [name.lower() for name in variety_manager.file_chill_models]
variety_manager.close()

# estimate GDD accumulation, stage and kill probability for this variety
for model_name in models:
    #  loop trough all GDD thresholds
    for lo_gdd_th, hi_gdd_th in variety_manager.gddThresholds(model_name):
        variety_manager.open('r')
        stage_grid = variety_manager.getStage(model_name, lo_gdd_th, hi_gdd_th,
                                              start_date, end_date)

        # estimate kill probability from stages and predicted mint
        kill_grid = variety_manager.estimateKill(stage_grid, mint)
        # no longer need stage grid
        del stage_grid
Beispiel #2
0
target_year = int(args[0])

# apple variety config
variety = getGrapeVariety(args[1])

# 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")
# MUST ALSO TURN OFF WARNING FILTERS AT END OF SCRIPT !!!!!

# get a chill data file manger
factory = AppleGridFactory()
from_manager = factory.getVarietyGridManager(target_year, variety.name, 'r')

acis_grid = from_manager.acis_grid
models = [name.lower() for name in from_manager.file_chill_models]
start_date = from_manager.start_date
end_date = from_manager.end_date
num_days = (end_date - start_date).days + 1

# get a manager for the restructured file
to_filepath = from_manager._hdf5_filepath.replace('.h5', '.new.h5')
if new_file:
    to_manager =\
    AppleVarietyGridManager.newManager(variety.name, from_manager.start_date,
                from_manager.end_date, from_manager.lons, from_manager.lats,
                from_manager.search_bbox, models,
                from_manager.gddThresholds('carolina'), acis_grid,
# 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")
# MUST ALSO TURN OFF WARNING FILTERS AT END OF SCRIPT !!!!!

# get the chill data file manger for the target year ... IT MUST ALREADY EXIST


# need to save the indexes where NANs occur
mint_nan_indexes = N.where(N.isnan(mint))

# get a Variety grid manager for the target year
old_manager = \
factory.getVarietyGridManager(target_year, variety_name, 'a', test_run)
models = [name.lower() for name in old_manager.file_chill_models]
gdd_thresholds = old_manager.gddThresholds()

new_manager = \
factory.newVarietyGridManager(target_year, variety_name, models, 
                              gdd_thresholds, old_manager.search_bbox,
                              old_manager.acis_grid, True)

def copyTemp(temp_type, new_manager, old_manager, old_prov_name):
    old_temp_dataset = old_manager.getDataset(temp_type)
    old_prov_dataset = old_manager.getDataset(old_prov_name)

    new_temp_dataset = new_manager.getDataset(temp_type)
    new_temp_dataset.attrs['created'] = old_temp_dataset.attrs['created']
    new_prov_dataset = new_manager.getDataset('%s_provenance' %temp_type)
Beispiel #4
0
factory = AppleGridFactory()
target_year = factory.getTargetYear(start_date)

# get the map directory path and the template for the map file name
map_dirpath = mapWorkingDir(target_year, variety.name, model_1.name,
                            'stage.diff', None, None, test_file)

filename_template = '%%s-Frost-Apple-%s-%s-%s-Stage-Diff.png'
filename_template = filename_template % (nameToFilepath(
    variety.name), nameToFilepath(model_1.name), nameToFilepath(model_2.name))
filepath_template = map_dirpath + os.sep + filename_template

title = '%s\nPhenological Stage Difference\n%s - %s' % (
    variety.description, model_1.name.title(), model_2.name.title())

manager = factory.getVarietyGridManager(target_year, variety.name, 'r',
                                        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
Beispiel #5
0
year = int(args[1])
month = int(args[2])
day = int(args[3])
date = datetime(year,month,day)
target_year = factory.getTargetYear(date)

# 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 !!!!!

variety_manager = factory.getVarietyGridManager(target_year, variety, 'r')
models = [name.lower() for name in variety_manager.file_chill_models]
variety_manager.close()

# make sure managers can read their data files

variety_titled = variety.name.replace('_',' ').title()
# estimate GDD accumulation, stage and kill probability for this variety
for model_name in models:
    variety_manager.open('r')
    gdd_thresholds = variety_manager.gddThresholds(model_name)
    
    #  loop trough all GDD thresholds
    for lo_gdd_th, hi_gdd_th in gdd_thresholds:
        # calculuate accumulated GDD from daily gdd
        # let GDD manger get accumulated GDD for previous day