Mercurial > repos > greg > insect_phenology_model
comparison insect_phenology_model.R @ 21:6349699fc9fa draft
Uploaded
author | greg |
---|---|
date | Thu, 08 Mar 2018 08:11:43 -0500 |
parents | 214217142600 |
children | 36d7bb034285 |
comparison
equal
deleted
inserted
replaced
20:214217142600 | 21:6349699fc9fa |
---|---|
253 } | 253 } |
254 | 254 |
255 render_chart = function(date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval, | 255 render_chart = function(date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval, |
256 replications, life_stage, group, group_std_error, group2=NULL, group2_std_error=NULL, group3=NULL, group3_std_error=NULL, | 256 replications, life_stage, group, group_std_error, group2=NULL, group2_std_error=NULL, group3=NULL, group3_std_error=NULL, |
257 life_stages_adult=NULL, life_stages_nymph=NULL) { | 257 life_stages_adult=NULL, life_stages_nymph=NULL) { |
258 cat("In render_chart, chart_type: ", chart_type, "\n"); | |
259 if (chart_type=="pop_size_by_life_stage") { | 258 if (chart_type=="pop_size_by_life_stage") { |
260 if (life_stage=="Total") { | 259 if (life_stage=="Total") { |
261 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); | 260 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); |
262 legend_text = c("Egg", "Nymph", "Adult"); | 261 legend_text = c("Egg", "Nymph", "Adult"); |
263 columns = c(4, 2, 1); | 262 columns = c(4, 2, 1); |
313 title_str = paste(":", life_stages_nymph, "Nymph Pop by Gen", ":", sep=" "); | 312 title_str = paste(":", life_stages_nymph, "Nymph Pop by Gen", ":", sep=" "); |
314 } else if (life_stage=="Adult") { | 313 } else if (life_stage=="Adult") { |
315 title_str = paste(":", life_stages_adult, "Adult Pop by Gen", ":", sep=" "); | 314 title_str = paste(":", life_stages_adult, "Adult Pop by Gen", ":", sep=" "); |
316 } | 315 } |
317 title = paste(insect, ": Reps", replications, title_str, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); | 316 title = paste(insect, ": Reps", replications, title_str, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); |
318 cat("In render_chart, title: ", title, "\n"); | |
319 cat("In render_chart, group: ", group, "\n"); | |
320 cat("In render_chart, group2: ", group2, "\n"); | |
321 cat("In render_chart, group3: ", group3, "\n"); | |
322 legend_text = c("P", "F1", "F2"); | 317 legend_text = c("P", "F1", "F2"); |
323 columns = c(1, 2, 4); | 318 columns = c(1, 2, 4); |
324 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3); | 319 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3); |
325 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3); | 320 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3); |
326 lines(days, group2, lwd=2, lty=1, col=2); | 321 lines(days, group2, lwd=2, lty=1, col=2); |
411 } else if (life_stage_adult=="Total") { | 406 } else if (life_stage_adult=="Total") { |
412 process_total_adults = TRUE; | 407 process_total_adults = TRUE; |
413 } | 408 } |
414 } | 409 } |
415 } | 410 } |
416 cat("process_eggs: ", process_eggs, "\n"); | |
417 cat("process_nymphs: ", process_nymphs, "\n"); | |
418 cat("process_young_nymphs: ", process_young_nymphs, "\n"); | |
419 cat("process_old_nymphs: ", process_old_nymphs, "\n"); | |
420 cat("process_total_nymphs: ", process_total_nymphs, "\n"); | |
421 cat("process_adults: ", process_adults, "\n"); | |
422 cat("process_previtellogenic_adults: ", process_previtellogenic_adults, "\n"); | |
423 cat("process_vitellogenic_adults: ", process_vitellogenic_adults, "\n"); | |
424 cat("process_diapausing_adults: ", process_diapausing_adults, "\n"); | |
425 cat("process_total_adults: ", process_total_adults, "\n"); | |
426 cat("life_stages: ", life_stages, "\n"); | |
427 cat("life_stages_nymph: ", life_stages_nymph, "\n"); | |
428 cat("life_stages_adult: ", life_stages_adult, "\n"); | |
429 | 411 |
430 # Initialize matrices. | 412 # Initialize matrices. |
431 if (process_eggs) { | 413 if (process_eggs) { |
432 Eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 414 Eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
433 } | 415 } |
434 cat("process_young_nymphs==TRUE: ", process_young_nymphs==TRUE, "\n"); | |
435 cat("process_total_nymphs==TRUE: ", process_total_nymphs==TRUE, "\n"); | |
436 if (process_young_nymphs==TRUE | process_total_nymphs==TRUE) { | 416 if (process_young_nymphs==TRUE | process_total_nymphs==TRUE) { |
437 YoungNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 417 YoungNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
438 } | 418 } |
439 if (process_old_nymphs==TRUE | process_total_nymphs==TRUE) { | 419 if (process_old_nymphs==TRUE | process_total_nymphs==TRUE) { |
440 OldNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 420 OldNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
1074 # Information needed for plots plots. | 1054 # Information needed for plots plots. |
1075 days = c(1:opt$num_days); | 1055 days = c(1:opt$num_days); |
1076 start_date = temperature_data_frame$DATE[1]; | 1056 start_date = temperature_data_frame$DATE[1]; |
1077 end_date = temperature_data_frame$DATE[opt$num_days]; | 1057 end_date = temperature_data_frame$DATE[opt$num_days]; |
1078 | 1058 |
1079 cat("life_stages: ", toString(life_stages), "\n"); | |
1080 cat("plot_generations_separately: ", plot_generations_separately, "\n"); | |
1081 if (plot_generations_separately) { | 1059 if (plot_generations_separately) { |
1082 for (life_stage in life_stages) { | 1060 for (life_stage in life_stages) { |
1083 cat("life_stage: ", life_stage, "\n"); | |
1084 if (life_stage == "Egg") { | 1061 if (life_stage == "Egg") { |
1085 # Start PDF device driver. | 1062 # Start PDF device driver. |
1086 dev.new(width=20, height=30); | 1063 dev.new(width=20, height=30); |
1087 file_path = get_file_path(life_stage, "egg_pop_by_generation.pdf") | 1064 file_path = get_file_path(life_stage, "egg_pop_by_generation.pdf") |
1088 pdf(file=file_path, width=20, height=30, bg="white"); | 1065 pdf(file=file_path, width=20, height=30, bg="white"); |
1089 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1066 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
1090 # Egg population size by generation. | 1067 # Egg population size by generation. |
1091 maxval = max(P_eggs+F1_eggs+F2_eggs) + 100; | 1068 maxval = max(P_eggs+F1_eggs+F2_eggs) + 100; |
1092 cat("maxval: ", maxval, "\n"); | |
1093 cat("P_eggs: ", toString(P_eggs), "\n"); | |
1094 cat("is.vector(P_eggs): ", is.vector(P_eggs), "\n"); | |
1095 cat("length(P_eggs): ", length(P_eggs), "\n"); | |
1096 cat("P_eggs.std_error: ", toString(P_eggs.std_error), "\n"); | |
1097 cat("F1_eggs: ", toString(F1_eggs), "\n"); | |
1098 cat("F1_eggs.std_error: ", toString(F1_eggs.std_error), "\n"); | |
1099 cat("F2_eggs: ", toString(F2_eggs), "\n"); | |
1100 cat("F2_eggs.std_error: ", toString(F2_eggs.std_error), "\n"); | |
1101 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1069 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
1102 opt$replications, life_stage, group=P_eggs, group_std_error=P_eggs.std_error, group2=F1_eggs, group2_std_error=F1_eggs.std_error, group3=F2_eggs, | 1070 opt$replications, life_stage, group=P_eggs, group_std_error=P_eggs.std_error, group2=F1_eggs, group2_std_error=F1_eggs.std_error, group3=F2_eggs, |
1103 group3_std_error=F2_eggs.std_error); | 1071 group3_std_error=F2_eggs.std_error); |
1104 # Turn off device driver to flush output. | 1072 # Turn off device driver to flush output. |
1105 dev.off(); | 1073 dev.off(); |
1106 } else if (life_stage == "Nymph") { | 1074 } else if (life_stage == "Nymph") { |
1107 for (life_stage_nymph in life_stages_nymph) { | 1075 for (life_stage_nymph in life_stages_nymph) { |
1108 cat("life_stage_nymph: ", life_stage_nymph, "\n"); | |
1109 # Start PDF device driver. | 1076 # Start PDF device driver. |
1110 dev.new(width=20, height=30); | 1077 dev.new(width=20, height=30); |
1111 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", life_stage_nymph=life_stage_nymph) | 1078 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", life_stage_nymph=life_stage_nymph) |
1112 pdf(file=file_path, width=20, height=30, bg="white"); | 1079 pdf(file=file_path, width=20, height=30, bg="white"); |
1113 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1080 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
1137 group2 = F1_total_nymphs; | 1104 group2 = F1_total_nymphs; |
1138 group2_std_error = F1_total_nymphs.std_error; | 1105 group2_std_error = F1_total_nymphs.std_error; |
1139 group3 = F2_total_nymphs; | 1106 group3 = F2_total_nymphs; |
1140 group3_std_error = F2_total_nymphs.std_error; | 1107 group3_std_error = F2_total_nymphs.std_error; |
1141 } | 1108 } |
1142 cat("XXX group: ", group, "\n"); | |
1143 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1109 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
1144 opt$replications, life_stage, group=group, group_std_error=group_std_error, group2=group2, group2_std_error=group2_std_error, | 1110 opt$replications, life_stage, group=group, group_std_error=group_std_error, group2=group2, group2_std_error=group2_std_error, |
1145 group3=group3, group3_std_error=group3_std_error, life_stages_nymph=life_stage_nymph); | 1111 group3=group3, group3_std_error=group3_std_error, life_stages_nymph=life_stage_nymph); |
1146 # Turn off device driver to flush output. | 1112 # Turn off device driver to flush output. |
1147 dev.off(); | 1113 dev.off(); |