appelmar / gdalcubes

Creating and analyzing Earth observation data cubes in R
https://gdalcubes.github.io
Other
120 stars 28 forks source link

Remove specific time slices #25

Closed mariofajardo closed 3 years ago

mariofajardo commented 4 years ago

Hi...congrats for this great package... It really has made my life much easier!

Is it a way to remove specific time slices from an irregular time series of let's say PlanetScope data (4 bands).

In my case I have something like this:

gdalCubeStack  <- create_image_collection(dir('CroppedImagery/',full.names = T,pattern = '.tif'),format = 'PlanetScope_3B_AnalyticMS_SR')

#dims is the Dimensions of first raster (they all have the same extent...They are 19 rasters covering 6 months at irregular intervals)
dims <- dim(brick('CroppedImagery/20190512_000540_1048_3B_AnalyticMS_SR.tif'))

v.overview = cube_view(extent=gdalCubeStack,nx = dims[1],ny = dims[2], dt='P1D',srs="EPSG:3857")

PlanetScope.cube <- raster_cube(gdalCubeStack,v.overview)

Now the problem is that PlanetScope.cube has 92 time slices ...most of them are just empty.

I basically want to remove the empty ones...and keep most of them. If I try reduce_time() I end up with a single slice.

I know that I can transform the object to a stars object... but i would love to remove these time slices before.

Thanks a lot for the effort in developing this great piece of work!

Cheers

Mario Fajardo Post Doctoral Research Fellow Sydney University

appelmar commented 4 years ago

Glad to hear that the package is useful to you. Removing empty time slices is not possible at the moment as the data model requires a regular time dimension without gaps. I think this would be worth implementing, e.g. in one of the following ways:

  1. Export functions write_ncdf() and write_tif() could receive an additional argument to remove empty time slices. This would be relatively easy to implement and would not require any changes in the data model.

  2. The data model could be changed to allow a labeled time axis. This would be much more generic though still doable (I still need to think about implications on implemented operations). Similar to select_band(), there could be a select_time() function (or even something like drop_na_slices()).

Would something like this be helpful?

mariofajardo commented 4 years ago

Simple things are usually the best ones.

write_ncdf() with an extra argument specifying that, would be awesome

:)

fengtian2017 commented 4 years ago

Glad to hear that the package is useful to you. Removing empty time slices is not possible at the moment as the data model requires a regular time dimension without gaps. I think this would be worth implementing, e.g. in one of the following ways:

  1. Export functions write_ncdf() and write_tif() could receive an additional argument to remove empty time slices. This would be relatively easy to implement and would not require any changes in the data model.
  2. The data model could be changed to allow a labeled time axis. This would be much more generic though still doable (I still need to think about implications on implemented operations). Similar to select_band(), there could be a select_time() function (or even something like drop_na_slices()).

Would something like this be helpful?

Hi @appelmar, a select_time() function would be extremely useful! For example, I would like to do analysis only on data from the summer months. In GEE, I did this using filterMetadata() with adding a new band property of e.g., month.

I greatly appreciate your efforts in making and improving this awesome package! After using GEE processing EO data for some time, I never want to go back using the traditional image processing concept. I believe gdalcubes will be the future for EO data processing in R. I also like the simplicity of gdalcubes handling with parallel processing!

Cheers, Feng

appelmar commented 4 years ago

The dev branch now has a (still experimental) select_time() function that simply takes a vector of date/time strings. The resulting data cube has a irregular / labeled time dimension. Since this required some modifications to the original data model, I'd like to do quite a bit more testing and improve error handling before submitting a new version to CRAN. Hope this is useful for you!