Skip to content
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

Merged
merged 12 commits into from Feb 15, 2016

Conversation

wmwv
Copy link
Contributor

@wmwv wmwv commented Feb 14, 2016

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.

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.
@timj
Copy link
Member

timj commented Feb 15, 2016

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. check.py and validate.py are executable but don't include a main. Is the shebang being used to convince the editor that it's python code? Doesn't the .py file suffix suffice for that?

@@ -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."""
Copy link
Member

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.

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

Copy link
Member

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.

@wmwv
Copy link
Contributor Author

wmwv commented Feb 15, 2016

Totally agree about no !/usr/bin/env python lines for the individual non-executable Python files. Thank you, this was just leftover from copying the header from other files.

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.
@wmwv
Copy link
Contributor Author

wmwv commented Feb 15, 2016

JSON test updated to real unittest. Thanks for catching this oversight.


if __name__ == "__main__":
if "--display" in sys.argv:
display = True
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

f325eec

@wmwv wmwv merged commit ed74ad9 into master Feb 15, 2016
import numpy as np


def saveKpmToJson(KpmStruct, filename):
Copy link
Contributor

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).

Copy link
Member

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).

Copy link
Contributor Author

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:

  1. json is in the Python standard library. There is no additional dependency being added by using JSON.
  2. JSON is a subset of YAML.
  3. 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).
  4. There is no current "other side of this interface" (DM-2050).

@timj
Copy link
Member

timj commented Feb 15, 2016

@wmwv I think you merged this code even though there were open comments on the new test code.

@wmwv
Copy link
Contributor Author

wmwv commented Feb 15, 2016

I did. I didn't realize that your original request was to review the test code.

@ktlim ktlim deleted the tickets/DM-4957 branch August 25, 2018 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants