7

I have tabular data with columns longitude, latitude, time, and intensity, like so:

library(lubridate)

## mock example data
ex <- tibble(longitude = 1:10, 
             latitude = 10:1, 
             date = today() : (today() + 9), 
             intensity = rnorm(10))

In reality, it is a collection of ~ 230 compressed tab-separated text files, 10 MB each, in the above format.

I am trying to go from this tabular representation (e.g. reading this data with readr::read_tsv()) to a stars object (eventually/ideally a stars_proxy object, given the data size).

One thing I've considered is converting to an st object first:

star1 <- ex %>% 
  st_as_sf(coords = c("longitude", "latitude"), 
         crs = 4326) %>% 
  st_as_stars()

but this creates a stars object with only one dimension, which is a geometry. Since I have a point geometry, I'd rather have this as x and y dimensions in the 4326 (WGS84) CRS, and I'd like time to be a dimension. I can coerce the dimension (I think), with:

star2 <- st_set_dimensions(star1, 1, star1$date, "date")

though I still see only 1 listed dimension:

star2
stars object with 1 dimensions and 2 attributes
attribute(s):
     date          intensity      
 Min.   :18332   Min.   :-1.3239  
 1st Qu.:18334   1st Qu.:-0.9127  
 Median :18336   Median :-0.1671  
 Mean   :18336   Mean   :-0.1405  
 3rd Qu.:18339   3rd Qu.: 0.4975  
 Max.   :18341   Max.   : 1.0076  
dimension(s):
         from to offset delta refsys point values
geometry    1 10  18332     1     NA  date   NULL

So, given data in this tabular format, how do I generate a proper a stars object (ideally stars_proxy object), with proper x,y, and time dimension attributes?

2
  • Welcome to GIS SE. As a new user, please take the Tour, which emphasizes the importance of asking One question per Question. Please Edit your question to ask a single question.
    – Vince
    Commented Mar 12, 2020 at 2:36
  • Thanks! I've revised my question accordingly!
    – cboettig
    Commented Mar 12, 2020 at 4:12

2 Answers 2

2

I think you just need to directly define the correct dimensions:

st_as_stars(ex, dims = c("longitude", "latitude", "date"))

stars object with 3 dimensions and 1 attribute
attribute(s):
                Min.    1st Qu.     Median       Mean  3rd Qu.     Max. NA's
intensity  -1.193894 -0.4824627 0.04344971 0.09380003 0.552871 1.687245  990
dimension(s):
          from to offset delta refsys point values x/y
longitude    1 10    0.5     1     NA    NA   NULL [x]
latitude     1 10   10.5    -1     NA    NA   NULL [y]
date         1 10  19241     1     NA    NA   NULL
0

Not full answer but

ex_star <- st_as_stars(ex) 

will create a stars with the first two columns from the tibble as the first two dimensions of the stars, so make sure you pass a tibble with the correct arrangement of columns. There is a dimensions argument which I honestly till now I thought that giving a number would tell st_stars to keep adding columns as dimensions but I tested it and does not seem to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.