-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add modelSize to piff config #23
Conversation
The modelSize is the internal PIFF model grid size. This gets sent to the piff config rather than stampSize for the "size" entry. modelSize defaults to 25. Update the stampSize to default to sqrt(2) * 25 ~ 35 to accomodate rotations Add a check that stamp size is big enough
This is an important check when working in sky coords Oddly at 45 degrees piff is giving a singlular matrix error and fails to fit. We should track this down before accepting this PR. 135 works fine so I wonder if there is something sepcial about 45 for this test
Will work for FITS wcs
The unit tests pass for me. Do we turn on the CI here or is that to be done later? |
We think its an issue with the underlying galsim code rather than the wrapper
There is a fix in galsim that allows the unit tests to pass. Should we add more test cases? |
If by more test cases you mean more angles, I'm happy to do that after merging this PR. But once you're happy with this PR as is, I'll merge it to the ticket branch and run CI tests, but only after the new GalSim release makes it to |
f'we require stampSize >= ' | ||
f'{min_stamp_size}, got {stamp_size}' | ||
) | ||
|
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.
Note to self: this is a check only on the config, so should be implemented in a validate
method.
Thanks again for this PR, Erin. If there are no more changes you're planning, I'll go ahead and merge it. |
No more changes |
# i) aperture flux with 12 pixel radius can be compared to PSF flux. | ||
# ii) fake sources injected to match the 12 pixel aperture flux get | ||
# measured correctly | ||
self.stampSize = 25 | ||
# Default modelSize is 25, and 35 is about sqrt(2) * 25 | ||
self.stampSize = 35 |
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.
Given that in the default processing we don't use sky coordinates, I'm inclined to keep this as 25 in the default here. For your testing purposes, you should be able to override this value.
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.
@rmjarvis Is there any disadvantage to having modelSize == stampSize
?
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.
Yes. You definitely don't want stampSize == modelSize. It should be larger for 3 reasons.
- The Lanczos interpolation extends the active modeling space out from the modelSize by interpolant.xrange(). I think your default is Lanczos(11), so it will reach out by 11 pixels on all sides. That alone suggests you want stampSize = modelSize + 22.
- Even if your centroids are absolutely perfect, there is a sub-pixel variation of half a pixel in some direction. So you would want to add one more pixel of data around the edges to make sure you are properly constraining all the pixels around the edge. That adds another +2 to the stamp size. Maybe a little more if you don't trust your centroids to be very sub-pixel accurate.
- Finally, the rotation. This multiplies that calculation by up to sqrt(2). (1/max(|sin(theta)|,|cos(theta)|) if you want to calculate it explicitly for a given WCS.)
And honestly, there is barely any down side to using a larger than needed stamp size. Piff will just ignore any pixels that are not being used to constrain the model. So I'd recommend the default being much larger in fact. Use 80x80 or something.
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.
The default I put in was 35 which was designed to account for your part 3. in the list, since the default modelSize
was set to 25. It seems like 1. and 2. imply we should go even larger
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.
The Lanczos interpolation extends the active modeling space out from the modelSize by interpolant.xrange()
Mike, could you confirm that this is needed even if the modeling is happening in pixel coordinates as opposed to sky coordinates?
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.
"Needed"? No. Not technically. But it will produce inaccurate PSF models near the edges if you don't.
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.
Also, I remember the compute scales as cubic power of the size, but does it as modelSize**3
or stampSize**3
? I hope the former.
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.
modelSize**6 actually.
if stamp_size % 2 == 0: | ||
raise ValueError(f'stampSize should be odd, got {stamp_size}') | ||
if model_size % 2 == 0: | ||
raise ValueError(f'modelSize should be odd, got {model_size}') |
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 this? I don't think there is any restriction that either of these must be odd. Odd model size is common, but not really necessary. Most PSF profiles have a lot of flux in the central 1 pixel, so odd helps model that better. But there could certainly be cases where even works better. (I did test both odd and even for DES, and the odd sizes in fact worked better in those tests -- I haven't switched to even sizes since then.)
And I usually use even stampSize actually. The default in Piff is 32, which is much larger than our modelSize in DES, even without any rotator.
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 there is no reason in principle.
In practice it is nice to have odd for some applications. For example, odd means the model can be centered on that center pixel, and then convolutions with the PSF image will not cause a shift.
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.
Hmm, stampSize
is enforced to be odd upstream as well, so even if we drop that requirement here, you can be guaranteed that stampSize
will be odd. Dropping that requirement upstream will have to get discussed within the Science Pipelines team but I can go with whatever is the consensus is on modelSize
. But based on Mike's comment, may be we should not make it a requirement just yet.
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.
We want it for shear
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.
In practice it is nice to have odd for some applications. For example, odd means the model can be centered on that center pixel, and then convolutions with the PSF image will not cause a shift.
This consideration is orthogonal to the reasons for having the model use an odd size. You can draw it onto an odd-sized image (and center it) regardless of what the underlying model uses.
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.
I thought that re-gridding the model from a center-near-pixel-boundary to center-at-pixel-center would introduce larger interpolation errors. If that's not the case then I withdraw my assertion
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'll be moving around the code a bit after merging, so I will drop the requirement then.
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 still think people should tend to use odd modelSize in most cases for other reasons. Mostly that typical PSFs have a hot spot right at the center, which an odd model size is better at describing. But making it a requirement feels a little heavy handed. E.g. modeling very out of focus stars, which don't have that central peak, might work better with an even model size for some reason.
Looks like we've converged on the various conversations here. I'll give it a few more hours and merge it by EOD. |
Continued in #25 . |
add modelSize to piff config