From 4fd9f5e30f3e2d18d7e093a8bd68d6bf88401a32 Mon Sep 17 00:00:00 2001 From: Matthew R Becker Date: Wed, 1 May 2024 12:19:31 -0400 Subject: [PATCH] REF set rng_num more completely --- montara/catalogsampler.py | 24 ++++++++++++++---------- montara/des_tile.py | 11 ++++++----- montara/input_desstar.py | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/montara/catalogsampler.py b/montara/catalogsampler.py index 96fabdd..870c3f3 100644 --- a/montara/catalogsampler.py +++ b/montara/catalogsampler.py @@ -5,6 +5,10 @@ from .utils import add_field +import logging + +logger = logging.getLogger("pipeline") + class CatalogSampler(object): """class for randomly sampling object properties from a catalog""" @@ -131,22 +135,22 @@ def CatalogRow(config, base, name): base['_catalog_used_rngnum'], config.get("rng_num", None) )) - print( - "sampling catalog row info: %s %s %s %s" % ( - index, - index_key, - base['_catalog_row_data_catalog_row_ind'], - config.get("rng_num", None), - ), - flush=True, - ) - return base['_catalog_row_data'], base['_catalog_colnames'] def CatalogValue(config, base, value_type): row_data, colnames = CatalogRow(config, base, value_type) col = galsim.config.ParseValue(config, 'col', base, str)[0] + + logger.log( + logging.DEBUG, + " sampling gal catalog band|index|col: %s %s %s" % ( + base["eval_variables"]["sband"], + base['_catalog_row_data_catalog_row_ind'], + col, + ), + ) + try: return float(row_data[colnames.index(col)]) except ValueError as e: diff --git a/montara/des_tile.py b/montara/des_tile.py index 87969c5..3eaf37f 100644 --- a/montara/des_tile.py +++ b/montara/des_tile.py @@ -2,6 +2,7 @@ import shutil from collections import OrderedDict import subprocess +import logging import fitsio import galsim @@ -560,7 +561,8 @@ def setup(self, config, base, file_num, logger): base['rng'] = galsim.BaseDeviate(seed) ngalaxies = galsim.config.ParseValue(nobjects, 'ngalaxies', base, int)[0] - logger.debug("simulating %d galaxies" % ngalaxies) + logger.log(logging.CRITICAL, "simulating %d galaxies" % ngalaxies) + if nobjects.get("use_all_stars", True): # Now the stars. In this case # use all the stars in the star input catalog. We need @@ -584,7 +586,8 @@ def setup(self, config, base, file_num, logger): # If use_all_stars is False, and nstars is not specified, then # set nstars to zero. No stars for you. nstars = 0 - logger.debug("simulating %d stars" % nstars) + logger.log(logging.CRITICAL, "simulating %d stars" % nstars) + nobj = nstars + ngalaxies # Save an object_type_list as a base_eval_variable, this can be used # with MixedScene to specify whether to draw a galaxy or star. @@ -692,9 +695,7 @@ def setup(self, config, base, file_num, logger): if 'star' in base: base['star']['rng_num'] = 1 if base["psf"]["type"] in ["DES_Piff", "DES_SmoothPiff"]: - for _key in ["gi_color", "iz_color"]: - if _key in base["psf"] and base["psf"][_key] is not None: - base['psf'][_key]['rng_num'] = 1 + base["psf"] = _set_catalog_sampler_rng_num(base["psf"], 1) if 'stamp' in base: base['stamp']['rng_num'] = 1 if 'image_pos' in base['image']: diff --git a/montara/input_desstar.py b/montara/input_desstar.py index 3ac114c..64b4dd0 100644 --- a/montara/input_desstar.py +++ b/montara/input_desstar.py @@ -5,6 +5,10 @@ import fitsio from .utils import add_field +import logging + +logger = logging.getLogger("pipeline") + class DESStarCatalog(object): _req_params = {'file_name': str} @@ -51,6 +55,16 @@ def _GenerateFromStarCatalog(config, base, value_type): kwargs, safe = galsim.config.GetAllParams(config, base, req=req, opt=opt) col = kwargs['col'] index = kwargs['index'] + + logger.log( + logging.DEBUG, + "sampling star catalog band|index|col: %s %s %s" % ( + base["eval_variables"]["sband"], + index, + col, + ), + ) + val = star_input.get(index, col) return val, safe