AHP Python Code
AHP Python Code
pairwise_matrix = np.array([
[1, 3, 3, 2, 5, 5, 7],
[1/3, 1, 3, 2, 3, 3, 5],
])
column_sums = pairwise_matrix.sum(axis=0)
weights = normalized_matrix.mean(axis=1)
CI = (lambda_max - n) / (n - 1)
CR = CI / RI if RI else 0
# Display results
print(pairwise_matrix)
print("\nNormalized Matrix:")
print(normalized_matrix)
print(f"\nλ_max: {lambda_max:.4f}")
if CR < 0.1:
else:
import numpy as np
# Define the file paths for each raster layer (update these with your file paths)
rasters = {
'PISR': 'path_to_pISR.tif',
'MAAT': 'path_to_MAAT.tif',
'LST': 'path_to_LST.tif',
'TWI': 'path_to_TWI.tif',
'LULC': 'path_to_LULC.tif',
'Slope': 'path_to_Slope.tif',
'Aspect': 'path_to_Aspect.tif'
weights = {
'PISR': 0.27,
'MAAT': 0.11,
'LST': 0.37,
'TWI': 0.08,
'LULC': 0.026,
'Slope': 0.055,
'Aspect': 0.068
# Function to read a raster file and return its values as a numpy array
def read_raster(raster_path):
def reclassify_to_5_scale(raster_array):
return reclassified
weighted_layers = []
reclassified_raster = reclassify_to_5_scale(raster_array)
weighted_layers.append(weighted_raster)
# For example, if you want the final result to stay between 1 and 5, use np.clip()
total_weighted_overlay = np.clip(total_weighted_overlay, 1, 5)
output_path = 'path_to_output_weighted_overlay.tif'
metadata = src.meta
metadata.update(dtype=rasterio.float32, count=1)
dst.write(total_weighted_overlay.astype(rasterio.float32), 1)