Skip to contents

This vignette runs through an example workflow to derive Environmental Covariates (ECs) from weather and soil data for a multi-environment trial analysis using the example datasets included in the EC4MET package.

Installing EC4MET

The EC4MET package can be installed from Github and loaded from your library.

# devtools::install_github("NickFlagleaf/EC4MET", build_vignettes = T)
library(EC4MET)

Example work flow

Load package and example dataset of info for field trial environments:

data("CAIGE20_22envs")

The example data set includes environment names, lat and lon values and sowing dates for 36 trial environments in Australia as part of the CAIGE project (Trethowan et al. 2024) as well as fitted environmental main effects and factor loadings fitted from a factor analytic mixed model multi-environment trial (MET) analysis as described by (Fradgley et al. 2025; Smith et al. 2021).

head(CAIGE20_22envs)

Get ECs for observed environments

Get daily weather data from SILO (Jeffrey et al. 2001) for each observed environment in the MET with the get.SILO.weather() function:

obs.wthr <- get.SILO.weather(
  Envs = CAIGE20_22envs$Environment,
  Lats = CAIGE20_22envs$Lat,
  Lons = CAIGE20_22envs$Long,
  Years = CAIGE20_22envs$Year,
  verbose = T
)

The get.BARRA.weather() function can similarly be used to extract different weather data from the BARRA-R2 data resource (Su et al. 2022) and should output data in the same format.

You can see that the $data output from this contains a data matrix for each of six weather variables with the 36 environments as rows and 365 days of the year as columns:

sapply(obs.wthr$data, dim)

A daily index of soil moisture can also be estimated be calculated based on the rainfall, temp, and day length and added to the weather data object:

obs.wthr <- add.SMI(obs.wthr)

The weather data can then be used to define crop growth stage specific ECs for each environment.

obs.weather.ECs <- get.W.ECs(
  weather = obs.wthr,
  sow.dates = CAIGE20_22envs$Sowing.date,
  verbose = T
)

You can see that the output from this function includes (ECs) a data frame of 104 ECs as columns for 36 environments as rows as well as a data frame (gs.dates) of estimated dates of crop growth stages that the ECS were calculated between:

dim(obs.weather.ECs$ECs)
head(obs.weather.ECs$gs.dates)

As well as weather related ECs, soil attribute covariates can be extracted using the get.S.ECs function from the SLGA data resource (Grundy et al. 2015).

obs.soil.ECs <- get.S.ECs(
  Envs = CAIGE20_22envs$Environment,
  Lats = CAIGE20_22envs$Lat,
  Lons = CAIGE20_22envs$Long,
  verbose = F
)

The soil EC data matrix is also in the same format with 36 environments as rows and 96 soil ECS as columns:

dim(obs.soil.ECs)

For more information on how ECs are calculated, see Fradgley et al. (2025) .

Get ECs for a wider set of unobserved environments

An example dataset of gridded environment locations that cover the extend of the Australian wheat belt is also included in the package. This dataset includes 5,091 unique environments between 2018 and 2020.

data("wheat.area.envs")
head(wheat.area.envs)
dim(wheat.area.envs)
unique(wheat.area.envs$Year)

ECs for all of these untested environments can be extracted and calculated in a similar way as for the observed data.

wheat.area.wthr <- get.SILO.weather(
  Envs = wheat.area.envs$Env,
  Lats = wheat.area.envs$Lat,
  Lons = wheat.area.envs$Lon,
  Years = wheat.area.envs$Year,
  verbose = T
)

wheat.area.wthr<-add.SMI(wheat.area.wthr)

wheat.area.wthr.ECs <- get.W.ECs(
  weather = wheat.area.wthr,
  sow.dates = wheat.area.envs$sow.dates,
  verbose = T
)

wheat.area.soil.ECs <- get.S.ECs(
  Envs = wheat.area.envs$Env,
  Lats = wheat.area.envs$Lat,
  Lons = wheat.area.envs$Lon,
  verbose = T
)

Combine weather and soil ECs for the observed and wheat belt environments:

obsECs <- cbind(obs.weather.ECs$ECs, obs.soil.ECs)

