예제 #1
0
 def getTargetYear(self, date, variety=None):
     return FrostGridFactory.getTargetYear(self, date, 'apple', variety)
if acis_grid is None: acis_grid = fromConfig('default.grid.acis')
# days_per_loop ... find a number that maximizes ACIS download performance
days_per_loop = relativedelta(days=options.days_per_loop - 1)
debug = options.debug
rebuild = options.rebuild
data_bbox = options.bbox
if data_bbox is None: data_bbox = fromConfig('default.bbox.data')
test_run = options.test_run
test_file = debug | test_run
verbose = options.verbose or debug
update_db = options.update

target_year = int(args[0])

# get a temperature data file manger
factory = FrostGridFactory()
filepath = factory.getTemperatureFilePath(target_year, test_file)
if not os.path.exists(os.path.normpath(filepath)):
    manager = factory.newTempGridManager(target_year, data_bbox, verbose,
                                         test_file)
else:
    manager = factory.getTemperatureManager(target_year, 'r', test_file)

# extract the time span for the target year
start_year = target_year - 1
start_month, day = fromConfig('default.start_day')
target_start_date = datetime(start_year, start_month, day)
month, day = fromConfig('default.end_day')
target_end_date = datetime(target_year, month, day)

# download several days at a time
예제 #3
0
 def getTargetDateSpan(self, year_or_date, variety=None):
     return FrostGridFactory.getTargetDateSpan(self, year_or_date, 'apple',
                                               variety)
예제 #4
0
if len(args) == 1:
    target_year = int(args[0])
    today = None
else:
    target_year = datetime.date.today().year
    today = datetime.date.today()

# 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()
start_date, end_date = factory.getTargetDateSpan(target_year)
# handle case where new file is constructed in cron for the next year
if today is not None and today.month > end_date.month: target_year += 1

manager = factory.newTempGridManager(target_year)
print 'created frost temperature for', target_year
print manager._hdf5_filepath
manager.close()

if download_temps:
    current_date = datetime.datetime.now()
    if target_year <= current_date.year:
        if target_year == current_date.year:
            if current_date >= start_date and current_date <= end_date:
                end_date = current_date
예제 #5
0
if debug: print '\ndownload_latest_temp_grids.py', args

num_args = len(args)
if num_args == 0:
    start_date = datetime.now()
elif num_args == 3:
    year = int(args[0])
    month = int(args[1])
    day = int(args[2])
    start_date = datetime(year,month,day)
else:
    errmsg = 'Invalid number of arguments (%d).' % num_args
    raise SyntaxError, errmsg

factory = FrostGridFactory()
# target year is the year that we want to predict frost damage
target_year = factory.getTargetYear(start_date)
if target_year is None: exit()

if debug: print 'dates', target_year, start_date

season_start = datetime(target_year-1, *fromConfig('crops.apple.start_day'))
season_end = datetime(target_year, *fromConfig('crops.apple.end_day'))
temp_end = season_end + ONE_DAY
if start_date > temp_end and start_date < season_start: exit()

# get a temperature data file manger
filepath = factory.getTempGridFilePath(target_year, test_file)
if debug:
    print 'temp filepath', os.path.exists(os.path.normpath(filepath)), filepath
예제 #6
0
    if date_args == 3: end_date = None
    elif date_args == 4:
        end_date = start_date + relativedelta(days=int(args[4])-1)
    elif date_args == 6:
        year = int(args[4])
        month = int(args[5])
        day = int(args[6])
        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

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

# create the map filepath template
template = '%%s-Frost-%s-%s-Map.png' % (temp_group.title(), temp_type.title())
map_dirpath = tempPlotDir(target_year, temp_group, temp_type, 'maps')
map_filepath = map_dirpath + os.sep + template

# create the map title tmplate
title_units = chr(176) + units
title = u"%s Temperature\n%%-.f < %s > %%-.F" % ( TEMP_NAMES[temp_type],
                                                  title_units.decode('latin1') )

# get temp manager and lot, lon data
manager = factory.getTempGridManager(target_year, 'r', test_file)
lats = manager.lats
from frost.factory import FrostGridFactory

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

from optparse import OptionParser
parser = OptionParser()

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

options, args = parser.parse_args()

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

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

target_year = int(args[0])

frost_factory = FrostGridFactory()

temp_manager = frost_factory.getTempGridManager(target_year, 'a')
bbox = temp_manager.getFileAttribute('search_bbox')
temp_manager.setFileAttribute('data_bbox', bbox)
temp_manager.deleteFileAttribute('search_bbox')
temp_manager.close()

예제 #8
0
 def getTargetDateSpan(self, year_or_start_date, variety=None):
     return FrostGridFactory.getTargetDateSpan(self, year_or_start_date,
                                               'grape', variety)