changeset 54:5bb1d76c29ca draft

Uploaded
author greg
date Fri, 02 Nov 2018 11:16:46 -0400
parents b7c9837047d9
children 8c2b9eb9f9af
files insect_phenology_model.R insect_phenology_model.xml
diffstat 2 files changed, 52 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/insect_phenology_model.R	Thu Oct 18 10:17:02 2018 -0400
+++ b/insect_phenology_model.R	Fri Nov 02 11:16:46 2018 -0400
@@ -229,16 +229,49 @@
     return(mortality.probability)
 }
 
-mortality.egg = function(temperature) {
-    if (temperature < 12.7) {
-        mortality.probability = 0.8;
+mortality.egg = function(temperature, adj=0) {
+    # If no input from adjustment, default
+    # value is 0 (data from Nielsen, 2008).
+    T.mortality = c(15, 17, 20, 25, 27, 30, 33, 35);
+    egg.mortality = c(50, 2, 1, 0, 0, 0, 5, 100);
+    # Calculates slopes and intercepts for lines.
+    slopes = NULL;
+    intercepts = NULL;
+    for (i in 1:length(T.mortality)) {
+        slopes[i] = (egg.mortality[i+1] - egg.mortality[i]) / (T.mortality[i+1] - T.mortality[i]);
+        intercepts[i] = -slopes[i] * T.mortality[i] + egg.mortality[i];
     }
-    else {
-        mortality.probability = 0.8 - temperature / 40.0;
-        if (mortality.probability < 0) {
-            mortality.probability = 0.01;
-        }
+    # Calculates mortality based on temperature.
+    mortality.probability = NULL;
+    for (j in 1:length(temperature)) {
+        mortality.probability[j] = if(temperature[j] <= T.mortality[2]) {
+                           temperature[j] * slopes[1] + intercepts[1];
+                       } else if (temperature[j] > T.mortality[2] && temperature[j] <= T.mortality[3]) {
+                           temperature[j] * slopes[2] + intercepts[2];
+                       } else if (temperature[j] > T.mortality[3] && temperature[j] <= T.mortality[4]) {
+                           temperature[j] * slopes[3] + intercepts[3];
+                       } else if (temperature[j] > T.mortality[4] && temperature[j] <= T.mortality[5]) {
+                           temperature[j] * slopes[4] + intercepts[4];
+                       } else if (temperature[j] > T.mortality[5] && temperature[j] <= T.mortality[6]) {
+                           temperature[j] * slopes[5] + intercepts[5];
+                       } else if (temperature[j] > T.mortality[6] && temperature[j] <= T.mortality[7]) {
+                           temperature[j] * slopes[6] + intercepts[6];
+                       } else if (temperature[j] > T.mortality[7]) {
+                           temperature[j] * slopes[7] + intercepts[7];
+                       }
+        # If mortality > 100, make it equal to 100.
+        mortality.probability[mortality.probability>100] = 100;
+        # If mortality <0, make equal to 0.
+        mortality.probability[mortality.probability<0] = 0;
     }
+    # Make mortality adjustments based on adj parameter.
+    mortality.probability = (100 - mortality.probability) * adj + mortality.probability;
+    # if mortality > 100, make it equal to 100.
+    mortality.probability[mortality.probability>100] = 100;
+    # If mortality <0, make equal to 0.
+    mortality.probability[mortality.probability<0] = 0;
+    # Change percent to proportion.
+    mortality.probability = mortality.probability / 100;
     return(mortality.probability)
 }
 
@@ -811,7 +844,7 @@
             }
             if (vector.individual[2] == 0) {
                 # Egg.
-                death.probability = opt$egg_mortality * mortality.egg(mean.temp);
+                death.probability = opt$egg_mortality * mortality.egg(mean.temp, adj=opt$egg_mortality);
             }
             else if (vector.individual[2] == 1 | vector.individual[2] == 2) {
                 # Nymph.
--- a/insect_phenology_model.xml	Thu Oct 18 10:17:02 2018 -0400
+++ b/insect_phenology_model.xml	Fri Nov 02 11:16:46 2018 -0400
@@ -1,4 +1,4 @@
-<tool id="insect_phenology_model" name="Insect phenology model" version="1.1.0">
+<tool id="insect_phenology_model" name="Insect phenology model" version="1.2.0">
     <description>expressing stage-specific phenology and population dynamics</description>
     <requirements>
         <requirement type="package" version="1.4.4">r-optparse</requirement>
@@ -84,15 +84,15 @@
         <param name="replications" type="integer" value="10" min="2" label="Number of replications"/>
         <param name="insects_per_replication" type="integer" value="1000" min="1" label="Number of insects with which to start each replication"/>
         <param name="photoperiod" type="float" value="13.5" min="0" label="Critical photoperiod for diapause induction/termination"/>
-        <param name="egg_mortality" type="integer" value="1" min="0" label="Adjustment rate for egg mortality"/>
-        <param name="nymph_mortality" type="integer" value="1" min="0" label="Adjustment rate for nymph mortality"/>
-        <param name="adult_mortality" type="integer" value="1" min="0" label="Adjustment rate for adult mortality"/>
-        <param name="oviposition" type="integer" value="1" min="0" label="Adjustment oviposition rate"/>
-        <param name="min_clutch_size" type="integer" value="0" min="0" label="Adjustment of minimum clutch size"/>
-        <param name="max_clutch_size" type="integer" value="0" min="0" label="Adjustment of maximum clutch size"/>
-        <param name="young_nymph_accumulation" type="integer" value="0" min="0" label="Adjustment of degree-days accumulation (egg->young nymph)"/>
-        <param name="old_nymph_accumulation" type="integer" value="0" min="0" label="Adjustment of degree-days accumulation (young nymph->old nymph)"/>
-        <param name="adult_accumulation" type="integer" value="0" min="0" label="Adjustment of degree-days accumulation (old nymph->adult)"/>
+        <param name="egg_mortality" type="float" value="1" min="0" max="1" label="Adjustment rate for egg mortality"/>
+        <param name="nymph_mortality" type="float" value="1" min="0" label="Adjustment rate for nymph mortality"/>
+        <param name="adult_mortality" type="float" value="1" min="0" label="Adjustment rate for adult mortality"/>
+        <param name="oviposition" type="float" value="1" min="0" label="Adjustment oviposition rate"/>
+        <param name="min_clutch_size" type="float" value="0" min="0" label="Adjustment of minimum clutch size"/>
+        <param name="max_clutch_size" type="float" value="0" min="0" label="Adjustment of maximum clutch size"/>
+        <param name="young_nymph_accumulation" type="float" value="0" min="0" label="Adjustment of degree-days accumulation (egg->young nymph)"/>
+        <param name="old_nymph_accumulation" type="float" value="0" min="0" label="Adjustment of degree-days accumulation (young nymph->old nymph)"/>
+        <param name="adult_accumulation" type="float" value="0" min="0" label="Adjustment of degree-days accumulation (old nymph->adult)"/>
         <param name="plot_generations_separately" type="select" label="Plot generations separately?">
             <option value="yes" selected="True">Yes</option>
             <option value="no">No</option>