A simple example of using the Daisy wrapper for remote execution. Daisy files are included in the script, so theres no external dependencies.

See https://github.com/nitrogensensor/daisywrapper for more information.

First download the wrapper (daisy.jar) so we can run simulations remotely, if we don’t have it already

if (!file.exists("daisy.jar")) 
  download.file("https://daisy.nitrogensensor.eu/resultat/diverse/daisy.jar", "daisy.jar")

Create input directory and a Daisy script file

unlink("daisyInput", recursive = TRUE)
dir.create("daisyInput")

script='
;; Including external library-files
(input file "tillage.dai")
(input file "crop.dai")
(input file "fertilizer.dai")
(input file "log.dai")

;; Weather data
(weather default "dk-taastrup.dwf")

;;  Defining soil horizons of a fine sandy loam
(defhorizon      "Ap F.S.L." FAO3
    "Data from Jacobsen 1983"
    (dry_bulk_density 1.53 [g/cm^3])
    (clay 0.113 [])
    (silt 0.277 [])
    (sand 0.584 [])
    (humus 0.026 [])
    (C_per_N 11.0 [g C/g N]))

(defhorizon "B F.S.L." FAO3
    (dry_bulk_density 1.51 [g/cm^3]) 
    (clay 0.235 [])
    (silt 0.253 [])
    (sand 0.507 [])
    (humus 0.005 [])
    (C_per_N 11.0 [g C/g N]))

(defhorizon "C F.S.L." FAO3
    (dry_bulk_density 1.57 [g/cm^3]) 
    (clay 0.244 [])
    (silt 0.283 [])
    (sand 0.471 [])
    (humus 0.002 [])
    (C_per_N  11.0))    ; Note that the dimension is omittet

;;  Parameterisation of column (Fine sandy loam)
(defcolumn "Fine sandy loam" default
     (Soil (MaxRootingDepth 100 [cm])
           (horizons (  -30 [cm] "Ap F.S.L.")
                     (  -80 [cm] "B F.S.L.")
                     ( -400 [cm] "C F.S.L.")))
     (Groundwater deep)
     (OrganicMatter original (init (input 3000 [kg C/ha/y]))))

;; Spring Barley setup.
(defaction "SBarley_management" activity
  (wait_mm_dd 3 20)
  (plowing)
  (wait_mm_dd 4 15) 
  (seed_bed_preparation)
  (sow "Spring Barley")
  (wait_mm_dd 4 20) 
  (fertilize (N25S (weight 95 [kg N/ha])))
  (wait (or (crop_ds_after "Spring Barley" 2.0) ;Ripe
            (mm_dd 9 1))) (harvest "Spring Barley"))

;;  Selecting column
(column "Fine sandy loam")

;; Start and end of simulation.
(time 1993 1 1)
(stop 1995 1 1)

;; Selecting management
(manager activity
  "SBarley_management"
)
;; Selecting output 
;;  Description that will occur in all output files
(description "Spring Barley; Soil: Fine sandy loam; Weather: Taastrup")

;(activate_output (after 1993 03 31 23))
(log_prefix "Ex1/")
(output harvest
        ("Crop Production" (when daily))
;;      Water balance 0-100 cm  
        ("Field water" (to -400 [cm])(when daily)
         (where "Daily_FWB.csv") (print_header false) (print_dimension false))  
;;      Nitrogen balance 0-100 cm  
        ("Field nitrogen" (to -400 [cm])(when daily)
          (where "Daily_FNB.dlf"))  
;;      Soil profile data
        ("Soil Water Content"       (when daily))
        ("Soil Water Potential (pF)"(when daily))
        ("Soil NO3 Concentration"   (when daily))
)
'

write(script,"daisyInput/Exercise01.dai")
dir.create("daisyInput/Ex1/")

Run a single daisy simulation.

This chunk runs daisy on Exercise01.dai. Make sure that you have that file in the same directory as this script.

getwd()
## [1] "/cloud/project"
# unlink("daisyOutput", recursive = TRUE)
system2("java", "-jar daisy.jar client -d daisyInput Exercise01.dai -o daisyOutput")

Load daisy results into a dataframe

Daily_FWB <- read.delim("daisyOutput/Exercise01/Ex1/Daily_FWB.csv")
Daily_FWB$date <- as.Date(paste(Daily_FWB$year, Daily_FWB$month, Daily_FWB$mday, sep = '-'), format = '%Y-%m-%d')
head(Daily_FWB)
##   year month mday hour Precipitation Irrigation Potential.evapotranspiration
## 1 1993     1    1    0             0          0                            0
## 2 1993     1    2    0             0          0                            0
## 3 1993     1    3    0             0          0                            0
## 4 1993     1    4    0             0          0                            0
## 5 1993     1    5    0             0          0                            0
## 6 1993     1    6    0             0          0                            0
##   Actual.evapotranspiration Matrix.percolation Biopore.percolation
## 1                         0          0.0000000                   0
## 2                         0          0.0778966                   0
## 3                         0          0.0778069                   0
## 4                         0          0.0776550                   0
## 5                         0          0.0775995                   0
## 6                         0          0.0775350                   0
##   Matrix.drain.flow Biopore.drain.flow Runoff Biopore.water Soil.matrix.water
## 1                 0                  0      0             0           1200.70
## 2                 0                  0      0             0           1200.62
## 3                 0                  0      0             0           1200.54
## 4                 0                  0      0             0           1200.47
## 5                 0                  0      0             0           1200.39
## 6                 0                  0      0             0           1200.31
##   Surface.water       date
## 1             0 1993-01-01
## 2             0 1993-01-02
## 3             0 1993-01-03
## 4             0 1993-01-04
## 5             0 1993-01-05
## 6             0 1993-01-06

Plot the results

plot(Daily_FWB$date, Daily_FWB$Actual.evapotranspiration)