Skip to content

example_data

Ben Tupper edited this page Dec 22, 2022 · 4 revisions

Example Data

twinkle includes three example datasets to augment those available in the stars package and elsewhere. These include examples of

Penobscot Bay Dataset

MUR Sea Surface Temperature

One month of daily MUR SST rasters (as one GeoTIFF) from 2014 covering Penobscot Bay, Maine. The bounding box [west, east, south, north] is [-69.2, -68.49, 43.78, 44.5]. Dates provided are 2014-06-01 through 2014-06-30. Also provided are daily sst slope and daily cumulative sst (origin January 1). These are named 20140601-20140630-sst.tif, 20140601-20140630-sst_slope.tif amd 20140601-20140630-sst_cum.tif.

sst <- stars::read_stars(system.file("datasets/20140601-20140630-sst.tif", 
                                     package = "twinkle"))
# stars object with 3 dimensions and 1 attribute
# attribute(s):
#  20140601-20140630-sst.tif 
#  Min.   :281.4             
#  1st Qu.:283.7             
#  Median :284.5             
#  Mean   :284.4             
#  3rd Qu.:285.2             
#  Max.   :287.6             
#  NA's   :46050             
# dimension(s):
#      from to  offset delta refsys point values x/y
# x       1 71 -69.195  0.01 WGS 84 FALSE   NULL [x]
# y       1 72  44.505 -0.01 WGS 84 FALSE   NULL [y]
# band    1 30      NA    NA     NA    NA   NULL  
slope <- stars::read_stars(system.file("datasets/20140601-20140630-sst_slope.tif", 
                                       package = "twinkle"))
cum <- stars::read_stars(system.file("datasets/20140601-20140630-sst_cum.tif", 
                                     package = "twinkle"))

These data are derived from… > JPL MUR MEaSUREs Project. 2015. GHRSST Level 4 MUR Global Foundation Sea Surface Temperature Analysis. Ver. 4.1. PO.DAAC, CA, USA. Dataset accessed [2021-02-08] at https://doi.org/10.5067/GHGMR-4FJ04

Penobscot Bay Points

100 points within Penobscot Bay, selected at random, stored in geopackage format. Use sf::read_sf(system.file("datasets/penbay-points.gpkg", package = 'twinkle')) to read them in.

pts <- sf::read_sf(system.file("datasets/penbay-points.gpkg", package = 'twinkle'))
# Simple feature collection with 100 features and 5 fields
# geometry type:  POINT
# dimension:      XY
# bbox:           xmin: -69.18 ymin: 43.79 xmax: -68.49 ymax: 44.41
# geographic CRS: WGS 84
# # A tibble: 100 x 6
#     index  cell   col   row  band           geom
#     <int> <dbl> <dbl> <dbl> <dbl>    <POINT [°]>
#  1  95384  3368    31    48    19 (-68.89 44.03)
#  2  19875  4539    66    64     4 (-68.54 43.87)
#  3 136212  3300    34    47    27 (-68.86 44.04)
#  4 145992  2856    16    41    29  (-69.04 44.1)
#  5 130243  2443    29    35    26 (-68.91 44.16)
#  6  78418  1738    34    25    16 (-68.86 44.26)
#  7  60452  4220    31    60    12 (-68.89 43.91)
#  8 104298  2058    70    29    21  (-68.5 44.22)
#  9  55121  4001    25    57    11 (-68.95 43.94)
# 10  64280  2936    25    42    13 (-68.95 44.09)
# # … with 90 more rows

Penobscot Bay polygon

A polygon within Penobscot Bay stored in geopackage format. Use sf::read_sf(system.file("datasets/penbay-polygons.gpkg", package = 'twinkle')) to them in.

poly <- sf::read_sf(system.file("datasets/penbay-polygons.gpkg", package = 'twinkle'))
# Simple feature collection with 1 feature and 0 fields
# geometry type:  POLYGON
# dimension:      XY
# bbox:           xmin: -69 ymin: 43.9 xmax: -68.6 ymax: 44.2
# geographic CRS: WGS 84
# # A tibble: 1 x 1
#                                             geom
#                                    <POLYGON [°]>
# 1 ((-69 43.9, -68.6 43.9, -68.8 44.2, -69 43.9))
par(mfrow = c(1,2))
i <- 1
plot(sst[1,,,i], reset = FALSE, key.pos = NULL,
   main = paste("sst", i),
   add.geom = list(sf::st_geometry(dplyr::filter(pts, band == i)), 
                   col = "orange", pch = 19))
plot(poly, add = TRUE, border = "pink", col = NA, lwd = 2)


i <- 2
plot(sst[1,,,i], reset = FALSE, key.pos = NULL,
   main = paste("sst", i),
   add.geom = list(sf::st_geometry(dplyr::filter(pts, band == i)), 
                   col = "olivedrab", pch = 19))
