Skip to content
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

non-standard pixel sizes for distortion #669

Merged
merged 8 commits into from
Jul 27, 2023
25 changes: 14 additions & 11 deletions webbpsf/distortion.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
Value used to fill in any blank space by the skewed PSF. Default = 0.
If set to None, values outside the domain are extrapolated.
to_frame : str
Type of input coordinates.
Requested type of output coordinate frame.

* 'tel': arcsecs V2,V3
* 'sci': pixels, in conventional DMS axes orientation
Expand Down Expand Up @@ -116,29 +116,25 @@
# Pixel scale information
ny, nx = hdu_list[ext].shape
pixelscale = hdu_list[ext].header["PIXELSCL"] # the pixel scale carries the over-sample value
oversamp = hdu_list[ext].header["DET_SAMP"] # PSF oversampling relative to detector

# Get 'sci' reference location where PSF is observed
xsci_cen = hdu_list[ext].header["DET_X"] # center x location in pixels ('sci')
ysci_cen = hdu_list[ext].header["DET_Y"] # center y location in pixels ('sci')

# Convert the PSF center point from pixels to arcseconds using pysiaf
xidl_cen, yidl_cen = aper.sci_to_idl(xsci_cen, ysci_cen)

# ###############################################
# Create an array of indices (in pixels) for where the PSF is located on the detector
nx_half, ny_half = ( (nx-1)/2., (ny-1)/2. )
xlin = np.linspace(-1*nx_half, nx_half, nx)
ylin = np.linspace(-1*ny_half, ny_half, ny)
xarr, yarr = np.meshgrid(xlin, ylin)

# Convert the PSF center point from pixels to arcseconds using pysiaf
xidl_cen, yidl_cen = aper.sci_to_idl(xsci_cen, ysci_cen)

# Get 'idl' coords
xidl = xarr * pixelscale + xidl_cen
yidl = yarr * pixelscale + yidl_cen

# ###############################################
# Create an array of indices (in pixels) that the final data will be interpolated onto
xnew_cen, ynew_cen = aper.convert(xsci_cen, ysci_cen, 'sci', to_frame)

# If new x and y values are specified, create a meshgrid
if (xnew_coords is not None) and (ynew_coords is not None):
if len(xnew_coords.shape)==1 and len(ynew_coords.shape)==1:
Expand All @@ -147,9 +143,16 @@
assert xnew_coords.shape==ynew_coords.shape, "If new x and y inputs are a grid, must be same shapes"
xnew, ynew = xnew_coords, ynew_coords
elif to_frame=='sci':
xnew = xarr / oversamp + xnew_cen
ynew = yarr / oversamp + ynew_cen
osamp_x = aper.XSciScale / pixelscale
osamp_y = aper.YSciScale / pixelscale
osamp = (osamp_x + osamp_y) / 2
xnew = xarr / osamp + xnew_cen
ynew = yarr / osamp + ynew_cen
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the logic here for averaging osamp? This computes first a distinct oversampling factor in each of X and Y, but then computes xnew and ynew using the average oversampling factor. Wouldn't it be more precise to calculate using the distinct oversampling factors per axis, like xnew = xarr / osamp_x + xnew_cen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally tried doing it per-axis, but test_apply_distortion_pixel_scale() would fail. I did not have time to look into why the test was failing, as I didn't quite understand the logic behind the test. Reverting to a single oversampling applied across both axes fixed the issue. Need to investigate further.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, yeah, now that I look at that test... I do not understand the logic either. 🤣

else:
# Get 'idl' coords
xidl = xarr * pixelscale + xidl_cen
yidl = yarr * pixelscale + yidl_cen

Check warning on line 154 in webbpsf/distortion.py

View check run for this annotation

Codecov / codecov/patch

webbpsf/distortion.py#L153-L154

Added lines #L153 - L154 were not covered by tests

xv, yv = aper.convert(xidl, yidl, 'idl', to_frame)
xmin, xmax = (xv.min(), xv.max())
ymin, ymax = (yv.min(), yv.max())
Expand Down