Skip to content
Open
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
2 changes: 1 addition & 1 deletion example/unions_800/cat_matched.param
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ FLAG_TILING
# magnitude, mainly for plots
MAG_AUTO

# SNR from SExtractor, used for cuts on GALSIM shapes
# SNR from SExtractor, used for shape cuts
SNR_WIN

# PSF size measured on original image
Expand Down
2 changes: 1 addition & 1 deletion src/shapepipe/modules/make_cat_package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
spread model and :math:`\sigma_s` is the spread model error; default value
is ``0.01``
SHAPE_MEASUREMENT_TYPE : list
Shape measurement method, valid options are ``ngmix`` and/or ``galsim``
Shape measurement method; the only supported option is ``ngmix``
SAVE_PSF_DATA : bool, optional
Save PSF information if ``True``; default value is ``False``
TILE_LIST : str, optional
Expand Down
142 changes: 3 additions & 139 deletions src/shapepipe/modules/make_cat_package/make_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from astropy import coordinates as coords
from astropy import units as u
from astropy.wcs import WCS
from cs_util import size as cs_size
from sqlitedict import SqliteDict

from shapepipe.pipeline import file_io
Expand Down Expand Up @@ -243,7 +242,7 @@ def process(
Parameters
----------
mode : str
Run mode, options are ``ngmix``, ``galsim`` or ``psf``
Run mode, options are ``ngmix`` or ``psf``
cat_path : str
Path to input catalogue
moments : bool
Expand All @@ -263,15 +262,13 @@ def process(
err_msg = None
if mode == "ngmix":
err_msg = self._save_ngmix_data(cat_path, moments)
elif mode == "galsim":
self._save_galsim_shapes(cat_path)
elif mode == "psf":
self._save_psf_data(cat_path)
else:
err_msg = (
f"Invalid process mode ({mode}) for "
+ '``make_cat.Savecatalogue``. Options are "ngmix", '
+ '"galsim" or "psf".'
+ '``make_cat.Savecatalogue``. Options are "ngmix" '
+ 'or "psf".'
)

if err_msg is None:
Expand Down Expand Up @@ -543,139 +540,6 @@ def _save_ngmix_data(self, ngmix_cat_path, moments=False):

return None

def _save_galsim_shapes(self, galsim_cat_path):
"""Save GalSim Shapes.

Save the GalSim catalogue into the final one.

Parameters
----------
galsim_cat_path : str
Path to GalSim catalogue to save

"""
galsim_cat_file = file_io.FITSCatalogue(galsim_cat_path)
galsim_cat_file.open()

self._key_ends = galsim_cat_file.get_ext_name()[1:]

galsim_id = galsim_cat_file.get_data()["id"]

for key_str in (
"GALSIM_T_",
"GALSIM_T_PSF_",
"GALSIM_FLUX_",
"GALSIM_MAG_",
):
self._update_dict(key_str, np.zeros(len(self._obj_id)))
for key_str in ("GALSIM_FLUX_ERR_", "GALSIM_MAG_ERR_", "GALSIM_RES_"):
self._update_dict(key_str, np.ones(len(self._obj_id)) * -1)
for key_str in (
"GALSIM_G1_",
"GALSIM_G2_",
"GALSIM_G1_ERR_",
"GALSIM_G2_ERR_",
"GALSIM_G1_UNCORR_",
"GALSIM_G2_UNCORR_",
"GALSIM_G1_PSF_",
"GALSIM_G2_PSF_",
):
self._update_dict(key_str, np.ones(len(self._obj_id)) * -10.0)
self._update_dict(
"GALSIM_FLAGS_",
np.ones(len(self._obj_id), dtype="int16"),
)

for idx, id_tmp in enumerate(self._obj_id):
ind = np.where(id_tmp == galsim_id)[0]
if len(ind) > 0:

for key in self._key_ends:

gcf_data = galsim_cat_file.get_data(key)

if key == "ORIGINAL_PSF":

# PSF columns sourced from the galaxy uncorr fields
# for this special extension (asymmetry preserved).
self._add2dict(
f"GALSIM_G1_PSF_{key}",
gcf_data["gal_uncorr_g1"][ind[0]], idx
)
self._add2dict(
f"GALSIM_G2_PSF_{key}",
gcf_data["gal_uncorr_g2"][ind[0]], idx
)
self._add2dict(
f"GALSIM_T_PSF_{key}",
cs_size.sigma_to_T(gcf_data["gal_sigma"][ind[0]]),
idx
)

else:

self._add2dict(
f"GALSIM_G1_{key}", gcf_data["gal_g1"][ind[0]], idx
)
self._add2dict(
f"GALSIM_G2_{key}", gcf_data["gal_g2"][ind[0]], idx
)
self._add2dict(
f"GALSIM_G1_ERR_{key}",
gcf_data["gal_g1_err"][ind[0]], idx
)
self._add2dict(
f"GALSIM_G2_ERR_{key}",
gcf_data["gal_g2_err"][ind[0]], idx
)

self._add2dict(
f"GALSIM_G1_UNCORR_{key}",
gcf_data["gal_uncorr_g1"][ind[0]], idx
)
self._add2dict(
f"GALSIM_G2_UNCORR_{key}",
gcf_data["gal_uncorr_g2"][ind[0]], idx
)

self._add2dict(
f"GALSIM_T_{key}",
cs_size.sigma_to_T(gcf_data["gal_sigma"][ind[0]]),
idx
)

self._add2dict(
f"GALSIM_G1_PSF_{key}",
gcf_data["psf_g1"][ind[0]], idx
)
self._add2dict(
f"GALSIM_G2_PSF_{key}",
gcf_data["psf_g2"][ind[0]], idx
)
self._add2dict(
f"GALSIM_T_PSF_{key}",
cs_size.sigma_to_T(gcf_data["psf_sigma"][ind[0]]),
idx
)

flux = gcf_data["gal_flux"][ind[0]]
flux_err = gcf_data["gal_flux_err"][ind[0]]
self._add2dict(f"GALSIM_FLUX_{key}", flux, idx)
self._add2dict(f"GALSIM_FLUX_ERR_{key}", flux_err, idx)

mag = gcf_data["gal_mag"][ind[0]]
mag_err = gcf_data["gal_mag_err"][ind[0]]
self._add2dict(f"GALSIM_MAG_{key}", mag, idx)
self._add2dict(f"GALSIM_MAG_ERR_{key}", mag_err, idx)

flags = gcf_data["gal_flag"][ind[0]]
self._add2dict(f"GALSIM_FLAGS_{key}", flags, idx)

res = gcf_data["gal_resolution"][ind[0]]
self._add2dict(f"GALSIM_RES_{key}", res, idx)

galsim_cat_file.close()

def _save_psf_data(self, galaxy_psf_path):
"""Save PSF data.

Expand Down
12 changes: 3 additions & 9 deletions src/shapepipe/modules/make_cat_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ def make_cat_runner(
"SHAPE_MEASUREMENT_TYPE",
)
for shape_type in shape_type_list:
if shape_type.lower() not in ["ngmix", "galsim"]:
raise ValueError(
"SHAPE_MEASUREMENT_TYPE must be in [ngmix, galsim]"
)
if shape_type.lower() != "ngmix":
raise ValueError("SHAPE_MEASUREMENT_TYPE must be ngmix")

# Fetch PSF data option
if config.has_option(module_config_sec, "SAVE_PSF_DATA"):
Expand Down Expand Up @@ -125,11 +123,7 @@ def make_cat_runner(
w_log.info("Save shape measurement data")
for shape_type in shape_type_list:
w_log.info(f"Save {shape_type.lower()} data")
cat_path = (
shape2_cat_path if shape_type == "galsim" else shape1_cat_path
)
err_msg = sc_inst.process(shape_type.lower(), cat_path)

err_msg = sc_inst.process(shape_type.lower(), shape1_cat_path)

# If error message: delete (incomplete) output file and raise error
if err_msg is not None:
Expand Down
Loading