plot(poly, add = TRUE, border = "pink", col = NA, lwd = 2)

par(mfrow = c(1,1))

Volcano dataset

A stars version of this nice example of the built in volcano dataset. Points and polygons are also provided but not shown here. See volcano_points() and volcano_polygon().

First read in the volcano data with a single band, but three different attributes (variables). Note that each attribute is independently scaled.

Note that to plot multiple attributes in one view, there are fewer options for plotting notably applying a legend. The method is to set the mfrow argument to par() to your desired layout, then call the stars plot method with reset = FALSE, key.pos = NULL. twinkle includes a simple wrapper function, mplot(), to manage this for you. The second attribute values are ‘flipped’ to dramatize the value ranges which are scaled separately.

By attribute

v_a <- volcano_multi(what = "attributes") |>
  rlang::set_names(c("volcano_1", "volcano_2", "volcano_3")) |>
  dplyr::mutate(volcano_2 = abs(232 - volcano_2))
# stars object with 2 dimensions and 3 attributes
# attribute(s):
#       v1               v2              v3        
#  Min.   : 90.28   Min.   :111.9   Min.   :108.0  
#  1st Qu.:103.72   1st Qu.:128.6   1st Qu.:124.0  
#  Median :119.09   Median :147.6   Median :142.4  
#  Mean   :125.03   Mean   :155.0   Mean   :149.5  
#  3rd Qu.:144.06   3rd Qu.:178.6   3rd Qu.:172.3  
#  Max.   :187.28   Max.   :232.2   Max.   :224.0  
# dimension(s):
#   from to  offset delta                       refsys point values x/y
# x    1 87 6478705    10 NZGD49 / New Zealand Map ...    NA   NULL [x]
# y    1 61 2668015   -10 NZGD49 / New Zealand Map ...    NA   NULL [y]

mplot(v_a)

By band

But we can reorganize so that instead of three different attributes with single bands that we have three bands for a single attribute. Note the plot scales all bands into the same color scale - something that does not happen when plotting multiple attributes.

v_b <- volcano_multi(what = "bands", threshold = 120)
# stars object with 3 dimensions and 1 attribute
# attribute(s):
#        X         
#  Min.   : 92.43  
#  1st Qu.:118.63  
#  Median :136.69  
#  Mean   :142.79  
#  3rd Qu.:164.81  
#  Max.   :229.56  
# dimension(s):
#         from to  offset delta                       refsys point     values x/y
# x          1 87 6478705    10 NZGD49 / New Zealand Map ...    NA       NULL [x]
# y          1 61 2668015   -10 NZGD49 / New Zealand Map ...    NA       NULL [y]
# volcano    1  3      NA    NA                           NA    NA v1, v2, v3    

plot(v_b)

Tiny Toy Dataset

A multiband dataset with very small dimensions, with convenient polygons and points.

toy <- toy_multi()
# stars object with 3 dimensions and 1 attribute
# attribute(s):
#        X        
#  Min.   :  1.0  
#  1st Qu.:115.5  
#  Median :234.0  
#  Mean   :237.0  
#  3rd Qu.:356.5  
#  Max.   :500.0  
#  NA's   :225    
# dimension(s):
#      from to offset delta refsys point    values x/y
# x       1 10      0     1     NA    NA      NULL [x]
# y       1 10     10    -1     NA    NA      NULL [y]
# band    1  5     NA    NA     NA    NA b1,...,b5    

pts <- toy_points()
# Simple feature collection with 10 features and 2 fields
# geometry type:  POINT
# dimension:      XY
# bbox:           xmin: 1.858451 ymin: 4.611483 xmax: 8.521713 ymax: 8.987802
# CRS:            NA
# # A tibble: 10 x 3
#       id band             geometry
#    <int> <chr>             <POINT>
#  1     1 b3    (1.858451 6.031725)
#  2     2 b4    (1.981977 8.810914)
#  3     3 b1    (7.698303 5.102966)
#  4     4 b5    (4.586549 5.620073)
#  5     5 b2    (1.906566 6.416532)
#  6     6 b1    (8.521713 6.300849)
#  7     7 b3    (5.645839 8.987802)
#  8     8 b2     (4.17234 4.611483)
#  9     9 b3    (5.397651 6.953142)
# 10    10 b3    (4.491615 4.644204)

poly <- toy_polygon()
# Simple feature collection with 1 feature and 1 field
# geometry type:  POLYGON
# dimension:      XY
# bbox:           xmin: 3 ymin: 2 xmax: 8 ymax: 8
# CRS:            NA
#   id                           geom
# 1  1 POLYGON ((5 8, 8 5, 5 2, 3 ...

plot(toy[,,,1], axes = TRUE, reset = FALSE)
plot(sf::st_geometry(pts), add = TRUE, pch = 19, col = "orange")
plot(poly, add = TRUE, border = "green", col = NA)