<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: need to clear scratch memory cache in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/need-to-clear-scratch-memory-cache/m-p/306929#M23874</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't have a specific solution to your problem as specific code but I have a general suggestion for working with NetCDF.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Having said that I have made similar code for NetCDF data but have taken a different approach structurally with my code and have not run into any problems.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Essentially I have split this code into three sections that are tied together with my main function but can be run consecutively as seperate functions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Firstly I extract the data to individual rasters.&amp;nbsp; Then there is a bit of metadata stuff that I retrieve from external sources.&amp;nbsp; Then I add the info to a mosaic dataset.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you split your code into parts as opposed to dealing with it in nested loops I think you are less likely to run into memory problems.&amp;nbsp; I also find code like this easier to debug but that is just personal preference.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 06 Feb 2012 02:07:44 GMT</pubDate>
    <dc:creator>HenryColgate</dc:creator>
    <dc:date>2012-02-06T02:07:44Z</dc:date>
    <item>
      <title>need to clear scratch memory cache</title>
      <link>https://community.esri.com/t5/python-questions/need-to-clear-scratch-memory-cache/m-p/306928#M23873</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have looked at several posts here and on other sites but have not found a solution to the problem I am having with this python script. In this script I use 2 nested 'for' loops to extract a series of variables by month (month = 0 - 11) from 5 netcdf files and then mosaic together each extracted variable. The script runs but after processing about 3 variables, I get the following error statement:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: ERROR 999999: Error executing function. Failed to copy raster dataset Failed to execute (MosaicToNewRaster).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My suspicion is that the cache memory has been exceeded. I tried using arcpy.Delete_management(SCRATCH) but then received the error that the scratch space no longer existed after only one variable was processed. Maybe I am putting that statement in the wrong place? Any other suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
# Import arcpy module
import arcpy
import os

# Set Geoprocessing environments
arcpy.env.scratchWorkspace = "C:\\WORKSPACE\\Process_4"
SCRATCH = arcpy.env.scratchWorkspace


# Script arguments
ENA = arcpy.GetParameterAsText(0)
if ENA == '#' or not ENA:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ENA = "F:\\GISdata\\Projects\\USGSClimateChange\\climateproj\\srf_ena_eh5_2030-2034_avg_trim_v4.nc" # provide a default value if unspecified

NRM = arcpy.GetParameterAsText(1)
if NRM == '#' or not NRM:
&amp;nbsp;&amp;nbsp;&amp;nbsp; NRM = "F:\\GISdata\\Projects\\USGSClimateChange\\climateproj\\srf_nrm_eh5_2030-2034_avg_trim_v4.nc" # provide a default value if unspecified

PNW = arcpy.GetParameterAsText(2)
if PNW == '#' or not PNW:
&amp;nbsp;&amp;nbsp;&amp;nbsp; PNW = "F:\\GISdata\\Projects\\USGSClimateChange\\climateproj\\srf_pnw_eh5_2030-2034_avg_trim_v4.nc" # provide a default value if unspecified

PSW = arcpy.GetParameterAsText(3)
if PSW == '#' or not PSW:
&amp;nbsp;&amp;nbsp;&amp;nbsp; PSW = "F:\\GISdata\\Projects\\USGSClimateChange\\climateproj\\srf_psw_eh5_2030-2034_avg_trim_v4.nc" # provide a default value if unspecified

SRM = arcpy.GetParameterAsText(4)
if SRM == '#' or not SRM:
&amp;nbsp;&amp;nbsp;&amp;nbsp; SRM = "F:\\GISdata\\Projects\\USGSClimateChange\\climateproj\\srf_srm_eh5_2030-2034_avg_trim_v4.nc" # provide a default value if unspecified


Output_Location = arcpy.GetParameterAsText(5)
if Output_Location == '#' or not Output_Location:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Output_Location = "F:\\GISdata\\Projects\\USGSClimateChange\\climateproj\\summary\\" # provide a default value if unspecified
 

