-
Notifications
You must be signed in to change notification settings - Fork 65
Add diagnostic metadata property to constituents object; use existing diagnostic name metadata attribute #695
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
Changes from 2 commits
aab4a9e
9d8fe6a
549e2ac
2d189fc
e73a7bc
4601a0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -128,6 +128,44 @@ def find_vertical_dimension(dims): | |||||||||||||||||||||
| # end for | ||||||||||||||||||||||
| return (var_vdim, vindex) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ######################################################################## | ||||||||||||||||||||||
| def local_name_to_diag_name(prop_dict, context=None): | ||||||||||||||||||||||
| ######################################################################## | ||||||||||||||||||||||
| """ | ||||||||||||||||||||||
| Translate a local_name to its default diagnostic name. | ||||||||||||||||||||||
| Currently, this is just equal to the local name. If no local name | ||||||||||||||||||||||
| exists in the property dictionary, a truncation of the standard | ||||||||||||||||||||||
| name is used. (256 characters = max length of NetCDF variable name) | ||||||||||||||||||||||
| >>> local_name_to_diag_name({'local_name':'foo', 'standard_nam':'cloud_optical_depth'}) | ||||||||||||||||||||||
|
||||||||||||||||||||||
| >>> local_name_to_diag_name({'local_name':'foo', 'standard_nam':'cloud_optical_depth'}) | |
| >>> local_name_to_diag_name({'local_name':'foo', 'standard_name':'cloud_optical_depth'}) |
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.
nope! fixed!
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.
I might add a couple of tests for more complete code coverage:
| """ | |
| >>> local_name_to_diag_name({'local_name':'', 'standard_name':'cloud_optical_depth'}) #doctest: +ELLIPSIS | |
| Traceback (most recent call last): | |
| ... | |
| parse_source.CCPPError: No standard name or local name to convert to diagnostic name | |
| >>> local_name_to_diag_name({'standard_name':''}) #doctest: +ELLIPSIS | |
| Traceback (most recent call last): | |
| ... | |
| parse_source.CCPPError: No standard name or local name to convert to diagnostic name | |
| """ |
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 the extra doctests! added!
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.
I wonder if hardcoding this value in this particular place is a good idea. I would be surprised if we didn't have a parameter for the maximum length of a standard name somewhere else already.
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.
@climbfuji it looks like we're not enforcing a maximum standard name length anywhere! At least that I can find.
I'm enforcing it here because NetCDF has a maximum length for variable names.
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 that a good opportunity then to define that maxlen parameter in the appropriate place, or do you want to keep it here for now/simplicity?
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.
I'm not sure! I don't know if we want a hard limit on the standard name length?
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.
It does sound like a limitation if we say standard names cannot be longer than the maximum string length in netcdf, but it makes total sense to me. I would question the usefulness of standard names longer than 256, maybe even 128 characters.
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.
Sounds like something we should discuss at a framework meeting - I'll make an issue.
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! We can come back and clean this up later if needed. Good to merge I think.
Outdated
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 necessary?
From https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str
"The slice of s from i to j is defined as the sequence of items with index k such that i <= k < j. If i or j is greater than len(s), use len(s)."
| maxlen = 256 | |
| diag_name = stdname[:maxlen] if len(stdname) > maxlen else stdname | |
| maxlen = 256 | |
| diag_name = stdname[:maxlen] |
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.
@peverwhee Do you have an answer to this question?
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.
yes sorry for the delay! I've pushed up @gold2718 's suggested change
Uh oh!
There was an error while loading. Please reload this page.