biopsichas / SWATprepR

SWAT+ model input data preparation helper
https://biopsichas.github.io/SWATprepR/
MIT License
8 stars 2 forks source link

script workflow to produce SWAT+ dataset from netcdf file [Climate projections] #4

Closed echiaradia closed 9 months ago

echiaradia commented 9 months ago

Hi @biopsichas/all starting from a list of existing weather stations, I'd like to produce the weather scenarios from netCDF files so I followed these steps:

  1. load template file (OK)
    temp_path <- paste0("./test/", "weather_data.xlsx")
    met_lst <- load_template(temp_path, 4326)
  2. load cordex netCDF files (OK, I see all the file processed and also plotting functions work as expected)
    cordex_path <- paste0('./09-gridded_NEW/CORDEX-BC/')
    climate_lst <- load_netcdf_weather(cordex_path, met_lst)
  3. prepare climate dataset for rcp26/2 (NOT OK)
    prepare_climate(climate_lst$rcp26$"2", "./test2", "1991-01-01", "2020-12-31")

    Step 3 returns the following error:

    [1] "weather-wgn.cli file was successfully written."
    [1] "weather-sta.cli file was successfully written."
    Error in UseMethod("mutate") : 
    no applicable method for 'mutate' applied to an object of class "NULL"
    In addition: Warning message:
    In prepare_wgn(meteo_lst) :
    These variables MAXHHR are missing for some of the stations.
      Closest stations with data will be used to fill existing gaps. MAXHHR will be calculated by PCP*0.38. 
    Please use optional function parameters, if you want specific data to be used in filling missing variables for stations.

    Is the workflow correct? Could you provide a sample script?

biopsichas commented 9 months ago

Hi Enrico, sorry for delay. I wonder if you have the latest version of prepR? If yes, this workflow in step 4 has what you are asking. Also in this github page the last code presents (in less efficient way), how it should be run to obtain model files. The easiest explanation would be that your folder is missing these files "aquifer.con", "chandeg.con", "hru.con", "reservoir.con", "rout_unit.con", "time.sim". They have to be in your "./test2" directory as they are updated for the weather data. Maybe not needed in your case, but just the way it works now. Please let me know if this helped you.

echiaradia commented 9 months ago

thanks @biopsichas ! finally I realized that the problem was with the nickname of the weather stations that must be in CAPITALS in the excel file. enrico