-
Notifications
You must be signed in to change notification settings - Fork 2
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
More General Utilities With Representation Of Time In idata Objects #35
More General Utilities With Representation Of Time In idata Objects #35
Conversation
#28 can be covered in this PR given the PR's scope. |
…al of option 3 to forecasttools functions
@damonbayer Can you take a quick look at the changes?
|
@dylanhmorris Current situation is that I would like you first to look at this file, then decide which option is closest to what you believe is best, then suggest changes to that option (code-changes or broader changes). I've selected Option 3 (pass date, group, and dim_name as a tuple). Finally, this file begins to set up the tests for Option 3 (but this could be applied to the other options as well). I would appreciate some suggestions on this file. A rendered version of the test file as a pdf with additional output can be found here. |
In communications between DHM and the author, a decision has been made to cease using |
The author's remark:
from datetime import date, datetime, timedelta
import arviz as az
import numpy as np
import polars as pl
import xarray as xr
coords = {"obs_dim_0": [0, 1, 2, 3, 5]}
data = xr.Dataset(
{"obs": ("obs_dim_0", np.array([10, 20, 30, 40, 50]))}, coords=coords
)
idata = az.InferenceData(observed_data=data)
# test parameters
group = "observed_data"
variable = "obs"
dimension = "obs_dim_0"
start_date = date(2022, 8, 1)
expected_datetimes = np.array([
datetime(2022, 8, 1),
datetime(2022, 8, 2),
datetime(2022, 8, 3),
datetime(2022, 8, 4),
datetime(2022, 8, 5),
]).astype("datetime64[D]")
idata_group = getattr(idata, group)
variable_data = idata_group[variable]
interval_size = variable_data.sizes[dimension]
out = np.arange(
start_date, interval_size, np.timedelta64(1, "D")
)
print(out)
idata_group = idata_group.assign_coords({dimension: out})
setattr(idata, group, idata_group)
print(idata.observed_data.coords[dimension].values) Out:
Warning:
|
Yes, if |
Re: #35 (comment) With this, the author will still operate with using two paths, one for |
Sounds good, but to avoid the warning, you should coerce the |
Re: #35 (comment) Sounds good; I've been proceeding with properly placed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking very good, thanks @AFg6K7h4fhy2. A few final things.
Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
…n-idata-objects' of github.com:CDCgov/forecasttools-py into 34-more-general-utilities-with-representation-of-time-in-idata-objects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your hard work, @AFg6K7h4fhy2!
Generalize utilities to add dates and times to
az.InferenceData
objects. A demonstration of these utilities can be found in #40 .