<?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 Crashing pythonwin.exe when using Rescale By Function in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/crashing-pythonwin-exe-when-using-rescale-by/m-p/48206#M3818</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am attempting to use the Rescale By Function tool rescale my raster values using the "LARGE" transformation function, however instead of using the calculated value for the midpoint parameter, I would like to use the MEDIAN. In this code I convert the float raster to integer, get the median using zonal stats, convert the Result Object to long integer, and pass it into the Rescale By Function parameters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Local variables:
as_ppm = "C:\\Users\\nmoylan\\Documents\\Desktop Items\\Strategic Evaluations\\BC\\QUEST WEST\\Z9 Geochem and Grids\\as_ppm"
Constant_value = "1000"
process_mask = "C:\\Users\\nmoylan\\Documents\\Desktop Items\\Strategic Evaluations\\BC\\QUEST WEST\\Z9 Geochem and Grids\\process_mask"
as_ppb_int = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\as_ppb_int"
as_median = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\as_median"
as_ppb = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\as_ppb"
Final_Test = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\Final_Test"

# Process: Times
arcpy.gp.Times_sa(as_ppm, Constant_value, as_ppb)

# Process: Int - makes the MEDIAN option available in Zonal Stats
arcpy.gp.Int_sa(as_ppb, as_ppb_int)

# Process: Build Raster Attribute Table - Greater than 100000 values and 500 unique values
arcpy.BuildRasterAttributeTable_management(as_ppb_int, "Overwrite")

# Process: Zonal Statistics - to find the MEDIAN
arcpy.gp.ZonalStatistics_sa(process_mask, "VALUE", as_ppb_int, as_median, "MEDIAN", "DATA")

# Convert the Result Object from Zonal Stats to Long Integer Value
median_Result = long(arcpy.GetRasterProperties_management(as_median, "MEAN").getOutput(0))
print median_Result

# Process: Rescale by Function - rescale integer raster from 0 to 1 passing in MEDIAN value
arcpy.gp.RescaleByFunction_sa(as_ppb_int, Final_Test, "LARGE", median_Result, "5",&amp;nbsp; "# # # #", "0", "1")
print "Complete"&lt;/PRE&gt;&lt;P&gt;When I run it I get the following (6833 being the MEDIAN):&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" height="199" src="https://community.esri.com/legacyfs/online/103712_pastedImage_10.png" style="height: 199px; width: 474.633540372671px;" width="475" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the dialog eventually dissapears without producing the 'Final_Test' raster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I really just need a way of using the median as opposed to the mean to perform the LARGE transformation function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nick&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 21:51:37 GMT</pubDate>
    <dc:creator>NickMoylan</dc:creator>
    <dc:date>2021-12-10T21:51:37Z</dc:date>
    <item>
      <title>Crashing pythonwin.exe when using Rescale By Function</title>
      <link>https://community.esri.com/t5/python-questions/crashing-pythonwin-exe-when-using-rescale-by/m-p/48206#M3818</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am attempting to use the Rescale By Function tool rescale my raster values using the "LARGE" transformation function, however instead of using the calculated value for the midpoint parameter, I would like to use the MEDIAN. In this code I convert the float raster to integer, get the median using zonal stats, convert the Result Object to long integer, and pass it into the Rescale By Function parameters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Local variables:
as_ppm = "C:\\Users\\nmoylan\\Documents\\Desktop Items\\Strategic Evaluations\\BC\\QUEST WEST\\Z9 Geochem and Grids\\as_ppm"
Constant_value = "1000"
process_mask = "C:\\Users\\nmoylan\\Documents\\Desktop Items\\Strategic Evaluations\\BC\\QUEST WEST\\Z9 Geochem and Grids\\process_mask"
as_ppb_int = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\as_ppb_int"
as_median = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\as_median"
as_ppb = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\as_ppb"
Final_Test = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\Final_Test"

# Process: Times
arcpy.gp.Times_sa(as_ppm, Constant_value, as_ppb)

# Process: Int - makes the MEDIAN option available in Zonal Stats
arcpy.gp.Int_sa(as_ppb, as_ppb_int)

# Process: Build Raster Attribute Table - Greater than 100000 values and 500 unique values
arcpy.BuildRasterAttributeTable_management(as_ppb_int, "Overwrite")

# Process: Zonal Statistics - to find the MEDIAN
arcpy.gp.ZonalStatistics_sa(process_mask, "VALUE", as_ppb_int, as_median, "MEDIAN", "DATA")

