|
| 1 | + |
| 2 | + |
| 3 | +library(glmtools) |
| 4 | +sim_dir = run_example_sim() |
| 5 | + |
| 6 | +Sys.setenv(tz='UTC') |
| 7 | + |
| 8 | +#compare temps |
| 9 | +ncfile = file.path(sim_dir, 'output.nc') |
| 10 | +tempfield = file.path(sim_dir, 'field_data.csv') |
| 11 | +plot_temp_compare(ncfile, tempfield, resample = FALSE) |
| 12 | + |
| 13 | +rmse = validate_sim(ncfile, tempfield, 'water.temperature', fig_path=FALSE, report = TRUE) |
| 14 | + |
| 15 | +################################################################################ |
| 16 | +#Ice compare |
| 17 | +################################################################################ |
| 18 | +ice_obs = read.table(file.path(sim_dir, 'snow_ice_depth_obs.csv'), sep=',', header=TRUE) |
| 19 | +ice_obs$DateTime = as.POSIXct(ice_obs$sampledate, tz="GMT") |
| 20 | +ice_obs$avsnow = ice_obs$avsnow/100 |
| 21 | +ice_obs$whiteice = ice_obs$whiteice/100 |
| 22 | +ice_obs$blueice = ice_obs$blueice/100 |
| 23 | + |
| 24 | + |
| 25 | +snow = get_var(ncfile, 'hsnow') |
| 26 | +attributes(snow$DateTime)$tzone = 'GMT' |
| 27 | +wice = get_var(ncfile, 'hwice') |
| 28 | +attributes(wice$DateTime)$tzone = 'GMT' |
| 29 | +bice = get_var(ncfile, 'hice') |
| 30 | +attributes(bice$DateTime)$tzone = 'GMT' |
| 31 | +wtr = get_temp(ncfile, reference='surface') |
| 32 | +attributes(wtr$DateTime)$tzone = 'GMT' |
| 33 | + |
| 34 | +all_ice = merge(snow, ice_obs, all.x=TRUE, by='DateTime') |
| 35 | +all_ice = merge(wice, all_ice, all.x=TRUE) |
| 36 | +all_ice = merge(bice, all_ice, all.x=TRUE) |
| 37 | +all_ice$yday = as.POSIXlt(all_ice$DateTime)$yday |
| 38 | +all_ice$year = as.POSIXlt(all_ice$DateTime)$year + 1900 |
| 39 | + |
| 40 | +ice = get_ice(ncfile) |
| 41 | +attributes(ice$DateTime)$tzone = 'GMT' |
| 42 | +ice_on_off = mda.lakes::get_ice_onoff(ice, wtr) |
| 43 | + |
| 44 | +lter_on_off = read.table(file.path(sim_dir,'ice_duration_obs.csv'), sep=',', header=TRUE) |
| 45 | +all_ice = merge(all_ice, ice_on_off, all.x=TRUE) |
| 46 | +all_ice = merge(all_ice, lter_on_off, all.x=TRUE) |
| 47 | + |
| 48 | +all_ice = all_ice[order(all_ice$DateTime), ] |
| 49 | + |
| 50 | +################################################################################ |
| 51 | +## Now plots |
| 52 | +################################################################################ |
| 53 | +plot(all_ice$avsnow, all_ice$hsnow) |
| 54 | +abline(0,1) |
| 55 | + |
| 56 | +plot(all_ice$whiteice, all_ice$hwice) |
| 57 | +abline(0,1) |
| 58 | + |
| 59 | +plot(all_ice$blueice, all_ice$hice) |
| 60 | +abline(0,1) |
| 61 | + |
| 62 | +plot(hice~DateTime, subset(all_ice, year < 1990), type='l') |
| 63 | +points(all_ice$DateTime, all_ice$blueice) |
| 64 | + |
| 65 | +#png('figures/sp_bice.png', res=300, width=2000, height=2000) |
| 66 | +par(mfrow=c(3,1)) |
| 67 | +plot(hice~DateTime, subset(all_ice, year < 1990), type='l') |
| 68 | +title('Blue Ice') |
| 69 | +points(all_ice$DateTime, all_ice$blueice) |
| 70 | +plot(hice~DateTime, subset(all_ice, year > 1990 & year < 2000), type='l') |
| 71 | +points(all_ice$DateTime, all_ice$blueice) |
| 72 | +plot(hice~DateTime, subset(all_ice, year > 2000 & year < 2010), type='l') |
| 73 | +points(all_ice$DateTime, all_ice$blueice) |
| 74 | +#dev.off() |
| 75 | + |
| 76 | +#png('figures/sp_wice.png', res=300, width=2000, height=2000) |
| 77 | +par(mfrow=c(3,1)) |
| 78 | +plot(hwice~DateTime, subset(all_ice, year < 1990), type='l') |
| 79 | +title('White Ice') |
| 80 | +points(all_ice$DateTime, all_ice$whiteice) |
| 81 | +plot(hwice~DateTime, subset(all_ice, year > 1990 & year < 2000), type='l') |
| 82 | +points(all_ice$DateTime, all_ice$whiteice) |
| 83 | +plot(hwice~DateTime, subset(all_ice, year > 2000 & year < 2010), type='l') |
| 84 | +points(all_ice$DateTime, all_ice$whiteice) |
| 85 | +#dev.off() |
| 86 | + |
| 87 | +#png('figures/sp_snow.png', res=300, width=2000, height=2000) |
| 88 | +par(mfrow=c(3,1)) |
| 89 | +plot(hsnow~DateTime, subset(all_ice, year < 1990), type='l') |
| 90 | +title('Snow') |
| 91 | +points(all_ice$DateTime, all_ice$avsnow) |
| 92 | +plot(hsnow~DateTime, subset(all_ice, year > 1990 & year < 2000), type='l') |
| 93 | +points(all_ice$DateTime, all_ice$avsnow) |
| 94 | +plot(hsnow~DateTime, subset(all_ice, year > 2000 & year < 2010), type='l') |
| 95 | +points(all_ice$DateTime, all_ice$avsnow) |
| 96 | +#dev.off() |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +#### |
| 101 | +#ICE |
| 102 | + |
| 103 | +mean(abs(all_ice$firstopen - as.POSIXlt(all_ice$off)$yday+1), na.rm=TRUE) |
| 104 | +mean((all_ice$firstopen - as.POSIXlt(all_ice$off)$yday+1), na.rm=TRUE) |
| 105 | + |
| 106 | +plot(all_ice$firstopen, as.POSIXlt(all_ice$off)$yday+1) |
| 107 | +abline(0,1) |
| 108 | + |
| 109 | +mean(abs(all_ice$lastopen - as.POSIXlt(all_ice$on)$yday+1), na.rm=TRUE) |
| 110 | +mean((all_ice$lastopen - as.POSIXlt(all_ice$on)$yday+1), na.rm=TRUE) |
| 111 | + |
| 112 | +plot(all_ice$lastopen, as.POSIXlt(all_ice$on)$yday+1) |
| 113 | +abline(0,1) |
| 114 | + |
| 115 | + |
| 116 | +##figure for Hipsey paper |
| 117 | + |
| 118 | +#png('figures/sp_bws_plots.png', res=300, width=2000, height=2000) |
| 119 | +par(mfrow=c(3,1), oma=c(5,4,0,0), mar=c(0,0,1,1)) |
| 120 | + |
| 121 | +plot(hice~DateTime, subset(all_ice, year > 1990 & year < 2001), type='l', ylab='Blue Ice (m)', xaxt='n') |
| 122 | +lines(hice~DateTime, all_ice) |
| 123 | +points(all_ice$DateTime, all_ice$blueice, col=rgb(0, 0, 0, 0.5), pch=16) |
| 124 | +mtext(side=2, text='Blue Ice (m)', line=2.5) |
| 125 | +legend('topright', legend = 'A', bty = 'n', inset = c(-0.01,-0.06), cex=2) |
| 126 | + |
| 127 | +plot(hwice~DateTime, subset(all_ice, year > 1990 & year < 2001), type='l', ylab='White Ice (m)', xaxt='n') |
| 128 | +lines(hwice~DateTime, all_ice) |
| 129 | +points(all_ice$DateTime, all_ice$whiteice, col=rgb(0, 0, 0, 0.5), pch=16) |
| 130 | +mtext(side=2, text='White Ice (m)', line=2.5) |
| 131 | +legend('topright', legend = 'B', bty = 'n', inset = c(-0.01,-0.06), cex=2) |
| 132 | + |
| 133 | +legend('topleft', legend = c('Modeled', 'Observed'), pch = c(NA, 16), lty=c(1,NA), col=c('black', rgb(0, 0, 0, 0.5)), inset=c(0.01, 0.05)) |
| 134 | + |
| 135 | +plot(hsnow~DateTime, subset(all_ice, year > 1990 & year < 2001), type='l', ylab='Snow (m)') |
| 136 | +lines(hsnow~DateTime, all_ice) |
| 137 | +points(all_ice$DateTime, all_ice$avsnow, col=rgb(0, 0, 0, 0.5), pch=16) |
| 138 | +mtext(side=2, text='Snow (m)', line=2.5) |
| 139 | +mtext(side=1, text='Year', line=2.5) |
| 140 | +legend('topright', legend = 'C', bty = 'n', inset = c(-0.01,-0.06), cex=2) |
| 141 | + |
| 142 | +#dev.off() |
| 143 | + |
| 144 | + |
| 145 | +### Compare ice on and off for Hipsey paper |
| 146 | + |
| 147 | +library(mda.lakes) |
| 148 | +library(lubridate) |
| 149 | +onoff = lter_on_off |
| 150 | +mod_onoff = get_ice_onoff(get_ice(ncfile), get_temp(ncfile, reference = 'surface')) |
| 151 | + |
| 152 | +obsmod = merge(onoff, mod_onoff, by='year') |
| 153 | + |
| 154 | + |
| 155 | +#png('figures/sp_on_off_plots.png', res=300, width=2400, height=1500) |
| 156 | +par(mfrow=c(1,2), mar=c(5,4,1,1)) |
| 157 | + |
| 158 | +plot(yday(obsmod$on), yday(as.POSIXct(obsmod$datelastopen)), pch=16, col=rgb(0, 0, 0, 0.5), |
| 159 | + xlab='Modeled Ice On', ylab='Observed Ice On') |
| 160 | +abline(0,1) |
| 161 | +plot(yday(obsmod$off[-1]), yday(as.POSIXct(obsmod$datefirstopen[-1])), pch=16, col=rgb(0, 0, 0, 0.5), |
| 162 | + xlab='Modeled Ice Off', ylab='Observed Ice Off') |
| 163 | +abline(0,1) |
| 164 | + |
| 165 | +#dev.off() |
0 commit comments