Error when producing a supervision schedule based on real-time data. #172
GabyQueiroz
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I created a supervision schedule based on real-time data:
import pandas as pd
from aquacrop import AquaCropModel, Soil, Crop, InitialWaterContent, IrrigationManagement
Dados simulados para 5 dias
data = {
'MinTemp': [10.0, 11.0, 12.0, 13.0, 14.0],
'MaxTemp': [20.0, 21.0, 22.0, 23.0, 24.0],
'Precipitation': [0.0, 0.2, 0.5, 0.0, 0.0],
'ReferenceET': [4.0, 4.1, 4.2, 4.3, 4.4],
'Date': pd.date_range(start='2024-08-23', periods=5, freq='D')
}
Criar DataFrame original
weather_df = pd.DataFrame(data)
Extender os dados climáticos até 31 de dezembro de 2024
extended_dates = pd.date_range(start='2024-08-23', end='2024-12-31', freq='D')
min_temp_mean = weather_df['MinTemp'].mean()
max_temp_mean = weather_df['MaxTemp'].mean()
precipitation_mean = weather_df['Precipitation'].mean()
reference_et_mean = weather_df['ReferenceET'].mean()
Criar os dados estendidos
extended_data = {
'Date': extended_dates,
'MinTemp': [min_temp_mean] * len(extended_dates),
'MaxTemp': [max_temp_mean] * len(extended_dates),
'Precipitation': [precipitation_mean] * len(extended_dates),
'ReferenceET': [reference_et_mean] * len(extended_dates)
}
weather_df_extended = pd.DataFrame(extended_data)
Ajustar tipos de dados
weather_df_extended['Date'] = pd.to_datetime(weather_df_extended['Date'])
weather_df_extended['MinTemp'] = weather_df_extended['MinTemp'].astype(float)
weather_df_extended['MaxTemp'] = weather_df_extended['MaxTemp'].astype(float)
weather_df_extended['Precipitation'] = weather_df_extended['Precipitation'].astype(float)
weather_df_extended['ReferenceET'] = weather_df_extended['ReferenceET'].astype(float)
Assegurar que Date seja uma coluna normal
weather_df_extended.reset_index(drop=True, inplace=True)
Garantir a ordem das colunas
weather_df_extended = weather_df_extended[['Date', 'MinTemp', 'MaxTemp', 'Precipitation', 'ReferenceET']]
Verificar o DataFrame ajustado
print("Verificando o DataFrame ajustado 'weather_df_extended':")
print(weather_df_extended.dtypes)
print(weather_df_extended.head())
Configuração do solo e da cultura
loamy_sand = Soil('LoamySand')
potato = Crop('PotatoLocalGDD', planting_date='04/25')
Inicializar o conteúdo de água no solo (Capacidade de Campo)
fc = InitialWaterContent(value=['FC'])
Definir datas de início e término da simulação no formato correto
sim_start = '2024/08/23'
sim_end = '2024/09/30' # Reduzir o período para um mês, no formato correto
Lista para armazenar as datas e profundidades de irrigação
dates = []
depths = []
Critério de precipitação acumulada
precip_threshold = 10 # mm acumulados em 7 dias
irrigation_depth = 25 # mm por evento de irrigação
Verificar as condições climáticas dia a dia e decidir sobre a irrigação
for i, day in enumerate(weather_df_extended['Date']):
daily_precip = weather_df_extended.loc[weather_df_extended['Date'] == day, 'Precipitation'].values[0]
print(f"Data: {day}, Precipitação diária: {daily_precip} mm")
Criar o cronograma de irrigação
schedule = pd.DataFrame({'Date': dates, 'Depth': depths})
print(f"\nTabela de Irrigação Agendada:\n{schedule}")
Após criar o cronograma de irrigação
schedule = pd.DataFrame({'Date': dates, 'Depth': depths})
print(f"\nTabela de Irrigação Agendada:\n{schedule}")
Adicionar a verificação aqui
if schedule.empty:
# Adicionar um evento de irrigação padrão se o cronograma estiver vazio
schedule = pd.DataFrame({'Date': [sim_start], 'Depth': [irrigation_depth]})
print("Nenhuma irrigação necessária durante o período de simulação, adicionando irrigação padrão.")
Continuar com a configuração do gerenciamento de irrigação
irrigation_management = IrrigationManagement(irrigation_method=3, schedule=schedule)
Inicializar o modelo AquaCrop
try:
model = AquaCropModel(sim_start_time=sim_start,
sim_end_time=sim_end,
weather_df=weather_df_extended,
soil=loamy_sand,
crop=potato,
irrigation_management=irrigation_management,
initial_water_content=fc)
except ValueError as e:
print(f"Erro ao inicializar o modelo AquaCrop: {e}")
except IndexError as e:
print(f"Erro no cálculo do calendário de cultivo: {e}")
It turns out that it presents the following error: [125 rows x 2 columns] Error calculating the crop calendar: index -1 is out of bounds for axis 0 with length 0. What could it be?
Beta Was this translation helpful? Give feedback.
All reactions