-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix & improve grouped spi #50
Conversation
2c59561
to
ac470b7
Compare
if not groups.dtype.name == "int16": | ||
warn("Casting groups to int16!") | ||
groups = groups.astype("int16") | ||
groups, keys = to_linspace(np.array(groups, dtype="str")) |
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.
@Kirill888 the idea is that the user passes in a list / array / tuple / ... containing group labels which puts the time
dimension into bins. The downstream function requires these groups to be in a linear space, so from 0
to len(groups)-1
which was the expected input previously.
To take this burden off the user, this allows any labels and converts them to a str
array, which is then converted to linear space. Maybe not most efficient, but for these applications totally fine - does that make sense for you?
For a practical example, we'll be using this to calculate SPIs for the full timeseries, grouping the time dimension into dekads per year. The user can then pass simply xx.time.dekad.yidx
in without having to make sure the groups
array is 0
indexed.
hdc/algo/accessors.py
Outdated
|
||
if calstart_ix >= calstop_ix: | ||
raise ValueError("calibration_start < calibration_stop!") | ||
if calibration_start > tix[-1:]: |
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.
is this comparing str > [str]
?
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.
comparing str
to pd.Timestamp
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.
why tix[-1:]
and not tix[-1]
?
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.
needs to remain a pd.DateTimeIndex
with one element to work ... maybe bit hacky & counterintuitive
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.
we could explicitly convert the string to a date object (pd.Timestamp
or whatever) and then compare the elements if that's clearer
This PR contains fixes & improvements to the code relevant for grouped (along time dim) SPIs.
Changes:
hdc.zonal.mean
hdc.algo.spi