<jupyter_start><jupyter_text>Notebook IV - Soil Constraints  Importing Libraries<jupyter_code>'''import supporting libraries'''

import numpy as np
import matplotlib.pyplot as plt
import imageio

import sys
sys.path.append('./code/') # add path to source code directory<jupyter_output><empty_output><jupyter_text>Applying Soil Constraints<jupyter_code>'''importing library'''

import SoilConstraints
soil_constraints = SoilConstraints.SoilConstraints()

import UtilitiesCalc
obj_utilities = UtilitiesCalc.UtilitiesCalc()
'''reading data'''

yield_map_rain = imageio.imread('./sample_data/output/NB3/CropSuitability_rain_m3.tif');
yield_map_irr = imageio.imread('./sample_data/output/NB3/CropSuitability_irr_m3.tif');

soil_map = imageio.imread('./sample_data/input/Lao_Soil.tif');
'''calculate soil qualities and ratings and applying soil constraints - Rain-fed'''

soil_constraints.calculateSoilQualities('R') # I: Irrigated, R: Rain-fed
soil_constraints.calculateSoilRatings('I') # L: Low, I: Intermediate, H: High input

# extraction of soil qualities and soil rating if required
# print( soil_constraints.getSoilQualities() )
# print( soil_constraints.getSoilRatings() )

yield_map_rain_m4 = soil_constraints.applySoilConstraints(soil_map, yield_map_rain)
## get classified output
yield_map_rain_class_m4 = obj_utilities.classifyFinalYield(yield_map_rain_m4)
'''calculate soil qualities and ratings and applying soil constraints - Irrigated'''

soil_constraints.calculateSoilQualities('I') # I: Irrigated, R: Rain-fed
soil_constraints.calculateSoilRatings('I') # L: Low, I: Intermediate, H: High input

# extraction of soil qualities and soil rating if required
# print( soil_constraints.getSoilQualities() )
# print( soil_constraints.getSoilRatings() )

yield_map_irr_m4 = soil_constraints.applySoilConstraints(soil_map, yield_map_irr)
## get classified output
yield_map_irr_class_m4 = obj_utilities.classifyFinalYield(yield_map_irr_m4)
'''visualize result'''

plt.imshow(yield_map_rain_m4)
plt.show()

plt.imshow(yield_map_irr_m4)
plt.show()

plt.imshow(yield_map_rain_class_m4)
plt.show()

plt.imshow(yield_map_irr_class_m4)
plt.show()
'''save result'''

obj_utilities.saveRaster('./sample_data/input/LAO_Admin.tif', './sample_data/output/NB4/CropSuitability_rain_m4.tif', yield_map_rain_m4)
obj_utilities.saveRaster('./sample_data/input/LAO_Admin.tif', './sample_data/output/NB4/CropSuitability_irr_m4.tif', yield_map_irr_m4)

obj_utilities.saveRaster('./sample_data/input/LAO_Admin.tif', './sample_data/output/NB4/CropSuitability_rain_class_m4.tif',yield_map_rain_class_m4)
obj_utilities.saveRaster('./sample_data/input/LAO_Admin.tif', './sample_data/output/NB4/CropSuitability_irr_class_m4.tif',yield_map_irr_class_m4)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11421319796954314, 'fraction_numerical': 0.009427121102248005, 'mean_word_length': 8.016339869281046, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '469176', 'license': 'MIT', 'n_tokens_mistral': 1060, 'n_tokens_neox': 998, 'n_words': 156, 'path': 'NB4_SoilConstraints.ipynb', 'repo_name': 'thailengthol/PyAEZ', 'size': '2758'}