Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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")"outa.tif")

sd = CellStatistics(relevant_tifnames_year_i, "STD", "DATA")"outb.tif")

Atest= CellStatistics([mean,sd], "MEAN", "DATA")"outc.tif")

Traceback (most recent call last):
  File "<pyshell#81>", line 1, in <module>"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
    #calc mean of annual means for the decade
    Amean=CellStatistics(decadal_holder_Amn, "MEAN", "DATA")"outd.tif")
share|improve this question
It's not the answer, but I guess"outa.tif") is not what you want: >>> str(arcpy.env.workspace)+"outa.tif"' results in: 'G:\\Faculty\\Mann\\Historic_BCM\\Aggregated1080outa.tif'. It should be str(arcpy.env.workspace) + "\\" + "outa.tif"' or `str(arcpy.env.workspace) + os.sep + "outa.tif"' – Saleika Apr 23 '13 at 5:57
What's your arcpy.env.scratchFolder? Is it: G:\Faculty\Mann\Historic_BCM\Aggregated1080\Scratch? And does the specified scratch folder exists in your file System? – Saleika Apr 23 '13 at 6:22
In the comment above I ment the arcpy.env.scratchWorkspace and not the arcpy.env.scratchFolder – Saleika Apr 23 '13 at 6:36
yep sorry typo on the '\\' – mmann1123 Apr 23 '13 at 14:34
I have tried using a scratch workspace without any success, same problem – mmann1123 Apr 23 '13 at 14:36
up vote 3 down vote accepted

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"
share|improve this answer

You should do this (best practice with rasters to avoid unnecessary copying):

env.workspace = env.scratchWorkspace = "G:\\Faculty\\Mann\\Historic_BCM\\Aggregated1080\\"

then you can run"outa.tif")

and it will save to that folder. No need to specify the full path, which may be part of your issue.

share|improve this answer

Probably a little late, but my solution to this problem was saving the result in a different folder than the inputs. A temporary file is created in the work folder with a default name, which is erased after the process is finished, but it generates problems when the output is created.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.