Select to view content in your preferred language

Some files from temp directory being deleted while others not when using arcpy

457
2
01-03-2024 10:47 AM
Labels (2)
gsilva
by
New Contributor

I am working in a Python notebook within ArcGIS Pro. I am clipping rasters to the extent of a shapefile, then averaging the resulting rasters into one. From there I am trying to use zonal statistics on a set of bands from that processed raster to average out the values in the raster per census tract (so that the raster has the same value across the entire tract).  Whenever I run the zonal statistics tool, it gives me an error saying the files don't exist. I've checked the directory (temp directory because I don't want a ton of layers being added to the map for management reasons) and the files are indeed not there, but I stored them in a list and I can access and show them from the list, so they are being stored, but I guess are being deleted immediately from the directory. What is weird to me is that if I do the same thing, but use the preprocessed, clipped rasters instead of the averaged one, the files are saved in the temp directory and the tool runs fine.

 

This works fine

 

clipped_rasters245 = []
for raster in rasters245:
    temp_clip = arcpy.ia.Clip(raster,aoi=r'C:\Users\guilh\Downloads\OneDrive_3_8-23-2023\SABR.shp')
    clipped_rasters245.append(temp_clip)

cur_band=clipped_rasters245[1].bands()[0]
new_raster245 = arcpy.sa.ZonalStatistics(tracts,'FIPS',cur_band,'MEAN')

 

 

While this does not work because the files (when calling the bands function) don't exist

 

mean_raster245= arcpy.ia.Mean(clipped_rasters245,extent_type='IntersectionOf',
              cellsize_type='MeanOf',
              ignore_nodata = True
)

cur_band= mean_raster245.bands()[0]
new_raster245 = arcpy.sa.ZonalStatistics(tracts,'FIPS',cur_band,'MEAN')

 

 

Tags (2)
0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

could be the use of one-drive

Problem: ArcGIS pro and Cloud Storage Services (esri.com)


... sort of retired...
0 Kudos
gsilva
by
New Contributor

The temp folder isn't on OneDrive, though. Either way, I also made a project on my local drive and ran the script on that project, and it is still giving me the same problem. But now everything is getting deleted/isn't being saved. When I look at the raster bands it gives me a path, ex:

 

C:\Users\guilh\AppData\Local\Temp\ArcGISProTemp19664\x59a0fb9b_bca3_43a2_86cd_d5cf7e273e28y0.afr\wc2.1_30s_bioc_UKESM1-0-LL_ssp245_2021-2040_1

 But there is no file named that in the temp folder, yet I can access the raster itself since I stored it in a list. 

0 Kudos