-
Notifications
You must be signed in to change notification settings - Fork 7
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-27185: ptc.py fails with ptcFitType=FULLCOVARIANCE #60
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
122e4eb
Make cov weights nan safe
plazas 47cf78e
Adjust sizes so Table can save the dataset
plazas e7411ef
Fix docstring of funcPolynomial
plazas 1b075f7
Catch NaN when FULLCOV fit fails
plazas ce4674c
Add lower and upper bounds to EXPAPPROX params
plazas 732508c
Moved irlsFit to utils.py
plazas 7612da7
Sort raw arrays in extract
plazas 25e2528
Add warning messages
plazas 5a600b2
Multtiply w1, w2, and wdiff
plazas File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,6 +282,51 @@ def makeDataRefList(self, namespace): | |
self.refList += refList | ||
|
||
|
||
def irlsFit(initialParams, dataX, dataY, function, weightsY=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two commits adding this should be squashed together so the indentations are correct on the first ticket. |
||
"""Iteratively reweighted least squares fit. | ||
|
||
This uses the `lsst.cp.pipe.utils.fitLeastSq`, but applies | ||
weights based on the Cauchy distribution to the fitter. See | ||
e.g. Holland and Welsch, 1977, doi:10.1080/03610927708827533 | ||
|
||
Parameters | ||
---------- | ||
initialParams : `list` [`float`] | ||
Starting parameters. | ||
dataX : `numpy.array` [`float`] | ||
Abscissa data. | ||
dataY : `numpy.array` [`float`] | ||
Ordinate data. | ||
function : callable | ||
Function to fit. | ||
weightsY : `numpy.array` [`float`] | ||
Weights to apply to the data. | ||
|
||
Returns | ||
------- | ||
polyFit : `list` [`float`] | ||
Final best fit parameters. | ||
polyFitErr : `list` [`float`] | ||
Final errors on fit parameters. | ||
chiSq : `float` | ||
Reduced chi squared. | ||
weightsY : `list` [`float`] | ||
Final weights used for each point. | ||
|
||
""" | ||
if not weightsY: | ||
weightsY = np.ones_like(dataX) | ||
|
||
polyFit, polyFitErr, chiSq = fitLeastSq(initialParams, dataX, dataY, function, weightsY=weightsY) | ||
for iteration in range(10): | ||
# Use Cauchy weights | ||
resid = np.abs(dataY - function(polyFit, dataX)) / np.sqrt(dataY) | ||
weightsY = 1.0 / (1.0 + np.sqrt(resid / 2.385)) | ||
polyFit, polyFitErr, chiSq = fitLeastSq(initialParams, dataX, dataY, function, weightsY=weightsY) | ||
|
||
return polyFit, polyFitErr, chiSq, weightsY | ||
|
||
|
||
def fitLeastSq(initialParams, dataX, dataY, function, weightsY=None): | ||
"""Do a fit and estimate the parameter errors using using scipy.optimize.leastq. | ||
|
||
|
@@ -428,13 +473,13 @@ def funcPolynomial(pars, x): | |
Polynomial coefficients. Its length determines the polynomial order. | ||
|
||
x : `numpy.array` | ||
Signal mu (ADU). | ||
Abscisa array. | ||
|
||
Returns | ||
------- | ||
C_00 (variance) in ADU^2. | ||
Ordinate array after evaluating polynomial of order len(pars)-1 at `x`. | ||
""" | ||
return poly.polyval(x, [*pars]) # C_00 | ||
return poly.polyval(x, [*pars]) | ||
|
||
|
||
def funcAstier(pars, x): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are these errors not a problem anymore? Do they not cause raisable errors? Maybe just a comment that this triggers the "else" statement on ptc.py L536 if I'm following correctly (the errors yield a None that results in the bad amp detection and NaN entries as appropriate).
It might also be good to warn if it stops iterating from hitting the maxFitIter.