Skip to content

Commit

Permalink
REF set rng_num more completely
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr committed May 1, 2024
1 parent 6c0e416 commit 4fd9f5e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
24 changes: 14 additions & 10 deletions montara/catalogsampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions montara/des_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
from collections import OrderedDict
import subprocess
import logging

import fitsio
import galsim
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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']:
Expand Down
14 changes: 14 additions & 0 deletions montara/input_desstar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 4fd9f5e

Please sign in to comment.