EnMAP-Box / enmap-box

EnMAP-Box source code repository. See https://enmap-box.readthedocs.io for documentation
GNU General Public License v3.0
34 stars 16 forks source link

support temporal metadata provided by .aux.json files created with R-cran terra package #907

Closed janzandr closed 1 week ago

janzandr commented 1 month ago

Requested by @ffilipponi in #552 ...

Another source of datetime information associated to input raster data could be the found in .aux.json file generated when exporting raster data with explicit time dimension using R-cran terra package.

janzandr commented 1 month ago

@ffilipponi, please provide a small raster file created by R-cran terra package for testing.

ffilipponi commented 1 week ago

@janzandr , please find two small samples of raster time series exported from R-cran terra package in GeoTIFF format, complemented with '.aux.json' metadata containing time dimension information. R-cran terra package exports by default '.aux.json' file when the terra rast object to be exported has a defined time dimension (or other attributes).

Unevenly_spaced_time_series_R-cran_terra.zip

Thanks for considering the new feature request

janzandr commented 1 week ago

Thanks. Looks like the format supports different units (i.e. timestep). For now I will implement the "days" and "seconds" unit used in your examples: image image

If you need additional units, please provide some additional datasets (one for each unit).

janzandr commented 1 week ago

Done image

ffilipponi commented 1 day ago

Thanks for implementing the feature. Supported timesteps in R-cran terra package are: 'seconds' (POSIXlt), 'days' (Date), 'yearmonths' (decimal years), 'years', 'months'. When the timestep is not defined, it will be exported as 'raw'. From my point of view, it might be sufficient to have only 'days' and 'seconds' supported in EnMAP-Box. I forgot to specify that '.aux.json' file generated from R-cran terra package may contain various keys, depending on the properties associated to the object of class 'rast' that is exported. As a consequence, the keys 'time' and 'timestep' required to set time axis in EnMAP-Box may not always be defined in the '.aux.json' file. This needs an additional check to be integrated, in order to read time information only if it is defined in the '.aux.json' file. I suggest to modify line 787 in file 'rasterreader.py' as follows:

if self.terraMetadata is not None:
    if 'time' in self.terraMetadata.keys() and 'timestep' in self.terraMetadata.keys():