elif date_args == 6:
        year = int(args[5])
        month = int(args[6])
        day = int(args[7])
        end_date = datetime(year, month, day)
    else:
        errmsg = 'Invalid number of date arguments (%d).' % date_args
        raise ValueError, errmsg
else:
    errmsg = 'Invalid number of date arguments (%d).' % date_args
    raise ValueError, errmsg

if end_date is None: past_date = start_date + ONE_DAY
else: past_date = end_date + ONE_DAY

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.name, 'chill',
                            dataset, None, None, test_file)
filename_template = mapFilename('%s', variety.name, model.name, 'chill',
                                dataset, None, None, test_file)
filepath_template = map_dirpath + os.sep + filename_template

# get the map title template and initialize the map title
title_template = fromConfig('crops.apple.chill.maps.titles.accumulated')
title = title_template % {
    'model': model.description,
}
    day = int(args[3])
    start_date = datetime(year, month, day)
    if num_args == 3: end_date = None
    elif num_args == 4:
        end_date = start_date + relativedelta(days=int(args[4]) - 1)
    elif num_args == 6:
        year = int(args[4])
        month = int(args[5])
        day = int(args[6])
        end_date = datetime(year, month, day)
else:
    print sys.argv
    errmsg = 'Invalid number of arguments (%d).' % num_args
    raise ValueError, errmsg

factory = AppleGridFactory()
target_year = factory.getTargetYear(start_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 !!!!!

# get mint from temperature file
temp_reader = factory.getTempGridReader(target_year, test_file)
if forecast:
    mint = temp_reader.getTemp('forecast.mint', start_date, end_date)
else:
ONE_DAY = relativedelta(days=1)

import numpy as N

from atmosci.utils.options import stringToTuple
from atmosci.utils.timeutils import daysInYear, lastDayOfMonth

from frost.apple.factory import AppleGridFactory

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

from optparse import OptionParser

parser = OptionParser()

parser.add_option('-v', action='store_true', dest='verbose', default=False)
parser.add_option('-z', action='store_true', dest='test_file', default=False)

options, args = parser.parse_args()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

test_file = options.test_file
verbose = options.verbose

target_year = int(args[0])

factory = AppleGridFactory()
factory.newChillGridManager(target_year, None, test_file)
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)
Beispiel #5
0
# 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 !!!!!

from frost.factory import FrostGridFactory
factory = FrostGridFactory()

if copy_from_apple:
    from frost.apple.factory import AppleGridFactory
    from frost.temperature import FrostTempFileBuilder

    apple_factory = AppleGridFactory()
    start_date, end_date = factory.getTargetDateSpan(target_year)

    apple_manager = apple_factory.getChillGridManager(target_year, 'r')
    lats = apple_manager.lats
    lons = apple_manager.lons
    apple_manager.close()

    manager = FrostTempFileBuilder(start_date,
                                   end_date,
                                   lons,
                                   lats,
                                   bbox=apple_manager.search_bbox,
                                   acis_grid=apple_manager.acis_grid,
                                   verbose=verbose)
    manager.close()
Beispiel #6
0
verbose = options.verbose or debug

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,
Beispiel #7
0
    elif date_args == 6:
        year = int(args[6])
        month = int(args[7])
        day = int(args[8])
        end_date = datetime(year, month, day)
    else:
        errmsg = 'Invalid number of date arguments (%d).' % date_args
        raise ValueError, errmsg
else:
    errmsg = 'Invalid number of date arguments (%d).' % date_args
    raise ValueError, errmsg

if end_date is None: past_date = start_date + ONE_DAY
else: past_date = end_date + ONE_DAY

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',
Beispiel #8
0
from atmosci.utils.timeutils import lastDayOfMonth

from frost.apple.factory import AppleGridFactory
from frost.apple.linvill.grid import temp3DGridToHourly

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

from optparse import OptionParser
parser = OptionParser()
parser.add_option('-v', action='store_true', dest='verbose', default=False)
options, args = parser.parse_args()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

verbose = options.verbose
factory = AppleGridFactory()

num_args = len(args)
if num_args == 0:
    start_date = datetime.now() - ONE_DAY
    end_date = None
elif num_args == 2:
    year = int(args[0])
    month = int(args[1])
    start_date = datetime(year,month,1)
    end_date = datetime(year, month, lastDayOfMonth(year, month))
elif num_args in (3,4,6):
    year = int(args[0])
    month = int(args[1])
    day = int(args[2])
    start_date = datetime(year,month,day)
verbose = options.verbose

target_year = int(args[0])

