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-13054: Refactor colorterm calculations to use in jointcal #266

Merged
merged 2 commits into from Feb 9, 2019

Conversation

parejkoj
Copy link
Contributor

No description provided.

@parejkoj parejkoj force-pushed the tickets/DM-13054 branch 3 times, most recently from 99df351 to 5c131af Compare February 1, 2019 22:50

primaryMag = u.Quantity(primaryFlux, u.Jy).to_value(u.ABmag)
secondaryMag = u.Quantity(secondaryFlux, u.Jy).to_value(u.ABmag)

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a ticket for when refcats will be changed to nJy from Jy? (and they are in Jy now, right?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DM-17029

And yes, they are in Jy now.

refFluxErrArr = self.propagateFluxErrors(primaryErr, secondaryErr)

refMagErr = np.array([abMagErrFromFluxErr(rfe, rf)
for rfe, rf in zip(refFluxErrArr, primaryFlux)])
Copy link
Contributor

Choose a reason for hiding this comment

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

I just confirmed that abMagErrFromFluxErr works on arrays, so this should be:
refMagErr = abMagErrFromFluxErr(refFluxErrArr, primaryFlux). This is roughly 75x faster and might actually be noticeable for large catalogs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point.

That said, the code in this method is already ~20% faster than the code I pulled out of PhotoCalTask.extractMagArrays(), but the actual refcat loading takes so much more time that speeding this method up is almost unnoticeable.

refCat.reserve(len(matches))
for x in matches:
record = refCat.addNew()
record.assign(x.first)
Copy link
Contributor

Choose a reason for hiding this comment

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

And we confirmed that this always returns a contiguous catalog? I wasn't sure of the conclusion on slack.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

Or, at least, if it didn't, the code just below would fail.

else:
refMagArr = np.array([abMagFromFlux(rf) for rf in refFluxArrList[0]])
refMagArr = u.Quantity(refFluxArr, u.Jy).to_value(u.ABmag)
refMagErrArr = u.Quantity(refFluxErrArr, u.Jy).to_value(u.ABmag) # WRONG!
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this # WRONG! comment doing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I wrote something that I knew was wrong and had meant to fix it and forgot. Thanks for catching it.

refMag, refMagErr = self.colorterm.getCorrectedMagnitudes(refCat, 'r')
self.assertEqual(refMag, expectMag)
# NOTE: Not testing the returned errors, as I do not trust `propagateFluxErrors()`
# and there is some interesting logic involved in how the errors are propagated.
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 this needs to be ticketed. And I (at least) care about the reference flux error propagation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -386,8 +374,6 @@ def extractMagArrays(self, matches, filterName, sourceKeys):

srcMagErrArr = np.array([abMagErrFromFluxErr(sfe, sf)
for sfe, sf in zip(srcInstFluxErrArr, srcInstFluxArr)])
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also be vectorized as above. There are probably others in the code that weren't put into the GitHub change-log, which maybe outside the scope of this ticket, but shouldn't be too hard to do while doing the rearranging.

The existing code made it very painful to compute the colorterm corrections.
Now `Colorterm.getCorrectedMagnitudes()` does all the necessary work.

I am skeptical of the magnitude error calculations here, but I'm just copying
them from PhotoCalTask, so they're at least not any more wrong than before.

This change does fix a serious bug in the refMagErr calculation: it was
previously being done using the secondary flux, not the primary flux (the loop
was overwriting `refFluxArr` before it was used to calculate the refMagErr).
@parejkoj parejkoj merged commit b45e8e9 into master Feb 9, 2019
@parejkoj parejkoj deleted the tickets/DM-13054 branch September 1, 2021 20:37
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