Example #1
0
    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

    date = start_date
    while date <= end_date:
        if verbose: print '\ndownloading', date
        manager.open('a')
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
start_date = target_start_date
end_date = start_date + days_per_loop

while start_date <= target_end_date:
Example #3
0
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
if not os.path.exists(os.path.normpath(filepath)):
    manager = factory.newTempGridManager(target_year, None, verbose,
                                         test_file)
else: manager = factory.getTempGridManager(target_year, 'r', test_file)
if debug:
    print 'temp manager', manager
    print 'temp manager file', manager.filepath

# download current ACIS mint,maxt for current date
acis_grid = manager.getDatasetAttribute('reported.maxt', 'acis_grid')
manager.close()
data = factory.getAcisGridData('mint,maxt', start_date, None, None, 
                                manager.data_bbox, int(acis_grid),
                                debug=debug)
if debug: print 'temp data\n', data

manager.open('a')
manager.updateTemp('reported.maxt', data['maxt'], start_date)