def genBilGLUCInputs(): grasssetup.grassConfig() grass = grasssetup.grass grass.run_command('r.out.gdal', input='boundary', output='gluc/Data/boundary.bil', format='EHdr', type='Byte') grass.run_command('r.out.gdal', input='landcover', output='gluc/Data/landcover.bil', format='EHdr', type='Byte') grass.run_command('r.out.gdal', input='nogrowth', output='gluc/Data/nogrowth.bil', format='EHdr', type='Byte') grass.run_command('r.out.gdal', input='probmap_res', output='gluc/Data/growth_probmap_res.bil', format='EHdr', type='Float32') grass.run_command('r.out.gdal', input='probmap_com', output='gluc/Data/growth_probmap_com.bil', format='EHdr', type='Float32') #runlog.p('***use GLUC default pop_density') #runlog.p('***use GLUC default emp_density') if grass.find_file('pop_density', element='cell'): grass.run_command('r.out.gdal', input='pop_density', output='gluc/Data/pop_density.bil', format='EHdr',type='Float32') # needs to be Float32 runlog.p('***use uploaded pop_density in GLUC') else: runlog.p('***use GLUC default pop_density') if grass.find_file('emp_density', element='cell'): grass.run_command('r.out.gdal', input='emp_density', output='gluc/Data/emp_density.bil', format='EHdr', type='Float32') # needs to be Float32 runlog.p('***use uploaded emp_density in GLUC') else: runlog.p('***use GLUC default emp_density')
def genBilGLUCInputs(): grasssetup.grassConfig() grass = grasssetup.grass grass.run_command('r.out.gdal', input='boundary', output='gluc/Data/boundary.bil', format='EHdr', type='Byte') grass.run_command('r.out.gdal', input='landcover', output='gluc/Data/landcover.bil', format='EHdr', type='Byte') grass.run_command('r.out.gdal', input='nogrowth', output='gluc/Data/nogrowth.bil', format='EHdr', type='Byte') grass.run_command('r.out.gdal', input='probmap_res', output='gluc/Data/growth_probmap_res.bil', format='EHdr', type='Float32') grass.run_command('r.out.gdal', input='probmap_com', output='gluc/Data/growth_probmap_com.bil', format='EHdr', type='Float32') if grass.find_file('pop_density', element='cell'): grass.run_command('r.out.gdal', input='pop_density', output='gluc/Data/pop_density.bil', format='EHdr',type='Float32') # needs to be Float32 runlog.p('***use uploaded pop_density in GLUC') else: runlog.p('***use GLUC default pop_density') if grass.find_file('emp_density', element='cell'): grass.run_command('r.out.gdal', input='emp_density', output='gluc/Data/emp_density.bil', format='EHdr', type='Float32') # needs to be Float32 runlog.p('***use uploaded emp_density in GLUC') else: runlog.p('***use GLUC default emp_density')
def main(): # The system stdout and stderr will be in /leam/scratch/<scenarioname>/<scenarioname>.log jobstart = time.asctime() os.environ['PATH'] = ':'.join(['./bin', os.environ.get('BIN', '.'),'/bin', '/usr/bin']) configurl, user, password = parseFlags() print "Parsing configuration file.............\n" configfile = get_config(configurl, user, password) luc = LUC(configfile) print luc.growthmap[0] # luc has sorted luc.growthmap(drivers) in year and luc.growth(projections) print "Setting up GRASS environment.............\n" get_grassfolder(luc.scenario['grass_loc'], user, password) grasssetup.grassConfig() global grass grass = grasssetup.grass print "Connect to the LEAM storage server............." resultsdir = luc.scenario['results'] print resultsdir, '\n' title = luc.scenario['title'] global site, runlog # run.log will be stored in Log repository site = LEAMsite(resultsdir, user=user, passwd=password) #create runlog file site.createFolder("RunLog", resultsdir) runlog = RunLog(resultsdir+"/runlog", site, initmsg='Scenario ' + title) runlog.p('started at '+jobstart) # creat two folders site.createFolder("Details", resultsdir) site.createFolder("Results", resultsdir) global projectiontable projectiontable = ProjTable() growth = dict(deltapop=[0.0], deltaemp=[0.0]) if luc.growth: # note growthmap[0]...should change luc, using luc_new runlog.h('Processing Growth driver set.............') startyear, isprobmapcached = processDriverSets(luc.growthmap[0]) if not isprobmapcached: runlog.h('Building Probability Maps..............') runMulticostModel(resultsdir, site, runlog) cacheProbmaps(luc.growthmap[0]['url']) if luc.growthmap: runlog.h('Processing Growth Projection set........') demandstr = processProjectionSet(luc.growth[0]) genYearChangemap.executeGLUCModel(demandstr, title, runlog) runlog.h('Publishing all results..............') #wrap the simmap file to Results publishResults(title, site, resultsdir+"/results")
def main(): # The system stdout and stderr will be in /leam/scratch/<scenarioname>/<scenarioname>.log jobstart = time.asctime() os.environ['PATH'] = ':'.join( ['./bin', os.environ.get('BIN', '.'), '/bin', '/usr/bin']) configurl, user, password = parseFlags() print "Parsing configuration file.............\n" configfile = get_config(configurl, user, password) luc = LUC(configfile) print luc.growthmap[0] # luc has sorted luc.growthmap(drivers) in year and luc.growth(projections) print "Setting up GRASS environment.............\n" get_grassfolder(luc.scenario['grass_loc'], user, password) grasssetup.grassConfig() global grass grass = grasssetup.grass print "Connect to the LEAM storage server............." resultsdir = luc.scenario['results'] print resultsdir, '\n' title = luc.scenario['title'] global site, runlog # run.log will be stored in Log repository site = LEAMsite(resultsdir, user=user, passwd=password) #create runlog file site.createFolder("RunLog", resultsdir) runlog = RunLog(resultsdir + "/runlog", site, initmsg='Scenario ' + title) runlog.p('started at ' + jobstart) # creat two folders site.createFolder("Details", resultsdir) site.createFolder("Results", resultsdir) global projectiontable projectiontable = ProjTable() growth = dict(deltapop=[0.0], deltaemp=[0.0]) if luc.growth: # note growthmap[0]...should change luc, using luc_new runlog.h('Processing Growth driver set.............') startyear, isprobmapcached = processDriverSets(luc.growthmap[0]) if not isprobmapcached: runlog.h('Building Probability Maps..............') runMulticostModel(resultsdir, site, runlog) #open cache function temporarily cacheProbmaps(luc.growthmap[0]['url']) if luc.growthmap: runlog.h('Processing Growth Projection set........') demandstr = processProjectionSet(luc.growth[0]) genYearChangemap.executeGLUCModel(demandstr, title, runlog) runlog.h('Publishing all results..............') #wrap the simmap file to Results publishResults(title, site, resultsdir + "/results")
def writeConfig(confname='baseline.conf', start='2010', end='2040', prefix='', probmaps=False, tmpl='gluc/Config/baseline.tmpl', path='gluc/Config'): """ write a GLUC config file from a template. PREFIX,START_DATE, and END_DATE are replaced in the template. PREFIX is applied to probability maps name but the START_DATE is not. The GLUC model automatically appends the year during model execution. @confname - name of config file to be written (.conf appended if needed) @prefix - prefix applied to probmap names (growth, decline) @start - fills the START_DATE parameter in the template @end - fills the END_DATE parameter in the template @probmaps - toggle initial and final probmaps writing @tmpl - name of the temlate config file @path - destination for @Return - nothing # function copied from original startup.py """ # runlog.debug('writeConfig: confname=%s, prefix=%s, start=%s, end=%s' % \ # (confname, prefix, start, end)) # cleanup confname and add path grasssetup.grassConfig() grass = grasssetup.grass if not confname.endswith('.conf'): confname += '.conf' config = os.path.join(path, os.path.basename(confname)) # read the template file into string with open(tmpl, 'r') as f: template = f.read() d = dict(PREFIX=prefix, START_DATE=start, END_DATE=end) with open(config, 'w') as f: f.write(template.format(**d)) if probmaps: f.write('* INITIAL_PROB_RES_MAP M(M, 4, initial_probmap_res)\n') f.write('* INITIAL_PROB_COM_MAP M(M, 4, initial_probmap_com)\n') f.write('* FINAL_PROB_RES_MAP M(M, 4, final_probmap_res)\n') f.write('* FINAL_PROB_COM_MAP M(M, 4, final_probmap_com)\n') if grass.find_file('pop_density', element='cell'): f.write('* DENSITY_MAP_RES d(M, pop_density.bil)\n') if grass.find_file('emp_density', element='cell'): f.write('* DENSITY_MAP_COM d(M, emp_density.bil)\n')