# HG changeset patch
# User greg
# Date 1545315352 18000
# Node ID 39308558943830362cebab3948531b935f6268c4
# Parent 892cf703be62dd123a1e07cda360c036eca8d08e
Uploaded
diff -r 892cf703be62 -r 393085589438 insect_phenology_model.R
--- a/insect_phenology_model.R Wed Nov 21 11:42:37 2018 -0500
+++ b/insect_phenology_model.R Thu Dec 20 09:15:52 2018 -0500
@@ -250,50 +250,62 @@
return(mortality.probability)
}
-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];
+#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];
+# }
+# # 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)
+#}
+
+mortality.egg = function(temperature) {
+ if (temperature < 12.7) {
+ mortality.probability = 0.8;
+ } 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)
+ return (mortality.probability);
}
mortality.nymph = function(temperature) {
@@ -366,13 +378,6 @@
end_date_ytd_row = end_date_ytd_row[1];
# The end date is contained within the input_ytd data.
end_doy_ytd = as.integer(temperature_data_frame$DOY[end_date_ytd_row]);
- if (end_doy_ytd > end_date_ytd_row + 1) {
- # The input year-to-date dataset is missing 1 or more
- # days of data.
- days_missing = end_doy_ytd - end_date_ytd_row;
- msg = cat("The year-to-date dataset is missing ", days_missing, " days of data.\n");
- stop_err(msg);
- }
} else {
end_date_ytd_row = 0;
}
@@ -396,13 +401,6 @@
# Save the first DOY to later check if start_date is Jan 1.
start_doy_ytd = as.integer(temperature_data_frame$DOY[1]);
end_doy_ytd = as.integer(temperature_data_frame$DOY[num_ytd_rows]);
- if (end_doy_ytd > end_date_ytd_row + 1) {
- # The input year-to-date dataset is missing 1 or more
- # days of data.
- days_missing = end_doy_ytd - end_date_ytd_row;
- msg = cat("The year-to-date dataset is missing ", days_missing, " days of data.\n");
- stop_err(msg);
- }
}
} else {
# We're processing only the 30 year normals data, so create an empty
@@ -557,6 +555,8 @@
}
}
}
+ # Ensure all DOY values are consectuive integers.
+ validate_doys(temperature_data_frame);
# Add a column containing the daylight length for each day.
temperature_data_frame = add_daylight_length(temperature_data_frame);
return(list(temperature_data_frame, start_date, end_date, prepend_end_doy_norm, append_start_doy_norm, is_leap_year, location));
@@ -856,7 +856,8 @@
}
if (vector.individual[2] == 0) {
# Egg.
- death.probability = opt$egg_mortality * mortality.egg(mean.temp, adj=opt$egg_mortality);
+ # death.probability = opt$egg_mortality * mortality.egg(mean.temp, adj=opt$egg_mortality);
+ death.probability = opt$egg_mortality * mortality.egg(mean.temp);
}
else if (vector.individual[2] == 1 | vector.individual[2] == 2) {
# Nymph.
diff -r 892cf703be62 -r 393085589438 insect_phenology_model.xml
--- a/insect_phenology_model.xml Wed Nov 21 11:42:37 2018 -0500
+++ b/insect_phenology_model.xml Thu Dec 20 09:15:52 2018 -0500
@@ -66,13 +66,13 @@
value is not None and value.metadata.columns==10 and value.metadata.data_lines==366
-
+
-
- value is not None and value.metadata.columns==6
+
+ value is not None and value.metadata.columns==6
@@ -81,7 +81,7 @@
-
+
@@ -242,7 +242,7 @@
* **30 year normals temperature data** - the dataset from your history containing the 30-year normals temperature data (available at http://pestwatch.psu.edu/ghcn).
* **Merge year-to-date temperature data with 30 year normals temperature data** - select Yes to merge a year-to-date temperature dataset from your history into the selected 30 year normals temperature data.
- * **Year-to-date temperature data** - the dataset from your history containing the year-to-date temperature data (available at http://pestwatch.psu.edu/minmax).
+ * **Daily actuals temperature data** - the dataset from your history containing the daily actuals temperature data (available at http://pestwatch.psu.edu/minmax).
* **Location** - the location associated with the selected temperature data.
* **Select insect** - currently only the Brown Marmorated Stink Bug can be analyzed.
diff -r 892cf703be62 -r 393085589438 test-data/output_combined1.csv
--- a/test-data/output_combined1.csv Wed Nov 21 11:42:37 2018 -0500
+++ b/test-data/output_combined1.csv Thu Dec 20 09:15:52 2018 -0500
@@ -1,1 +1,1 @@
-"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","YOUNGNYMPH","YOUNGNYMPHSE","PRE.VITADULT","PRE.VITADULTSE"
+"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","DEGREE.DAYS","YOUNGNYMPH","YOUNGNYMPHSE","PRE.VITADULT","PRE.VITADULTSE"
diff -r 892cf703be62 -r 393085589438 test-data/output_combined2.csv
--- a/test-data/output_combined2.csv Wed Nov 21 11:42:37 2018 -0500
+++ b/test-data/output_combined2.csv Thu Dec 20 09:15:52 2018 -0500
@@ -1,1 +1,1 @@
-"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","EGG","EGGSE","TOTALNYMPH","TOTALNYMPHSE","TOTALADULT","TOTALADULTSE"
+"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","DEGREE.DAYS","EGG","EGGSE","TOTALNYMPH","TOTALNYMPHSE","TOTALADULT","TOTALADULTSE"
diff -r 892cf703be62 -r 393085589438 test-data/output_combined3.csv
--- a/test-data/output_combined3.csv Wed Nov 21 11:42:37 2018 -0500
+++ b/test-data/output_combined3.csv Thu Dec 20 09:15:52 2018 -0500
@@ -1,1 +1,1 @@
-"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","OLDNYMPH","OLDNYMPHSE"
+"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","DEGREE.DAYS","OLDNYMPH","OLDNYMPHSE"
diff -r 892cf703be62 -r 393085589438 test-data/output_combined4.csv
--- a/test-data/output_combined4.csv Wed Nov 21 11:42:37 2018 -0500
+++ b/test-data/output_combined4.csv Thu Dec 20 09:15:52 2018 -0500
@@ -1,1 +1,1 @@
-"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","EGG","EGGSE","TOTALNYMPH","TOTALNYMPHSE","TOTALADULT","TOTALADULTSE"
+"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","DEGREE.DAYS","EGG","EGGSE","TOTALNYMPH","TOTALNYMPHSE","TOTALADULT","TOTALADULTSE"
diff -r 892cf703be62 -r 393085589438 test-data/output_f1_3.csv
--- a/test-data/output_f1_3.csv Wed Nov 21 11:42:37 2018 -0500
+++ b/test-data/output_f1_3.csv Thu Dec 20 09:15:52 2018 -0500
@@ -1,1 +1,1 @@
-"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","OLDNYMPH.F1","OLDNYMPH.F1.SE"
+"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","DEGREE.DAYS","OLDNYMPH","OLDNYMPHSE","OLDNYMPH.F1","OLDNYMPH.F1.SE"
diff -r 892cf703be62 -r 393085589438 test-data/output_f1_4.csv
--- a/test-data/output_f1_4.csv Wed Nov 21 11:42:37 2018 -0500
+++ b/test-data/output_f1_4.csv Thu Dec 20 09:15:52 2018 -0500
@@ -1,1 +1,1 @@
-"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","EGG.F1","EGG.F1.SE","TOTALNYMPH.F1","TOTALNYMPH.F1.SE","TOTALADULT.F1","TOTALADULT.F1.SE"
+"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","DEGREE.DAYS","EGG","EGGSE","TOTALNYMPH","TOTALNYMPHSE","TOTALADULT","TOTALADULTSE","EGG.F1","EGG.F1.SE","TOTALNYMPH.F1","TOTALNYMPH.F1.SE","TOTALADULT.F1","TOTALADULT.F1.SE","ALL.TOTAL.F1","ALL.TOTAL.F1.SE"
diff -r 892cf703be62 -r 393085589438 test-data/output_f2_3.csv
--- a/test-data/output_f2_3.csv Wed Nov 21 11:42:37 2018 -0500
+++ b/test-data/output_f2_3.csv Thu Dec 20 09:15:52 2018 -0500
@@ -1,1 +1,1 @@
-"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","OLDNYMPH.F2","OLDNYMPH.F2.SE"
+"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","DEGREE.DAYS","OLDNYMPH","OLDNYMPHSE","OLDNYMPH.F2","OLDNYMPH.F2.SE"
diff -r 892cf703be62 -r 393085589438 test-data/output_f2_4.csv
--- a/test-data/output_f2_4.csv Wed Nov 21 11:42:37 2018 -0500
+++ b/test-data/output_f2_4.csv Thu Dec 20 09:15:52 2018 -0500
@@ -1,1 +1,1 @@
-"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","EGG.F2","EGG.F2.SE","TOTALNYMPH.F2","TOTALNYMPH.F2.SE","TOTALADULT.F2","TOTALADULT.F2.SE"
+"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","DEGREE.DAYS","EGG","EGGSE","TOTALNYMPH","TOTALNYMPHSE","TOTALADULT","TOTALADULTSE","EGG.F2","EGG.F2.SE","TOTALNYMPH.F2","TOTALNYMPH.F2.SE","TOTALADULT.F2","TOTALADULT.F2.SE","ALL.TOTAL.F2","ALL.TOTAL.F2.SE"
diff -r 892cf703be62 -r 393085589438 test-data/output_p_3.csv
--- a/test-data/output_p_3.csv Wed Nov 21 11:42:37 2018 -0500
+++ b/test-data/output_p_3.csv Thu Dec 20 09:15:52 2018 -0500
@@ -1,1 +1,1 @@
-"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","OLDNYMPH.P","OLDNYMPH.P.SE"
+"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","DEGREE.DAYS","OLDNYMPH","OLDNYMPHSE","OLDNYMPH.P","OLDNYMPH.P.SE"
diff -r 892cf703be62 -r 393085589438 test-data/output_p_4.csv
--- a/test-data/output_p_4.csv Wed Nov 21 11:42:37 2018 -0500
+++ b/test-data/output_p_4.csv Thu Dec 20 09:15:52 2018 -0500
@@ -1,1 +1,1 @@
-"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","EGG.P","EGG.P.SE","TOTALNYMPH.P","TOTALNYMPH.P.SE","TOTALADULT.P","TOTALADULT.P.SE","ALL.TOTAL.P","ALL.TOTAL.P.SE"
+"LATITUDE","LONGITUDE","DATE","DOY","TMIN","TMAX","DAYLEN","DEGREE.DAYS","EGG","EGGSE","TOTALNYMPH","TOTALNYMPHSE","TOTALADULT","TOTALADULTSE","EGG.P","EGG.P.SE","TOTALNYMPH.P","TOTALNYMPH.P.SE","TOTALADULT.P","TOTALADULT.P.SE","ALL.TOTAL.P","ALL.TOTAL.P.SE"
diff -r 892cf703be62 -r 393085589438 utils.R
--- a/utils.R Wed Nov 21 11:42:37 2018 -0500
+++ b/utils.R Thu Dec 20 09:15:52 2018 -0500
@@ -333,3 +333,21 @@
}
return(valid_date);
}
+
+validate_doys = function(temperature_data_frame) {
+ # Ensure all DOY values are consecutive integers.
+ last_doy = 0;
+ num_rows = dim(temperature_data_frame)[1];
+ for (i in 1:num_rows) {
+ doy = as.integer(temperature_data_frame$DOY[i]);
+ if (last_doy == 0) {
+ last_doy = doy;
+ } else {
+ if (doy != last_doy + 1) {
+ msg = paste("DOY ", doy, " is not consecutive (previous DOY is ", last_doy, ".", sep="");
+ stop_err(msg);
+ }
+ last_doy = doy;
+ }
+ }
+}