Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's day light savings isn't it!? #5

Open
thodson-usgs opened this issue Feb 13, 2023 · 5 comments
Open

It's day light savings isn't it!? #5

thodson-usgs opened this issue Feb 13, 2023 · 5 comments

Comments

@thodson-usgs
Copy link
Member

@gzt5142

@thodson-usgs
Copy link
Member Author

thodson-usgs commented Feb 13, 2023

This can be a teaching example for one of the earlier notebooks.
I think the simplest solution is to convert to UTC

@gzt5142
Copy link

gzt5142 commented Feb 13, 2023

Are you suggesting that the -5h offset is appropriate for half of the year, but not the other half? so only half the data matches... Hmm.

I would have thought that time stamps were UTC. I'll have to look at it tomorrow.

@gzt5142
Copy link

gzt5142 commented Feb 14, 2023

I think that the original notebook succeeded because of these lines:

# make sure the indices match
obs.index = obs.index.to_period('D')
mod.index = mod.index.to_period('D')
## note: mod and obs are pandas series

My hypothesis is that it re-indexed such that the time information was dropped. That particular pair of commands is specific to dataframes, which is why they worked on the pd.Series of that original notebook. Just need to find the equivalent action for an xarray dataset/dataarray, and I think that will solve the issue.

@gzt5142
Copy link

gzt5142 commented Feb 15, 2023

I think this will do it...

x = obs.sel(gage_id="USGS-03339000")
x_hat = model.sel(gage_id="USGS-03339000").resample(time='1D', offset='5h').mean()
x['time'] = x['time'].dt.floor('D')
x_hat['time'] = x_hat['time'].dt.floor('D')
(x.time == x_hat.time).count()

I get 15310 from that count.

The dt.floor('D') is the xarray replacement for the pandas to_period capability. Time data in xarray seems to have a special method associated with a datetime data type... .dt can do lots of stuff I've never considered before. Manipulates datetime values in useful ways.

@thodson-usgs
Copy link
Member Author

@gzt5142, thanks! Yes, I was aware of dt but I probably assumed floor did something else.

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

No branches or pull requests

2 participants