Skip to content

Commit

Permalink
fixed (again) bugs due to sm optional flags
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkilbinger committed Feb 12, 2025
1 parent bc33cf2 commit c24a74d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
15 changes: 9 additions & 6 deletions shapepipe/modules/make_cat_package/make_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def save_sm_data(
Threshold for galaxy selection; object is classified as galaxy if
:math:`{\rm class} >` ``gal_thresh``
nobj : int, optional
Number of objects, only used if sexcat_sm_path is ``None``
Number of objects, only used if sexcat_sm_path is ``-1``
Returns
-------
Expand All @@ -186,7 +186,7 @@ def save_sm_data(
sexcat_sm_file.open()

sm = np.copy(sexcat_sm_file.get_data()["SPREAD_MODEL"])
sm_err = np.copy(sexcat_sm_file.get_data()["SPREADERR_MODEL"]
sm_err = np.copy(sexcat_sm_file.get_data()["SPREADERR_MODEL"])

sexcat_sm_file.close()

Expand All @@ -207,7 +207,7 @@ def save_sm_data(

final_cat_file.close()

return cat_size
return n_obj


class SaveCatalogue:
Expand All @@ -221,13 +221,16 @@ class SaveCatalogue:
Final catalogue file name
cat_size_target : int
target catalogue size
w_log : logging.Logger
Logging instance
"""

def __init__(self, final_cat_file, cat_size_target):
def __init__(self, final_cat_file, cat_size_target, w_log):

self._final_cat_file = final_cat_file
self._cat_size_target = cat_size_target
self._w_log = w_log

def process(
self,
Expand Down Expand Up @@ -321,7 +324,7 @@ def _add2dict(self, key, value, index=None):
else:
self._output_dict[key] = value

def _save_ngmix_data(self, ngmix_cat_path, moments=False, w_log):
def _save_ngmix_data(self, ngmix_cat_path, moments=False):
"""Save NGMIX Data.
Save the NGMIX catalogue into the final one.
Expand Down Expand Up @@ -374,7 +377,7 @@ def _save_ngmix_data(self, ngmix_cat_path, moments=False, w_log):
f"{prefix}_FLAGS_",
f"{prefix}_T_PSFo_",
):
self._update_dict(key_str, np.zeros(n_obj)
self._update_dict(key_str, np.zeros(n_obj))
for key_str in (f"NGMIX{m}_FLUX_ERR_", f"NGMIX{m}_MAG_ERR_"):
self._update_dict(key_str, np.ones(len(self._obj_id)) * -1)
for key_str in (
Expand Down
35 changes: 18 additions & 17 deletions shapepipe/modules/make_cat_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,30 +97,31 @@ def make_cat_runner(
# Save SExtractor data
w_log.info("Save SExtractor data")
n_obj = make_cat.save_sextractor_data(final_cat_file, tile_sexcat_path)
cat_size_sextractor = n_obj

# Save spread-model data
w_log.info("Save spread-model data")
if sexcat_sm_path is None:
w_log.info("No sm cat input, setting spread model to 99")
n_obj
make_cat.save_sm_data(
final_cat_file,
sexcat_sm_path,
do_classif,
star_thresh,
gal_thresh,
n_obj=n_obj
)

if cat_size_sextractor != cat_size_sm:
raise ValueError(
f"SExtractor catalogue {tile_sexcat_path} has different size"
+ f" ({cat_size_sextractor} than spread_model catalogue"
+ f" {sexcat_sm_path} ({cat_size_sm})"
else:
w_log.info("Save spread-model data")
cat_size_sm = make_cat.save_sm_data(
final_cat_file,
sexcat_sm_path,
do_classif,
star_thresh,
gal_thresh,
n_obj=n_obj
)

if cat_size_sextractor != cat_size_sm:
w_log(
f"Warnign: SExtractor catalogue {tile_sexcat_path} has different size"
+ f" ({cat_size_sextractor} than spread_model catalogue"
+ f" {sexcat_sm_path} ({cat_size_sm})"
)

# Save shape data
sc_inst = make_cat.SaveCatalogue(final_cat_file, cat_size_sextractor)
sc_inst = make_cat.SaveCatalogue(final_cat_file, cat_size_sextractor, w_log)
w_log.info("Save shape measurement data")
for shape_type in shape_type_list:
w_log.info(f"Save {shape_type.lower()} data")
Expand Down

0 comments on commit c24a74d

Please sign in to comment.