Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Different time dimension reads across ncdf4 vs. xarray & panoply #3

Open
adamkemberling opened this issue Feb 25, 2021 · 2 comments
Open

Comments

@adamkemberling
Copy link

adamkemberling commented Feb 25, 2021

Hesitant to raise this issue because it felt above my head to diagnose, but here is a synopsis of deeper issue of an original question raised here on stackoverflow.

Original question was how to convert dates of a netcdf file, read into R using ncdf4::nc_open() that had units of "minutes since 1850-01-16T14:06:00"

Through exploring answers to the question we noticed that we could answer the original question of how to convert the dates, but the outputs never aligned with the expected results, which we knew from opening the same file in {xarray} and panoply. With the ultimate solution resulting in multiplying the time dimension by sixty before converting to datetime (which is counterintuitive to the netcdf units) and then correcting the alignment of the day.

I guess the larger question is whether anyone else has encountered this mismatch of time/attributes across packages.

Happy to provide more context if there is an avenue to diagnosing the issue. Also understand if this is an edge case where the juice is not worth the squeeze. Appreciate the work you do.

@adamkemberling
Copy link
Author

Not sure if this helps anything but it seems to be linked to the date structure, which is handled by cftimes by xarray. If this is something you are already aware of I can close the issue.

@mdsumner
Copy link
Member

mdsumner commented Mar 2, 2021

Hi this is just an old copy of ncdf4, where I was experimenting with windows support - to get fixes into the package you need to contact the author directly.

https://cran.r-project.org/web/packages/ncdf4/index.html

I'll probably archive this repository, best.

fwiw on SO I think the answer needs to not assume local time, but there's no information about whether a time zone is in use, the question doesn't include the full header output but it really needs that at least

origin <- "1850-01-16T14:06:00"
values <- c(52559874, 52602354, 52644834, 52688754, 
                    52732674, 52776594, 52820514, 52865154)


as.POSIXct(origin, tz = "UTC") + values * 60
[1] "1949-12-22 21:54:00 UTC" "1950-01-21 09:54:00 UTC"
[3] "1950-02-19 21:54:00 UTC" "1950-03-22 09:54:00 UTC"
[5] "1950-04-21 21:54:00 UTC" "1950-05-22 09:54:00 UTC"
[7] "1950-06-21 21:54:00 UTC" "1950-07-22 21:54:00 UTC"

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

No branches or pull requests

2 participants