Skip to content

Commit

Permalink
Merge pull request #770 from mperrin/ifu_sim_framework
Browse files Browse the repository at this point in the history
Infrastructure improvements for improved IFU sims
  • Loading branch information
obi-wan76 authored May 15, 2024
2 parents c5e2169 + a8416a1 commit 1c0121d
Show file tree
Hide file tree
Showing 7 changed files with 602 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:

- name: Get WebbPSF Data
run: | # Get WebbPSF data files (just a subset of the full dataset!) and set up environment variable
wget https://stsci.box.com/shared/static/0ojjfg3cieqdpd18vl1bjnpe63r82dx8.gz -O /tmp/minimal-webbpsf-data.tar.gz
wget https://stsci.box.com/shared/static/gkbnn3jwcootr9riwv0rv1t8rpvxl3vr.gz -O /tmp/minimal-webbpsf-data.tar.gz
tar -xzvf /tmp/minimal-webbpsf-data.tar.gz
echo "WEBBPSF_PATH=${{github.workspace}}/webbpsf-data" >> $GITHUB_ENV
Expand Down
12 changes: 12 additions & 0 deletions docs/relnotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,24 @@ See https://github.com/spacetelescope/webbpsf/issues for currently open issues a
Version History and Change Log
-------------------------------

Version 1.3.0
=============
*Date TBD*

This release comes with new features and improvements including but not limited to:

X. Improved support for NIRSpec and MIRI IFU PSF calculations, including addition of a ``mode`` attribute for toggling between imaging mode and IFU mode simulations; an option for much faster (but slightly simplified) IFU datacube PSF calculations. Spectral bandpass information added for the IFU bands for both NIRSpec and MIRI. For NIRSpec, IFU mode PSF outputs are rotated by an additional 90 degrees to match the convention used in pipeline-output s3d datacubes made using the IFUAlign orientation. This extra rotation can be optionally disabled if so desired; see the NIRSpec class docstring.


Version 1.2.1
=============
Minor documentation updates

Version 1.2.0
=============

*2023 August*

We are pleased to announce the release of the latest version of WebbPSF version 1.2.0, now available on PyPi and GitHub. This release comes with new features and improvements including but not limited to:

1. The addition of detector effects for JWST simulations. H2RG detector effects are included in two flavors, a simple ad hoc Gaussian convolution to model charge diffusion effects and a set of convolution kernels to model interpixel capacitance (IPC) and post-pixel coupling effects. We have found that these effects greatly improve the agreement between observations and simulations. See `JWST Detector Effects for more details. <https://webbpsf.readthedocs.io/en/latest/jwst_detector_effects.html>`_
Expand Down
2 changes: 1 addition & 1 deletion webbpsf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class UnsupportedPythonError(Exception):
# required. If changes to the code and data mean WebbPSF won't work
# properly with an old data package, increment this version number.
# (It's checked against $WEBBPSF_DATA/version.txt)
DATA_VERSION_MIN = (1, 2, 1)
DATA_VERSION_MIN = (1, 3, 0)


class Conf(_config.ConfigNamespace):
Expand Down
75 changes: 75 additions & 0 deletions webbpsf/tests/test_miri.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,78 @@ def test_miri_nonsquare_detector():
miri = webbpsf_core.MIRI()
miri.detector_position = (1023, 1031) # recall this is X, Y order
assert miri.detector_position == (1023, 1031)

def test_mode_switch():
"""Test switching between imaging and IFU modes, and switching IFU bands
Also checks this works to switch aperturenane, and conversely setting aperturename switches mode if needed.
Also checks that this automatically changes the rotation and pixelscale properties, as expected.
"""
miri = webbpsf_core.MIRI()
imager_rotation = miri._rotation
imager_pixelscale = miri.pixelscale

# Explicitly switch mode to IFU
miri.mode = 'IFU'
assert 'IFU' in miri.aperturename
assert miri.detector =='MIRIFUSHORT'
assert miri.aperturename.startswith('MIRIFU_CH')
assert miri._rotation != imager_rotation
assert miri.pixelscale > imager_pixelscale
# Explicitly switch back to imaging
miri.mode = 'imaging'
assert 'IFU' not in miri.aperturename
assert miri.detector =='MIRIM'
assert miri.aperturename.startswith('MIRIM_')
assert miri._rotation == imager_rotation
assert miri.pixelscale == imager_pixelscale


