Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions METIS/METIS_IMG_LM.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ effects:
class: FieldConstantPSF
kwargs:
filename: "!OBS.psf_file"
psf_name: "!OBS.psf_name"
psf_path: "METIS_psfs/"
filename_format: "METIS_psfs/PSF_{}.fits"
wave_key: "WAVELENG"
bkg_width: -1

Expand Down
3 changes: 3 additions & 0 deletions METIS/METIS_IMG_N.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ effects:
class: FieldConstantPSF
kwargs:
filename: "!OBS.psf_file"
psf_name: "!OBS.psf_name"
psf_path: "METIS_psfs/"
filename_format: "METIS_psfs/PSF_{}.fits"
wave_key: "WAVELENG"
bkg_width: -1

Expand Down
3 changes: 3 additions & 0 deletions METIS/METIS_LMS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ effects:
class: FieldConstantPSF
kwargs:
filename: "!OBS.psf_file"
psf_name: "!OBS.psf_name"
psf_path: "METIS_psfs/"
filename_format: "METIS_psfs/PSF_{}.fits"
wave_key: "WAVELENG"
bkg_width: -1

Expand Down
3 changes: 2 additions & 1 deletion METIS/METIS_WCU.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ effects:
pupil_masks:
names: [APP-LMS, APP-LM, CLS-LMS, CLS-LM, CLS-N, PPS-LMS, PPS-LM, PPS-N, PPS-CFO2, RLS-LMS, RLS-LM, SPM-LMS, SPM-LM, SPM-N, open]
transmissions: [0.6098, 0.6312, 0.5879, 0.6073, 0.5795, 0.7342, 0.7509, 0.7429, 0.6170, 0.4362, 0.4476, 0.6098, 0.6312, 0.6076, 0.8201]
current_mask: "open"
current_mask: "!OBS.pupil_mask"
message: "\nPupil mask has been changed; don't forget to update the PSF:\n\t metis['psf'].update(pupil_mask=\"%s\")"

- name: wcu_fits_keywords
description: FITS keywords specific to the WCU
Expand Down
74 changes: 74 additions & 0 deletions METIS/code/reformat_metis_psfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Reformat RvB's PSF cubes for use in scopesim

- scopesim uses multiextension fits files with a single PSF image per extension
- CUNIT3 "micrometer" replaced by "um"

