I am trying to save output raster in out_ws folder path with name r001_EVI, r002_EVI so on... but output raster goes to the main folder (MODIS_SURFACE_RF2012) with such output name rEVI_001_EVI.
How to link it with desire location with output name e.g r001_EVI, r002_EVI so on.
env.workspace = 'D:\MODIS_SURFACE_RF2012\EVI'
out_ws = 'D:\MODIS_SURFACE_RF2012\EVI1'
rasters = arcpy.ListRasters()
rastersCount = len(rasters)
counter = 0
dek = 1
# compute dekad rasters
while counter < rastersCount:
dekad = []
for i in range(counter,(counter+4)):
print i
dekad.append(rasters[i])
outCellStatistics = CellStatistics(dekad, "MEAN", "NODATA")
outRasterName = out_ws + 'r{:03d}_EVI.tif'.format (dek)
#outRasterName = "00" + str(dek) + ".tif"
outCellStatistics.save(outRasterName)
counter += 4
dek += 1
Solved! Go to Solution.
>>> out_ws = "c:/rasters/"
>>> dek = 1
>>> outRasterName = out_ws + 'r{:03d}_EVI.tif'.format(dek)
>>> outRasterName
'c:/rasters/r001_EVI.tif'
just use forward slashes ... it is the easiest option and totally acceptable
>>> out_ws = "c:/rasters/"
>>> dek = 1
>>> outRasterName = out_ws + 'r{:03d}_EVI.tif'.format(dek)
>>> outRasterName
'c:/rasters/r001_EVI.tif'
just use forward slashes ... it is the easiest option and totally acceptable
Dan Patterson. Thank you very much. I have solved the issue as per your suggestion. i replaced it by forward slashes.
But why the actual copied path is not working? is there any reason
raw formatting or double backslashes or forward slashes...
r'D:\MODIS_SURFACE_RF2012\EVI1'
I am not worried about your actual path. The suggest is to formulate paths that are simple and reproduceable and document externally what is where and what the path is called.
This link covers some of the wrong ways to do things and the right way options
/blogs/dan_patterson/2016/08/14/filenames-and-file-paths-in-python