Commit 221f50ea authored by Fang Yuedong's avatar Fang Yuedong
Browse files

move catalog initialization into add_objects.py

parent 98579c7c
......@@ -71,7 +71,7 @@ class Catalog(CatalogBase):
def __init__(self, config, chip, pointing, chip_output, filt, **kwargs):
super().__init__()
self.cat_dir = os.path.join(config["data_dir"], config["catalog_options"]["input_path"]["cat_dir"])
self.seed_Av = config["catalog_options"]["seed_Av"]
# self.seed_Av = config["catalog_options"]["seed_Av"]
self.cosmo = FlatLambdaCDM(H0=67.66, Om0=0.3111)
......
......@@ -93,7 +93,7 @@ class Observation(object):
chip = self.prepare_chip_for_exposure(chip, ra_cen, dec_cen, pointing)
# Load catalogues
self.cat = self.Catalog(config=self.config, chip=chip, pointing=pointing, cat_dir=cat_dir, sed_dir=sed_dir, chip_output=chip_output, filt=filt)
# self.cat = self.Catalog(config=self.config, chip=chip, pointing=pointing, cat_dir=cat_dir, sed_dir=sed_dir, chip_output=chip_output, filt=filt)
# Initialize SimSteps
sim_steps = SimSteps(overall_config=self.config, chip_output=chip_output, all_filters=self.all_filters)
......@@ -112,7 +112,7 @@ class Observation(object):
filt=filt,
tel=self.tel,
pointing=pointing,
catalog=self.cat,
catalog=self.Catalog,
obs_param=obs_param)
chip_output.Log_info("Finished simulation step: %s"%(step))
except Exception as e:
......
......@@ -13,7 +13,7 @@ def parse_args():
'''
parser = argparse.ArgumentParser()
parser.add_argument('--config_file', type=str, required=True, help='.yaml config file for simulation settings.')
parser.add_argument('--catalog', type=str, required=True, help='name of the catalog interface class to be loaded.')
parser.add_argument('--catalog', type=str, help='name of the catalog interface class to be loaded.')
parser.add_argument('-c', '--config_dir', type=str, help='Directory that houses the .yaml config file.')
parser.add_argument('-d', '--data_dir', type=str, help='Directory that houses the input data.')
parser.add_argument('-w', '--work_dir', type=str, help='The path for output.')
......
......@@ -12,6 +12,12 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param):
# Prepare output file(s) for this chip
self.chip_output.create_output_file()
# Load catalogues
if catalog is None:
self.chip_output.Log_error("Catalog interface class must be specified for SCIE-OBS")
raise ValueError("Catalog interface class must be specified for SCIE-OBS")
cat = catalog(config=self.overall_config, chip=chip, pointing=pointing, chip_output=self.chip_output, filt=filt)
# Prepare the PSF model
if self.overall_config["psf_setting"]["psf_model"] == "Gauss":
psf_model = PSFGauss(chip=chip, psfRa=self.overall_config["psf_setting"]["psf_rcont"])
......@@ -48,7 +54,7 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param):
chip_wcs = galsim.FitsWCS(header = self.h_ext)
# Loop over objects
nobj = len(catalog.objs)
nobj = len(cat.objs)
missed_obj = 0
bright_obj = 0
dim_obj = 0
......@@ -56,19 +62,19 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param):
# # [DEBUG] [TODO]
# if j >= 10:
# break
obj = catalog.objs[j]
obj = cat.objs[j]
# load and convert SED; also caculate object's magnitude in all CSST bands
try:
sed_data = catalog.load_sed(obj)
norm_filt = catalog.load_norm_filt(obj)
obj.sed, obj.param["mag_%s"%filt.filter_type.lower()], obj.param["flux_%s"%filt.filter_type.lower()] = catalog.convert_sed(
sed_data = cat.load_sed(obj)
norm_filt = cat.load_norm_filt(obj)
obj.sed, obj.param["mag_%s"%filt.filter_type.lower()], obj.param["flux_%s"%filt.filter_type.lower()] = cat.convert_sed(
mag=obj.param["mag_use_normal"],
sed=sed_data,
target_filt=filt,
norm_filt=norm_filt,
)
_, obj.param["mag_%s"%cut_filter.filter_type.lower()], obj.param["flux_%s"%cut_filter.filter_type.lower()] = catalog.convert_sed(
_, obj.param["mag_%s"%cut_filter.filter_type.lower()], obj.param["flux_%s"%cut_filter.filter_type.lower()] = cat.convert_sed(
mag=obj.param["mag_use_normal"],
sed=sed_data,
target_filt=cut_filter,
......
......@@ -4,6 +4,8 @@ from ObservationSim.Instrument.Chip import Effects
def apply_PRNU(self, chip, filt, tel, pointing, catalog, obs_param):
chip.img *= chip.prnu_img
if self.overall_config["output_setting"]["prnu_output"] == True:
chip.prnu_img.write("%s/FlatImg_PRNU_%s.fits" % (self.chip_output.subdir, chip.chipID))
return chip, filt, tel, pointing
def add_poisson_and_dark(self, chip, filt, tel, pointing, catalog, obs_param):
......
......@@ -60,6 +60,9 @@ def add_sky_flat_calibration(self, chip, filt, tel, pointing, catalog, obs_param
if obs_param["shutter_effect"] == True:
flat_normal = flat_normal * chip.shutter_img
flat_normal = np.array(flat_normal, dtype='float32')
if self.overall_config["output_setting"]["shutter_output"] == True: # output 16-bit shutter effect image with pixel value <=65535
shutt_gsimg = galsim.ImageUS(chip.shutter_img*6E4)
shutt_gsimg.write("%s/ShutterEffect_%s_1.fits" % (self.chip_output.subdir, chip.chipID))
if chip.survey_type == "photometric":
......
......@@ -21,14 +21,11 @@ run_counter: 1
# Run options
run_option:
use_mpi: NO
# NOTE: "n_threads" paramters is currently not used in the backend
# simulation codes. It should be implemented later in the web frontend
# in order to config the number of threads to request from NAOC cluster
n_threads: 80
# Output catalog only?
# If yes, no imaging simulation will run
out_cat_only: YES
# If yes, no imaging simulation will be run. Only the catalogs
# of corresponding footprints will be generated.
out_cat_only: NO
###############################################
# Catalog setting
......@@ -55,10 +52,10 @@ catalog_options:
# Only simulate galaxies?
galaxy_only: YES
# rotate galaxy ellipticity
rotateEll: 0. # [degree]
# # rotate galaxy ellipticity
# rotateEll: 0. # [degree]
seed_Av: 121212 # Seed for generating random intrinsic extinction
# seed_Av: 121212 # Seed for generating random intrinsic extinction
###############################################
# Observation setting
......@@ -133,8 +130,8 @@ shear_setting:
###############################################
output_setting:
output_format: "channels" # Whether to export as 16 channels (subimages) with pre- and over-scan ("image"/"channels")
shutter_output: OFF # Whether to export shutter effect 16-bit image
prnu_output: OFF # Whether to export the PRNU (pixel-to-pixel flat-fielding) files
shutter_output: NO # Whether to export shutter effect 16-bit image
prnu_output: NO # Whether to export the PRNU (pixel-to-pixel flat-fielding) files
###############################################
# Random seeds
......
......@@ -83,7 +83,10 @@ def run_sim():
config_out.write("###############################################\n")
# Initialize the simulation
if args.catalog is not None:
catalog_module = importlib.import_module('Catalog.'+args.catalog)
else:
catalog_module = None
obs = Observation(config=config, Catalog=catalog_module.Catalog, work_dir=config['work_dir'], data_dir=config['data_dir'])
# Run simulation
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment