PetroFit / petrofit

Python package for calculating Petrosian properties and fitting galaxy light profiles
https://petrofit.readthedocs.io
26 stars 6 forks source link

Accept oversampled PSF #180

Closed SterlingYM closed 1 year ago

SterlingYM commented 1 year ago

The PSF data for HST provided by STSci (https://www.stsci.edu/hst/instrumentation/wfc3/data-analysis/psf) are oversampled by factor of 4, but the current PSFConvolvedModel2D seems to assume the pixel scale is identical between the image and the PSF (please correct me if I'm mistaken). Is there any way to treat the pixel scale for PSF separately (i.e., convolve the oversampled image with the original, oversampled PSF, and then downscale to the correct output size)? Thank you for the help!

Current workaround:

# reduce PSF to scale 
from astropy.nddata import block_reduce
grid_factor = 4  # see https://www.stsci.edu/hst/instrumentation/wfc3/data-analysis/psf
PSF_reduced = block_reduce(PSF, grid_factor) 
PSF_reduced /= PSF_reduced.sum()

# convolved PSF with model
psf_sersic_model = PSFConvolvedModel2D(galaxy_model, psf=PSF_reduced)

Ideal case:

# convolved an oversampled PSF with model
psf_sersic_model = PSFConvolvedModel2D(galaxy_model, psf=PSF, psf_oversample_factor=4)

# psf_oversample_factor overrides the oversample behavior so that PSF and oversampled image scales match
# i.e., PSF is not oversampled and model is oversampled by factor of psf_oversample_factor.
# generated model image and PSF are convolved BEFORE downscaling
robelgeda commented 1 year ago

Thank you, this is very useful!

robelgeda commented 1 year ago

Thanks again for the suggestion @SterlingYM, I have added this update along with other upgrades to the image model. At this point the main branch is very much what v0.5.0 will be (the remaining changes are minor in comparison). Please give it a try and let me know if this is what you had in mind. Also please note that v0.5.0 will be backward incompatible but I think it will be much easier to use (please see current docs).