-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoil_data.py
More file actions
27 lines (24 loc) · 1.01 KB
/
Copy pathsoil_data.py
File metadata and controls
27 lines (24 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests
def get_soil_data(polygon_id, api_key):
api_url = f"http://api.agromonitoring.com/agro/1.0/soil?polyid={polygon_id}&appid={api_key}"
response = requests.get(api_url)
if response.status_code == 200:
return response.json()
else:
print(f"Error fetching soil data: {response.text}")
return None
def process_soil_data(soil_data):
if soil_data:
# Convert temperatures from Kelvin to Celsius
temperature_surface_c = soil_data['t0'] - 273.15
temperature_10cm_c = soil_data['t10'] - 273.15
# Convert moisture to percentage
moisture_percentage = soil_data['moisture'] * 100
processed_data = {
'Temperature at surface (°C)': round(temperature_surface_c, 2),
'Temperature at 10cm depth (°C)': round(temperature_10cm_c, 2),
'Soil moisture (%)': round(moisture_percentage, 2)
}
return processed_data
else:
return {'error':'No soil data available'}