# Implicitly switch to IFU
miri.set_position_from_aperture_name('MIRIFU_CHANNEL3B')
assert 'IFU' in miri.aperturename
assert miri.detector =='MIRIFULONG'
assert miri.aperturename == 'MIRIFU_CHANNEL3B'
assert miri._rotation != imager_rotation
assert miri.pixelscale > imager_pixelscale

# implicitly switch to imaging
# LRS is an odd case, SLIT aper type but operates like in imaging mode
miri.set_position_from_aperture_name('MIRIM_SLIT')
assert 'IFU' not in miri.aperturename
assert miri.detector =='MIRIM'
assert miri.aperturename.startswith('MIRIM_')
assert miri._rotation == imager_rotation
assert miri.pixelscale == imager_pixelscale

# And back to IFU again:
miri.mode = 'IFU'
assert 'IFU' in miri.aperturename
assert miri.detector =='MIRIFUSHORT'
assert miri.aperturename.startswith('MIRIFU_CH')
assert miri._rotation != imager_rotation
assert miri.pixelscale > imager_pixelscale

# band switching should toggle detector and aper name
miri.band = '4C'
assert miri.detector == 'MIRIFULONG'
assert miri.aperturename == 'MIRIFU_CHANNEL4C'
assert miri.pixelscale > 3*imager_pixelscale

miri.band = '2A'
assert miri.detector == 'MIRIFUSHORT'
assert miri.aperturename == 'MIRIFU_CHANNEL2A'
assert imager_pixelscale < miri.pixelscale < 2*imager_pixelscale

def test_IFU_wavelengths():
""" Test computing the wqvelength sampling for a sim IFU cube """
miri = webbpsf_core.MIRI()
# check mode swith to IFU
miri.mode = 'IFU'
miri.band = '2A'
waves = miri.get_IFU_wavelengths()
assert isinstance(waves, u.Quantity)

assert len(waves) > 900 # there are lots of wavelengths in MRScubes
# and test we can specify a reduced wavelength sampling:
for n in (10, 100):
assert len(miri.get_IFU_wavelengths(n)) == n
33 changes: 33 additions & 0 deletions webbpsf/tests/test_nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,36 @@ def test_calc_datacube_fast():
waves = np.linspace(3e-6, 5e-6, 3)

cube = nrs.calc_datacube_fast(waves, fov_pixels=30, oversample=1, compare_methods=True)


def test_mode_switch():
""" Test switch between IFU and imaging modes """
nrs = webbpsf_core.NIRSpec()
# check mode swith to IFU
nrs.mode = 'IFU'
assert 'IFU' in nrs.aperturename
assert nrs.band == 'PRISM/CLEAR'

# check switch of which IFU band
nrs.disperser = 'G395H'
nrs.filter = 'F290LP'
assert nrs.band == 'G395H/F290LP'

# check mode switch back to imaging
nrs.mode = 'imaging'
assert 'IFU' not in nrs.aperturename

def test_IFU_wavelengths():
""" Test computing the wqvelength sampling for a sim IFU cube """
nrs = webbpsf_core.NIRSpec()
# check mode swith to IFU
nrs.mode = 'IFU'
nrs.disperser = 'G235H'
nrs.filter = 'F170LP'
waves = nrs.get_IFU_wavelengths()
assert isinstance(waves, u.Quantity)

assert len(waves) > 3000 # there are lots of wavelengths in the high-resolution grating cubes
# and test we can specify a reduced wavelength sampling:
for n in (10, 100):
assert len(nrs.get_IFU_wavelengths(n)) == n
2 changes: 1 addition & 1 deletion webbpsf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ def determine_inst_name_from_v2v3(v2v3):
_log.debug('Field coordinates determined to be in NIRSpec field')
elif (
(v2v3[0] <= -6.2 * u.arcmin)
and (v2v3[0] >= -8.3 * u.arcmin)
and (v2v3[0] >= -8.5 * u.arcmin)
and (v2v3[1] <= -5.2 * u.arcmin)
and (v2v3[1] >= -7.3 * u.arcmin)
):
Expand Down
Loading

0 comments on commit 1c0121d

Please sign in to comment.