#Variable list
for variable in ['T33', 'TA', 'TAMAX', 'TAMIN', 'TOTRNF', 'ET', 'RT','RNFS']:
&amp;nbsp;&amp;nbsp;&amp;nbsp; 

#&amp;nbsp;&amp;nbsp;&amp;nbsp; SCRATCH = arcpy.env.scratchWorkspace&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I attempted to place SCRATCH within the loop thinking that it would be recreated.&amp;nbsp; Nope.

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Month Iteration
&amp;nbsp;&amp;nbsp;&amp;nbsp; for month in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENA_Layer = SCRATCH +"\\ENA"+variable+str(month)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NRM_Layer = SCRATCH +"\\NRM"+variable+str(month)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PNW_Layer = SCRATCH +"\\PNW"+variable+str(month)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PSW_Layer = SCRATCH +"\\PSW"+variable+str(month)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SRM_Layer = SCRATCH +"\\SRM"+variable+str(month)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Make NetCDF Raster Layer (169)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeNetCDFRasterLayer_md(ENA, variable, "x", "y", ENA_Layer, "", "time "+ str(month), "BY_INDEX")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Make NetCDF Raster Layer (157)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeNetCDFRasterLayer_md(NRM, variable, "x", "y", NRM_Layer, "", "time "+ str(month), "BY_INDEX")

&amp;nbsp; # Process: Make NetCDF Raster Layer (145)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeNetCDFRasterLayer_md(PNW, variable, "x", "y", PNW_Layer, "", "time "+ str(month), "BY_INDEX")

&amp;nbsp; # Process: Make NetCDF Raster Layer (133)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeNetCDFRasterLayer_md(PSW, variable, "x", "y", PSW_Layer, "", "time "+ str(month), "BY_INDEX") 

&amp;nbsp; # Process: Make NetCDF Raster Layer (121)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeNetCDFRasterLayer_md(SRM, variable, "x", "y", SRM_Layer, "", "time "+ str(month), "BY_INDEX")&amp;nbsp; 
&amp;nbsp; 
&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Mosaic To New Raster (25)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MosaicToNewRaster_management("\"" + ENA_Layer +";"+ NRM_Layer +";"+ PNW_Layer +";"+ PSW_Layer +";"+ SRM_Layer +"\"", Output_Location, variable+"_"+str(month)+"2032", "PROJCS['WGS_1984_Lambert_Conformal_Conic',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-102.3000030517578],PARAMETER['standard_parallel_1',30.0],PARAMETER['standard_parallel_2',60.0],PARAMETER['latitude_of_origin',52.0],UNIT['Kilometer',1000.0]]", "", "1", "1", "MEAN", "FIRST")

&amp;nbsp;&amp;nbsp; arcpy.Delete_management(SCRATCH)
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Feb 2012 13:31:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-to-clear-scratch-memory-cache/m-p/306928#M23873</guid>
      <dc:creator>JoannaWhittier</dc:creator>
      <dc:date>2012-02-02T13:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: need to clear scratch memory cache</title>
      <link>https://community.esri.com/t5/python-questions/need-to-clear-scratch-memory-cache/m-p/306929#M23874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't have a specific solution to your problem as specific code but I have a general suggestion for working with NetCDF.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Having said that I have made similar code for NetCDF data but have taken a different approach structurally with my code and have not run into any problems.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Essentially I have split this code into three sections that are tied together with my main function but can be run consecutively as seperate functions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Firstly I extract the data to individual rasters.&amp;nbsp; Then there is a bit of metadata stuff that I retrieve from external sources.&amp;nbsp; Then I add the info to a mosaic dataset.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you split your code into parts as opposed to dealing with it in nested loops I think you are less likely to run into memory problems.&amp;nbsp; I also find code like this easier to debug but that is just personal preference.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 02:07:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-to-clear-scratch-memory-cache/m-p/306929#M23874</guid>
      <dc:creator>HenryColgate</dc:creator>
      <dc:date>2012-02-06T02:07:44Z</dc:date>
    </item>
  </channel>
</rss>

