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
DM-4957: Generate JSON output from validate_drp for inclusion in a test harness #7
Conversation
Add makePrint, makePlot, makeJson keyword options to validate.run. Default to True, but will allow future more specific usage. Document new make* options. Specifying outputPrefix overrides repoNametoPrefix generation of the plot and JSON file prefix strings.
Use .tolist() instead of list() to convert numpy.ndarrays. .tolist() works for multi-dimensional numpy.arrays list() just converts the first dimension into a list. -- so you could get a list of numpy.ndarray from a 2D list. instead of the list of lists you get with .tolist() Rename magrange->magRange for consistency.
A struct is now return from the result of each calculation and that struct is then passed to print* or plot* functions. Refactor calcAMx, printAMx to move calculations to calc. printAMx is now just a calculation-free printing function. Removes need for printAM1, printAM2, printAM3 wrappers. magrange -> magRange Remove no-longer relevant plotAMx tests.
Gracefully catch new ValidateErrorNoStars for AM1, AM2, AM3. The astrometric repeatability looks a different distances: 5, 20, and 200 arcminutes. It quite possible that a small field, or single chip will not have the larger of these distances. ValidateErrorNoStars is raised for these cases and caught by the main validate.py, which then skips further printing, plotting, or saving of the AMx that was not calculable. Add `util.calcOrNone` function that catches a specified error and returns None if that error is raised. Otherwise returns the result of the function. Passes through any other errors.
Remove `pipe_tasks` from deps. Only `pipe.base` is needed.
Previously plotting and printing were each re-calculating PA1. Plotting was doing it once, while printing was doing in 50 times. New centralization standardizes and more clearly separates each of calculation, ploting, and printing and will allow for saving to JSON. The name of the Key Performance Metric is now stored in the .name field of Structs returnedy from calc* routines in calcSrd.py Improved printing of PA1. Uses srdSpec to look up target goals instead of using hardcoded values.
Units are just stored as simple strings for ease of reference and use in output functions. E.g., 'mmag', 'mag', 'mas', 'arcmin'
AM1, AM2, AM3, PA1, and PA2 metrics are now all saved as JSON files. Replace saveAmxToJson with general saveKpmToJson.
611264f
to
caabb2b
Compare
I have a general comment that I don't really agree that general python class files should be executable with shebangs. There is an implication that this means they should be able to run on their own but I don't think that is true. |
@@ -26,3 +26,7 @@ | |||
class ValidateError(Exception): | |||
"""Base classes for exceptions in validate_drp.""" | |||
pass | |||
|
|||
class ValidateErrorNoStars(ValidateError): | |||
"""Base classes for exceptions in validate_drp.""" |
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 don't think this comment is correct.
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 don't see how to comment on the general comment). The way that emacs identifies files is suffix, but failing that a comment of the form -*- python -*-
, not the #!
line
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 think you just add a PR-wide comment.
Totally agree about no These shebang lines have been removed from the routines not meant to be executed. |
Document 'outputPrefix'. Relabeled docstring 'Inputs'->'Parameters'. Updated README to note that the requirement is `pipe_base` not `pipe_tasks`. Whitespace fixes.
0d21d1a
to
ed74ad9
Compare
JSON test updated to real unittest. Thanks for catching this oversight. |
|
||
if __name__ == "__main__": | ||
if "--display" in sys.argv: | ||
display = True |
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.
The only mention of this variable is in this line. How does it have an effect?
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.
To be honest, I don't know. I copied this in from some test code from some other package. I thought it was standard boilerplate for running tests. It doesn't really make sense.
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 think it would be less confusing if it was removed.
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.
Agreed. See the commit I snuck into DM-5121 to improve this test.
import numpy as np | ||
|
||
|
||
def saveKpmToJson(KpmStruct, filename): |
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 think there was some prior conversation on this topic, which I appear to have missed, but I'm worried about 1) non-use of the Butler, 2) use of an explicit file format (what is the other side of this interface, if known?), and 3) use of an explicit file format other than YAML (effectively adding an additional dependency to the stack).
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.
You are right about the JSON in that I saw JSON but kept reading YAML (and it uses pyyaml
).
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.
@KTL For context, I understand the motivations behind your questions and don't really disagree.
But for the purposes of this Pull Request:
As part of DM-2050 I was told by @frossie to have validate_drp
output to JSON, so that's what I did. Happy to have a further discussion about how DM-4957 should have been implemented, but it's out of scope for the Pull Request.
A few notes:
json
is in the Python standard library. There is no additional dependency being added by using JSON.- JSON is a subset of YAML.
- I got a bit confused myself about YAML vs. JSON when answering @timj 's question above about implementing this in
pipe.base.Struct
(which is also beyond scope -- and a partial answer may be that pipe_base doesn't want to do do any serialization). - There is no current "other side of this interface" (DM-2050).
@wmwv I think you merged this code even though there were open comments on the new test code. |
I did. I didn't realize that your original request was to review the test code. |
Generates individual JSON output files for each of the 5 Key Project metrics:
AM1, AM2, AM3, PA1, PA2
Re-organized and standardized the calculation, passing around, printing, plotting, and saving of the key projects metric and associated information.