PredictiveEcology / CBMutils

Utilities for modelling carbon in R based on CBM-CFS3
0 stars 1 forks source link

need to check the overmature decline matrices assignments in the c++ function ComputeGrowthAndDeclineMatrices2( #7

Open cboisvenue opened 4 years ago

cboisvenue commented 4 years ago

In the process of making checking functions for the c transactions, I saw that, in the case of the sims I was looking for only one pixelGroup has a matrix that was not all 1s. That pixelGroup was 2 years old...Some checking of how these are assgined in the c++ function is required.

##### OVER MATURE DECLINE
### CAREFUL: names here are a little off from pixelGroups - they are in the same
### order, but not equal.
overmatDT <- matrixDT(matricesIn = processes$OvermatureDecline, indicesIn = c(1:length(processes$OvermatureDecline)))
overmatcheckProp <- checkProp(overmatDT)

# there is only one pixelGroup where the noLoss is not equal to 1
# overmatcheckProp[which(overmatcheckProp$noLoss != 1),]
# name row   noLoss
# 1:  840   1 1.174843
# 2:  840   1 1.174843
# 3:  840   1 1.174843
# 4:  840   1 1.174843
# 5:  840   1 1.174843

# row number 840 is pixelGroup 841, and has an age of 2 - so it does not make sense
# check all the transactions
range(overmatDT$value)
# [1] 0.002914955 1.000000000
overmatDT[value != 1,]
# row 840 is the only one that has an over mature...but it is two years old.
## there is something wrong with how the overmature decline seems to be assigned
cboisvenue commented 3 years ago

IMPORTANT: as it stands overmaturedecline matrices take carbon from row 1 exclusively and but it in cols 12:15.

overmatDT[value != 1,]
#   row col       value name
#1:   1  14 0.002914955  841
#2:   1  15 0.002914955  841
#3:   1  12 0.084506420  841
#4:   1  13 0.084506420  841

That has to be wrong. row #1 is input, i.e., the atmosphere. So at best, that should be change to row 2:6 is softwood or 7:11 is hardwood. Going to rows 12:15 which are "AboveGroundVeryFastSoil", "BelowGroundVeryFastSoil", "AboveGroundFastSoil", "BelowGroundFastSoil" seems ok. Again, all these matrices are calculated in the c++ scripts, in the function ComputeGrowthAndDeclineMatrices2(). A temporary work around would be to change the overmature decline matrices is to change the values for the rows...not sure if it is worth the effort since the fact that this is applied to a very young pixelGroup means it is wrong anyway. Conclusion: I am not going to work on this until we (@achubaty ) can look and possibly fix the c++ function.

cboisvenue commented 3 years ago

Adding to this issue: we need to figure out what happens to the increments once the pixel age goes beyond the maximum ages on the growth curves provided. Do they continue with the same increments? No -

fireReturnSims <- spadesCBMout
fireReturnSims$cbmPools[simYear == 2540 & ages>400,]
# pixel group 1 is 531 years old
fireReturnSims$cbmPools[1:5,]
# pixelGroup ==1 is in the 1st position in the $allProcesses$Growth1 list
fireReturnSims$allProcesses$Growth1[[1]]
     row col       value
 [1,]   1  11 0.113738318
 [2,]   1  10 0.006197548
 [3,]   1   1 1.000000000
 [4,]   2   2 1.000000000
 [5,]   3   3 1.000000000
 [6,]   4   4 1.000000000
 [7,]   5   5 1.000000000
 [8,]   6   6 1.000000000
 [9,]   7   7 1.000000000
[10,]   8   8 1.000000000
[11,]   9   9 1.000000000
[12,]  10  10 1.000000000
[13,]  11  11 1.000000000
[14,]  12  12 1.000000000
[15,]  13  13 1.000000000
[16,]  14  14 1.000000000
[17,]  15  15 1.000000000
[18,]  16  16 1.000000000
[19,]  17  17 1.000000000
[20,]  18  18 1.000000000
[21,]  19  19 1.000000000
[22,]  20  20 1.000000000
[23,]  21  21 1.000000000
[24,]  22  22 1.000000000
[25,]  23  23 1.000000000
[26,]  24  24 1.000000000
[27,]  25  25 1.000000000
[28,]  26  26 1.000000000```
while the growth curve at the max(age) is this:
```# trying to find the right gcid - fireReturnsSims$growth_increments have id
# column going from 1 to 310. These are factor levels created from  fireReturnSims$curveID
# [1] "growth_curve_component_id" "ecozones". Need to figure out which is matching pixelGroup 1
curveID <- fireReturnSims$curveID
gcidsLevels <- levels(fireReturnSims$level3DT$gcids)
# ecozone and growth_curve_component_id for pixelGroup 1
fireReturnSims$pixelGroupC[pixelGroup == 1,]
# find those
which(gcidsLevels == "4001001_4")
pg1gc <- as.data.table(fireReturnSims$growth_increments[
  fireReturnSims$growth_increments[,1] == which(gcidsLevels == "4001001_4"),])
pg1gc[age == max(age),]
   id age swmerch swfol swother     hwmerch         hwfol     hwother
1: 120 299       0     0       0 -0.07414916 -0.0006227542 -0.01446324```

this has to do with overmature decline