= 7 # Soil pH
pH
if pH >= 0 and pH < 7:
= 'Acidic'
soil_class elif pH == 7:
= 'Neutral'
soil_class elif pH > 7 and pH <= 14:
= 'Alkaline'
soil_class else:
= 'pH value out of range.'
soil_class
print(soil_class)
Neutral
if
statements control the flow of a program by evaluating whether a certain condition is true or false, and then executing specific actions based on that evaluation. The core syntax of an if
statement involves specifying a condition and an action to be executed if that condition is true.
if condition:
# Code block executes if condition is true
elif another_condition:
# Code block executes if another condition is true
else:
# Code block executes if none of the above conditions are true
Soil pH is a measure of soil acidity or alkalinity. The pH scale ranges from 0 to 14, with a pH of 7 considered neutral. Acidic soils have pH values below 7, indicating an abundance of hydrogen ions (H+), while alkaline soils have pH values above 7, indicating an excess of hydroxide ions (OH-). Soil pH plays a vital role in nutrient availability to plants, microbial activity, and soil structure.
= 7 # Soil pH
pH
if pH >= 0 and pH < 7:
= 'Acidic'
soil_class elif pH == 7:
= 'Neutral'
soil_class elif pH > 7 and pH <= 14:
= 'Alkaline'
soil_class else:
= 'pH value out of range.'
soil_class
print(soil_class)
Neutral
For instance, in soil science we can use if
statements to categorize soils into saline, saline-sodic, or sodic based on electrical conductivity (EC) and the Sodium Adsorption Ratio (SAR). Sometimes soil pH is also a component of this classification, but to keep it simple we will only use EC and SAR for this example. We can write a program that uses if
statements to classify salt-affected soils following this widely-used table:
Soil Type | EC | SAR |
---|---|---|
Normal | < 4.0 dS/m | < 13 |
Saline | ≥ 4.0 dS/m | < 13 |
Sodic | < 4.0 dS/m | ≥ 13 |
Saline-Sodic | ≥ 4.0 dS/m | ≥ 13 |
Here is a great fact sheet where you can learn more about saline, sodic, and saline-sodic soils
= 3 # electrical conductivity in dS/m
ec = 16 # sodium adsorption ratio (dimensionless)
sar
# Determine the category of soil
if (ec >= 4.0) and (sar < 13):
= "Saline"
classification
elif (ec < 4.0) and (sar >= 13):
= "Sodic"
classification
elif (ec >= 4.0) and (sar >= 13):
= "Saline-Sodic"
classification
else:
= "Normal"
classification
print(f'Soil is {classification}')
Soil is Sodic
To understand global climate variations, one useful metric is the Aridity Index (AI), which compares annual precipitation to atmospheric demand. Essentially, a lower AI indicates a drier region:
AI = \frac{P}{PET}
where P is the annual precipitation in mm and PET is the annual cummulative potential evapotranspiration in mm.
Over time, the definition of AI has evolved, leading to various classifications in the literature. Below is a simplified summary of these classifications:
Climate class | Value |
---|---|
Hyper-arid | 0.03 < AI |
Arid | 0.03 < AI ≤ 0.20 |
Semi-arid | 0.20 < AI ≤ 0.50 |
Dry sub-humid | 0.50 < AI ≤ 0.65 |
Sub-humid | 0.65 < AI ≤ 0.75 |
Humid | AI > 0.75 |
# Define annual precipitation and atmospheric demand for a location
= 1200 # mm per year
P = 1800 # mm per year
PET
# Compute Aridity Inde
= P/PET
AI
# Find climate class
if AI <= 0.03:
= 'Arid'
climate_class
elif AI > 0.03 and AI <= 0.2:
= 'Arid'
climate_class
elif AI > 0.2 and AI <= 0.5:
= 'Semi-arid'
climate_class
elif AI > 0.5 and AI <= 0.65:
= 'Dry sub-humid'
climate_class
elif AI > 0.65 and AI <= 0.75:
= 'Sub-humid'
climate_class
else:
= 'Humid'
climate_class
print('Climate classification for this location is:',climate_class,'(AI='+str(round(AI,2))+')')
Climate classification for this location is: Sub-humid (AI=0.67)
If
statements= 7 # Soil pH
pH
if pH >= 0 and pH < 7:
= 'Acidic'
soil_class elif pH == 7:
= 'Neutral'
soil_class elif pH > 7 and pH <= 14:
= 'Alkaline'
soil_class else:
= 'pH value out of range.'
soil_class
print(soil_class)
pH = 7; % Soil pH
if pH >= 0 && pH < 7
soil_class = 'Acidic';
elseif pH == 7
soil_class = 'Neutral';
elseif pH > 7 && pH <= 14
soil_class = 'Alkaline';
else
soil_class = 'pH value out of range.';
end
disp(soil_class)
= 7 # Soil pH
pH
if 0 <= pH < 7
= "Acidic"
soil_class elseif pH == 7
= "Neutral"
soil_class elseif 7 < pH <= 14
= "Alkaline"
soil_class else
= "pH value out of range."
soil_class end
println(soil_class)
<- 7 # Soil pH
pH
if (pH >= 0 & pH < 7) {
<- "Acidic"
soil_class else if (pH == 7) {
} <- "Neutral"
soil_class else if (pH > 7 & pH <= 14) {
} <- "Alkaline"
soil_class else {
} <- "pH value out of range."
soil_class
}
print(soil_class)
let pH = 7; // Soil pH
let soil_class;
if (pH >= 0 && pH < 7) {
= 'Acidic';
soil_class else if (pH === 7) {
} = 'Neutral';
soil_class else if (pH > 7 && pH <= 14) {
} = 'Alkaline';
soil_class else {
} = 'pH value out of range.';
soil_class
}
console.log(soil_class);
if
keyword to start the statement.<
, ==
, <=
) to evaluate true or false.else if
or its equivalent for additional conditions.else
to handle cases that don’t meet any if
or else if
conditions.{}
in JavaScript, end
in Matlab and Julia).Havlin, J. L., Tisdale, S. L., Nelson, W. L., & Beaton, J. D. (2016). Soil fertility and fertilizers. Pearson Education India.
Spinoni, J., Vogt, J., Naumann, G., Carrao, H. and Barbosa, P., 2015. Towards identifying areas at climatological risk of desertification using the Köppen–Geiger classification and FAO aridity index. International Journal of Climatology, 35(9), pp.2210-2222.
Zhang, H. 2017. Interpreting Soil Salinity Analyses. L-297. Oklahoma Cooperative Extension Service. Link
Zomer, R. J., Xu, J., & Trabucco, A. (2022). Version 3 of the global aridity index and potential evapotranspiration database. Scientific Data, 9(1), 409.