wengngai / NSSF_IBMs

Spatially explicit individual based models of tree species in the Nee Soon Freshwater Swamp Forest (NSSF) catchment in Singapore
1 stars 0 forks source link

Error from inter.calc, possibly related to missing grid number #16

Closed hrlai closed 3 years ago

hrlai commented 3 years ago

The three-species script fails with the following errors:

Error in { : 
  task 1 failed - "NA/NaN/Inf in foreign function call (arg 1)"
Calls: inter.calc -> %dopar% -> <Anonymous>

This happens consistently at around year 6. I suspect it is related to a new warning message related to the p_bz function:

In addition: Warning message:
In rbinom(n = length(linear.p), prob = 1/(1 + exp(-linear.p)), size = 1) :
  NAs produced

Still debugging it, but very slowly. Any idea?

hrlai commented 3 years ago

When I ran the script locally with very high dilution factor (1000), it did not fail.

My gut feeling is still that largish dilution factor (>10) generates some zero-length population vectors...

hrlai commented 3 years ago

Since it says arg 1, if it means the first argument in inter.calc then trees.hetero may be the culprit.

wengngai commented 3 years ago

Sorry for the slow reply. Did settting the dilution factor back to 10 resolve the issue? I can't really figure out what is wrong, because I cannot replicate the error. But I agree that you're probably right that all of the seedlings might have died out, leaving a zero-length n to the rbinom function? Is the model running now or are we still looking for a fix before restarting the simulation?

hrlai commented 3 years ago

Did settting the dilution factor back to 10 resolve the issue?

Yes it did. The output is now pushed. Let's deal with the issue later. Closing for now.

hrlai commented 3 years ago

Opening this issue again, because I am facing the same issue now as of b87ab095b23686872d00fda4fecb5a080e85bf01 .

In year 2 I got the following error message:

task 579 failed - "NA/NaN/Inf in foreign function call (arg 1)"

and troubleshot it to the inter.calc function. The root seems to be the grid column in ppoS having NAs:

> summary(ppoS)
       x                y            logheight          grid      
 Min.   :366994   Min.   :153004   Min.   :1.970   Min.   : 1.00  
 1st Qu.:367133   1st Qu.:153150   1st Qu.:2.879   1st Qu.: 6.00  
 Median :367291   Median :153268   Median :3.067   Median :13.00  
 Mean   :367268   Mean   :153267   Mean   :3.067   Mean   :12.75  
 3rd Qu.:367400   3rd Qu.:153393   3rd Qu.:3.253   3rd Qu.:19.00  
 Max.   :367496   Max.   :153507   Max.   :4.153   Max.   :25.00  
                                                   NA's   :90 

Are these the seedlings that dispersed outside of the map extent, so they have NA ?

wengngai commented 3 years ago

sorry I must have missed this. I've checked and you are right. these grid NAs are all from just outside the boundary. I've inserted a quick and dirty fix. we will eventually make the landscape a torus so I think that this fix is good enough for now

hrlai commented 3 years ago

Nice this seems to have been resolved now. The simulation runs into 10+ as of now without issue.