kammerje / spaceKLIP

Pipeline for reducing JWST high-contrast imaging data. Published in Kammerer et al. 2022 and Carter et al. 2022.
https://ui.adsabs.harvard.edu/abs/2022SPIE12180E..3NK/abstract
MIT License
16 stars 11 forks source link

Error during raw contrast curve calculation #2

Closed AarynnCarter closed 1 year ago

AarynnCarter commented 2 years ago

The following error appears for me when I try to calculate the contrast of the images. Seems like it's to do with the webbpsf / poppy dependency as opposed to the code itself.

This is with:

webbpsf = 1.0.0 poppy = 1.0.2

Haven't had a chance to dig into this in detail yet.

File "/Users/acarter/Documents/DIRECT_IMAGING/JWST/HIFI_SIMS/pyKLIP_for_Webb/run_pyklip_config.py", line 1802, in <module>
    proc.raw_contrast_curve(mstar,
  File "/Users/acarter/Documents/DIRECT_IMAGING/JWST/HIFI_SIMS/pyKLIP_for_Webb/run_pyklip_config.py", line 514, in raw_contrast_curve
    offsetpsf = self.get_offsetpsf(filt, mask, key)
  File "/Users/acarter/Documents/DIRECT_IMAGING/JWST/HIFI_SIMS/pyKLIP_for_Webb/run_pyklip_config.py", line 1524, in get_offsetpsf
    self.gen_offsetpsf(filt, mask)
  File "/Users/acarter/Documents/DIRECT_IMAGING/JWST/HIFI_SIMS/pyKLIP_for_Webb/run_pyklip_config.py", line 1571, in gen_offsetpsf
    hdul = nircam.calc_psf(oversample=1)
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/webbpsf/webbpsf_core.py", line 1047, in calc_psf
    psf = SpaceTelescopeInstrument.calc_psf(self, outfile=outfile, source=source, nlambda=nlambda,
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/poppy/instrument.py", line 260, in calc_psf
    self.optsys = self._get_optical_system(fov_arcsec=fov_arcsec, fov_pixels=fov_pixels,
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/poppy/instrument.py", line 626, in _get_optical_system
    return self.get_optical_system(*args, **kwargs)
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/webbpsf/webbpsf_core.py", line 811, in get_optical_system
    optsys = SpaceTelescopeInstrument.get_optical_system(self,
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/webbpsf/webbpsf_core.py", line 427, in get_optical_system
    pupil_optic = self._get_telescope_pupil_and_aberrations()
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/webbpsf/webbpsf_core.py", line 914, in _get_telescope_pupil_and_aberrations
    pupil_optic = opds.OTE_Linear_Model_WSS(
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/webbpsf/opds.py", line 1235, in __init__
    self.update_opd()
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/webbpsf/opds.py", line 2431, in update_opd
    self._apply_field_dependence_model()
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/webbpsf/opds.py", line 1464, in _apply_field_dependence_model
    field_dep_nominal = self._get_field_dependence_nominal_ote(self.v2v3, reference=reference, **kwargs)
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/webbpsf/opds.py", line 1604, in _get_field_dependence_nominal_ote
    perturbation = poppy.zernike.opd_from_zernikes(zernike_coeffs * opd_to_meters,
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/poppy/zernike.py", line 1152, in compose_opd_from_basis
    basis_set = basis(
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/poppy/zernike.py", line 438, in zernike_basis_faster
    zernike_result = norm_coeff * cached_R(n, np.abs(m)) * np.cos(np.abs(m) * theta) * aperture
  File "/Users/acarter/anaconda3/envs/coro_pipeline/lib/python3.10/site-packages/poppy/zernike.py", line 423, in cached_R
    (factorial(k) * factorial((n + m) / 2. - k) * factorial((n - m) / 2. - k)))
TypeError: 'float' object cannot be interpreted as an integer
AarynnCarter commented 2 years ago

This is a bug with poppy, line 423 in zernike.py should be:

(factorial(k) factorial(int((n + m) / 2) - k) factorial(int((n - m) / 2) - k)))

Alternatively, grab the corrected version from my personal poppy branch.