Author: Oliver Czoske
Date: 2025-11-24
"""
import sys
from pathlib import Path
import numpy as np
from astropy.io import fits
from astropy.wcs import WCS

def reformat_file(infile):
"""Convert the file `infile`"""
with fits.open(infile) as hdul:
nwave = hdul[0].data.shape[0]
crval = hdul[0].header["CRVAL3"]
cdelt = hdul[0].header["CDELT3"]
# Fix some header keywords
if hdul[0].header["CUNIT3"] == "micrometer":
hdul[0].header["CUNIT3"] = "um"
else:
print("What?", hdul[0].header["CUNIT3"])
if "CTYPE1" not in hdul[0].header or hdul[0].header["CTYPE1"] == "":
hdul[0].header["CTYPE1"] = "LINEAR"
hdul[0].header["CTYPE2"] = "LINEAR"

wavelengths = np.exp(crval + cdelt * np.arange(1, nwave+1))

wcs = WCS(hdul[0].header).sub(2)
phdu = fits.PrimaryHDU()
phdu.header["FILETYPE"] = "Point Spread Functions"
phdu.header["AUTHOR"] = "Roy van Boekel, Oliver Czoske"
phdu.header["DATE"] = "2025-11-24"
phdu.header["ORIGDATE"] = "2025-10-30"
phdu.header["ORIGFILE"] = (Path(infile).name, "original file name")
phdu.header["COLDSTOP"] = (hdul[0].header["COLDSTOP"], "name cold pupil mask")
if "WCU" in infile:
phdu.header["ELTMASK"] = False
wcustr = "_WCU"
else:
phdu.header["ELTMASK"] = True
wcustr = ""
phdu.header["PUPILPS"] = (hdul[0].header["PUPILPS"], "[mm] pupil model pixel size")
phdu.header["NPIXFFT"] = (hdul[0].header["NPIXFFT"], "number of pixels used in FFT")
phdu.header["PUPILPS"] = (hdul[0].header["OSAMP"], "over-sampling factor")
phdu.header["PSIZEPUP"] = (hdul[0].header["PSIZEPUP"], "[mm] pixel size in pupil image")
outhdul = fits.HDUList([phdu])
if "IMG" in infile:
substr = "IMG"
elif "LMS" in infile:
substr = "LMS"
else:
raise ValueError("Unknown subsystem")
outfile = f"psfs/PSF_{substr}_{phdu.header['COLDSTOP']}{wcustr}.fits"
for i in range(nwave):
psfimg = hdul[0].data[i,]
hdr = wcs.to_header()
hdr['WAVELENG'] = (wavelengths[i], "[um] Wavelength of PSF image")
hdr['WAVEUNIT'] = 'um'
hdr['EXTNAME'] = f"PSF_{wavelengths[i]:.2f}um"

hdu = fits.ImageHDU(data=psfimg, header=hdr)
outhdul.append(hdu)
outhdul.writeto(outfile, overwrite=True)


if __name__ == "__main__":
infilelist = sys.argv[1:]

for thefile in infilelist:
reformat_file(thefile)
28 changes: 22 additions & 6 deletions METIS/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ properties:
ra: 0.0
dec: 0.0
# These defaults are overruled by the individual modes:
psf_name: none
Copy link
Contributor

Choose a reason for hiding this comment

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

What will be used as the default PSF now? Previously, it was PSF_SCAO_9mag_06seeing.fits, but now I don't see any actual filename as a default. Just to make sure a default METIS simulation now still uses a PSF at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The sky modes all have a psf_file (in default.yaml). I'll check whether that still works.

filter_name: open
nd_filter_name: open

Expand Down Expand Up @@ -257,7 +258,9 @@ mode_yamls:
- METIS_DET_IMG_LM.yaml
properties:
ins_mode: IMG_LM # use as FITS header keyword
psf_file: PSF_SCAO_9mag_06seeing.fits # REPLACE!
pupil_mask: PPS-LM
psf_file: none
psf_name: "!OBS.pupil_mask"
filter_name: Lp
nd_filter_name: open
slit: false
Expand All @@ -276,7 +279,9 @@ mode_yamls:
- METIS_DET_IMG_N_GeoSnap.yaml
properties:
ins_mode: IMG_N # use as FITS header keyword
psf_file: PSF_SCAO_9mag_06seeing.fits # REPLACE!
pupil_mask: PPS-N
psf_file: none
psf_name: "!OBS.pupil_mask"
filter_name: N2
nd_filter_name: open
slit: false
Expand All @@ -298,7 +303,9 @@ mode_yamls:
- METIS_DET_IMG_LM.yaml
properties:
ins_mode: LSS_L # use as FITS header keyword
psf_file: PSF_LM_9mag_06seeing.fits # REPLACE!
pupil_mask: PPS-CFO2
psf_file: none
psf_name: "!OBS.pupil_mask"
trace_file: TRACE_LSS_L.fits
efficiency_file: TER_grating_L.fits
slit: C-38_1
Expand All @@ -322,7 +329,9 @@ mode_yamls:
- METIS_DET_IMG_LM.yaml
properties:
ins_mode: LSS_M # use as FITS header keyword
psf_file: PSF_LM_9mag_06seeing.fits # REPLACE!
pupil_mask: PPS-CFO2
psf_file: none
psf_name: "!OBS.pupil_mask"
trace_file: TRACE_LSS_M.fits
efficiency_file: TER_grating_M.fits
slit: C-38_1
Expand All @@ -346,7 +355,9 @@ mode_yamls:
- METIS_DET_IMG_N_GeoSnap.yaml
properties:
ins_mode: LSS_N # use as FITS header keyword
psf_file: PSF_N_9mag_06seeing.fits # REPLACE!
pupil_mask: PPS-CFO2
psf_file: none
psf_name: "!OBS.pupil_mask"
trace_file: TRACE_LSS_N.fits
efficiency_file: TER_grating_N.fits
slit: D-57_1
Expand All @@ -371,7 +382,9 @@ mode_yamls:
- METIS_DET_IFU.yaml
properties:
ins_mode: LMS # use as FITS header keyword
psf_file: PSF_LM_9mag_06seeing.fits # REPLACE!
pupil_mask: PPS-LMS
psf_file: none
psf_name: "!OBS.pupil_mask"
slit: false
adc: false
trace_file: TRACE_LMS.fits
Expand All @@ -390,6 +403,9 @@ mode_yamls:
- METIS_DET_IFU.yaml
properties:
ins_mode: LMS # use as FITS header keyword
pupil_mask: PPS-LMS
psf_file: none
psf_name: "!OBS.pupil_mask"
slit: false
adc: false
detector_readout_mode: slow
Expand Down
Loading