Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BiomeE output contains repeated cID since splitting does not generate a new cID #280

Open
5 tasks
fabern opened this issue Jan 9, 2025 · 2 comments
Open
5 tasks
Assignees

Comments

@fabern
Copy link
Member

fabern commented Jan 9, 2025

The column cID in the BiomeE model output contains repeated values for single years.
I would expect each cID to appear only once for each year.

> rsofun::biomee_p_model_output$data[[1]]$output_annual_cohorts |> tibble() |> arrange(year)
# A tibble: 5 × 35
  cohort  year   cID   PFT layer density flayer    DBH   dDBH height   age        BA      dBA  Acrown   Aleaf
  <chr>  <dbl> <dbl> <dbl> <dbl>   <dbl>  <dbl>  <dbl>  <dbl>  <dbl> <dbl>     <dbl>    <dbl>   <dbl>   <dbl>
1 1        251    25     1     1   122.  0.206  23.7   0.429   17.5  80.9  0.0442     1.58e-3 17.3    54.6   
2 2        251    25     1     1    12.9 0.0130 16.9   0.391   14.8  80.9  0.0224     1.02e-3 10.4    32.8   
3 3        251    25     1     1  4783.  0.781   5.18  0.268    8.19 29.8  0.00211    2.13e-4  1.77    5.57  
4 4        251    25     1     2  1298.  0.0252  4.19  0.0599   7.37 29.8  0.00138   -5.15e-4  1.29    2.03  
5 5        251    25     1     2 37832.  0.0831  0.371 0.0300   2.19  2.85 0.0000108 -7.82e-9  0.0339  0.0366
# ℹ 20 more variables: nsc <dbl>, seedC <dbl>, leafC <dbl>, rootC <dbl>, sapwC <dbl>, woodC <dbl>, nsn <dbl>,
#   treeG <dbl>, fseed <dbl>, fleaf <dbl>, froot <dbl>, fwood <dbl>, GPP <dbl>, NPP <dbl>, Rauto <dbl>,
#   Nupt <dbl>, Nfix <dbl>, n_deadtrees <dbl>, c_deadtrees <dbl>, deathrate <dbl>

