-
Notifications
You must be signed in to change notification settings - Fork 68
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
BUG: datawc does not work on a time axis. #2007
Conversation
This happened because datawc is converted to cdtime.reltime type.
@doutriaux1 @aashish24 Please review. |
@danlipsa can we not write comparison operator for time axis? http://stackoverflow.com/questions/5824382/enabling-comparison-for-classes |
cdtime and cdtime object have a comparison operator (cmp) |
@aashish24 Can you overload the comparison operator to compare to float as well as to cdtime.reltime? Note also that cdtime.reltime is C code. |
@danlipsa you cannot have multiple definitions of operators since python is type agnostic but what you can do is something like here:
I would define this operator in axis class since that is in python. Referenced from here: The advantage might be that once defined in axis.py, the comparison will work everywhere and hence reduced code duplication. |
@aashish24 Thanks for the pattern to override operators. Still, the problem we have to solve is to compare gm.datawc_ (either a float or the type returned by 'cdtime.reltime') with 1.e20. So it seems we would have to override = for cdtime.reltime which is C code. Not sure I would like to hide through an operator the fact that datawc can have different types. I would rather investigate why datawc needs that, and make it only be float. @doutriaux1 Do you know why datawc gets converted to cdtime.reltime? |
@danlipsa it gets converted to relative time to accommodate for plotting data with different time units. For example 2016-06-06 is 157 days since 2016-01-01 but is 5 days since 2016-06-01 So if you plot two datasets with the time but different untis, we need to convert to some "same units" (and calendar) time format ot be able to align the times properly. Does that make sense? |
@doutriaux1 Thanks for the explanation. |
@doutriaux1 Do we have a test for this? |
you could refactor these:
|
@doutriaux1 @aashish24 is OK with merging this as is. If you are OK as well, I'll merge it. |
# datawc_ can be a float or a cdtime.reltime | ||
# TODO: Investigate why datawc is converted to a cdtime.reltime | ||
def getDataWcValue(v): | ||
if (type(v) is type(cdtime.reltime(0, 'months since 1900'))): |
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.
@danlipsa why months since 1900
, we should use the gm.datawc_units
and gm.datawc_calendar
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.
@doutriaux1 This is a way to get the type, so the actual value does not matter. I got this from Canvas.py:3051. Is there a better way to get the type returned by cdtime.reltime?
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.
what about component time?
a=cdtime.reltime(45,"months since 1945")
b=cdtime.comptime(2000)
gm = x.createboxfill()
gm.datawc_x1 = b
type(gm.datawc_x1) is type(a)
False
Is it ok to return v
if it's a component time?
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.
@doutriaux1 What is comptime? I did not try it, so probably not. It does not work with rel time either - I did try that. Its not clear from the documentation that datawc_ accepts objects beyond float values. I added an issue for this and we can fix it and add tests.
#2009
The question is: should we do this for 2.6 or leave it for later? Note this PR solves the user's issue. @aashish24 ?
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.
ok. A comptime
is a componentTime. Basically a date. Whereas reltime
is a relative time, i.e a delta since some reference date. You should take a look at: http://uvcdat.llnl.gov/documentation/cdms/cdms_3.html
@doutriaux1 @danlipsa few things:
|
@aashish24 there's no local in comptime, it's a good suggestion, we might want to add this.
|
@doutriaux1 @aashish24 Should we merge this? We can clean-up and fix additional related datawc/time axis bugs in subsequent PRs. |
No description provided.