Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • airGRiwrm airGRiwrm
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 27
    • Issues 27
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 3
    • Merge requests 3
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar

La forge institutionnelle d'INRAE étant en production depuis le 10 juin 2025, nous vous invitons à y créer vos nouveaux projets.

  • IN-WOP
  • airGRiwrmairGRiwrm
  • Issues
  • #138
Closed
Open
Issue created Jul 31, 2023 by Thibault Hallouin@thibault.hallouin

Problem when trying to fix parameter values in semi-distributed mode

Hi,

I think there is a bug when trying to fix parameters in a semi-distributed mode. It seems to be due to the varying numbers of parameters for each sub-basin (depending on the presence of a lag model or not). Here is an example (reusing some code written by @guillaume.thirel, thanks Guillaume):

library(airGRiwrm)
rm(list = ls())

data(Severn)
data(X0310010)

## hydro network
gauges <- c("54057", "54032", "54001")
nodes <- Severn$BasinsInfo[, c("gauge_id", "downstream_id", "distance_downstream", "area")]
nodes <- nodes[nodes$gauge_id %in% gauges, ]
nodes$model <- "RunModel_CemaNeigeGR4J"

griwrm <- airGRiwrm::CreateGRiwrm(
  nodes, 
  list(id="gauge_id", down="downstream_id", length="distance_downstream")
)

## inputs
basins_obs <- Severn$BasinsObs

dates <- basins_obs[[1]]$DatesR

precip_tot <- cbind(sapply(basins_obs, function(x) {x$precipitation}))
pot_evap_tot <- cbind(sapply(basins_obs, function(x) {x$peti}))
q_obs <- cbind(sapply(basins_obs, function(x) {x$discharge_spec}))

precip <- airGRiwrm::ConvertMeteoSD(griwrm, precip_tot[, griwrm$id])
pot_evap <- airGRiwrm::ConvertMeteoSD(griwrm, pot_evap_tot[, griwrm$id])

hypso <- array(
  data=rep(BasinInfo$HypsoData, 3),
  dim=c(101,3)
)
colnames(hypso) <- gauges

inputs_model <- airGRiwrm::CreateInputsModel(
  griwrm, 
  DatesR=dates, 
  Precip=precip, 
  PotEvap=pot_evap,
  TempMean=pot_evap+5,  # fake Temp
  HypsoData=hypso,
  NLayers=setNames(c(5, 6, 7), gauges),
  IsHyst=TRUE
)

calib_options <- airGRiwrm::CreateCalibOptions(
  inputs_model, 
  FixedParam=c(
    NA,   # C      (lag)
    NA,   # X1     (GR4J)
    NA,   # X2     (GR4J)
    NA,   # X3     (GR4J)
    NA,   # X4     (GR4J)
    0.25, # cT     (CemaNeige)
    NA,   # Kf     (CemaNeige)
    10,   # Gacc   (CemaNeige)
    NA    # Gseuil (CemaNeige)
  )
)

which results for me in the following error:

Error in (function (FUN_MOD, FUN_CALIB = Calibration_Michel, FUN_TRANSFO = NULL, : Incompatibility between 'FixedParam' length and 'FUN_MOD'

The following trick (provided to me by @laurent.strohmenger, thanks Laurent) bypasses the problem:

calib_options <- airGRiwrm::CreateCalibOptions(
  inputs_model
)

for (code in names(calib_options))
{
  n_param <- length(calib_options[[code]]$FixedParam)
  
  if (n_param == 9)
  {
    calib_options[[code]]$FixedParam <- c(
      NA,   # C      (lag)
      NA,   # X1     (GR4J)
      NA,   # X2     (GR4J)
      NA,   # X3     (GR4J)
      NA,   # X4     (GR4J)
      0.25, # cT     (CemaNeige)
      NA,   # Kf     (CemaNeige)
      10,   # Gacc   (CemaNeige)
      NA    # Gseuil (CemaNeige)
    )
  }
  else if (n_param == 8)
  {
    calib_options[[code]]$FixedParam <- c(
      NA,   # X1     (GR4J)
      NA,   # X2     (GR4J)
      NA,   # X3     (GR4J)
      NA,   # X4     (GR4J)
      0.25, # cT     (CemaNeige)
      NA,   # Kf     (CemaNeige)
      10,   # Gacc   (CemaNeige)
      NA    # Gseuil (CemaNeige)
    )
  }
  else
  {
    stop("sub-basin with number of parameters not equal to 8 or 9")
  }
}
Edited Jul 31, 2023 by Thibault Hallouin
Assignee
Assign to
Time tracking