def mapFilename(date, variety, model_name, map_group, map_type, lo_gdd_th=None, hi_gdd_th=None, test_path=False): params = { 'model': nameToFilepath(model_name), } if isinstance(date, basestring): params['date_str'] = date else: params['date_str'] = asAcisQueryDate(date) if variety is not None: template = fromConfig('crops.apple.filenames.maps.variety') params['variety'] = nameToFilepath(varietyName(variety)) else: template = fromConfig('crops.apple.filenames.maps.%s' % map_group) if map_type == 'gdd': params['map_type'] = 'GDD' else: params['map_type'] = nameToFilepath(map_type) if lo_gdd_th is not None: params['thresholds'] = gddThresholdName(lo_gdd_th, hi_gdd_th) return template % params
def animationFilename(target_year, variety, model_name, map_group, map_type, lo_gdd_th=None, hi_gdd_th=None, test_path=False): params = { 'model': nameToFilepath(model_name), } if isinstance(target_year, basestring): params['date_str'] = target_year else: params['date_str'] = str(target_year) if variety is not None: template = fromConfig('crops.apple.filenames.animation.variety') params['variety'] = nameToFilepath(varietyName(variety)) else: template = fromConfig('crops.apple.filenames.animation.%s' % map_group) if map_type == 'gdd': params['map_type'] = 'GDD' else: params['map_type'] = nameToFilepath(map_type) return template % params
def animationFilename(target_year, variety, map_key, test_path=False): params = { } params['variety'] = nameToFilepath(variety.description) params['anim_key'] = nameToFilepath(map_key) if isinstance(target_year, basestring): params['year'] = target_year else: params['year'] = str(target_year) template = fromConfig('crops.grape.filenames.anim.variety') return template % params
def webGraphicFilename(date, variety, graphic_key, ext, parse_keywords=True): params = { 'variety': nameToFilepath(variety.description), 'ext': ext } if isinstance(date, basestring): params['date_str'] = date else: params['date_str'] = asAcisQueryDate(date) template = fromConfig('crops.grape.filenames.web_graphic.variety') if parse_keywords: params['keywords'] = nameToFilepath(graphic_key) else: params['keywords'] = graphic_key return template % params
def mapFilename(date, variety, map_key, map_type=None, test_path=False): params = { 'variety' : nameToFilepath(variety.description), } if isinstance(date, basestring): params['date_str'] = date else: params['date_str'] = asAcisQueryDate(date) if map_type is None and '.' in map_key: map_group, map_type = map_key.split('.') else: map_group = map_key if map_type == 'gdd': params['map_key'] = '%s-GDD' % nameToFilepath(map_group) else: params['map_key'] = '%s-%s' % ( nameToFilepath(map_group), nameToFilepath(map_type) ) template = fromConfig('crops.grape.filenames.maps.variety') return template % params
def webMapFilename(date, variety, model_name, map_group, map_type, config_key='web_maps'): params = { 'model': nameToFilepath(model_name), } if isinstance(date, basestring): params['date_str'] = date else: params['date_str'] = asAcisQueryDate(date) if variety is not None: template = fromConfig('crops.apple.filenames.%s.variety' % config_key) params['variety'] = nameToFilepath(varietyName(variety)) else: template = \ fromConfig('crops.apple.filenames.%s.%s' % (config_key, map_group)) params['map_type'] = nameToFilepath(map_type) return template % params
end_date = datetime(year, month, day) else: errmsg = 'Invalid number of date arguments (%d).' % date_args raise ValueError, errmsg target_year = factory.getTargetYear(start_date) 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 visualizer = factory.getVarietyVisualizer(target_year, variety, test_file) date = start_date while date < past_date: path = visualizer.drawHardinessMap(date, verbose) date += ONE_DAY print 'map saved to :', path sys.stdout.flush() if animate: print 'creating animation' png_path = '*Hardiness-Map.png' template = '%d-Frost-Grape-%s-Hardiness-Map-animation.gif' anim_filename = template % (target_year, nameToFilepath(variety.name)) anim_path = os.path.join(map_dirpath, anim_filename) os.chdir(map_dirpath) os.system('convert -delay %d %s -loop 0 %s' % (delay, png_path, anim_path)) print 'animation complete', anim_path
if args[2] == 'chill': map_group = 'chill' map_type = 'accumulated' else: map_group, map_type = args[2].split('.') # generate a set of parameters for each plot plots = [ ] for model_name in model_names: plots.append( (None, model_name, map_group, map_type) ) for variety, model_name, map_group, map_type in plots: if debug: print '\nanimating', variety, model_name, map_group, map_type map_filepath = \ mapFilename('date', variety, model_name, map_group, map_type) if map_type == 'gdd': plot_key = 'GDD' else: plot_key = nameToFilepath(map_type) png_path = '*%s' % map_filepath[map_filepath.find(plot_key):] anim_filepath = \ animationFilepath(target_year, variety, model_name, map_group, map_type) working_dir = \ mapWorkingDir(target_year, variety, model_name, map_group, map_type) os.chdir(working_dir) _cmd_ = _cmd_tmpl_ % (png_path, anim_filepath) if debug: print _cmd_ os.system(_cmd_)
def varietyFilepath(target_year, variety, test_path=False): variety_dir = varietyWorkingDir(target_year, 'apple', variety, test_path) template = fromConfig('crops.apple.filenames.data.variety') filename = \ template % (int(target_year), nameToFilepath(varietyName(variety))) return os.path.join(variety_dir, filename)
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 = varietyWorkingDir(target_year, variety.name, test_file) map_dirpath = os.path.join(map_dirpath, model_1.name, 'chill.diff') filename_template = '%%s-Frost-Apple-%s-%s-%s-Chill-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 # get GDD map options map_options = fromConfig('crops.apple.chill.maps.options.accumulated.attrs') 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
if len(args) > 4: # end date specified year = int(args[4]) month = int(args[5]) day = int(args[6]) end_date = datetime(year, month, day) else: end_date = start_date else: start_date = datetime.now() - relativedelta(days=options.days_ago) end_date = start_date target_year = targetYearFromDate(start_date) if target_year is None: exit() log_filepath = options.log_filepath if log_filepath is None: log_filename = '%%s-apple-variety-%s-build.log' % nameToFilepath(variety) log_filepath = buildLogFilepath(target_year, 'apple', log_filename, os.getpid()) reporter = Reporter(PID, log_filepath) process_server = ProcessServer(reporter, variety, build_grids, draw_maps, debug, test_run) date = start_date while date <= end_date: # do not start new date after quit time if quit_time is None or datetime.now() < quit_time: process_server.run(date) else: reason = 'time limit exceeded' exit() date += ONE_DAY
test_path = options.test_path animate_cmd_path = fromConfig('animate_cmd_path') _cmd_tmpl_ = '%s -delay %d %%s -loop 0 %%s' % (animate_cmd_path, delay) # target year target_year = int(args[0]) # grape variety variety = getGrapeVariety(args[1]) # type of map to animate map_key = args[2] map_filepath = mapFilename('date', variety, map_key) anim_map_key = nameToFilepath(map_key) png_path = '*%s' % map_filepath[map_filepath.find(anim_map_key):] anim_filepath = animationFilepath(target_year, variety, map_key) working_dir = \ mapWorkingDir(target_year, variety, *map_key.split(',')) os.chdir(working_dir) _cmd_ = _cmd_tmpl_ % (png_path, anim_filepath) if debug: print _cmd_ os.system(_cmd_) print 'animation saved to :', anim_filepath
def varietyFilename(target_year, variety): template = fromConfig('crops.grape.filenames.data.variety') if isinstance(variety, basestring): return template % (int(target_year), nameToFilepath(variety)) else: return template % (int(target_year), nameToFilepath(variety.name))
def plotFilename(date, variety, plot_key, test_path=False): params = { 'variety' : nameToFilepath(variety.description), 'plot_key' : plot_key } if isinstance(date, basestring): params['date_str'] = date else: params['date_str'] = asAcisQueryDate(date) return fromConfig('crops.grape.filenames.plots.variety') % params