Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select_time() with one time returns cubes without end-times, creating errors for st_as_stars() etc #86

Open
cboettig opened this issue Jun 24, 2023 · 0 comments

Comments

@cboettig
Copy link

When we apply gdalcubes::select_time() with a single time value, we get an object that does not have a start and end time. When we then use st_as_stars() to convert this to a stars object, we get an erroneous end time. (Sometimes this is the origin time, 1970-01-01, which is bad, but sometimes I get non-date-times for this, which lead to breaking errors).

We can see this error using a simple modification to the example code for select_time()

# create image collection from example Landsat data only 
# if not already done in other examples
if (!file.exists(file.path(tempdir(), "L8.db"))) {
  L8_files <- list.files(system.file("L8NY18", package = "gdalcubes"),
                         ".TIF", recursive = TRUE, full.names = TRUE)
  create_image_collection(L8_files, "L8_L1TP", file.path(tempdir(), "L8.db"), quiet = TRUE) 
}

L8.col = image_collection(file.path(tempdir(), "L8.db"))
v = cube_view(extent=list(left=388941.2, right=766552.4, 
                          bottom=4345299, top=4744931, t0="2018-04", t1="2018-07"),
              srs="EPSG:32618", nx = 497, ny=526, dt="P1M")
L8.cube = raster_cube(L8.col, v) 
L8.rgb = select_bands(L8.cube, c("B02", "B03", "B04"))

Now select only one time:

L8.rgb = select_time(L8.rgb, c("2018-04"))
st_as_stars(L8.rgb)

gives us:

image

Note the erroneous end time (1970-01-01).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant