The CalCOFI grid (cc_grid) and centroids
(cc_grid_ctrs) show the CalCOFI
Station Positions – CalCOFI at varying separation distances of
station positions (sta_dpos) in the CalCOFI coordinate
system from nearshore (5), to offshore (10) to
outside the 113 extended station pattern to historically visited areas
(20).
This allows summarization of effort within each station and defining
a study area according to these criteria (e.g.,
sta_dpos).
# show first 6 rows of example data frame with temperature in space as variable
head(cc_bottle)
#> # A tibble: 6 × 10
#> lon lat date quarter depth_m sta_dpos t_degc salinity o2sat n
#> <dbl> <dbl> <date> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <int64>
#> 1 -134. 42.5 1972-05-16 2 0 20 11.2 32.9 109 1
#> 2 -134. 42.5 1972-05-16 2 10 20 11.2 32.9 109. 1
#> 3 -134. 42.5 1972-05-16 2 20 20 10.9 32.9 110. 1
#> 4 -134. 42.5 1972-05-16 2 30 20 10.6 32.9 110 1
#> 5 -134. 42.5 1972-05-16 2 50 20 9.97 32.9 108. 1
#> 6 -134. 42.5 1972-05-16 2 55 20 9.83 32.9 107. 1
# summarize temperature by location and convert to points
d_t <- cc_bottle %>%
filter(
!is.na(t_degc)) %>%
group_by(lon, lat) %>%
summarize(
n = n(),
v = mean(t_degc),
.groups = "drop") %>%
st_as_sf(
coords = c("lon", "lat"), remove = F,
crs = 4326)You can map the contours of input data using the faster, rougher
Inverse-Distance Weighting (IDW; pts_to_rast_idw(),
rast_to_contours()) technique or the slower, smoother
Generalized Additive Model (GAM;
pts_to_contours_gam()).
# interpolate points to raster using IDW
r_k_all <- pts_to_rast_idw(d_t, "v", cc_grid_zones)
mapView(st_as_stars(r_k_all))
# generate contour polygons from raster
p_k_all <- rast_to_contours(r_k_all, cc_grid_zones)
mapView(p_k_all, zcol = "z_avg")
aoi_ext <- cc_grid_zones |>
filter(
sta_pattern %in% c("standard", "extended"))
# interpolate points to raster using IDW
r_k_ext <- pts_to_rast_idw(d_t, "v", aoi_ext)
mapView(st_as_stars(r_k_ext), layer.name="Temp.(C)")
# generate contour polygons from raster
p_k_ext <- rast_to_contours(r_k_ext, aoi_ext)
mapView(p_k_ext, zcol = "z_avg", layer.name="Temp.(C)")
aoi_stdnr <- cc_grid_zones %>%
filter(
sta_pattern == "standard",
sta_shore == "nearshore")
# interpolate points to raster using IDW
r_k_stdnr <- pts_to_rast_idw(d_t, "v", aoi_stdnr)
mapView(st_as_stars(r_k_stdnr), layer.name="Temp.(C)")
# generate contour polygons from raster
p_k_stdnr <- rast_to_contours(r_k_stdnr, aoi_stdnr)
mapView(p_k_stdnr, zcol = "z_avg", layer.name="Temp.(C)")Plot time series of an oceanographic variable from CTD cast bottle data.
# get variables
(v <- get_variables())
#> # A tibble: 3 × 6
#> category table_field plot_title plot_label plot_color color_palette
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Oceanographic ctd_bottles.sali… Salinity Salinity … purple Purples
#> 2 Oceanographic ctd_bottles.o2sat Oxygen Sa… Oxygen pe… blue Blues
#> 3 Oceanographic ctd_bottles.t_de… Temperatu… Temperatu… red Reds
# fetch time series data for the first variable from CalCOFI API
(d <- get_timeseries("ctd_bottles.t_degc"))
#> # A tibble: 71 × 4
#> year val_avg val_sd n_obs
#> <dbl> <dbl> <dbl> <dbl>
#> 1 1949 9.12 4.68 28081
#> 2 1950 9.12 4.37 38298
#> 3 1951 9.19 4.54 40459
#> 4 1952 10.4 4.03 31690
#> 5 1953 10.6 3.71 29789
#> 6 1954 10.8 4.33 18874
#> 7 1955 10.1 4.71 23248
#> 8 1956 11.2 4.41 14274
#> 9 1957 13.0 5.04 19072
#> 10 1958 12.1 4.71 24324
#> # ℹ 61 more rows
# plot time series with the first variable
with(v[1,],
plot_timeseries(
# data and columns (from d)
d, year, val_avg, val_sd,
# plot attributes (from v)
plot_title, plot_label, plot_color))Plot depth of an oceanographic variable from CTD cast bottle data.
head(bottle_temp_depth)
#> # A tibble: 6 × 3
#> # Groups: cast_count [1]
#> cast_count depth_m v
#> <int> <dbl> <dbl>
#> 1 12874 0 15.5
#> 2 12874 8 14.8
#> 3 12874 10 14.7
#> 4 12874 20 14.2
#> 5 12874 23 14.2
#> 6 12874 30 14.2
# plot depth with the station data
plot_depth(df = bottle_temp_depth, variable = "Temperature")