Skip to content
Open
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
27 changes: 26 additions & 1 deletion src/shapepipe/modules/fake_psf_package/fake_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,30 @@

import numpy as np
from astropy.io import fits
from cs_util import size as cs_size
from sqlitedict import SqliteDict


def _galaxy_psf_shapes(shapes):
"""Map a simulation PSF ``SHAPES`` dict to the galaxy-PSF schema.

The SKiLLS PSF dictionary stores HSM shapes as ``E1_PSF_HSM``,
``E2_PSF_HSM``, ``SIGMA_PSF_HSM`` and ``FLAG_PSF_HSM``; ``make_cat``
reads ``HSM_G1_PSF``, ``HSM_G2_PSF``, ``HSM_T_PSF`` and ``HSM_FLAG_PSF``
(the keys ``psfex_interp`` writes). A dict already in that schema is
returned unchanged. The fourth-moment keys are absent, so ``make_cat``
leaves those slots at their fill values.
"""
if "HSM_FLAG_PSF" in shapes:
return shapes
return {
"HSM_G1_PSF": float(shapes["E1_PSF_HSM"]),
"HSM_G2_PSF": float(shapes["E2_PSF_HSM"]),
"HSM_T_PSF": float(cs_size.sigma_to_T(shapes["SIGMA_PSF_HSM"])),
"HSM_FLAG_PSF": int(shapes["FLAG_PSF_HSM"]),
}


class FakePsf:
"""Fake PSF.

Expand Down Expand Up @@ -101,7 +122,11 @@ def process(self):
f"Galaxy {galaxy_number}: key '{exp_ccd}' not in PSF dict"
)
continue
gal_dict[exp_ccd] = psf_dict[exp_ccd]
entry = psf_dict[exp_ccd]
gal_dict[exp_ccd] = {
**entry,
"SHAPES": _galaxy_psf_shapes(entry["SHAPES"]),
}
output_file[str(galaxy_number)] = gal_dict

output_file.commit()
Expand Down
Loading