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-24731: Create a unit test framework for AssembleCoaddTask #393

Merged
merged 3 commits into from Jul 14, 2020

Conversation

isullivan
Copy link
Contributor

This creates mock data references that mimic the API of the Gen 2 and Gen 3 butler in order to pass simulated test data to AssembleCoaddTask without having to instantiate a real Butler. I have only written fairly basic unit tests to demonstrate their use, but they exercise most of the coadd assembly code and work through the difficult part of getting the metadata set up properly.

Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new MockCoaddTestData object seems useful enough that it could live in pipe/tasks/mocks: it looks like it might be a more specific coadd mocking system than the existing ones.

It's not clear to me that the gen2/gen3 part of this is testing what you think it's testing. Or maybe I'm confused about what is being done here. Your tests call runDataRef and runQuantum, but your modified versions of appear to be not at all different, and do not follow the API for those methods.

That the new files have mostly un-namespaced imports bothers me, but it seems I've de facto lost that argument?

tests/assembleCoaddTestUtils.py Outdated Show resolved Hide resolved
tests/assembleCoaddTestUtils.py Outdated Show resolved Hide resolved
"""Very simple object that looks like a Gen2 data reference to an exposure.

Attributes
----------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to go this route, you also need a Parameters section, since this is missing the exposure argument, but also has things that aren't arguments. In fact, I don't see an Attributes section in our python doc guide at all:
https://developer.lsst.io/python/numpydoc.html#documenting-constants-and-class-attributes

Given that tests do not get built documentation, I don't think it's worth doing the full Parameters+Attributes documentation per the dev guide, since most of these parameters become attributes. Also, since these are mocks, they're supposed to look like a specific object, so you could just reference that object, if you're not using unittest.mock.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to document the class attributes, since I personally find that very helpful. The Attributes section is part of numpydoc even if it's not in our python doc guide, but I can change this to a Parameters section and move the remaining docstrings to in-line comments where the attributes are defined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use the inline comment method, you need to specify those attributes as class attributes, outside of __init__ (default value None if nothing else suits).

https://developer.lsst.io/python/numpydoc.html#attributes-set-in-init-methods

tests/assembleCoaddTestUtils.py Outdated Show resolved Hide resolved
tests/assembleCoaddTestUtils.py Show resolved Hide resolved
tests/test_assembleCoadd.py Outdated Show resolved Hide resolved
tests/test_assembleCoadd.py Outdated Show resolved Hide resolved
tests/test_assembleCoadd.py Show resolved Hide resolved
tests/assembleCoaddTestUtils.py Show resolved Hide resolved
tests/assembleCoaddTestUtils.py Outdated Show resolved Hide resolved
@isullivan
Copy link
Contributor Author

It's not clear to me that the gen2/gen3 part of this is testing what you think it's testing. Or maybe I'm confused about what is being done here. Your tests call runDataRef and runQuantum, but your modified versions of appear to be not at all different, and do not follow the API for those methods.

That is correct, the modified versions of runDataRef and runQuantum are not intended to test the original versions of those methods, or to have the same API as the originals. The gen2/gen3 components that are being tested are the calls to butler data references/deferred data handles that are used throughout the coaddition code.

"""Very simple object that looks like a Gen2 data reference to an exposure.

Attributes
----------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use the inline comment method, you need to specify those attributes as class attributes, outside of __init__ (default value None if nothing else suits).

https://developer.lsst.io/python/numpydoc.html#attributes-set-in-init-methods

raise ValueError(f"A bbox must be supplied for dataset {datasetType}")
else:
if bbox is not None:
raise ValueError(f"A bbox cannot be supplied for dataset {datasetType}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what happens when you supply bbox to a real butler dataRef?

@@ -318,36 +323,62 @@ def __init__(self, shape=geom.Extent2I(201, 301), offset=geom.Point2I(-123, -45)
self.ra = ra
self.dec = dec
self.rotAngle = 0.*degrees
"Rotation of the pixel grid on the sky, East from North (`lsst.geom.Angle`)."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, all of these pseudo-docstrings need to be done via class member declarations and docstrings: https://developer.lsst.io/python/numpydoc.html#attributes-set-in-init-methods

supplementaryData = self.makeSupplementaryData(mockSkyInfo, warpRefList=inputs.tempExpRefList)

retStruct = self.run(mockSkyInfo, inputs.tempExpRefList, inputs.imageScalerList,
inputs.weightList, supplementaryData=supplementaryData)
return retStruct

def runDataRef(self, mockSkyInfo, selectDataList=None, warpRefList=None):
"""Simplified API for testing image coaddition algorithms.
"""Modified interface for testing coaddition algorithms without a Butler.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, that's better wording.

tests/assembleCoaddTestUtils.py Outdated Show resolved Hide resolved
Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification on the Mock*CoaddTask docstrings: their purpose is now clearer. Also, the checkGen2Gen3 test code makes those tests a lot easier to follow.

You need to make class members to get attribute docstrings. I've given a link to our dev guide on that.

This makes writing unit tests easier because getPsf() is used elsewhere.
@isullivan
Copy link
Contributor Author

I've done as you asked for the attribute docstrings. All I really wanted, though, was simple code comments to help future people out who were looking at the code, since docs don't get built for tests.

Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, shoot, I totally forgot/didn't notice that these were tests. Yeah, docs don't get built for those. Ah well, I think it's easier to follow now anyway.

…asses.

Only very simple unit tests have been added at this point, to demonstrate usage.
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

2 participants