I am having trouble saving outputs from CellStatistics but only when I run it on a list of rasters. This was working on python 26 but not 27.
I know this example is nonsense, but:
env.workspace = "G:\\Faculty\\Mann\\Historic_BCM\\Aggregated1080\\"
relevant_tifnames_year_i= ['cwd1975jan.tif', 'cwd1975feb.tif', 'cwd1975mar.tif', 'cwd1975apr.tif', 'cwd1975may.tif', 'cwd1975jun.tif', 'cwd1975jul.tif', 'cwd1975aug.tif', 'cwd1975sep.tif', 'cwd1975oct.tif', 'cwd1975nov.tif', 'cwd1975dec.tif']
mean = CellStatistics(relevant_tifnames_year_i, "MEAN", "DATA")
mean.save(str(env.workspace)+"outa.tif")
sd = CellStatistics(relevant_tifnames_year_i, "STD", "DATA")
sd.save(str(env.workspace)+"outb.tif")
Atest= CellStatistics([mean,sd], "MEAN", "DATA")
Atest.save(str(env.workspace)+"outc.tif")
Traceback (most recent call last):
File "", line 1, in
Atest.save(str(env.workspace)+"out3.tif")
RuntimeError: ERROR 010240: Could not save raster dataset to G:\Faculty\Mann\Historic_BCM\Aggregated1080\Scratch\meanc_ras3 with output format GRID.
Notice that I can save CellStats run on a list of files from my working directory, but not on a list made up of my intermediate inputs "sd" and "mean". I know that I can run it if I pass the file paths, but in my actual code I need to run it off of intermediate inputs. Am I missing something here?
Note: Overwrite = True has been set. There are no files with the same name in the output folder etc.
Here is the actual code (storing rasters to a list and then running CellStats)
for year in base_year:
# paths for files
relevant_tifnames_year = [v for v in relevant_tifnames if int(re.sub('[^0-9]','',v) or 0) >= year and int(re.sub('[^0-9]','',v) or 0) <= year+years_to_end ]
#list to store annual means
decadal_holder_Amn = []
# for each period of interest
for year_i in range(year, (year+years_to_end+1)):
# get relevant paths
relevant_tifnames_year_i = filter(lambda x: str(year_i) in x,relevant_tifnames_year)
#calc annual mean
mean = CellStatistics(relevant_tifnames_year_i, "MEAN", "DATA")
#append mean mean to list of annual means
decadal_holder_Amn.append(mean)
#calc mean of annual means for the decade
Amean=CellStatistics(decadal_holder_Amn, "MEAN", "DATA")
Amean.save(str(env.workspace)+"outd.tif")
Answer
Amazingly all my troubles have to do with the lack of gdb use. As soon as I assigned the scratchWorkspace to a .gdb my write errors started going away!
env.scratchWorkspace ="G:\\Faculty\\Mann\\Historic_BCM\\Aggregated1080\\Scratch.gdb"
No comments:
Post a Comment