Below MWE indicates, that upon splitting of cohorts no new cIDs are generated.
Thus we end up with multiple times the same ID for distinct cohorts.

  • check if the main culprit is in relayer_cohorts()
    • probably here it should attribute a new ccID and increase MaxCohortID, instead of copying over the old one (Should we rename this to nextFreeCcID?)
      newCC(i) = oldCC(idx(k))
  • check what happens when vegn_mergecohorts() (can we make it so that ccID of the larger one remains?)
  • in both the above functions what happens with cohort properties other than ccID
  • side-quest: in below MWE why do we get extremely small numbers (1e-323) or 9999 when setting: spinup <- FALSE (Note that cohort is at 8188. One-off error?
@fabern
Copy link
Member Author

fabern commented Jan 9, 2025

Promised MWE:

MWE (for test-driven-development)

# Test gs_leuning simulation:
new_biomee_gs_leuning_output <- runread_biomee_f(
  biomee_gs_leuning_drivers,
  makecheck = TRUE,
  parallel = FALSE)
new_biomee_gs_leuning_output_cohort <- new_biomee_gs_leuning_output |>
  unnest_wider(data, simplify = FALSE) |>
  unnest(output_annual_cohorts)
new_biomee_gs_leuning_output_cohort |>
  group_by(year) |>
  summarise(cohort_IDs = paste0(cID, collapse=","),
            has_duplicated_cID = any(duplicated(cID))) |>
  tail()

# Test p_model transient simulation over 250 years (remove spinup to understand what happens):
new_biomee_p_model_drivers <- biomee_p_model_drivers
forcing_2009 <- new_biomee_p_model_drivers$forcing[[1]]
new_forcing <- forcing_2009
base_year <- lubridate::year(new_forcing$date[1])
for (it in 1:250){
  add_year_forcing <- forcing_2009
  lubridate::year(add_year_forcing$date) <- base_year + it
  new_forcing <- bind_rows(new_forcing, add_year_forcing)
}
new_biomee_p_model_drivers$forcing[[1]] <- new_forcing
new_biomee_p_model_drivers$params_siml[[1]]$spinup <- TRUE # NOTE if we set this to FALSE this gives gibberish output
new_biomee_p_model_drivers$params_siml[[1]]$spinupyears <- 0
new_biomee_p_model_drivers$params_siml[[1]]$nyeartrend  <- nrow(new_biomee_p_model_drivers$forcing[[1]])/365
new_biomee_p_model_output <- runread_biomee_f(
  new_biomee_p_model_drivers,
  makecheck = TRUE,
  parallel = FALSE)
new_biomee_p_model_output_cohort <- new_biomee_p_model_output |>
  unnest_wider(data, simplify = FALSE) |>
  select(sitename, output_annual_cohorts) |>
  unnest(output_annual_cohorts)
# new_biomee_p_model_output_cohort |> print(n=100)
# new_biomee_p_model_output_cohort |> group_by(cID) |> summarise(years = paste0(year, collapse=","))
new_biomee_p_model_output_cohort |> group_by(year) |> 
  summarise(cohort_IDs = paste0(cID, collapse=","),
            has_duplicated_cID = any(duplicated(cID))) |> print(n=50) # duplication starts in year 38
  # # A tibble: 251 × 3
  #     year cohort_IDs                      has_duplicated_cID
  #    <dbl> <chr>                           <lgl>             
  #  1     1 1                               FALSE             
  #  2     2 1                               FALSE             
  #  3     3 1                               FALSE             
  #  4     4 1                               FALSE             
  #  5     5 1                               FALSE             
  #  6     6 1                               FALSE             
  #  7     7 1                               FALSE             
  #  8     8 1                               FALSE             
  #  9     9 1                               FALSE             
  # 10    10 1,2                             FALSE             
  # 11    11 1,2                             FALSE             
  # 12    12 1,2                             FALSE             
  # 13    13 1,2,3                           FALSE             
  # 14    14 1,2,3                           FALSE             
  # 15    15 1,2,3,4                         FALSE             
  # 16    16 1,2,3,4                         FALSE             
  # 17    17 1,2,3,4,5                       FALSE             
  # 18    18 1,2,3,4,5,6                     FALSE             
  # 19    19 1,2,3,4,5,7                     FALSE             
  # 20    20 1,2,3,4,5,7,8                   FALSE             
  # 21    21 1,2,3,4,5,7,9                   FALSE             
  # 22    22 1,2,3,4,5,7,9,10                FALSE             
  # 23    23 1,2,3,4,5,7,9,11                FALSE             
  # 24    24 1,2,3,4,5,7,9,11,12             FALSE             
  # 25    25 1,2,3,5,7,9,11,13               FALSE             
  # 26    26 1,2,3,5,7,9,11,13,14            FALSE             
  # 27    27 1,2,3,5,7,9,11,13,15            FALSE             
  # 28    28 1,2,3,5,7,9,11,13,15,16         FALSE             
  # 29    29 1,2,3,5,7,9,11,13,15,17         FALSE             
  # 30    30 1,2,3,5,9,11,13,15,17,18        FALSE             
  # 31    31 1,2,3,5,9,11,13,15,17,19        FALSE             
  # 32    32 1,2,3,5,9,11,13,15,17,19,20     FALSE             
  # 33    33 1,2,3,5,9,11,13,15,17,19,21     FALSE             
  # 34    34 1,2,3,5,9,11,15,17,19,21,22     FALSE             
  # 35    35 1,2,3,5,9,11,15,17,19,21,23     FALSE             
  # 36    36 1,2,3,5,9,11,15,17,19,21,23,24  FALSE             
  # 37    37 1,2,5,9,11,15,17,19,21,23,24,25 FALSE             
  # 38    38 1,2,5,9,11,15,19,21,21,23,25    TRUE              
  # 39    39 1,2,5,11,15,15,19,21,23,25      TRUE    

new_biomee_p_model_output_cohort |> group_by(year) |> 
  summarise(cohort_IDs = paste0(cID, collapse=","),
            has_duplicated_cID = any(duplicated(cID))) |> tail()      # now only cohort 25 remains duplicated
  # # A tibble: 6 × 3
  #    year cohort_IDs        has_duplicated_cID
  #   <dbl> <chr>             <lgl>             
  # 1   246 25,25,25,25,25,25 TRUE              
  # 2   247 25,25,25,25,25    TRUE              
  # 3   248 25,25,25,25,25    TRUE              
  # 4   249 25,25,25,25,25    TRUE              
  # 5   250 25,25,25,25,25    TRUE              
  # 6   251 25,25,25,25,25    TRUE    

@fabern fabern assigned fabern and marcadella and unassigned fabern Jan 9, 2025
@fabern
Copy link
Member Author

fabern commented Jan 9, 2025

Below plot shows an animation of the DBH of distinct cohorts, labelled with their IDs. Towards the end (years ~110) we can see how cohort with cID 25 grows in the top layer and spawns subcanopy cohorts with the same cID.

animated_plot1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants