<?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 Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149503#M63904</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've been pulling out my hair trying to find a solution to this enigma. &lt;STRONG&gt;Zonal Statistics as Table&lt;/STRONG&gt; takes less than two hours if I run it using the AG Pro 2.9.2 tool. If I copy the python code and run it in a 64-bit IDLE shell (3.7.11), it takes almost two days.&lt;/P&gt;&lt;P&gt;I've tested this on my workstation and three different virtual desktops. All are fairly well equipped Win10 environments with plenty of disk space, RAM, graphic card or graphic support, etc. There's plenty of available cpu- and gpu-resources during the process.&lt;/P&gt;&lt;P&gt;Here's the long and short of the situation:&lt;/P&gt;&lt;P&gt;1. The &lt;EM&gt;in_zone_data&lt;/EM&gt; is comprised of slightly more than 4000 polygons that have been converted to a raster with 10 m resolution and a unique ID. The raster has a defined coordinate system and is approximately 5000 X 5000 pixels, unsigned 16-bit;&lt;/P&gt;&lt;P&gt;2. The &lt;EM&gt;in_value_raster&lt;/EM&gt; is the result of two pre-processes. First, the red band is extracted from a RGB-image via Raster Functions (in AG Pro) or arcpy.ia.ExtractBand (in Python). Focal Statistics is then run on the red band via Raster Functions (in AG Pro) or arcpy.ia.FocalStatistics (in Python). The two processes are done almost instantaneously in both AG Pro and Python. The raster has a defined coordinate system, 0.16 m resolution, 625 000 X 625 000 pixels, unsigned 8-bit. In AG Pro, the raster layer source for the Focal Stats raster is on a separate drive (D:\Temp\ArcGISProTemp9836\);&lt;/P&gt;&lt;P&gt;3. &lt;STRONG&gt;Zonal Statistics as Table&lt;/STRONG&gt;. Running this tool in AG Pro on the Raster Layers takes about one hour and forty-five minutes. Running the same process (arcpy.ia.ZonalStatisticsAsTable) in Python takes days.&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. I've set up the environments so that they are identical (workspace, scratch, extent,&amp;nbsp; etc). The processing times are the same.&lt;/P&gt;&lt;P&gt;5. I've converted the &lt;EM&gt;in_zone_data&lt;/EM&gt;&amp;nbsp;to a raster layer via arcpy.management.MakeRasterLayer. The processing times are essentially the same.&lt;/P&gt;&lt;P&gt;Any explanation? Anyone experience something similar? This snippet is part of a larger program that iterates through tons of different areas so I really need to be able to run this via a script and not manually.&lt;/P&gt;&lt;P&gt;No, I cannot provide anyone with the input data but certainly all help appreciated.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2022 11:08:39 GMT</pubDate>
    <dc:creator>MichaelLedwith</dc:creator>
    <dc:date>2022-03-02T11:08:39Z</dc:date>
    <item>
      <title>Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149503#M63904</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've been pulling out my hair trying to find a solution to this enigma. &lt;STRONG&gt;Zonal Statistics as Table&lt;/STRONG&gt; takes less than two hours if I run it using the AG Pro 2.9.2 tool. If I copy the python code and run it in a 64-bit IDLE shell (3.7.11), it takes almost two days.&lt;/P&gt;&lt;P&gt;I've tested this on my workstation and three different virtual desktops. All are fairly well equipped Win10 environments with plenty of disk space, RAM, graphic card or graphic support, etc. There's plenty of available cpu- and gpu-resources during the process.&lt;/P&gt;&lt;P&gt;Here's the long and short of the situation:&lt;/P&gt;&lt;P&gt;1. The &lt;EM&gt;in_zone_data&lt;/EM&gt; is comprised of slightly more than 4000 polygons that have been converted to a raster with 10 m resolution and a unique ID. The raster has a defined coordinate system and is approximately 5000 X 5000 pixels, unsigned 16-bit;&lt;/P&gt;&lt;P&gt;2. The &lt;EM&gt;in_value_raster&lt;/EM&gt; is the result of two pre-processes. First, the red band is extracted from a RGB-image via Raster Functions (in AG Pro) or arcpy.ia.ExtractBand (in Python). Focal Statistics is then run on the red band via Raster Functions (in AG Pro) or arcpy.ia.FocalStatistics (in Python). The two processes are done almost instantaneously in both AG Pro and Python. The raster has a defined coordinate system, 0.16 m resolution, 625 000 X 625 000 pixels, unsigned 8-bit. In AG Pro, the raster layer source for the Focal Stats raster is on a separate drive (D:\Temp\ArcGISProTemp9836\);&lt;/P&gt;&lt;P&gt;3. &lt;STRONG&gt;Zonal Statistics as Table&lt;/STRONG&gt;. Running this tool in AG Pro on the Raster Layers takes about one hour and forty-five minutes. Running the same process (arcpy.ia.ZonalStatisticsAsTable) in Python takes days.&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. I've set up the environments so that they are identical (workspace, scratch, extent,&amp;nbsp; etc). The processing times are the same.&lt;/P&gt;&lt;P&gt;5. I've converted the &lt;EM&gt;in_zone_data&lt;/EM&gt;&amp;nbsp;to a raster layer via arcpy.management.MakeRasterLayer. The processing times are essentially the same.&lt;/P&gt;&lt;P&gt;Any explanation? Anyone experience something similar? This snippet is part of a larger program that iterates through tons of different areas so I really need to be able to run this via a script and not manually.&lt;/P&gt;&lt;P&gt;No, I cannot provide anyone with the input data but certainly all help appreciated.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 11:08:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149503#M63904</guid>
      <dc:creator>MichaelLedwith</dc:creator>
      <dc:date>2022-03-02T11:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149509#M63905</link>
      <description>&lt;P&gt;a listing of the script section would help&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 11:34:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149509#M63905</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-03-02T11:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149526#M63906</link>
      <description>&lt;P&gt;Well, the AG Pro "script" is:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcpy.ia.ZonalStatisticsAsTable("U2_LPIS_m10_10rast1", "BLOCKID", "Focal Statistics_Extract Bands", r"D:\Projekt\SJV_Blockkontroll2022_XXXXXXX_MILE\Arbete\Produktion\U2\ZonalStatistics\U2_zonalstats.gdb\U2_LPIS_m10_10rast1_textur", "DATA", "MEAN", "CURRENT_SLICE", 90, "AUTO_DETECT")&lt;/LI-CODE&gt;&lt;P&gt;That probably doesn't help you much.&lt;/P&gt;&lt;P&gt;The Python script (the last one of many, many that I've tried) is:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;from arcpy import CheckInExtension, CheckOutExtension
