def CheckModelOutput(self,strncPathIn,strtxtForcePathIn): #1 run model fileset = formic.FileSet(include="**/*.nc", directory=strncPathIn) nFile = 0 # print process file ID # varTimeDataArray = None; for file_name in fileset: nFile+=1 print "################################################################" print "Current file is : " + file_name + "; It is the " + str(nFile) print "################################################################" #get date info if (varTimeDataArray is None): getNcFileDate = getSingleNcFileDate(file_name) varTimeDataArray = getNcFileDate.getNcFileDate("Times","Noah") ncFileProcess = NcFileProcess(file_name) alllayerMonthMean = ncFileProcess.getAllLayerMeanTempByMonth(5,varTimeDataArray) maxListValue = max(alllayerMonthMean[0]) if (maxListValue < 250) or (maxListValue > 310): InputFileDir,InputFile = os.path.split(file_name) filename, file_extension = os.path.splitext(InputFile) strFileFix = filename+".txt" srcfile = strtxtForcePathIn + strFileFix if not os.path.exists(srcfile): print "Error there have no " + srcfile os.system("pause") exit(0) dstdir = os.path.join("F:\\worktemp\\Permafrost(Change)\\Run(S)\\", strFileFix) shutil.copy(srcfile, dstdir)
def RunCalPermafrostChange(self,strncPathIn,strOutputTxtIn,startYear=1983,endYear=2012): #1 run model fileset = formic.FileSet(include="**/*.nc", directory=strncPathIn) nFile = 0 # print process file ID # varTimeDataArray = None; with open(strOutputTxtIn, "w") as text_file: for file_name in fileset: nFile+=1 print "################################################################" print "Current file is : " + file_name + "; It is the " + str(nFile) print "################################################################" InputFileDir,InputFile = os.path.split(file_name) filename, file_extension = os.path.splitext(InputFile) FileNameS = filename.split("_") calPermafrost = CalPermafrostProperties(file_name) #get date info if (varTimeDataArray is None): getNcFileDate = getSingleNcFileDate(file_name) varTimeDataArray = getNcFileDate.getNcFileDate("Times","Noah") text_file.write(FileNameS[0]+" " + FileNameS[1]) strTypeList = calPermafrost.IsPermafrostByYear(varTimeDataArray,startYear, endYear) text_file.write(" " + str(strTypeList)) text_file.write("\n") print "File : " + strOutputTxtIn + " write is ok !!!!!"
def RunStaPermafrostCount(self,strncPathIn,strOutputTxtIn,startYear=1983,endYear=2012): #1 run model fileset = formic.FileSet(include="**/*.nc", directory=strncPathIn) nFile = 0 # print process file ID # varTimeDataArray = None; countPermafrost = np.zeros(endYear-startYear) with open(strOutputTxtIn, "w") as text_file: for file_name in fileset: nFile+=1 print "################################################################" print "Current file is : " + file_name + "; It is the " + str(nFile) print "################################################################" InputFileDir,InputFile = os.path.split(file_name) filename, file_extension = os.path.splitext(InputFile) FileNameS = filename.split("_") calPermafrost = CalPermafrostProperties(file_name) #get date info if (varTimeDataArray is None): getNcFileDate = getSingleNcFileDate(file_name) varTimeDataArray = getNcFileDate.getNcFileDate("Times","Noah") #set array index index = 0 for year in range(startYear,endYear): nType = calPermafrost.StaPermafrostByYear(varTimeDataArray,year) countPermafrost[index]+=nType index =index+1 #write reslut index =0 for year in range(startYear,endYear): text_file.write(str(year) + " " + str(countPermafrost[index]) +"\n") index = index + 1 print "File : " + strOutputTxtIn + " write is ok !!!!!"
def RunCalPermafrostFeature(self,strPointShpPath,strNcFilePath,calType = "ALT"): db = dbf.Dbf(strPointShpPath) #Batch nPoint = len(db) # nFile = 0 # print process file ID # varTimeDataArray = None; for i in range(0,nPoint): nFile+=1 print "################################################################" print "Current file is the " + str(nFile) print "################################################################" #update 1 veg soil rec = db[i] Longitude = float(rec[0]) Latitude = float(rec[1]) calPermafrostFeature = 0 strFileFix = str(Longitude)+"_"+str(Latitude)+".nc" ncfilePath = strNcFilePath + strFileFix if not os.path.exists(ncfilePath): print "Error there have no " + file_name os.system("pause") exit(0) calPermafrost = CalPermafrostProperties(ncfilePath) #get date info if (varTimeDataArray is None): getNcFileDate = getSingleNcFileDate(ncfilePath) varTimeDataArray = getNcFileDate.getNcFileDate("Times","Noah") if calType == "ALT": calPermafrostFeature = calPermafrost.CalCalPermafrostALT(varTimeDataArray) rec[calType] = calPermafrostFeature elif calType == "ALTSEA": calPermafrostFeature = calPermafrost.CalCalPermafrostALTOfSeasonally(varTimeDataArray) rec[calType] = calPermafrostFeature elif calType == "MAGT": calPermafrostFeature = calPermafrost.CalCalPermafrostMAGT(varTimeDataArray) rec[calType] = calPermafrostFeature[0] rec["DAZZ"] = calPermafrostFeature[1] elif calType == "ICE": calPermafrostFeature = calPermafrost.CalCalPermafrostICE(varTimeDataArray) rec[calType] = calPermafrostFeature rec.store() #del rec db.close()
modelRes = ncFileProcess.getNcDataByDay(modelAttr,nlayer,varTimeDataArray,startTime,endTime) if (modelAttr == "STC"): modelRes = map(lambda x:x - 273.15,modelRes) if (modelAttr == "SH2O"): modelRes = map(lambda x:x*100,modelRes) return modelRes #Main code if __name__ == '__main__': # nc files ncFileProcess = NcFileProcess("D:\\worktemp\\Permafrost(NOAH)\\Data\\Run(S)\\TGLCH.nc") #get varTimeDataArray getNoahDateAll = getSingleNcFileDate("D:\\worktemp\\Permafrost(NOAH)\\Data\\Run(S)\\TGLCH.nc") varTimeDataArray = getNoahDateAll.getNcFileDate("Times","Noah") exctType = 1 # 1 temp 2 mos workbook = xlwt.Workbook() sheet = workbook.add_sheet('test') if exctType == 1: nLayerListSim = [2,3,5,8,12,15,18,22,23] if exctType == 2: nLayerListSim = [2,3,5,8,10] for i in range(0,len(nLayerListSim)): modelLayer = nLayerListSim[i] if exctType == 1: modelRes = getModelData(ncFileProcess,modelLayer,varTimeDataArray,"STC")
# start Time start = time.clock() results=[] # init infomation rep = 5000 nlayer = 10 #if else parameter soilType = 1 # type peType = "STC" #SH2O STC #optimal parameter type optParmType = 2 # optParmType =1 -> soil ptParmType =2 -> general #get varTimeDataArray getNoahDateAll = getSingleNcFileDate("F:\\worktemp\\Permafrost(Change)\\Run(S)\\OUTPUT(NEW).nc") varTimeDataArray = getNoahDateAll.getNcFileDate("Times","Noah") sampler = spotpy.algorithms.fast(spot_setup(nlayer,soilType,peType,optParmType,varTimeDataArray), dbname='GENPARM', dbformat='csv') #Create samplers for fast algorithm: sampler.sample(rep) results = sampler.getdata() end = time.clock() print "This is request: %f s" % (end - start)