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-14253: Modernize python in meas_base and meas_algorithms #119
Conversation
Remove `from __future__ import...` Remove use of future module, including `with_metaclass`
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.
Fro the try blocks catching Exception
do we know anything more specific or is it really anything is as bad as anything else?
from .coaddPsf import CoaddPsfControl | ||
from lsst.pex.config import makeConfigClass | ||
|
||
makeConfigClass(CoaddPsfControl, "CoaddPsfConfig") | ||
CoaddPsfConfig = makeConfigClass(CoaddPsfControl, "CoaddPsfConfig") |
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.
How did this work before?
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'm not sure it did work before. I suspect it was a no-op.
In most cases the bare exceptions were in plotting code, where it seemed that a "best effort" was intended, instead of expecting some particular exception. In cases where that was not true I tried to be more careful. |
That said, changing |
Let it go. It's easy to find them if we ever feel the need to look again. |
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 recall when I did this that there were a handful of builtins
imports hidden below other imports: did you do an all file search for future
and builtins
?
tests/test_dynamicDetection.py
Outdated
|
||
from builtins import zip | ||
|
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.
Did this leave 3 empty lines here?
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.
Not that I can see in my copy. I wonder why this got hidden as outdated? I have not pushed anything since May 1
@@ -39,7 +39,7 @@ | |||
from .spatialModelPsf import createKernelFromPsfCandidates, countPsfCandidates, \ | |||
fitSpatialKernelFromPsfCandidates, fitKernelParamsToImage | |||
from .pcaPsf import PcaPsf | |||
from . import utils as maUtils | |||
from . import utils as mautils |
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.
Why change this name to non-camelCase?
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.
Because flake8 complained
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.
Complained about what? maUtils
is follows our other camelCase renamings better.
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.
warning flake8: N812 lowercase 'maUtils' imported as non lowercase
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.
Can you instead just do from . import utils
instead of renaming it?
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.
OK
normalize=normalizeResiduals, | ||
showBadCandidates=showBadCandidates, | ||
variance=True) | ||
except: | ||
except Exception: |
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.
Can you look at what showPsfCandidates could raise, so as to make this exception more specific?
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 that is reasonable. It's 200 lines of code, with no documentation as to what exceptions it might raise. I admit that many of those lines are contained in their own try/except Exception blocks, but it's still a big job to try to figure out all the possible errors it might raise.
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 marked the except Exception
blocks that I think could use a little more investigation (they only call one or two things). Give them each a minute or two of looking at the try
-ed code to see if you can narrow down the list.
I don't like the others, but I've filed DM-14310 to deal with it more broadly.
@@ -224,7 +224,7 @@ def showPsfCandidates(exposure, psfCellSet, psf=None, frame=None, normalize=True | |||
# residuals using spatial model | |||
try: | |||
subtractPsf(psf, im, xc, yc) | |||
except: | |||
except Exception: |
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.
Please check if there's an obvious exception(s) raised by subtractPSf
here.
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.
Here is the full documentation for subtractPsf:
/**
* Subtract a PSF from an image at a given position
*/
template<typename MaskedImageT>
double subtractPsf(afwDetection::Psf const& psf, ///< the PSF to subtract
MaskedImageT *data, ///< Image to subtract PSF from
double x, ///< column position
double y, ///< row position
double psfFlux ///< object's PSF flux (if not NaN)
)
I think this is a clear case where except Exception:
is actually reasonable. This means "make a best effort to subtract the PSF and continue if it fails". Fortunately this is plotting code.
@@ -246,7 +246,7 @@ def showPsfCandidates(exposure, psfCellSet, psf=None, frame=None, normalize=True | |||
|
|||
try: | |||
noSpatialKernel = psf.getKernel() | |||
except: | |||
except Exception: |
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.
Please check if there's an obvious exception(s) raised by psf.getKernel()
here.
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.
It is C++ code, with different versions for different PSF classes. And none of it documents any exceptions that I can find.
tests/test_psfDetermination.py
Outdated
I = I0*psfVal(ix, iy, x + dx, y + dy, sigma1, sigma2, b) | ||
Isample = rand.poisson(I) if addNoise else I | ||
Ival = I0*psfVal(ix, iy, x + dx, y + dy, sigma1, sigma2, b) | ||
Isample = rand.poisson(Ival) if addNoise else Ival |
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.
Is intensity
a better name here?
tests/test_psfDetermination.py
Outdated
@@ -258,7 +258,7 @@ def subtractStars(self, exposure, catalog, chi_lim=-1): | |||
if bbox.contains(afwGeom.PointI(int(xc), int(yc))): | |||
try: | |||
measAlg.subtractPsf(psf, subtracted, xc, yc) | |||
except: | |||
except Exception: |
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.
Please check if there's an obvious exception(s) raised by subtractPSf here (as above).
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 agree that a unit test is a very nasty spot to ignore errors. I tried leaving out the try/except to see what got raised in the and nothing did, so I removed it.
I did indeed search for "future" and "builtins" and removed all associated imports. |
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.
Please check that the doxygen builds without errors/warnings after this change.
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.
A few comments warranting further investigation. I'll trust your judgment on those.
Further thought about |
I fixed one try/except Exception in a unit test and am declaring that enough. The plotting code is riddled with them and I think it will take some care and exercising the code to understand where exceptions should be logged or their scope reduced. |
both with scons and github Travis
This eliminates a source of warnings from the Python interpreter (e.g. unrecognized escape sequence \p)
No description provided.