Conversation
arunkannawadi
left a comment
There was a problem hiding this comment.
I've taken only a quick pass for now, but wanted to leave the comments I have so far.
|
|
||
| # Optics | ||
| from .optical_model import Optical, optical_templates | ||
| from .roman_psf import Roman, RomanOptics |
There was a problem hiding this comment.
Unlike other items, this seems very Roman-specific. Do we want this in our namespace by default? Could we do something like you have for des below?
There was a problem hiding this comment.
Sure. That's a good idea. We can have a roman directory with this file and any others we decide to add relevant to the Roman PSF.
| ) | ||
|
|
||
|
|
||
| class Roman(Model): |
There was a problem hiding this comment.
I find the naming unintuitive. If I saw a bare Roman class in code, I wouldn't know what that's actually referring to. RomanPSF would be better given the docstring.
There was a problem hiding this comment.
Agreed. These aren't great names. How about RomanOpticalModel and RomanOpticalPSF.
There was a problem hiding this comment.
I think I prefer RomanOptics over RomanOptical for the written type in the config file, so I think RomanOpticsPSF for the class name works better. But RomanOpticalModel is still good for the model class name.
| ) | ||
|
|
||
|
|
||
| class RomanOptics(PSF): |
There was a problem hiding this comment.
Given that this is subclassing PSF, I wonder if this should be RomanOpticalPSF or something like that. I see other examples of the parent class' name appearing, like RomanSCAInterp when it inherits from Interp.
There was a problem hiding this comment.
A few small changes here and there, feel free to resolve as necessary. Also, in running the pytest for this branch, I also got an error in test_input.py in test_stars() where assert len(stars) == 90 fails on line 1683 under the "gratuitous coverage test"
I was running the tests with the wrong environment - all tests passed on my end with the correct environment, sorry for the confusion
| select: | ||
|
|
||
| min_snr: 50 # reject very faint stars | ||
| #max_snr: 500 # don't over-weight very bright stars |
There was a problem hiding this comment.
Could change max_snr to max_snr_weight - I think this gets the main point of the parameter across better
| #max_snr: 500 # don't over-weight very bright stars | |
| #max_snr_weight: 500 # don't over-weight very bright stars |
There was a problem hiding this comment.
Good idea. I like this name. I'll keep the other one as deprecated, but I agree this is a better name.
| mean = np.array([self.sca_mean[s] for s in sca]) | ||
| data = np.array( | ||
| list(zip(sca, mean)), | ||
| dtype=[('sca', int), ('mean', float, (len(self.global_mean),))], |
There was a problem hiding this comment.
This line confused me at first - might be good to document to say "writes an n_param length array for each sca"
| each SCA. For each ``(sca, params)`` state we build corner PSFs at the four SCA corners and | ||
| interpolate between them at each star position. This keeps the optical model much faster when | ||
| many stars on a chip share similar parameter vectors. | ||
| """ |
There was a problem hiding this comment.
Seems like a reasonable strategy. I do know that Cycle9 Zernikes are actually measured at 5 points across the chip - 4 corners and the center. Does it make sense to use all 5 points and do some kind of grid interpolation? (I guess the improvement is marginal, but its nice to have a one to one between the cycle9 data and the drawing in this case)
There was a problem hiding this comment.
OK. I could think about how to interpolate that. 5 is a bit awkward for interpolation. I guess you get a single quadratic term? 4 gives you (1,x,y,xy). 5 gives either (1,x,y,x^2,y^2) or (1,x,y,xy,x^2+y^2) I guess. Or we could do linear in each triangle?
There was a problem hiding this comment.
Here's a function that we use in psfsim to interpolate the Zernikes. I think scipy.interpolate.griddata can also work
def altgriddata(points, values, xi):
"""
Quadratic fitting function.
This is a substitute for ``scipy.interpolate.griddata`` when we have 5 points
and want to fit a quadratic, minus the x^2-y^2 term.
Paramters
---------
points : np.ndarray of float
The coordinates of the 5 points where we have values; shape (5, 2).
values : np.ndarray of flat
The values to interpolate; shape (5,).
xi : (float, float)
The location to interpolate to.
Returns
-------
float
The interpolated value.
"""
# Set up the linear system.
# Order of coefficients is 1, x, y, x*y, x^2+y^2.
bval = np.zeros((5, 5)) # bval[i,j] is the ith basis function at jth point
bval[0, :] = 1.0
bval[1, :] = points[:, 0]
bval[2, :] = points[:, 1]
bval[3, :] = points[:, 0] * points[:, 1]
bval[4, :] = points[:, 0] ** 2 + points[:, 1] ** 2
mat = bval @ bval.T
vec = bval @ values
coefs = np.linalg.solve(mat, vec)
return (
coefs[0]
+ coefs[1] * xi[0]
+ coefs[2] * xi[1]
+ coefs[3] * xi[0] * xi[1]
+ coefs[4] * (xi[0] ** 2 + xi[1] ** 2)
)
There was a problem hiding this comment.
Right. Thanks. So (1,x,y,xy,x^2+y^2) then. I can implement that. I'll do it in a different PR though.
| assert isinstance(psf2.interp, RomanSCAInterp) | ||
| assert psf2.interp.global_mean is None | ||
| assert psf2.interp.sca_mean == {} | ||
|
|
There was a problem hiding this comment.
I think these tests look okay. I haven't been able to check for comprehensive coverage given the size of the file, but I think something like codecov would do a better job than me.
There was a problem hiding this comment.
I do use codecov. Looks like I missed one line of coverage when I pulled out this subset. I think the roman branch has 100% coverage. But I guess I missed one test line when I was assembling this subset.
cf. https://github.com/rmjarvis/Piff/pull/195/checks?check_run_id=67957433502
Co-authored-by: Nihar Dalal <140463192+nihardalal@users.noreply.github.com>
Co-authored-by: Nihar Dalal <140463192+nihardalal@users.noreply.github.com>
Co-authored-by: Nihar Dalal <140463192+nihardalal@users.noreply.github.com>
nihardalal
left a comment
There was a problem hiding this comment.
I think everything looks okay now, so good to merge whenever
|
I think I'm up to date with responding to suggestions. |
|
I can take another look, but if I don't get back to you by EOD tomorrow, don't wait up for me. |
I think this set of commits is pretty much the minimum set of changes to implement the Roman PSF type. It's not quite everything that I have in the
romanbranch, but the main swaths of the code are here.Things still to come in later PRs (to help ease the code review burden):
aberration_interp="linear"optionchromatic=True(This technically has it, but it is too inefficient to be useful.)