#Dryophytes avivoca Crop Hot Spot Analysis - No Dispersal
#Date Created: 4/30/2025

#Purpose: Generate spatial files to assess overlap of areas with high suitability for Dryophytes avivoca occurrence and high agricultural activity. Compare how the overlap changes in the future under different climate scenarios with no dispersal.

#See Figure 1 for flow chart of geoprocessing steps


#################################################


#biomod2 Output Preparation and Raster Calculator

#SDM - Current Distribution Model


#Clip biomod2 Raster
arcpy.management.Clip(
    in_raster="proj_Current_Dryophytes.avivoca_ensemble.img",
    rectangle="-95.1583960962029 29.6621393576453 -80.8267258945843 37.9734770491266",
    out_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\proj_Current_Dryophytes_avivoca_Clip",
    in_template_dataset="Dryophytes_avivoca",
    nodata_value="",
    clipping_geometry="ClippingGeometry",
    maintain_clipping_extent="MAINTAIN_EXTENT"
)

#clipped based on current IUCN distribution

#Convert to binary 

out_raster = arcpy.sa.Con(
    in_conditional_raster="proj_Current_Dryophytes_avivoca_Clip",
    in_true_raster_or_constant=1,
    in_false_raster_or_constant=0,
    where_clause="VALUE >= 530"
)
out_raster.save(r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\Con_proj_current_Dryophytes_avivoca_binary")

#Note: 530 represents the TSS ensemble cutoff from biomod2 ensemble model output


#Project the raster into NAD1983 and resample to 30m raster cell size
arcpy.management.ProjectRaster(
    in_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\Con_proj_current_Dryophytes_avivoca_binary",
    out_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\CurrentDryoAvi_binary_ProjectRaster",
    out_coor_system='PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]',
    resampling_type="NEAREST",
    cell_size="30 30",
    geographic_transform="WGS_1984_(ITRF00)_To_NAD_1983",
    Registration_Point=None,
    in_coor_system='GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]',
    vertical="NO_VERTICAL"
)

#Output is SDM binary that has been resampled to 30m and projected in NAD1983


#

#Raster Calculation with Current SDM Binary
#Note: Raster calculation script may need to be rerun if there is an error due to the process timing out. Use print messages to track completed raster calculations

#Raster calculation with current SDM binary and cotton frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["CurrentDryoAvi_binary_ProjectRaster", "Con_CottonFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_CurrentDryoAvi_CottonFreq")

print('Raster calculation with current SDM binary and cotton frequency complete!')


#

#Raster calculation with current SDM binary and corn frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["CurrentDryoAvi_binary_ProjectRaster", "Con_CornFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_CurrentDryoAvi_CornFreq")

print('Raster calculation with current SDM binary and corn frequency complete!')


#

#Raster calculation with current SDM binary and soybeans frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["CurrentDryoAvi_binary_ProjectRaster", "Con_SoybeansFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_CurrentDryoAvi_SoybeansFreq")

print('Raster calculation with current SDM binary and soybeans frequency complete!')


#

#Raster calculation with current SDM binary and cultivated frequency
#Note: not used in the formal analysis

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["CurrentDryoAvi_binary_ProjectRaster", "Con_CultivatedFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_CurrentDryoAvi_CultivatedFreq")

print('Raster calculation with current SDM binary and cultivated frequency complete!')


##################################################



#SDM - ssp245 Distribution Model

#Clip biomod2 Raster
arcpy.management.Clip(
    in_raster="proj_2100_ssp245_Dryophytes.avivoca_ensemble.img",
    rectangle="-95.1583960962029 29.6621393576453 -80.8267258945843 37.9734770491266",
    out_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\proj_ssp245_Dryophytes_avivoca_Clip_NoDisp",
    in_template_dataset="Dryophytes_avivoca",
    nodata_value="",
    clipping_geometry="ClippingGeometry",
    maintain_clipping_extent="MAINTAIN_EXTENT"
)

#Clipped based on maximum dispersal layer

#Convert to binary 

out_raster = arcpy.sa.Con(
    in_conditional_raster="proj_ssp245_Dryophytes_avivoca_Clip_NoDisp",
    in_true_raster_or_constant=1,
    in_false_raster_or_constant=0,
    where_clause="VALUE >= 530"
)
out_raster.save(r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\Con_proj_ssp245_Dryophytes_avivoca_binary_NoDisp")

#Note: 530 represents the TSS ensemble cutoff from biomod2 ensemble model output


#Project the raster into NAD1983 and resample to 30m raster cell size
arcpy.management.ProjectRaster(
    in_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\Con_proj_ssp245_Dryophytes_avivoca_binary_NoDisp",
    out_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\ssp245DryoAvi_binary_ProjectRaster_NoDisp",
    out_coor_system='PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]',
    resampling_type="NEAREST",
    cell_size="30 30",
    geographic_transform="WGS_1984_(ITRF00)_To_NAD_1983",
    Registration_Point=None,
    in_coor_system='GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]',
    vertical="NO_VERTICAL"
)

#Output is SDM binary that has been resampled to 30m and projected in NAD1983

#

#Raster Calculation with ssp245 SDM Binary
#Note: Raster calculation script may need to be rerun if there is an error due to the process timing out. Use print messages to track completed raster calculations

#Raster calculation with ssp245 SDM binary and cotton frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp245DryoAvi_binary_ProjectRaster_NoDisp", "Con_CottonFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp245DryoAvi_CottonFreq_NoDisp")


print('Raster calculation with ssp245 SDM binary and cotton frequency complete!')

#

#Raster calculation with ssp245 SDM binary and corn frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp245DryoAvi_binary_ProjectRaster_NoDisp", "Con_CornFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp245DryoAvi_CornFreq_NoDisp")


print('Raster calculation with ssp245 SDM binary and corn frequency complete!')

#

#Raster calculation with ssp245 SDM binary and soybeans frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp245DryoAvi_binary_ProjectRaster_NoDisp", "Con_SoybeansFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp245DryoAvi_SoybeansFreq_NoDisp")


print('Raster calculation with ssp245 SDM binary and soybeans frequency complete!')

#

#Raster calculation with ssp245 SDM binary and cultivated frequency
#Note: not used in the formal analysis

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp245DryoAvi_binary_ProjectRaster_NoDisp", "Con_CultivatedFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp245DryoAvi_CultivatedFreq_NoDisp")


print('Raster calculation with ssp245 SDM binary and cultivated frequency complete!')


#####################################################



#SDM - ssp370 Distribution Model

#Clip biomod2 Raster
arcpy.management.Clip(
    in_raster="proj_2100_ssp370_Dryophytes.avivoca_ensemble.img",
    rectangle="-95.1583960962029 29.6621393576453 -80.8267258945843 37.9734770491266",
    out_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\proj_ssp370_Dryophytes_avivoca_Clip_NoDisp",
    in_template_dataset="Dryophytes_avivoca",
    nodata_value="",
    clipping_geometry="ClippingGeometry",
    maintain_clipping_extent="MAINTAIN_EXTENT"
)

#Clipped based on maximum dispersal layer

#Convert to binary 

out_raster = arcpy.sa.Con(
    in_conditional_raster="proj_ssp370_Dryophytes_avivoca_Clip_NoDisp",
    in_true_raster_or_constant=1,
    in_false_raster_or_constant=0,
    where_clause="VALUE >= 530"
)
out_raster.save(r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\Con_proj_ssp370_Dryophytes_avivoca_binary_NoDisp")

#Note: 530 represents the TSS ensemble cutoff from biomod2 ensemble model output


#Project the raster into NAD1983 and resample to 30m raster cell size
arcpy.management.ProjectRaster(
    in_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\Con_proj_ssp370_Dryophytes_avivoca_binary_NoDisp",
    out_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\ssp370DryoAvi_binary_ProjectRaster_NoDisp",
    out_coor_system='PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]',
    resampling_type="NEAREST",
    cell_size="30 30",
    geographic_transform="WGS_1984_(ITRF00)_To_NAD_1983",
    Registration_Point=None,
    in_coor_system='GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]',
    vertical="NO_VERTICAL"
)

#

#Raster Calculation with ssp370 SDM Binary
#Note: Raster calculation script may need to be rerun if there is an error due to the process timing out. Use print messages to track completed raster calculations

#Raster calculation with ssp370 SDM binary and cotton frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp370DryoAvi_binary_ProjectRaster_NoDisp", "Con_CottonFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp370DryoAvi_CottonFreq_NoDisp")

print('Raster calculation with ssp370 SDM binary and cotton frequency complete!')

#

#Raster calculation with ssp370 SDM binary and corn frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp370DryoAvi_binary_ProjectRaster_NoDisp", "Con_CornFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp370DryoAvi_CornFreq_NoDisp")

print('Raster calculation with ssp370 SDM binary and corn frequency complete!')

#

#Raster calculation with ssp370 SDM binary and soybeans frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp370DryoAvi_binary_ProjectRaster_NoDisp", "Con_SoybeansFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp370DryoAvi_SoybeansFreq_NoDisp")

print('Raster calculation with ssp370 SDM binary and soybeans frequency complete!')

#

#Raster calculation with ssp370 SDM binary and cultivated frequency
#Note: not used in the formal analysis

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp370DryoAvi_binary_ProjectRaster_NoDisp", "Con_CultivatedFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp370DryoAvi_CultivatedFreq_NoDisp")

print('Raster calculation with ssp370 SDM binary and cultivated frequency complete!')


####################################################################



#SDM - ssp585 Distribution Model

#Clip biomod2 Raster
arcpy.management.Clip(
    in_raster="proj_2100_ssp585_Dryophytes.avivoca_ensemble.img",
    rectangle="-95.1583960962029 29.6621393576453 -80.8267258945843 37.9734770491266",
    out_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\proj_ssp585_Dryophytes_avivoca_Clip_NoDisp",
    in_template_dataset="Dryophytes_avivoca",
    nodata_value="",
    clipping_geometry="ClippingGeometry",
    maintain_clipping_extent="MAINTAIN_EXTENT"
)

#Clipped based on maximum dispersal layer

#Convert to binary 

out_raster = arcpy.sa.Con(
    in_conditional_raster="proj_ssp585_Dryophytes_avivoca_Clip_NoDisp",
    in_true_raster_or_constant=1,
    in_false_raster_or_constant=0,
    where_clause="VALUE >= 530"
)
out_raster.save(r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\Con_proj_ssp585_Dryophytes_avivoca_binary_NoDisp")

#Note: 530 represents the TSS ensemble cutoff from biomod2 ensemble model output


#Project the raster into NAD1983 and resample to 30m raster cell size
arcpy.management.ProjectRaster(
    in_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\Con_proj_ssp585_Dryophytes_avivoca_binary_NoDisp",
    out_raster=r"E:\SpatialAnalysis\ArcGIS_PesticideAnalysis\CropHotSpotAnalysis\DryoAvi_CropHotSpotAnalysis.gdb\ssp585DryoAvi_binary_ProjectRaster_NoDisp",
    out_coor_system='PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]',
    resampling_type="NEAREST",
    cell_size="30 30",
    geographic_transform="WGS_1984_(ITRF00)_To_NAD_1983",
    Registration_Point=None,
    in_coor_system='GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]',
    vertical="NO_VERTICAL"
)

#

#Raster Calculation with ssp585 SDM Binary
#Note: Raster calculation script may need to be rerun if there is an error due to the process timing out. Use print messages to track completed raster calculations

#Raster calculation with ssp585 SDM binary and cotton frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp585DryoAvi_binary_ProjectRaster_NoDisp", "Con_CottonFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp585DryoAvi_CottonFreq_NoDisp")

print('Raster calculation with ssp585 SDM binary and cotton frequency complete!')

#

#Raster calculation with ssp585 SDM binary and corn frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp585DryoAvi_binary_ProjectRaster_NoDisp", "Con_CornFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp585DryoAvi_CornFreq_NoDisp")

print('Raster calculation with ssp585 SDM binary and corn frequency complete!')

#

#Raster calculation with ssp585 SDM binary and soybeans frequency

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp585DryoAvi_binary_ProjectRaster_NoDisp", "Con_SoybeansFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp585DryoAvi_SoybeansFreq_NoDisp")

print('Raster calculation with ssp585 SDM binary and soybeans frequency complete!')

#

#Raster calculation with ssp585 SDM binary and cultivated frequency
#Note: not used in the formal analysis

with arcpy.EnvManager(extent='-10614787.2303579 3444089.87283375 -8975433.53245331 4600656.94976704 PROJCS["NAD_1983_Contiguous_USA_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]]'):
	output_raster = arcpy.sa.RasterCalculator(["ssp585DryoAvi_binary_ProjectRaster_NoDisp", "Con_CultivatedFrequencyEastUS"], ["x", "y"], "x*y")
output_raster.save(r"e:\spatialanalysis\arcgis_pesticideanalysis\crophotspotanalysis\DryoAvi_CropHotSpotAnalysis.gdb\RastCalc_ssp585DryoAvi_CultivatedFreq_NoDisp")

print('Raster calculation with ssp585 SDM binary and cultivated frequency complete!')












