|
| 1 | +## Download FISHBOT data from ERDDAP |
| 2 | +end = Sys.Date() |
| 3 | +start = end - lubridate::days(7) |
| 4 | +url = paste0( |
| 5 | + "https://erddap.ondeckdata.com/erddap/tabledap/fishbot_realtime.csvp?time%2Ctemperature%2Cgrid_id%2Clatitude%2Clongitude&time%3E=", |
| 6 | + lubridate::year(start), |
| 7 | + "-", |
| 8 | + lubridate::month(start), |
| 9 | + "-", |
| 10 | + lubridate::day(start), |
| 11 | + "T00%3A00%3A00Z&time%3C=", |
| 12 | + lubridate::year(Sys.Date()), |
| 13 | + "-", |
| 14 | + lubridate::month(Sys.Date()), |
| 15 | + "-", |
| 16 | + lubridate::day(Sys.Date()), |
| 17 | + "T00%3A00%3A00Z" |
| 18 | +) |
| 19 | +# url=paste0( |
| 20 | +# 'https://erddap.ondeckdata.com/erddap/tabledap/fishbot_realtime.csvp?time%2Ctemperature%2Ctemperature_count%2Cdata_provider%2Cgrid_id%2Clatitude%2Clongitude&time%3E=2025-08-21T00%3A00%3A00Z&time%3C=2025-08-28T00%3A00%3A00Z' |
| 21 | +# ) |
| 22 | +data = read.csv(url) |
| 23 | +## Download bathymetric data |
| 24 | +bath = marmap::getNOAA.bathy( |
| 25 | + lon1 = min(-80.83), |
| 26 | + lon2 = max(-56.79), |
| 27 | + lat1 = min(34), |
| 28 | + lat2 = max(46.89), |
| 29 | + resolution = 1 |
| 30 | +) |
| 31 | +## Create color ramp |
| 32 | +blues = c( |
| 33 | + "lightsteelblue4", |
| 34 | + "lightsteelblue3", |
| 35 | + "lightsteelblue2", |
| 36 | + "lightsteelblue1" |
| 37 | +) |
| 38 | +## Set up plot |
| 39 | +filename = paste0(here::here("data-raw/scripts/2026/FISHBOT.png")) |
| 40 | +file.create(filename) |
| 41 | + |
| 42 | +png( |
| 43 | + filename, |
| 44 | + height = 1000, |
| 45 | + width = 800, |
| 46 | + units = "px" |
| 47 | +) |
| 48 | +plot( |
| 49 | + bath, |
| 50 | + step = 100, |
| 51 | + deepest.isobath = -1000, |
| 52 | + shallowest.isobath = 0, |
| 53 | + col = "darkgray", |
| 54 | + image = TRUE, |
| 55 | + land = TRUE, |
| 56 | + lwd = 0.1, |
| 57 | + bpal = list( |
| 58 | + c(0, max(bath), "gray"), |
| 59 | + c(min(bath), 0, blues) |
| 60 | + ), |
| 61 | + main = paste0( |
| 62 | + "Gridded Bottom Temperature Observations ", |
| 63 | + start, |
| 64 | + " to ", |
| 65 | + end |
| 66 | + ), |
| 67 | + xlim = c(-76, -66), |
| 68 | + ylim = c(34, 45) |
| 69 | +) |
| 70 | +## Load the shapefile |
| 71 | +grid = sf::read_sf(here::here( |
| 72 | + "data-raw/scripts/2026/7km_trimmed_fixedgeometries/7km_grid_clipped_fixed_geometry.shp" |
| 73 | +)) |
| 74 | +grid = subset(grid, grid$id %in% data$grid_id) |
| 75 | +grid$temp = NA |
| 76 | +grid$color = NA |
| 77 | +for (i in 1:nrow(grid)) { |
| 78 | + grid$temp[i] = mean( |
| 79 | + subset(data, data$grid_id == grid$id[i])$temperature..degree_C. |
| 80 | + ) |
| 81 | +} |
| 82 | +grid$TEMP = grid$temp * 9 / 5 + 32 |
| 83 | +mintemp = floor(min(grid$TEMP)) |
| 84 | +maxtemp = ceiling(max(grid$TEMP)) |
| 85 | +tempcol = viridis::magma(n = length(seq(mintemp, maxtemp, 1))) |
| 86 | +for (i in 1:nrow(grid)) { |
| 87 | + grid$color[i] = tempcol[which( |
| 88 | + seq(mintemp, maxtemp, 1) == round(grid$TEMP[i], 0) |
| 89 | + )] |
| 90 | +} |
| 91 | +plot( |
| 92 | + sf::st_geometry(grid), |
| 93 | + max.plot = 1, |
| 94 | + add = TRUE, |
| 95 | + border = grid$color, |
| 96 | + col = grid$color |
| 97 | +) |
| 98 | +datacolors = data.frame( |
| 99 | + TEMP = seq(mintemp, maxtemp, 1), |
| 100 | + COL = tempcol |
| 101 | +) |
| 102 | +datacolors = subset( |
| 103 | + datacolors, |
| 104 | + datacolors$TEMP %in% round(quantile(datacolors$TEMP), 0) |
| 105 | +) |
| 106 | +legend( |
| 107 | + 'bottomright', |
| 108 | + fill = datacolors$COL, |
| 109 | + border = datacolors$COL, |
| 110 | + legend = datacolors$TEMP, |
| 111 | + title = "Bottom Temperature (F)" |
| 112 | +) |
| 113 | +dev.off() |
0 commit comments