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

Regeneration during the dormant period cause model crash #102

Open
trotsiuk opened this issue Nov 27, 2024 · 0 comments
Open

Regeneration during the dormant period cause model crash #102

trotsiuk opened this issue Nov 27, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@trotsiuk
Copy link
Owner

trotsiuk commented Nov 27, 2024

Description

If there is a new cohort regenerated of broadleaf species during the dormant period it seems to cause the model crash. This issue is occurring most likely due to the correct_bias part, where we have the log(age). At this point in time the age is 0 which case the issue.

https://github.com/trotsiuk/r3PG/blob/master/src/md_3PG.f95#L1643

This issue seems not to be a problem if the regeneration occurs during the growing period (not dormant).

Another explanation can be that there are some further allocations related to it.

Code

This is very specific issue. With the code below everything works well those. Need more tests for the code

library(r3PG)
library(dplyr)
library(ggplot2)


# Run with regeneration ---------------------------------------------------

# create a regeneration part

d_species_r <- d_species %>%
  dplyr::mutate( species = paste0(species, '_r'),
                 planted = '2006-01',
                 stems_n = 1000,
                 biom_stem = 1,
                 biom_root = 1,
                 biom_foliage = 1) %>%
  # dplyr::bind_rows(dplyr::mutate(d_species, dplyr::across( c(stems_n, biom_stem, biom_root, biom_foliage), ~.*0.2)), .)
  dplyr::bind_rows( d_species, .)

d_thinning_r <- d_thinning %>%
  dplyr::mutate(stems_n = stems_n * 0.2)

d_parameters_r <- d_parameters %>%
  dplyr::rename_at( vars(-parameter),function(x) paste0(x,"_r") ) %>%
  dplyr::inner_join( d_parameters, ., by = 'parameter')

d_sizeDist_r <- d_sizeDist %>%
  dplyr::rename_at( vars(-parameter),function(x) paste0(x,"_r") ) %>%
  dplyr::inner_join( d_sizeDist, ., by = 'parameter')

  
out_3PG <- run_3PG(
  site        = d_site, 
  species     = d_species_r, 
  climate     = d_climate, 
  # thinning    = NULL,
  thinning    = d_thinning_r,
  parameters  = d_parameters_r, 
  size_dist   = d_sizeDist_r,
  settings    = list(light_model = 2, transp_model = 2, phys_model = 2, 
                     height_model = 1, correct_bias = 1, calculate_d13c = 0),
  check_input = TRUE, df_out = TRUE)


i_var <- c('stems_n',  'dbh', 'height', 'biom_stem', 'biom_root', 'biom_foliage')
i_lab <- c('Stem density', 'DBH', 'Height', 'Stem biomass', 'Root biomass', 'Foliage biomass')

out_3PG %>%
  filter(variable %in% i_var) %>%
  mutate(variable = factor(variable, levels = i_var)) %>%
  ggplot( aes(date, value))+
  geom_line( aes(color = species), size = 0.5)+
  facet_wrap( ~ variable, scales = 'free_y', ncol = 3, 
              labeller = labeller(variable = setNames(i_lab, i_var) )) +
  scale_color_brewer('', palette = 'Dark2') +
  theme_classic()+
  theme(legend.position="bottom")+
  xlab("Calendar date") + ylab('Value')  


explore.data <- out_3PG %>%
  dplyr::filter( date %in% c(as.Date('2006-12-31'), as.Date('2006-01-31'), as.Date('2006-02-28'), as.Date('2006-03-31'), as.Date('2006-04-30'), as.Date('2006-05-31'))) %>%
  tidyr::pivot_wider( names_from = 'date', values_from = 'value')


image

@trotsiuk trotsiuk self-assigned this Nov 27, 2024
@trotsiuk trotsiuk added the bug Something isn't working label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant