6180 Geoprocessing with Python 

Link to jupyter notebook here

Below is the code to run the site suitability analysis. The code is written in Python version 3.

# -*- coding: utf-8 -*-
"""Generated by ArcGIS ModelBuilder on: 2019-12-05 15:29:21
All ModelBuilder functionality may not be exported. Edits may be required for equivalency with the original model.
"""

import arcpy

# To allow overwriting the outputs change the overwrite option to true.
arcpy.env.overwriteOutput = True

# Script parameters
Slope__3_ = arcpy.GetParameterAsText(0) or r"N:\Geoprocessing_python\Auto_SSA\Auto_SSA.gdb\Slope"

# Local variables:
#Spatial extent
ID_Clip_shp = r"N:\Geoprocessing_python\ID_Clip.shp"
#Excluding data types
LAnduse__3_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
LAnduse__4_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
LAnduse__5_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
LAnduse__6_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
LAnduse__7_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
LAnduse__8_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
LAnduse__9_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
LAnduse__10_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
LAnduse__11_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
LAnduse__12_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
LAnduse__13_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
#Ave temps for Winter months
PRISM_tmean_stable_4kmM2_201701_bil_bil = r"N:\Geoprocessing_python\PRISM_tmean_stable_4kmM2_2017_all_bil\PRISM_tmean_stable_4kmM2_201701_bil.bil"
PRISM_tmean_stable_4kmM2_201702_bil_bil = r"N:\Geoprocessing_python\PRISM_tmean_stable_4kmM2_2017_all_bil\PRISM_tmean_stable_4kmM2_201702_bil.bil"
PRISM_tmean_stable_4kmM2_201703_bil_bil = r"N:\Geoprocessing_python\PRISM_tmean_stable_4kmM2_2017_all_bil\PRISM_tmean_stable_4kmM2_201703_bil.bil"
PRISM_tmean_stable_4kmM2_201710_bil_bil = r"N:\Geoprocessing_python\PRISM_tmean_stable_4kmM2_2017_all_bil\PRISM_tmean_stable_4kmM2_201710_bil.bil"
PRISM_tmean_stable_4kmM2_201711_bil_bil = r"N:\Geoprocessing_python\PRISM_tmean_stable_4kmM2_2017_all_bil\PRISM_tmean_stable_4kmM2_201711_bil.bil"
PRISM_tmean_stable_4kmM2_201712_bil_bil = r"N:\Geoprocessing_python\PRISM_tmean_stable_4kmM2_2017_all_bil\PRISM_tmean_stable_4kmM2_201712_bil.bil"
#cumulative ave of temps
tempave = r"N:\Geoprocessing_python\temp.gdb\tempave"
#temps inverted so higher temps have lower valy=ues
tempaveinv = r"N:\Geoprocessing_python\temp.gdb\tempaveinv"
#Final temp output in GDB
Temp = r"N:\Geoprocessing_python\Auto_SSA\Auto_SSA.gdb\Temp"
#Landuse raster file
LAnduse__2_ = r"N:\Geoprocessing_python\temp.gdb\LAnduse"
#Final output of Landuse based on Raster Calc
LandUse__14_ = r"N:\Geoprocessing_python\Auto_SSA\Auto_SSA.gdb\LandUse"

#30yr Precip averages for all 12 months - National Dataset
PRISM_ppt_30yr_normal_4kmM2_12_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_12_bil.bil"
PRISM_ppt_30yr_normal_4kmM2_11_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_11_bil.bil"
PRISM_ppt_30yr_normal_4kmM2_10_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_10_bil.bil"
PRISM_ppt_30yr_normal_4kmM2_09_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_09_bil.bil"
PRISM_ppt_30yr_normal_4kmM2_08_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_08_bil.bil"
PRISM_ppt_30yr_normal_4kmM2_07_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_07_bil.bil"
PRISM_ppt_30yr_normal_4kmM2_06_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_06_bil.bil"
PRISM_ppt_30yr_normal_4kmM2_05_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_05_bil.bil"
PRISM_ppt_30yr_normal_4kmM2_04_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_04_bil.bil"
PRISM_ppt_30yr_normal_4kmM2_03_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_03_bil.bil"
PRISM_ppt_30yr_normal_4kmM2_02_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_02_bil.bil"
PRISM_ppt_30yr_normal_4kmM2_01_bil_bil = r"N:\Geoprocessing_python\PRISM_ppt_30yr_normal_4kmM2_all_bil\PRISM_ppt_30yr_normal_4kmM2_01_bil.bil"
#Cumulative averages
Precip_ave = r"N:\Geoprocessing_python\temp.gdb\Precip_ave"
#Precip_ave clipped to Idaho
Precip_ave_ID = r"N:\Geoprocessing_python\temp.gdb\Precip_ave_ID"
#Final precip raster in gdb
Precip = r"N:\Geoprocessing_python\Auto_SSA\Auto_SSA.gdb\Precip"

#Source DEM
id_dem = r"N:\Geoprocessing_python\id_dem"
#DEM read into temp gdb
Ele = r"N:\Geoprocessing_python\temp.gdb\Ele"
#Elevation parameters - Inverted and two sep rasters with High Ranges and low Ranges
Ele_inv = r"N:\Geoprocessing_python\temp.gdb\Ele_inv"
Ele_L = r"N:\Geoprocessing_python\temp.gdb\Ele_L"
Ele_H = r"N:\Geoprocessing_python\temp.gdb\Ele_H"
#Elevation average of two rasters
Ele_ave = r"N:\Geoprocessing_python\Auto_SSA\Auto_SSA.gdb\Ele_ave"

#Slope Derived from Elevation model
Slope__4_ = r"N:\Geoprocessing_python\ModelBuilder_trial.gdb\Slope"

#Final output of Hop site selection
HopSiteSelection_ID = r"N:\Geoprocessing_python\Auto_SSA\Auto_SSA.gdb\HopSiteSelection_ID"


# Process: Raster Calculator - Averaging temperatures from 2017
arcpy.gp.RasterCalculator_sa(expression="( "%PRISM_tmean_stable_4kmM2_201701_bil.bil%" +  "%PRISM_tmean_stable_4kmM2_201702_bil.bil%" + "%PRISM_tmean_stable_4kmM2_201703_bil.bil%" + "%PRISM_tmean_stable_4kmM2_201710_bil.bil%" + "%PRISM_tmean_stable_4kmM2_201711_bil.bil%" + "%PRISM_tmean_stable_4kmM2_201712_bil.bil%")/6", output_raster=tempave)

