Index: wflow-py/wflow/pcrglobwb/virtualOS.py =================================================================== diff -u -reb7893184fde21791181658e3d28cbc3de067728 -r1738c121cfc83b76d915b8ed55747cb1bb9a2f64 --- wflow-py/wflow/pcrglobwb/virtualOS.py (.../virtualOS.py) (revision eb7893184fde21791181658e3d28cbc3de067728) +++ wflow-py/wflow/pcrglobwb/virtualOS.py (.../virtualOS.py) (revision 1738c121cfc83b76d915b8ed55747cb1bb9a2f64) @@ -71,7 +71,7 @@ logger.debug('Check whether the variable: '+str(varName)+' is defined in the file: '+str(ncFile)) - if ncFile in filecache.keys(): + if ncFile in list(filecache.keys()): f = filecache[ncFile] #~ print "Cached: ", ncFile else: @@ -81,7 +81,7 @@ varName = str(varName) - return varName in f.variables.keys() + return varName in list(f.variables.keys()) def netcdf2PCRobjCloneWithoutTime(ncFile, varName, @@ -100,7 +100,7 @@ # Only works if cells are 'square'. # Only works if cellsizeClone <= cellsizeInput # Get netCDF file and variable name: - if ncFile in filecache.keys(): + if ncFile in list(filecache.keys()): f = filecache[ncFile] #~ print "Cached: ", ncFile else: @@ -200,7 +200,7 @@ logger.debug('reading variable: '+str(varName)+' from the file: '+str(ncFile)) - if ncFile in filecache.keys(): + if ncFile in list(filecache.keys()): f = filecache[ncFile] #~ print "Cached: ", ncFile else: @@ -427,7 +427,7 @@ logger.debug('reading variable: '+str(varName)+' from the file: '+str(ncFile)) - if ncFile in filecache.keys(): + if ncFile in list(filecache.keys()): f = filecache[ncFile] #~ print "Cached: ", ncFile else: @@ -1068,7 +1068,7 @@ cOut,err = subprocess.Popen(str('mapattr -p %s ' %(cloneMap)), stdout=subprocess.PIPE,stderr=open(os.devnull),shell=True).communicate() if err !=None or cOut == []: - print "Something wrong with mattattr in virtualOS, maybe clone Map does not exist ? " + print("Something wrong with mattattr in virtualOS, maybe clone Map does not exist ? ") sys.exit() cellsize = float(cOut.split()[7]) if arcDegree == True: cellsize = round(cellsize * 360000.)/360000. @@ -1086,7 +1086,7 @@ cOut,err = subprocess.Popen(str('mapattr -p %s ' %(cloneMap)), stdout=subprocess.PIPE,stderr=open(os.devnull),shell=True).communicate() #print cOut if err !=None or cOut == []: - print "Something wrong with mattattr in virtualOS, maybe clone Map does not exist ? " + print("Something wrong with mattattr in virtualOS, maybe clone Map does not exist ? ") sys.exit() #print cOut.split() co = None; err = None @@ -1209,7 +1209,7 @@ nrRows= coordinates.shape[0] x= np.ones((nrRows))* MV tmpIDArray= pcr.pcr2numpy(pcrX,MV) - for iCnt in xrange(nrRows): + for iCnt in range(nrRows): row,col= coordinates[iCnt,:] if row != MV and col != MV: x[iCnt]= tmpIDArray[row,col] @@ -1224,7 +1224,7 @@ #print tempIDArray temporary= tempIDArray nrRows= coord.shape[0] - for iCnt in xrange(nrRows): + for iCnt in range(nrRows): row,col= coord[iCnt,:] if row != MV and col != MV: tempIDArray[row,col]= (x[iCnt]) @@ -1364,7 +1364,7 @@ # if abs(a) > 1e-5 or abs(b) > 1e-5: # if abs(a) > 1e-4 or abs(b) > 1e-4: if abs(a) > threshold or abs(b) > threshold: - print "WBError %s Min %f Max %f Mean %f" %(processName,a,b,c) + print("WBError %s Min %f Max %f Mean %f" %(processName,a,b,c)) # if abs(inflow + deltaS - outflow) > 1e-5: # print "Water balance Error for %s on %s: in = %f\tout=%f\tdeltaS=%f\tBalance=%f" \ # %(processName,dateStr,inflow,outflow,deltaS,inflow + deltaS - outflow) @@ -1464,7 +1464,7 @@ remainingcellVolDemand, zoneVolDemand, smallNumber) * zoneAbstraction # water balance check - if debug_water_balance and not isinstance(zone_area,types.NoneType): + if debug_water_balance and not isinstance(zone_area,type(None)): waterBalanceCheck([pcr.cover(pcr.areatotal(cellAbstraction, allocation_zones)/zone_area, 0.0)],\ [pcr.cover(pcr.areatotal(cellAllocation , allocation_zones)/zone_area, 0.0)],\ [pcr.scalar(0.0)],\ @@ -1489,7 +1489,7 @@ sumCellAllocation += cell_allocat_for_every_power_number[str(power_number)] # water balance check - if debug_water_balance and not isinstance(zone_area,types.NoneType): + if debug_water_balance and not isinstance(zone_area,type(None)): waterBalanceCheck([pcr.cover(pcr.areatotal(sumCellAbstraction, allocation_zones)/zone_area, 0.0)],\ [pcr.cover(pcr.areatotal(sumCellAllocation , allocation_zones)/zone_area, 0.0)],\ [pcr.scalar(0.0)],\ @@ -1512,7 +1512,7 @@ # demand volume in each cell (unit: m3) cellVolDemand = pcr.max(0.0, water_demand_volume) - if not isinstance(landmask, types.NoneType): + if not isinstance(landmask, type(None)): cellVolDemand = pcr.ifthen(landmask, pcr.cover(cellVolDemand, 0.0)) if ignore_small_values: # ignore small values to avoid runding error cellVolDemand = pcr.rounddown(pcr.max(0.0, water_demand_volume)) @@ -1524,7 +1524,7 @@ # total available water volume in each cell cellAvlWater = pcr.max(0.0, available_water_volume) - if not isinstance(landmask, types.NoneType): + if not isinstance(landmask, type(None)): cellAvlWater = pcr.ifthen(landmask, pcr.cover(cellAvlWater, 0.0)) if ignore_small_values: # ignore small values to avoid runding error cellAvlWater = pcr.rounddown(pcr.max(0.00, available_water_volume)) @@ -1533,7 +1533,7 @@ # total available water volume in each zone/segment (unit: m3) # - to minimize numerical errors, separating cellAvlWater - if not isinstance(high_volume_treshold,types.NoneType): + if not isinstance(high_volume_treshold,type(None)): # mask: 0 for small volumes ; 1 for large volumes (e.g. in lakes and reservoirs) mask = pcr.cover(\ pcr.ifthen(cellAvlWater > high_volume_treshold, pcr.boolean(1)), pcr.boolean(0)) @@ -1555,7 +1555,7 @@ if ignore_small_values: # ignore small values to avoid runding error cellAbstraction = pcr.rounddown(pcr.max(0.00, cellAbstraction)) # to minimize numerical errors, separating cellAbstraction - if not isinstance(high_volume_treshold,types.NoneType): + if not isinstance(high_volume_treshold,type(None)): # mask: 0 for small volumes ; 1 for large volumes (e.g. in lakes and reservoirs) mask = pcr.cover(\ pcr.ifthen(cellAbstraction > high_volume_treshold, pcr.boolean(1)), pcr.boolean(0)) @@ -1590,7 +1590,7 @@ pcr.areatotal(remainingCellDemand, allocation_zones), smallNumber) - if debug_water_balance and not isinstance(zone_area,types.NoneType): + if debug_water_balance and not isinstance(zone_area,type(None)): waterBalanceCheck([pcr.cover(pcr.areatotal(cellAbstraction, allocation_zones)/zone_area, 0.0)],\ [pcr.cover(pcr.areatotal(cellAllocation , allocation_zones)/zone_area, 0.0)],\ @@ -1605,7 +1605,7 @@ def findLastYearInNCFile(ncFile): # open a netcdf file: - if ncFile in filecache.keys(): + if ncFile in list(filecache.keys()): f = filecache[ncFile] else: f = nc.Dataset(ncFile)