from arcpy.ia import ExtractBand, FocalStatistics, NbrRectangle, ZonalStatisticsAsTable
from datetime import datetime as dt
from os import path

print("Starting at {0}".format(dt.now()))

CheckOutExtension("ImageAnalyst")
proj_mapp = path.join(r"D:\Projekt", "SJV_Blockkontroll2022_XXXXXXX_MILE")
arb_dir = path.join(proj_mapp, "Arbete")
prod_dir = path.join(arb_dir, "Produktion")
mos_dir = path.join(prod_dir, "U2", "Mosaik")
mos_gdb = path.join(mos_dir, "U2_mosaic.gdb")
in_md = path.join(mos_gdb, "NIR_red_green_mosaic")
red_band = ExtractBand(in_md, [1])
textur = FocalStatistics(red_band, NbrRectangle(3, 3, "CELL"), "RANGE")
m10 = path.join(arb_dir, "Indata", "U2", "LPIS", "U2_LPIS.gdb", "U2_LPIS_m10_del1")
print("Starting Zonal Stats at {0}".format(dt.now()))
ZonalStatisticsAsTable(m10, "BLOCKID", textur, path.join(prod_dir, "U2", "ZonalStatistics", "U2_zonalstats.gdb", "U2_LPIS_m10_10rast1_textur_python"), "DATA", "MEAN", "CURRENT_SLICE", 90, "AUTO_DETECT")
CheckInExtension("ImageAnalyst")