# Process: Raster Calculator - Creating inverted raster to weight lower temps more heavily
arcpy.gp.RasterCalculator_sa(expression="1 - "%tempave%", output_raster=tempaveinv)

# Process: Clip Raster - to work extent
arcpy.Clip_management(in_raster=tempaveinv, rectangle="-117.243026999796 41.9880570003303 -111.043564000078 49.001145999988", out_raster=Temp, in_template_dataset=ID_Clip_shp, nodata_value="", clipping_geometry="NONE", maintain_clipping_extent="NO_MAINTAIN_EXTENT")

# Process: Raster Calculator - pulling out not acceptable land use types - assigning Boolean output
arcpy.gp.RasterCalculator_sa(expression="Con(("%LAnduse (2)%" == 195) | ( "%LAnduse (2)%"==176) | ( "%LAnduse (2)%" == 152 )  |  ( "%LAnduse (2)%" == 143 )|  ( "%LAnduse (2)%" == 142 ) |  ( "%LAnduse (2)%" == 141 )|  ( "%LAnduse (2)%" == 124 )|  ( "%LAnduse (2)%" == 123 ) |  ( "%LAnduse (2)%" == 122 ) |  ( "%LAnduse (2)%" == 121 )|  ( "%LAnduse (2)%" == 112 )|  ( "%LAnduse (2)%" == 111 ), 0,1)", output_raster=LandUse__14_)

# Process: Raster Calculator - Averaging 30yr precip averages for all 12 months
arcpy.gp.RasterCalculator_sa(expression="( "%PRISM_ppt_30yr_normal_4kmM2_12_bil.bil%"  + "%PRISM_ppt_30yr_normal_4kmM2_11_bil.bil%" +  "%PRISM_ppt_30yr_normal_4kmM2_10_bil.bil%" + "%PRISM_ppt_30yr_normal_4kmM2_09_bil.bil%" +  "%PRISM_ppt_30yr_normal_4kmM2_08_bil.bil%"+  "%PRISM_ppt_30yr_normal_4kmM2_07_bil.bil%"+  "%PRISM_ppt_30yr_normal_4kmM2_06_bil.bil%" + "%PRISM_ppt_30yr_normal_4kmM2_05_bil.bil%" +  "%PRISM_ppt_30yr_normal_4kmM2_04_bil.bil%"+  "%PRISM_ppt_30yr_normal_4kmM2_03_bil.bil%" +  "%PRISM_ppt_30yr_normal_4kmM2_02_bil.bil%" + "%PRISM_ppt_30yr_normal_4kmM2_01_bil.bil%")/12", output_raster=Precip_ave)

# Process: Clip Raster - to work Extent
arcpy.Clip_management(in_raster=Precip_ave, rectangle="-117.243026999796 41.9880570003303 -111.043564000078 49.001145999988", out_raster=Precip_ave_ID, in_template_dataset=ID_Clip_shp, nodata_value="", clipping_geometry="NONE", maintain_clipping_extent="NO_MAINTAIN_EXTENT")

# Process: Raster Calculator - Scale Precip 0 - 1
arcpy.gp.RasterCalculator_sa(expression="(("%Precip_ave_ID%")/1000)*5", output_raster=Precip)

# Process: Copy Raster - read in Elevation model to working gdb
arcpy.CopyRaster_management(in_raster=id_dem, out_rasterdataset=Ele, config_keyword="", background_value="", nodata_value="-3.402823e+38", onebit_to_eightbit="NONE", colormap_to_RGB="NONE", pixel_type="32_BIT_FLOAT", scale_pixel_value="NONE", RGB_to_Colormap="NONE", format="TIFF", transform="NONE", process_as_multidimensional="CURRENT_SLICE", build_multidimensional_transpose="NO_TRANSPOSE")

# Process: Slope - from Elevation model
arcpy.gp.Slope_sa(in_raster=Ele, out_raster=Slope__4_, output_measurement="DEGREE", z_factor="1", method="PLANAR", z_unit="METER")

# Process: Raster Calculator - assigning fuzzy boundaries to slope raster
arcpy.gp.RasterCalculator_sa(expression="Con("%Slope (4)%" < 1.5, 1,Con("%Slope (4)%" < 12, 1/("%Slope (4)%"),0))", output_raster=Slope__3_)

# Process: Raster Calculator - inverting Elevation so high elevation is a low value
arcpy.gp.RasterCalculator_sa(expression="(1/ "%Ele%")*100", output_raster=Ele_inv)

# Process: Raster Calculator - assigning fuzzy boundaries to elevation raster - high range
arcpy.gp.RasterCalculator_sa(expression="Con( "%Ele_inv%" >= 0.35, 0 , Con( "%Ele_inv%" < 0.35, 0, 1))", output_raster=Ele_L)

# Process: Raster Calculator - assigning fuzzy boundaries to elevation raster - low range
arcpy.gp.RasterCalculator_sa(expression=" Con("%Ele_inv%" >= 0.4, 0, Con( "%Ele_inv%" <= 0.04, 0, 1))", output_raster=Ele_H)

# Process: Raster Calculator - Averaging High and low value
arcpy.gp.RasterCalculator_sa(expression=" ("%Ele_L%" +  "%Ele_H%")/2", output_raster=Ele_ave)

# Process: Raster Calculator - Final averaging of all variables for site selection output
arcpy.gp.RasterCalculator_sa(expression="( "%Temp%" + "%LandUse (14)%" +  "%Precip%" + "%Slope (3)%" +   "%Ele_ave%")/6", output_raster=HopSiteSelection_ID) World!</p>