femiguez / apsimx

R package for APSIM-X

Home Page:https://femiguez.github.io/apsimx-docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Weather file using apsimx library and get_iem_apsim_met() not working

pathakprecisionag opened this issue · comments

I am writing an rscript to simulate the corn growth using APSIM and using the following code to extract the weather:
current_date <-Sys.Date()`

current_year <- format(current_date,"%Y")

`start_date <- paste("01-01",current_year, sep ="-")`

`start_date <- as.Date(start_date, format = "%d-%m-%Y")`

`end_date <- current_date - 1`

`print(start_date)`

`print(en_date)`

`weat_cur<-get_iem_apsim_met(lonlat = c(input$longitude, input$latitude), dates = c(start_date, en_date))`

`print(weat_cur)`

and getting the following error:
Warning in open.connection(con, "rb") :
cannot open URL 'http://mesonet.agron.iastate.edu/geojson/network.php?network=INCLIMATE': HTTP status was '503 Service Unavailable'
Warning: Error in open.connection: cannot open the connection to 'http://mesonet.agron.iastate.edu/geojson/network.php?network=INCLIMATE'

Just to clarify, I am simulating this experiment for Indiana using mesonet rather than power.

Any guidance/help will be highly appreciated

@pathakprecisionag If I were to create a 'met' object for APSIM I would try to get at least 30 years of data. You seem to want to start your simulations for the current year. Depending on your objectives, you want to start the model a bit before the period of interest. The error message seems to indicate that the server was not available. This happens every once in a while. Can you try again? This works for me. I picked July 1st, but data are often available almost immediately, so you could try with something closer to the current date.

iem.wl <- get_iem_apsim_met(lonlat = c(-86.9, 40.3),
                            dates = c("1990-01-01", "2024-07-01"))

Something I notice now is that you enter the dates as 'Date' objects, but the function expects just a 'character' in the format "%Y-%m-%d". I can add a check for the format in the function.

Thanks much for your help. I think there was some issue on the end of API and now works well!