print("Finished at {0}".format(dt.now()))&lt;/LI-CODE&gt;&lt;P&gt;Like I wrote, the script works without any errors and the process time up to running Zonal Statistics as Table can be counted in microseconds.&lt;/P&gt;&lt;P&gt;The reason for the excessive amount of path variables has to do with the main script, of which this little snippet is a part.&lt;/P&gt;&lt;P&gt;My problem is that it takes about 24 times as long to run it as a Python script than from within ArcGIS Pro.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 12:50:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149526#M63906</guid>
      <dc:creator>MichaelLedwith</dc:creator>
      <dc:date>2022-03-02T12:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149549#M63907</link>
      <description>&lt;P&gt;It's probably the 64-bit IDLE. Try running it in the 32 bit or another IDE, pointing to the python.exe located in the esri conda env.&lt;/P&gt;&lt;P&gt;C:\Users\&amp;lt;you&amp;gt;\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\python.exe&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 14:02:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149549#M63907</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-03-02T14:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149552#M63908</link>
      <description>&lt;P&gt;I'll try this, if simply out of curiosity, but I wonder if you could provide a reason as to why reducing the amount of available RAM from 32 GB (64-bit processor) to 4 GB (32-bit processor) would make such a huge difference in time of process.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;: Please inform me as to how I can run arcpy commands for python 3.7.11 in a 32-bit IDLE shell. The Desktop 32-bit IDLE shell doesn't work because I don't have Image Analyst available for Desktop (only Pro). The python.exe file (mentioned above) opens a 64-bit shell.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 14:40:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149552#M63908</guid>
      <dc:creator>MichaelLedwith</dc:creator>
      <dc:date>2022-03-02T14:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149556#M63909</link>
      <description>&lt;P&gt;&lt;EM&gt;By default, this tool will take advantage of multicore processors. The maximum number of cores that can be used is four.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;To use fewer cores, use the parallelProcessingFactor environment setting.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;You might want to check to see whether this applies if your python is external to the arcgis pro environment.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 14:25:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149556#M63909</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-03-02T14:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149560#M63910</link>
      <description>&lt;P&gt;&lt;EM&gt;Python 3.7.11 [MSC v.1927 64 bit (AMD64)]&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Type "copyright", "credits" or "license" for more information.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;IPython 7.21.0 -- An enhanced Interactive Python.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;As a side note, python in the Pro environment (no clone) is above and it is 64-bit.&amp;nbsp; ArcMap I suspect was different, but that was for python 2.7&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 14:31:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149560#M63910</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-03-02T14:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149580#M63911</link>
      <description>&lt;P&gt;I suppose that I haven't explained the situation clearly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I run ZonalStatisticsAsTable from within ArcGIS Pro using the tool. It takes about 1.5 hours.&lt;/P&gt;&lt;P&gt;I run ZonalStatisticsAsTable from IDLE (ArcGIS Pro, i.e. python 3.7.11 - 64-bit) using arcpy. It takes about 36 hours.&lt;/P&gt;&lt;P&gt;The computer, data sources, environmental settings are exactly the same for both. The only obvious difference is that the inputs are opened in the Table of Contents within ArcGIS Pro (presumably as raster layers).&lt;/P&gt;&lt;P&gt;In neither cases are the computer's resources being utilized excessively.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 14:54:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149580#M63911</guid>
      <dc:creator>MichaelLedwith</dc:creator>
      <dc:date>2022-03-02T14:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149612#M63912</link>
      <description>&lt;P&gt;And as I was suggesting, perhaps the parallel processing factor, which is supposed to be using 4 cores by default, is somehow getting ignored when run from a standalone script.&amp;nbsp; Set it in your script to be sure, next time&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 15:30:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149612#M63912</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-03-02T15:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149716#M63914</link>
      <description>&lt;P&gt;Agreeing with DanPatterson here. It's a likely possibility that a standalone script may not be applying the parallel processing factor. Here is a link to documentation with the scripting portion highlighted:&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/2.8/tool-reference/environment-settings/parallel-processing-factor.htm#:~:text=Scripting%20syntax,env.parallelProcessingFactor%20%3D%20%2250%25%22" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/2.8/tool-reference/environment-settings/parallel-processing-factor.htm#:~:text=Scripting%20syntax,env.parallelProcessingFactor%20%3D%20%2250%25%22&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 17:18:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149716#M63914</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-03-02T17:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149729#M63915</link>
      <description>&lt;P&gt;Well, I certainly want it to be understood that I do appreciate any and all help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been using ESRI products (starting with ArcInfo) since the late 80's so I do know a bit about things. What would be great would be an explanation that goes along with any suggestions. For example, why would running the process in a 32-bit IDLE shell speed up the time?&lt;/P&gt;&lt;P&gt;Now I don't know what the default parallel processing parameter is for Pro and I didn't change it when I ran the original process. The CPU on my workstation is a&amp;nbsp;Intel i7-6700K with four cores (it's also hyperthreaded, so that makes eight possible cores). I'll re-run the script with a parallel process value of 75% and see what happens. However, I still can't imagine that this parameter could have the effect of changing a process time from 36 hours to less than 2.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 17:55:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149729#M63915</guid>
      <dc:creator>MichaelLedwith</dc:creator>
      <dc:date>2022-03-02T17:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149941#M63925</link>
      <description>&lt;P&gt;This is very curious and I hope somebody from ESRI can explain it.&amp;nbsp; To answer your question there are some cases when memory is constrained that running in 32 bit mode can be more efficient due to the smaller pointer size (4 bytes vs&amp;nbsp; 8 bytes) - this results in smaller stack and heap sizes and less swapping to disk. But I'm quite sure that is not the problem here.&amp;nbsp; You could try to run the Python Profiler (cProfile) which will tell you which python functions are consuming the most time but this gives you no visibility into the underlying C code which is where I'd guess the real work is happening.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 21:57:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1149941#M63925</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-03-02T21:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150107#M63926</link>
      <description>&lt;P&gt;I increased the parallel processing to 75% and re-started the process at 18:42 last evening. It finished at 09:33 this morning. So that's about 15 hours. Definitely better than 36 hours but the improvement might have something to do with less activity on the server during the night.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;: I ran ZonalStatisticsAsTable again this morning in ArcGIS Pro with parallel processing set to 75% and the process time was 1:57:32 (slightly longer).&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 10:16:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150107#M63926</guid>
      <dc:creator>MichaelLedwith</dc:creator>
      <dc:date>2022-03-03T10:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150150#M63927</link>
      <description>&lt;P&gt;Looks like you got some good advice in other directions so my post may not be worth anything. The point of the post was to try other &lt;EM&gt;IDE&lt;/EM&gt;'s pointed to the env. &lt;EM&gt;Try running it in the 32 bit or another IDE.&lt;/EM&gt; Sorry for my mistake using '32 bit'. I was thinking of ArcMap's 2.7 arcpy but since you don't have the license, have Pro, and the 2.7 IDLE is still 64 I don't think it's worth pursuing.&lt;/P&gt;&lt;P&gt;A few times I've had gp tasks take more time in 3.x than they once did in 2.7, and I also experienced time variance between IDE's executing the same scripts. Not significant like 24 hours difference, but some instances were double digit minutes. Running from the shell... you may try executing the script from the command line. We have a dissolve process that will only fully dissolve the dataset and not leave any tiles if it is ran as a sub process from the command line in both 2.7 and 3.7. But the other advice given seems more plausible.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 13:29:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150150#M63927</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-03-03T13:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150303#M63931</link>
      <description>&lt;P&gt;Hi Michael, thank you for reporting this.&amp;nbsp;I am a Senior Product Engineer from the Spatial Analyst team, I have a few questions for you:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;What is the environment&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/environment-settings/cell-size.htm" target="_blank" rel="noopener"&gt;Cell size&lt;/A&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/environment-settings/parallel-processing-factor.htm" target="_blank" rel="noopener"&gt;&amp;nbsp;&lt;/A&gt;within Pro and the standalone Python environment?&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;I am assuming you are setting&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/environment-settings/parallel-processing-factor.htm" target="_blank" rel="noopener"&gt;Parallel processing factor&lt;/A&gt;&amp;nbsp;to 75% as you mentioned in your comment for both within Pro and Python. Are you setting it as a percentage or as a number of processors.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Have you&amp;nbsp;saved the output of Focal statistics before using it as input in Zonal Statistics tools in Pro? If so, what is the output format? And what is the cell size of this output?&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Are you setting the Output&amp;nbsp;Coordinate&amp;nbsp;System environment in either Pro or Python? If so, is it same as the value_raster or something else?&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Thu, 03 Mar 2022 19:02:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150303#M63931</guid>
      <dc:creator>SarmisthaChatterjee</dc:creator>
      <dc:date>2022-03-03T19:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150598#M63944</link>
      <description>&lt;P&gt;1. The cell size is unchanged, which means that it's 10m (Maximum if Inputs);&lt;/P&gt;&lt;P&gt;2. Percentage: (75%);&lt;/P&gt;&lt;P&gt;3, Saving the output from the Focal Statistics (in this case16 cm resolution, 625 000 X 625 000 pixels) takes hours and hours. The whole reason for using Raster Functions is to greatly increase the speed of the operation;&lt;/P&gt;&lt;P&gt;4. All the inputs have the same defined coordinate system (EPSG: 3006). No settings have been changed or given.&lt;/P&gt;&lt;P&gt;Honestly, I'm running the same exact commands. In ArcGIS Pro, the process goes fast, in Python 3.7.11 (IDLE, 64-bit), it goes amazingly slow.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 09:24:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150598#M63944</guid>
      <dc:creator>MichaelLedwith</dc:creator>
      <dc:date>2022-03-04T09:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150599#M63945</link>
      <description>&lt;P&gt;Update:&lt;/P&gt;&lt;P&gt;I converted a single polygon to raster (10m res, 55 X 66 pixels) and reran ZonalStatisticsAsTable. In ArcGIS Pro, it took two (2) seconds! In Python, the process took slightly less than 12 hours.&lt;/P&gt;&lt;P&gt;N.B.: it's only ZonalStatisticsAsTable that's giving me trouble. Other arcpy commands run at typical speeds in Python.&lt;/P&gt;&lt;P&gt;I've tested this in three different Virtual Desktop environments and on my workstation. The results are all similar. My next step is to completely remove all ESRI traces from one of the VD instances and re-install Pro.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 09:30:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150599#M63945</guid>
      <dc:creator>MichaelLedwith</dc:creator>
      <dc:date>2022-03-04T09:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150974#M63962</link>
      <description>&lt;P&gt;Thank you for your response.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Recommendations:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Based on your response and your script, I have the following recommendations:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Before executing Focal Statistics, specify&lt;OL&gt;&lt;LI&gt;arcpy.env.cellSize to your zone raster (10m)&lt;/LI&gt;&lt;LI&gt;arcpy.env.snapRaster to your value raster&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Before executing Zonal Statistics or Zonal Statistics as Table, you can save the output from Focal Statistics on disc, to check how much time it takes to create this raster dataset. You can also check the cell size to make sure that it is 10m (OPTIONAL).&lt;/LI&gt;&lt;LI&gt;You can specify the output from Focal Statistics as value raster to Zonal Statistics or Zonal Statistics as Table. At this point, the output from Focal Statistics, if not saved earlier will be saved at 10m cell size, which should take substantially less time.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;STRONG&gt;Comments:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I have also put together some comments below to explain my recommendations.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;1. Cell size:&lt;/STRONG&gt; It looks like you have not explicitly specified the environment cell size. The Zonal Statistics or Zonal Statistics as Table tool is executing with default cell size, which is Maximum of inputs. So, your Zonal Statistics output cell size is 10m. The Zonal Statistics as Table output is also calculated based on 10m cell size.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. Focal Statistics:&lt;/STRONG&gt; Since there is no analysis environment cell size specified, Focal Statistics is calculated with 0.16m cell size, resulting in a large raster. You are not immediately saving this large raster, and passing the output from Focal Statistics to Zonal Statistics or Zonal Statistics as Table. Since you are not saving the Focal Statistics output, it feels like Focal Statistics is executing quickly. In reality, Focal Statistics is returning a raster function, which stores the analytical model only, but not a raster dataset on disc.&lt;/P&gt;&lt;P&gt;If you are not interested in the Focal Statistics output as the final result, you can use this raster function output to another tool/raster function. However, depending on the nature of the subsequent operation, the raster function will be extended with additional analytical operation (function chain) or first a dataset will be created, and then used as input in the analytical tool.&lt;/P&gt;&lt;P&gt;Usually, the local and focal operations create function chain, where a raster dataset can be created by saving the final output at the end of the analysis, which makes the execution faster.&lt;/P&gt;&lt;P&gt;If a raster function or a function chain is used as input to zonal or global tools/raster functions, a dataset will first be created internally, before executing that in the tool. &amp;nbsp;In this case, the local/focal operation is not chained together with the zonal/global operation.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3. Zonal Statistics as Table:&lt;/STRONG&gt; You are specifying the output of Focal Statistics as input to Zonal Statistics or Zonal Statistics as Table. Due to the nature of the operation (zonal), the tool requires a raster dataset as value. So, it triggers the save internally, which is creating a large raster with 0.16m cell size. This raster is then internally resampled to a 10m value raster for performing the analysis with a 10m zone raster. All this extra work in Zonal Statistics as Table is probably taking the additional time, which can be avoided by specifying analysis cell size and snap raster before performing Focal Statistics.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is not very clear yet why the tool is executing faster in Pro compared to your standalone python script. I am hoping by specifying the cell size and snap raster explicitly, you will see a performance improvement. We can then take a closer look at your workflow in Pro to understand the source of the execution time difference.&lt;/P&gt;&lt;P&gt;Please let me know if this works with your dataset, and if you have additional questions.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sarmistha&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2022 04:02:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1150974#M63962</guid>
      <dc:creator>SarmisthaChatterjee</dc:creator>
      <dc:date>2022-03-05T04:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1151052#M63967</link>
      <description>&lt;P&gt;Thanks for the explanation Sarmistha (particularly about the internal save), it appears that setting env.cellSize&amp;nbsp; to 10m did the trick. Interestingly enough, setting the cellSize within EnvManager didn't work but setting the cellSize on a separate line cut the time down from 36 hours to less than two.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 10:12:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1151052#M63967</guid>
      <dc:creator>MichaelLedwith</dc:creator>
      <dc:date>2022-03-06T10:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: Zonal Statistics takes 1.5 hours  in AGPro, in Python the same code takes a few days</title>
      <link>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1503590#M71029</link>
      <description>&lt;P&gt;I was just up against this.&amp;nbsp; One thing that helped is to set the processing extent to the polygon you want to run.&amp;nbsp; Went from 5 hours to 17 seconds.&amp;nbsp; I also copied the one polygon out to its own FC and then ran on that and it went to 17 seconds also.&amp;nbsp; It seems to run the Entire raster if you just run it with a selection which is a bit weird.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 14:46:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonal-statistics-takes-1-5-hours-in-agpro-in/m-p/1503590#M71029</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2024-07-10T14:46:27Z</dc:date>
    </item>
  </channel>
</rss>