# apple variety config
variety = getAppleVariety(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 variety grid file manger
factory = AppleGridFactory()
reader = factory.getVarietyGridReader(target_year, variety)

if len(args) > 2: to_filepath = os.path.abspath(args[1])
else: to_filepath = reader._hdf5_filepath.replace('.h5', '.new.h5')

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

# get a manager for the restructured file
if new_file:
    from frost.apple.variety.grid import AppleVarietyGridBuilder

    builder_attributes = {
parser.add_option('-y', action='store_true', dest='test_run', default=False)
parser.add_option('-z', action='store_true', dest='debug', default=False)

options, args = parser.parse_args()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

debug = options.debug
test_run = options.test_run
test_file = debug | test_run
verbose = options.verbose or debug

variety_name = args[0]
target_year = int(args[1])

factory = AppleGridFactory()

# 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
update_gdd = options.update_gdd
update_models = options.update_models
update_temps = options.update_temps
verbose = options.verbose

target_year = int(args[0])

# 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 grid file manger
factory = AppleGridFactory()
reader = factory.getChillGridReader(target_year)

if len(args) > 1: to_filepath = os.path.abspath(args[1])
else: to_filepath = reader._hdf5_filepath.replace('.h5', '.new.h5')

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

# get a manager for the restructured file
if new_file:
    from frost.apple.chill.grid import AppleChillGridBuilder

    builder_attributes = {
options, args = parser.parse_args()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

acis_grid = options.acis_grid
calc_gdd = options.calc_gdd
data_bbox = options.bbox
debug = options.debug
forecast = options.forecast
models = options.models
test_file = options.test_file
verbose = options.verbose or debug
update_db = options.update

factory = AppleGridFactory()

num_args = len(args)
if num_args == 0:
    start_date = datetime.datetime.now() - ONE_DAY
    end_date = None
elif num_args == 2:
    year = int(args[0])
    month = int(args[1])
    start_date = datetime.datetime(year, month, 1)
    end_date = datetime.datetime(year, month, lastDayOfMonth(year, month))
elif num_args in (3, 4, 5, 6):
    year = int(args[0])
    month = int(args[1])
    day = int(args[2])
    start_date = datetime.datetime(year, month, day)
Beispiel #13
0
options, args = parser.parse_args()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

acis_grid = options.acis_grid
calc_gdd = options.calc_gdd
debug = options.debug
download_mint = options.download_mint
forecast = options.forecast
test_file = options.test_file
verbose = options.verbose or debug
update_db = options.update

variety = getAppleVariety(args[0])

factory = AppleGridFactory()

num_args = len(args[1:])
if num_args == 1:
    target_year = int(args[1])
    start_date = None
    end_date = None
elif num_args == 2:
    year = int(args[1])
    month = int(args[2])
    start_date = datetime.datetime(year, month, 1)
    last_day = lastDayOfMonth(year, month)
    end_date = datetime.datetime(year, month, last_day)
    target_year = factory.getTargetYear(start_date)
elif num_args in (3, 4, 6):
    year = int(args[1])
Beispiel #14
0
        end_date = start_date + relativedelta(days=int(date_args[3]) - 1)
    elif num_date_args == 6:
        year = int(date_args[3])
        month = int(date_args[4])
        day = int(date_args[5])
        end_date = datetime(year, month, day)
    else:
        errmsg = 'Invalid number of date arguments (%d).' % date_args
        raise ValueError, errmsg
else:
    errmsg = 'Invalid number of date arguments (%d).' % date_args
    raise ValueError, errmsg

if end_date is None: end_date = start_date

factory = AppleGridFactory()
target_year = factory.getTargetYear(start_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 !!!!!

for variety in varieties:
    visualizer = \
        factory.getVarietyVisualizer(target_year,variety.name,'r', test_file)
    for model in models:
        gdd_thresholds = visualizer.gddThresholds(model.name)
Beispiel #15
0
parser.add_option('-u', action='store_false', dest='update', default=True)
parser.add_option('-v', action='store_true', dest='verbose', default=False)
parser.add_option('-z', action='store_true', dest='debug', default=False)

options, args = parser.parse_args()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

debug = options.debug
update = options.update
verbose = options.verbose or debug

variety = getAppleVariety(args[0])
model = args[1]

factory = AppleGridFactory()

num_args = len(args[2:])
if num_args in (3,4,6):
    year = int(args[2])
    month = int(args[3])
    day = int(args[4])
    start_date = datetime(year,month,day)
    if num_args == 3: end_date = None
    elif num_args == 4:
        end_date = start_date + relativedelta(days=int(args[5])-1)
    elif num_args == 6:
        year = int(args[5])
        month = int(args[6])
        day = int(args[7])
        end_date = datetime(year,month,day)
    year = int(args[5])
    month = int(args[6])
    day = int(args[7])
    end_date = datetime(year, month, day)
else:
    end_date = datetime.date.today() - relativedelta(days=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")
warnings.filterwarnings('ignore', "Mean of empty slice")
# MUST ALSO TURN OFF WARNING FILTERS AT END OF SCRIPT !!!!!

factory = AppleGridFactory()
target_year = factory.getTargetYear(start_date)

plot_options = \
fromConfig('crops.apple.variety.plots.options.hardiness_vs_temp').copy()
plot_options['coords'] = coords
plot_options['location'] = location
plot_options['variety'] = variety.description
temp_units = plot_options.temp_units

# initialize figure and GCA
figure = pyplot.figure(figsize=plot_options.figsize, dpi=100)
axis = figure.gca()

# read the reported mint for the current season
reader = factory.getTempGridReader(target_year)
Beispiel #17
0
from optparse import OptionParser, OptionValueError
parser = OptionParser()

parser.add_option('-v', action='store_true', dest='verbose', default=False)
parser.add_option('-z', action='store_true', dest='debug', default=False)

options, args = parser.parse_args()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

debug = options.debug
verbose = options.verbose or debug

variety = getAppleVariety(args[0])

factory = AppleGridFactory()

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