ncsu-landscape-dynamics / pops-core

PoPS Core: C++ library for the Pest or Pathogen Spread Model
https://ncsu-landscape-dynamics.github.io/pops-core
GNU General Public License v2.0
5 stars 2 forks source link

fix bug in establishment_dispersers and weather #185

Closed ChrisJones687 closed 2 years ago

ChrisJones687 commented 2 years ago

weather at origin was being used to test for establishment rather than the weather at the destination.

wenzeslaus commented 2 years ago

The tests actually need to change when the establishment is limited by number of S hosts. The fix for the tests is:

diff --git a/tests/test_model.cpp b/tests/test_model.cpp
index 5ed811c..9e06692 100644
--- a/tests/test_model.cpp
+++ b/tests/test_model.cpp
@@ -253,6 +253,14 @@ int test_deterministic()

     auto expected_dispersers = config.reproductive_rate * infected;
     auto expected_established_dispersers = config.reproductive_rate * infected;
+    // Limit established dispersers by number of available hosts.
+    for (int row = 0; row < susceptible.rows(); ++row) {
+        for (int col = 0; col < susceptible.cols(); ++col) {
+            if (expected_established_dispersers(row, col) > susceptible(row, col)) {
+                expected_established_dispersers(row, col) = susceptible(row, col);
+            }
+        }
+    }
     int step = 0;

     Model<Raster<int>, Raster<double>, Raster<double>::IndexType> model(config);
@@ -395,6 +403,14 @@ int test_deterministic_exponential()

     auto expected_dispersers = config.reproductive_rate * infected;
     auto expected_established_dispersers = config.reproductive_rate * infected;
+    // Limit established dispersers by number of available hosts.
+    for (int row = 0; row < susceptible.rows(); ++row) {
+        for (int col = 0; col < susceptible.cols(); ++col) {
+            if (expected_established_dispersers(row, col) > susceptible(row, col)) {
+                expected_established_dispersers(row, col) = susceptible(row, col);
+            }
+        }
+    }

     int step = 0; 

I can add that to the PR if needed.

ChrisJones687 commented 2 years ago

Definitely want to change the established dispersers to addition rather than subtraction in the future.