Package firetools :: Module Static
[hide private]
[frames] | no frames]

Source Code for Module firetools.Static

 1  """Static Spatial Variable 
 2   
 3   
 4  """ 
 5  from GP_Util import *  
 6   
7 -def Import(study,varname,inraster):
8 """ Import a static spatial variable 9 A static spatial variable is one that is constant through the entire 10 study period. (ie elevation). Its value will be associated with 11 corresponding study points though all sample dates 12 13 Inputs 14 varname name of source data and output variable name 15 inraster raster containing source data """ 16 17 vardict = { 18 'type' : 'static', 19 'inraster' : inraster, 20 } 21 22 study.AddSource(varname,vardict)
23
24 -def Extract(study,varname):
25 log.info('Extract Static : '+varname.ljust(30)) 26 vardict = study.infodict[varname] 27 inraster = vardict['inraster'] 28 29 os.chdir(study.workingdir) 30 datadir = MakeFolder(os.path.abspath(varname)) 31 32 outraster = os.path.abspath(varname) 33 extraster = outraster+'_r' 34 asciifile = outraster+'.txt' 35 npyfile = outraster+'.npy' 36 37 ## Cut out only the cells within the study area 38 gp.ExtractByMask_sa(inraster, study.studyshp, extraster) 39 40 ## intersect (so to speak) with the study points / raster 41 gp.Resample_management(extraster, outraster, study.cellsize) 42 43 ##Convert to Text and Load to npy 44 gp.RasterToASCII_Conversion(outraster,asciifile) 45 data = num.loadtxt(asciifile,skiprows=6).flatten() 46 47 ## organize into (point,date) table format 48 ## where static var is one column vector repeated 49 ## for each study date 50 colvect = data.reshape((data.shape[0],1)) 51 dtable = colvect * num.ones((1,study.enddates.shape[0])) 52 53 ## Save and whatnot 54 num.save(npyfile,dtable) 55 vardict = {'name':varname, 'file':npyfile, 'list':[] } 56 study.AddSeries(vardict) 57 58 ## Cleanup temp files 59 os.remove(asciifile) 60 gp.delete(extraster)
61