# Convert the Result Object from Zonal Stats to Long Integer Value
median_Result = long(arcpy.GetRasterProperties_management(as_median, "MEAN").getOutput(0))
print median_Result

# Process: Rescale by Function - rescale integer raster from 0 to 1 passing in MEDIAN value
arcpy.gp.RescaleByFunction_sa(as_ppb_int, Final_Test, "LARGE", median_Result, "5",&amp;nbsp; "# # # #", "0", "1")
print "Complete"&lt;/PRE&gt;&lt;P&gt;When I run it I get the following (6833 being the MEDIAN):&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" height="199" src="https://community.esri.com/legacyfs/online/103712_pastedImage_10.png" style="height: 199px; width: 474.633540372671px;" width="475" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the dialog eventually dissapears without producing the 'Final_Test' raster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I really just need a way of using the median as opposed to the mean to perform the LARGE transformation function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nick&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:51:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/crashing-pythonwin-exe-when-using-rescale-by/m-p/48206#M3818</guid>
      <dc:creator>NickMoylan</dc:creator>
      <dc:date>2021-12-10T21:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Crashing pythonwin.exe when using Rescale By Function</title>
      <link>https://community.esri.com/t5/python-questions/crashing-pythonwin-exe-when-using-rescale-by/m-p/48207#M3819</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A few things I noticed:&lt;/P&gt;&lt;P&gt;I think the extension name is case sensitive (not sure). It is written as "Spatial" in the help files.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your paths are very long, and have spaces in them. The best way is to make a folder directly in the root of your C drive for GIS analysis, such as C:\gis\, and to avoid spaces in folder names. This prevents a lot of issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The syntax for raster analysis tools is:&lt;/P&gt;&lt;P&gt;outTimes = Times_sa(inRaster, inConstant)&lt;/P&gt;&lt;P&gt;The gp syntax is outdated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 16:31:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/crashing-pythonwin-exe-when-using-rescale-by/m-p/48207#M3819</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-05-26T16:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: Crashing pythonwin.exe when using Rescale By Function</title>
      <link>https://community.esri.com/t5/python-questions/crashing-pythonwin-exe-when-using-rescale-by/m-p/48208#M3820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Sephe Fox,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The paths were ok to have spaces (this was the test data, real data resides on a lengthy server path)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Changing the syntax of the tools cause python to produce an actual error rather than crashing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Rescale By Function() takes at most 4 arguments (currently 7 total)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the solution is to create a transformation function object to pass into the tool, works great now:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create the TfLarge object - to pass into the Rescale By Function Tool&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; midpoint = median_Result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; spread = 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lowerthresh = "#"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; valbelowthresh = "#"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; upperthresh = "#"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; valabovethresh = "#"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myTfFunction = TfLarge(midpoint, spread, lowerthresh, valbelowthresh, upperthresh, valabovethresh)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Rescale by Function - rescale integer raster from 0 to 1 passing in MEDIAN value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Final_Test = RescaleByFunction(as_ppb_int, myTfFunction, "0", "1")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//005m000000s9000000"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#//005m000000s9000000&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 17:18:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/crashing-pythonwin-exe-when-using-rescale-by/m-p/48208#M3820</guid>
      <dc:creator>NickMoylan</dc:creator>
      <dc:date>2015-05-26T17:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Crashing pythonwin.exe when using Rescale By Function</title>
      <link>https://community.esri.com/t5/python-questions/crashing-pythonwin-exe-when-using-rescale-by/m-p/48209#M3821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you explain your &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Rescale_by_Function/009z000000zt000000/"&gt;RescaleByFunction&lt;/A&gt;&amp;nbsp; it looks very different from those in the help file.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 17:19:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/crashing-pythonwin-exe-when-using-rescale-by/m-p/48209#M3821</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-26T17:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Crashing pythonwin.exe when using Rescale By Function</title>
      <link>https://community.esri.com/t5/python-questions/crashing-pythonwin-exe-when-using-rescale-by/m-p/48210#M3822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The original script i was working with was an Export from a ModelBuilder Model I was working on.&amp;nbsp; ModelBuilder seems to have exported it with extra arguments&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 17:25:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/crashing-pythonwin-exe-when-using-rescale-by/m-p/48210#M3822</guid>
      <dc:creator>NickMoylan</dc:creator>
      <dc:date>2015-05-26T17:25:32Z</dc:date>
    </item>
  </channel>
</rss>

