Skip to content

Add prefer_datetime keyword for Raster constructor#1002

Open
felixcremer wants to merge 7 commits into
rafaqz:mainfrom
felixcremer:fc/prefer_datetime
Open

Add prefer_datetime keyword for Raster constructor#1002
felixcremer wants to merge 7 commits into
rafaqz:mainfrom
felixcremer:fc/prefer_datetime

Conversation

@felixcremer
Copy link
Copy Markdown
Contributor

This adds the prefer_datetime keyword argument to the Raster constructor and forwards it to cfvariable.

This closes #1000.

@rafaqz
Copy link
Copy Markdown
Owner

rafaqz commented Aug 13, 2025

Just need to add the same arguments to the ArchGDAL method, even if it just gets ignored there

@felixcremer
Copy link
Copy Markdown
Contributor Author

I added the prefer_datetime arg also to the _dims method of a RasterDataset. I also bumped the CDM version to 0.3.10 because this is where this keyword landed.

This should be good to go now that the change was merged into CDM.

Comment thread Project.toml Outdated
@rafaqz rafaqz closed this Aug 22, 2025
@rafaqz rafaqz reopened this Aug 22, 2025
@rafaqz rafaqz closed this Sep 12, 2025
@rafaqz rafaqz reopened this Sep 12, 2025
Comment thread src/sources/commondatamodel.jl Outdated
@rafaqz
Copy link
Copy Markdown
Owner

rafaqz commented Mar 2, 2026

@felixcremer is this meant to work now?

@rafaqz
Copy link
Copy Markdown
Owner

rafaqz commented Mar 6, 2026

Bump @felixcremer

@felixcremer
Copy link
Copy Markdown
Contributor Author

felixcremer commented Mar 13, 2026

Unfortunately this uncovered a bug with reading date times in Rasters.
The unit information that is available in the zarr data is not properly read in rasters and therefore the time axis is wrong.

I would need some hint where this is done so that I can fix it.
See the MWE below with this example dataset
testdata.zip

using Rasters
using Zarr
using ZarrDatasets
using Dates
testdatapath = Downloads.download("https://github.com/user-attachments/files/25968262/testdata.zip")
zstore = Zarr.ZipStore(Mmap.mmap(testdatapath))
z = zopen(zstore)

ras = Raster(ZarrDataset(zstore), prefer_datetime=false)

rti = dims(ras, :azimuth_time)
rti_diffs = Dates.value.(diff(rti.val))
zdiffs = diff(z.arrays["azimuth_time"][:])
zdiffs == rti_diffs

CFTime.units(rti[1]) # Whould have expected "nanoseconds since 2025-06-26T05:34:21.819152" as they are written in the .zattrs

@felixcremer
Copy link
Copy Markdown
Contributor Author

I thought that this might be related to the fact, that the units of the element type of the time axis are microseconds since 1900-01-01 but I fixed this locally and the time axis is still wrong.
I am not sure, whether this problem is actually happening in Rasters or in CommonDataModel.
@Alexander-Barth maybe you have some idea what might be the underlying issue.

@rafaqz
Copy link
Copy Markdown
Owner

rafaqz commented May 25, 2026

Netcdf handles this - so I suspect this is a CommonDataModel problem

@Alexander-Barth
Copy link
Copy Markdown

Per default CommonDataModel currently converts the time values to DateTimes (unless prefer_datetime = false).

Note that Dates.value does return milliseconds for julia's DateTime structures but for CFTime structures the units on the metadata.

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

Successfully merging this pull request may close these issues.

Cannot open Zarr file with nanosecond time information

3 participants