I have downloaded a publicly available file containing a set of datasets in .tif format. Using R's stars package, I would like to take at look at the attribute values present in the raster, but I am facing some difficulties when trying to do so. I managed to perform this task using a toy file that comes with the stars package, but the same steps did not work with the data that I am using.
Below I provide the details of what I managed to do and what I did not. First I show how everything went fine with the toy data present in the stars package.
# Libraries
library(stars)
# Example with toy data
dfrt <- read_stars(system.file('tif/L7_ETMs.tif', package = 'stars'))
dfrt[[1]][1:5, 1:5, 1] # Displaying (a subset of) attribute values
# dfrt[1, 1:5, 1:5, 1][[1]] # Produces the same result as above
# dfrt %>% slice(., along = 'band', index = 1) %>%
# .[[1]] %>% .[1:5, 1:5] # Produces the same result as above
The above code produces the following intended result:
, , 1
[,1] [,2] [,3] [,4] [,5]
[1,] 69 74 68 61 60
[2,] 69 68 64 61 63
[3,] 63 59 61 63 65
[4,] 60 58 60 60 58
[5,] 61 58 59 56 57
I tried to do something analogous with a dataset that is publicly available, but I did not succeed. The code for downloading and reading the file was the following:
# Obtaining the file
download.file(paste('https://dataverse.harvard.edu/file.xhtml?persistentId',
'doi:10.7910/DVN/YSWMDR/FUQ16M&version=1.1', sep = '='),
'BUPR.tar.gz')
untar('BUPR.tar.gz', files = file.path('BUPR', 'BUPR_2010.tif'))
# Reading the file
dfdp <- read_stars('BUPR_2010.tif', proxy = TRUE)
The characteristics of the data that I downloaded are the following:
stars_proxy object with 1 attribute in 1 file(s):
$BUPR_2010.tif
[1] "[...]/BUPR_2010.tif"
dimension(s):
from to offset delta refsys point values x/y
x 1 18459 -2356399 250 USA_Contiguous_Albers_Equ... FALSE NULL [x]
y 1 11615 3172999 -250 USA_Contiguous_Albers_Equ... FALSE NULL [y]
Writing something similar to what worked with the toy data does not produce the intended results. This problem seems embarrassingly trivial, but I think that my lack familiarity with this kind of data is preventing me from finding the solution. How do I perform a task similar to what I did with the dfrt data?