Index: wflow-py/Scripts/e2o-getfromwci.py =================================================================== diff -u -r58f139b2afc2424fc9f8796934878bd6e49c31de -r12ea40dc08628f654753679e0972e87b7bb12f7a --- wflow-py/Scripts/e2o-getfromwci.py (.../e2o-getfromwci.py) (revision 58f139b2afc2424fc9f8796934878bd6e49c31de) +++ wflow-py/Scripts/e2o-getfromwci.py (.../e2o-getfromwci.py) (revision 12ea40dc08628f654753679e0972e87b7bb12f7a) @@ -43,7 +43,7 @@ # Processing if verbose: - print('Writing to temporary file ' + fileName + '.tif') + print "Writing to temporary file " + fileName + ".tif" # Create Output filename from (FEWS) product name and date and open for writing TempDataset = driver1.Create( fileName + ".tif", data.shape[1], data.shape[0], 1, gdal.GDT_Float32 @@ -52,9 +52,9 @@ xul = x[0] - (x[1] - x[0]) / 2 yul = y[0] + (y[0] - y[1]) / 2 - print(xul) - print(yul) - TempDataset.SetGeoTransform( [ xul, x[1]-x[0], 0, yul, 0, y[1]-y[0] ] ) + print xul + print yul + TempDataset.SetGeoTransform([xul, x[1] - x[0], 0, yul, 0, y[1] - y[0]]) # get rasterband entry TempBand = TempDataset.GetRasterBand(1) # fill rasterband with array @@ -63,25 +63,24 @@ TempBand.SetNoDataValue(FillVal) # Create data to write to correct format (supported by 'CreateCopy') if verbose: - print('Writing to ' + fileName + '.map') + print "Writing to " + fileName + ".map" outDataset = driver2.CreateCopy(fileName, TempDataset, 0) TempDataset = None outDataset = None if verbose: - print('Removing temporary file ' + fileName + '.tif') - os.remove(fileName + '.tif'); + print "Removing temporary file " + fileName + ".tif" + os.remove(fileName + ".tif") if verbose: - print('Writing to ' + fileName + ' is done!') + print "Writing to " + fileName + " is done!" - tot = [] cnt = 0 for year in years: for mon in months: rainurl = baseurl % (year, year, mon) - print("processing: " + rainurl) + print "processing: " + rainurl # create a dataset object ncdataset = netCDF4.Dataset(rainurl) lat = ncdataset.variables["lat"][:] @@ -95,10 +94,10 @@ (latidx,) = logical_and(lat >= BB["lat"][0], lat < BB["lat"][1]).nonzero() (lonidx,) = logical_and(lon >= BB["lon"][0], lon < BB["lon"][1]).nonzero() - print(lonidx) - print(latidx) - print(lat[latidx]) - print(lon[lonidx]) + print lonidx + print latidx + print lat[latidx] + print lon[lonidx] # get rid of the non used lat/lon now lat = lat[latidx] lon = lon[lonidx] @@ -129,8 +128,8 @@ # mesh = pcolormesh(Lon,Lat,p_select.sum(axis=0)) # title("Cumulative precipitation") p_mean = p_select.mean(axis=1).mean(axis=1) - print(lon) - print(lat) + print lon + print lat ncdataset.close() if len(tot) == 0: @@ -143,10 +142,26 @@ cnt = cnt + 1 below_thousand = cnt % 1000 above_thousand = cnt / 1000 - mapname = str(mapstackname + '%0' + str(8-len(mapstackname)) + '.f.%03.f') % (above_thousand, below_thousand) - print("saving map: " + os.path.join(lowresout,mapname)) - writeMap(os.path.join(lowresout,mapname),"PCRaster",lon,lat[::-1],flipud(p_select[arcnt,:,:]),-999.0) + mapname = str( + mapstackname + "%0" + str(8 - len(mapstackname)) + ".f.%03.f" + ) % (above_thousand, below_thousand) + print "saving map: " + os.path.join(lowresout, mapname) + writeMap( + os.path.join(lowresout, mapname), + "PCRaster", + lon, + lat[::-1], + flipud(p_select[arcnt, :, :]), + -999.0, + ) arcnt = arcnt + 1 - execstr = "resample --clone " + clonemap + " " + os.path.join(lowresout,mapname) + " " + os.path.join(finalout,mapname) - print("resampling map: " + execstr) + execstr = ( + "resample --clone " + + clonemap + + " " + + os.path.join(lowresout, mapname) + + " " + + os.path.join(finalout, mapname) + ) + print "resampling map: " + execstr os.system(execstr)