Skip to content

Problems with Pandas time formatting when ARM files do not start at 0000 UTC. #418

Answered by mgrover1
AdamTheisen asked this question in Q&A
Discussion options

You must be logged in to vote

So it looks like it's an issue that cftime can solve.. for example:

ds = xr.open_dataset('houkasacrcfrM1.a1.20210922.150006.nc',
                     use_cftime=True)

print(ds)
<xarray.DataArray 'time' (time: 64)>
array([cftime.DatetimeGregorian(2021, 9, 22, 15, 0, 6, 471754, has_year_zero=False),
       cftime.DatetimeGregorian(2021, 9, 22, 15, 0, 8, 445242, has_year_zero=False),
       cftime.DatetimeGregorian(2021, 9, 22, 15, 0, 10, 418669, has_year_zero=False),
       cftime.DatetimeGregorian(2021, 9, 22, 15, 0, 12, 392112, has_year_zero=False),

We can convert this to np.datetime by using:

ds['time'] = ds.indexes['time'].to_datetimeindex()

print(ds.time)
<xarray.DataArray 'time' (time

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mgrover1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #403 on March 14, 2022 14:42.