wheat.area.ECs <- cbind(wheat.area.wthr.ECs$ECs, wheat.area.soil.ECs)

Predict into unobserved environments

Predict environmental effects defibed in the observed environments dataset for all wheat belt environments based on the ECs using the pred.env.effs() function:

obs.env.effs <- CAIGE20_22envs[, c("Main_E_effect", "FA1", "FA2", "FA3")]
rownames(obs.env.effs) <- CAIGE20_22envs$Environment
wheat.area.preds <- pred.env.effs(
  train.ECs = obsECs,
  new.ECs = wheat.area.ECs,
  E.effs = obs.env.effs
)

Environment type iClasses that are defined from the combination of either positive or negative factor loadings for each environment can be calculated as described by Smith et al. (2021). These iClass environement types can then be plotted for all environments in the Australian grain belt on maps for each year:

iclasses <- apply(wheat.area.preds[, c("FA1", "FA2", "FA3")], 1, function(x) paste(ifelse(x > 0, "p", "n"), collapse = ""))

iclass.cols <- c("#30123BFF", "#1AE4B6FF", "#FABA39FF", "#7A0403FF")
names(iclass.cols) <- unique(iclasses)
par(mfrow = c(2, 2), mar = c(1, 1, 1, 1))
for (y in unique(wheat.area.envs$Year)) {
  oz::oz()
  points(wheat.area.envs$Lon[wheat.area.envs$Year == y],
    wheat.area.envs$Lat[wheat.area.envs$Year == y],
    pch = 15, cex = .5,
    col = iclass.cols[iclasses[wheat.area.envs$Year == y]]
  )
  mtext(text = y, side = 3, line = -1.5, cex = 1.2)
}

References

Fradgley, Nick, Guillermo Gerard, Velu Govindan, Julie M. Nicol, Amit Singh, Wuletaw Tadesse, Alexander B. Zwart, Richard Trethowan, Ben Trevaskis, and Jessica Hyles. 2025. “Prediction of Australian Wheat Genotype by Environment Interactions and Mega-Environments.” Under Review.
Grundy, M. J., R. A. Viscarra Rossel, R. D. Searle, P. L. Wilson, C. Chen, L. J. Gregory, M. J. Grundy, et al. 2015. “Soil and Landscape Grid of Australia.” Soil Research 53 (8): 835–44. https://doi.org/10.1071/SR15191.
Jeffrey, Stephen J., John O. Carter, Keith B. Moodie, and Alan R. Beswick. 2001. “Using Spatial Interpolation to Construct a Comprehensive Archive of Australian Climate Data.” Environmental Modelling & Software 16 (4): 309–30. https://doi.org/10.1016/S1364-8152(01)00008-1.
Smith, Alison, Adam Norman, Haydn Kuchel, and Brian Cullis. 2021. “Plant Variety Selection Using Interaction Classes Derived from Factor Analytic Linear Mixed Models: Models with Independent Variety Effects.” Frontiers in Plant Science 12. https://www.frontiersin.org/articles/10.3389/fpls.2021.737462.
Su, Chun-Hsu, Imtiaz Dharssi, John Le Marshall, Tan Le, Susan Rennie, Andy Smith, Christian Stassen, Peter Steinle, Joshua Torrance, and Carl Wang. 2022. BARRA2: Development of the Next-Generation Australian Regional Atmospheric Reanalysis. Bureau of Meteorology. https://www.researchgate.net/profile/Chun-Hsu-Su/publication/386087051_BARRA2_Development_of_the_next-generation_Australian_regional_atmospheric_reanalysis/links/6743073b868c966b932ab725/BARRA2-Development-of-the-next-generation-Australian-regional-atmospheric-reanalysis.pdf.
Trethowan, Richard M., Julie M. Nicol, Amit Singh, Ravi P. Singh, Wuletaw Tadesse, Velu Govidan, Leonardo Crespo-Herrera, et al. 2024. “The CIMMYT Australia ICARDA Germplasm Evaluation Concept: A Model for International Cooperation and Impact.” Frontiers in Plant Science 15 (July). https://doi.org/10.3389/fpls.2024.1435837.