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-28368: Fix id check so that all components can use readComponent. #558

Merged
merged 3 commits into from Jan 19, 2021

Conversation

erykoff
Copy link
Contributor

@erykoff erykoff commented Jan 15, 2021

Note that the TransmissionCurve is special in some way and
does not work with the current implementation.

Copy link
Member

@kfindeisen kfindeisen left a comment

Choose a reason for hiding this comment

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

Sorry, I don't know why TransmissionCurve is behaving differently. Given the existing code I assume there should be one in the first place. 😕

@@ -182,18 +182,29 @@ def checkExposureFitsReader(self, exposureIn, fileName, dtypesOut):
self.assertEqual(exposureIn.getMetadata().toDict(), reader.readMetadata().toDict())
self.assertWcsAlmostEqualOverBBox(exposureIn.getWcs(), reader.readWcs(), self.bbox,
maxDiffPix=0, maxDiffSky=0*degrees)
self.assertWcsAlmostEqualOverBBox(exposureIn.getWcs(), reader.readComponent('SKYWCS'),
Copy link
Member

Choose a reason for hiding this comment

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

I recommend using ExposureInfo.KEY_WCS, if only to minimize cargo-culting of magic values.

self.assertEqual(exposureIn.getInfo().getVisitInfo().getExposureTime(),
reader.readVisitInfo().getExposureTime())
point = Point2D(2.3, 3.1)
wavelengths = np.linspace(4000, 5000, 5)
self.assertFloatsEqual(exposureIn.getInfo().getTransmissionCurve().sampleAt(point, wavelengths),
reader.readTransmissionCurve().sampleAt(point, wavelengths))
# Note: readComponent('TRANSMISSION_CURVE') does not work.
Copy link
Member

Choose a reason for hiding this comment

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

Nothing obviously jumps out at me; it should behave the same as every other component. Are you getting None, or some kind of error?

For None, the only possibility I can think of is that the logic in https://github.com/lsst/afw/blob/master/src/image/ExposureFitsReader.cc#L360-L363 is failling. Can you manually inspect the file and see if it has an ARCHIVE_ID_TRANSMISSION_CURVE keyword, and that it matches the old-style TRANSMISSION_CURVE_ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It returns a generic Storable that hasn't been casted to a TransmissionCurve.

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 that means there's a bug in TransmissionCurve's pybind11 wrapper. The formal C++ type is Storable, but that shouldn't matter in Python.

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 don't know how this works, and looking at the transmissionCurve.cc it seems okay to me compared to others like it. Any hints greatly appreciated!

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I can't figure it out, either. I think you may need @TallJimbo to weigh in, he knows more about the guts of pybind11 than I do.

Another possibility is that, because the type checking in the current implementation of ArchiveReader::getComponent is sloppier than it could be, the component really is a Storable but not of a type known to Python. I don't know of any such type, though.

Copy link
Member

Choose a reason for hiding this comment

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

If you mean the Doxygen docs, then yes.

Copy link
Member

Choose a reason for hiding this comment

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

I'd also add an implementation note to TransmissionCurve that says most objects are of a subclass, and that this may affect pybind11 behavior. It may, as @TallJimbo says, be a good pattern in general, but it's very unusual in our code.

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 added 53cd70a for the readComponent note, but I need explicit direction on these other doc edits since it's further in the weeds of c++ that I don't have the vocabulary/knowledge to describe what is going on here.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what to say for Storable (it's not really an issue specific to that class), but I can push a blurb for TransmissionCurve.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be awesome, thanks! (And I agree, this isn't a Storable issue per-se, though I can see that the doc string needs to be modified to say that these pybind11 wrappers are non-trivial in some cases?)

Note that the TransmissionCurve is special in some way and
does not work with the current implementation.
@@ -401,6 +401,10 @@ class ExposureFitsReader::ArchiveReader {
*
* @throws pex::exceptions::NotFoundError Thrown if the component is
* registered in the file metadata but could not be found.
*
* @note When accessing via %pybind11, components with derived subclasses, such
Copy link
Member

Choose a reason for hiding this comment

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

I'd say "from Python"; I'm not sure all our Python developers think of themselves as pybind11 users.

EDIT: sorry for putting my original comment on the commit rather than the PR!

@erykoff
Copy link
Contributor Author

erykoff commented Jan 19, 2021

@kfindeisen Thanks! So is this good to go when Jenkins is green?

@erykoff erykoff merged commit 7bed000 into master Jan 19, 2021
@erykoff erykoff deleted the tickets/DM-28368 branch January 19, 2021 18:55
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

3 participants