I cannot perform the Con tool over all the raster images with same date in two folders. What I am trying to achieve is producing an image where the pixel values of 1 are converted to 0 and the pixel values of 0 are replaced with the pixel values of another image using the images with the same dates.
This is the script I have worked upon so far.
import arcpy, os
from arcpy.sa import *
# Set the current workspace
location_a = "D:/datasets/regression_interpolation_rasters/airtemp_snowmask_regression_rasters"
location_b = "D:/datasets/regression_interpolation_rasters/regression_rasters"
location = "D:/datasets/regression_interpolation_rasters/snowmask_rasters"
# get the names of rasters
arcpy.env.workspace = location_a
snow_raster = arcpy.ListRasters("", "TIF")
for snow_ras in snow_raster:
snow = Raster(snow_ras)
#print(type(snow))
snow_name = snow_ras.split("_")
snow_values = snow_name[2]
#print(snow_values)
# get the names of rasters
arcpy.env.workspace = location_b
airtemp_raster = arcpy.ListRasters("", "TIF")
#print(airtemp_raster)
for airtemp_ras in airtemp_raster:
airtemp = Raster(airtemp_ras)
airtemp_name = airtemp_ras.split("_")
airtemp_values = airtemp_name[0]
#print(airtemp_values)
if airtemp_values == snow_values:
output_raster = Con(snow_raster==1, 0, airtemp_raster)
output = os.path.join(location,airtemp_ras.split("_")[0] +'_airtemp'+ '.tif')
output_raster.save(output)
#print("yes")
else:
print("action cannot take place")
All it is showing the else statement even though the dates match.The placement of the dates vary but the format of dates are similar.These are the images in location_b

These are the images in location_a
