def returnMapValue(self,pcrX,x): #-retrieves value from an array and update values in the map if self.nrEntries <> None: tempIDArray= pcr2numpy(pcrX,self.MV) for iCnt in xrange(self.nrEntries): row,col= self.coordinates[iCnt,:] tempIDArray[row,col]= x[iCnt] pcrX= numpy2pcr(pcr.Scalar,tempIDArray,self.MV) return pcrX
def returnMapValue(self, pcrX, x): #-retrieves value from an array and update values in the map if self.nrEntries <> None: tempIDArray = pcr2numpy(pcrX, self.MV) for iCnt in xrange(self.nrEntries): row, col = self.coordinates[iCnt, :] tempIDArray[row, col] = x[iCnt] pcrX = numpy2pcr(pcr.Scalar, tempIDArray, self.MV) return pcrX
def retrieveMapValue(self,pcrX): #-retrieves values from a map and returns an array conform the IDs stored in properties if self.nrEntries <> None: x= np.ones((self.nrEntries))*self.MV tmpIDArray= pcr2numpy(pcrX,self.MV) for iCnt in xrange(self.nrEntries): row,col= self.coordinates[iCnt,:] x[iCnt]= tmpIDArray[row,col] return x else: return np.zeros(self.ID.shape)
def retrieveMapValue(self, pcrX): #-retrieves values from a map and returns an array conform the IDs stored in properties if self.nrEntries <> None: x = np.ones((self.nrEntries)) * self.MV tmpIDArray = pcr2numpy(pcrX, self.MV) for iCnt in xrange(self.nrEntries): row, col = self.coordinates[iCnt, :] x[iCnt] = tmpIDArray[row, col] return x else: return np.zeros(self.ID.shape)
def __init__(self,distributionMap,outletMap,typeMap,channelBreadthMap,averageQMap,bankfulQMap,LDDMap,parameterTBL,deltaTime,clippedRead): #-clippedRead self.clippedRead= clippedRead #-constants self.deltaTime= deltaTime self.MV= -999.9 self.cLake= 1.7 self.minLimit= 0.0 #-spatial field of nominal IDs delineating the extent of the respective waterbodies self.distribution= self.clippedRead.get(distributionMap,'nominal') self.outlet= self.clippedRead.get(outletMap,'nominal') waterBodiesType= self.clippedRead.get(typeMap,'nominal') LDD= self.clippedRead.get(LDDMap,'ldd') endorheicLakes= pcr.ifthen((pcr.areatotal(pcr.scalar(self.outlet != 0),self.distribution) == 0) & (self.distribution != 0),\ self.distribution) self.location= pcr.cover(pcr.ifthen(self.outlet != 0,self.outlet),\ pcr.ifthenelse((self.distribution != 0) & (LDD == 5),self.distribution,0)) pcr.report(self.location,'maps/waterbodies_reportlocations.map') #-extract ID and location as row and column number for outlets; these are subsequently used to extract type from other maps tempIDArray= pcr2numpy(self.location,self.MV) nrRows,nrCols= tempIDArray.shape iCnt= 0 self.ID= np.ones((1))*self.MV self.coordinates= np.ones((2))*self.MV for row in xrange(nrRows): for col in xrange(nrCols): if tempIDArray[row,col] > 0: iCnt+= 1 if iCnt > 1: self.ID= np.append(self.ID,tempIDArray[row,col]) self.coordinates= np.vstack((self.coordinates,\ np.array([row,col]))) else: self.ID= np.array([tempIDArray[row,col]]) self.coordinates= np.array([row,col]) #-process valid entries if self.ID[0] <> self.MV: #-reset nrRows to nr of rowwise entries in ID self.nrEntries= self.ID.shape[0] #-sort on ID indices= self.ID.argsort() self.ID= self.ID[indices] self.coordinates= self.coordinates[indices] else: self.nrEntries= None self.coordinates= np.array([]) #-read from maps: type, channel breadth and average discharge self.type= self.retrieveMapValue(self.clippedRead.get(typeMap,'nominal')) self.channelWidth= self.retrieveMapValue(self.clippedRead.get(channelBreadthMap)) self.averageQ= self.retrieveMapValue(self.clippedRead.get(averageQMap)) self.bankfulQ= self.retrieveMapValue(self.clippedRead.get(bankfulQMap)) self.endorheic= self.retrieveMapValue(pcr.cover(endorheicLakes,0)) #-set to zero, to be updated in script self.demand= np.zeros((self.nrEntries)) self.actualStorage= np.zeros((self.nrEntries)) self.actualArea= np.zeros((self.nrEntries)) self.actualQ= np.zeros((self.nrEntries)) #-read from table self.capacity= np.ones((self.nrEntries))*self.MV self.maxLimit= np.ones((self.nrEntries))*self.MV self.avParameter= np.ones((self.nrEntries))*self.MV tempIDArray= np.loadtxt(parameterTBL) if self.nrEntries <> None: for iCnt in xrange(self.nrEntries): ID= self.ID[iCnt] mask= tempIDArray[:,0] == ID if np.any(mask): #-entry in table with reservoir properties #-set capacity, fractional maximum storage limit and area-volume parameter self.capacity[iCnt]= tempIDArray[:,1][mask] self.maxLimit[iCnt]= tempIDArray[:,2][mask] self.avParameter[iCnt]= tempIDArray[:,3][mask] else: #-lake or wetland: set capacity and upper limit to zero and the area-volume parameter # to default values self.capacity[iCnt]= 0. self.maxLimit[iCnt]= 0. if self.type[iCnt] == 1: #-lake self.avParameter[iCnt]= 210.5 else: #-wetland self.avParameter[iCnt]= 1407.2
def __init__(self, distributionMap, outletMap, typeMap, channelBreadthMap, averageQMap, bankfulQMap, LDDMap, parameterTBL, deltaTime, clippedRead): #-clippedRead self.clippedRead = clippedRead #-constants self.deltaTime = deltaTime self.MV = -999.9 self.cLake = 1.7 self.minLimit = 0.0 #-spatial field of nominal IDs delineating the extent of the respective waterbodies self.distribution = self.clippedRead.get(distributionMap, 'nominal') self.outlet = self.clippedRead.get(outletMap, 'nominal') waterBodiesType = self.clippedRead.get(typeMap, 'nominal') LDD = self.clippedRead.get(LDDMap, 'ldd') endorheicLakes= pcr.ifthen((pcr.areatotal(pcr.scalar(self.outlet != 0),self.distribution) == 0) & (self.distribution != 0),\ self.distribution) self.location= pcr.cover(pcr.ifthen(self.outlet != 0,self.outlet),\ pcr.ifthenelse((self.distribution != 0) & (LDD == 5),self.distribution,0)) pcr.report(self.location, 'maps/waterbodies_reportlocations.map') #-extract ID and location as row and column number for outlets; these are subsequently used to extract type from other maps tempIDArray = pcr2numpy(self.location, self.MV) nrRows, nrCols = tempIDArray.shape iCnt = 0 self.ID = np.ones((1)) * self.MV self.coordinates = np.ones((2)) * self.MV for row in xrange(nrRows): for col in xrange(nrCols): if tempIDArray[row, col] > 0: iCnt += 1 if iCnt > 1: self.ID = np.append(self.ID, tempIDArray[row, col]) self.coordinates= np.vstack((self.coordinates,\ np.array([row,col]))) else: self.ID = np.array([tempIDArray[row, col]]) self.coordinates = np.array([row, col]) #-process valid entries if self.ID[0] <> self.MV: #-reset nrRows to nr of rowwise entries in ID self.nrEntries = self.ID.shape[0] #-sort on ID indices = self.ID.argsort() self.ID = self.ID[indices] self.coordinates = self.coordinates[indices] else: self.nrEntries = None self.coordinates = np.array([]) #-read from maps: type, channel breadth and average discharge self.type = self.retrieveMapValue( self.clippedRead.get(typeMap, 'nominal')) self.channelWidth = self.retrieveMapValue( self.clippedRead.get(channelBreadthMap)) self.averageQ = self.retrieveMapValue( self.clippedRead.get(averageQMap)) self.bankfulQ = self.retrieveMapValue( self.clippedRead.get(bankfulQMap)) self.endorheic = self.retrieveMapValue(pcr.cover(endorheicLakes, 0)) #-set to zero, to be updated in script self.demand = np.zeros((self.nrEntries)) self.actualStorage = np.zeros((self.nrEntries)) self.actualArea = np.zeros((self.nrEntries)) self.actualQ = np.zeros((self.nrEntries)) #-read from table self.capacity = np.ones((self.nrEntries)) * self.MV self.maxLimit = np.ones((self.nrEntries)) * self.MV self.avParameter = np.ones((self.nrEntries)) * self.MV tempIDArray = np.loadtxt(parameterTBL) if self.nrEntries <> None: for iCnt in xrange(self.nrEntries): ID = self.ID[iCnt] mask = tempIDArray[:, 0] == ID if np.any(mask): #-entry in table with reservoir properties #-set capacity, fractional maximum storage limit and area-volume parameter self.capacity[iCnt] = tempIDArray[:, 1][mask] self.maxLimit[iCnt] = tempIDArray[:, 2][mask] self.avParameter[iCnt] = tempIDArray[:, 3][mask] else: #-lake or wetland: set capacity and upper limit to zero and the area-volume parameter # to default values self.capacity[iCnt] = 0. self.maxLimit[iCnt] = 0. if self.type[iCnt] == 1: #-lake self.avParameter[iCnt] = 210.5 else: #-wetland self.avParameter[iCnt] = 1407.2