Commit 0697a198 authored by Fang Yuedong's avatar Fang Yuedong
Browse files

v0 for testing

parent e1458fd3
......@@ -14,13 +14,13 @@ class ChipOutput(object):
self.ra_cen = ra_cen
self.dec_cen = dec_cen
else:
self.ra_cen = config["ra_center"]
self.dec_cen = config["dec_center"]
self.ra_cen = config["obs_setting"]["ra_center"]
self.dec_cen = config["obs_setting"]["dec_center"]
exp_name = imgKey0 + "_%s_%s.fits"
self.chipLabel = focal_plane.getChipLabel(chip.chipID)
self.img_name = prefix + exp_name%(self.chipLabel, filt.filter_type)
# self.cat_name = self.img_name[:-5] + ".cat"
self.cat_name = 'MSC_' + config["date_obs"] + config["time_obs"] + "_" + str(pointing_ID).rjust(7, '0') + "_" + self.chipLabel.rjust(2,'0') + ".cat"
self.cat_name = 'MSC_' + config["obs_setting"]["date_obs"] + config["obs_setting"]["time_obs"] + "_" + str(pointing_ID).rjust(7, '0') + "_" + self.chipLabel.rjust(2,'0') + ".cat"
self.subdir = subdir
# hdr1 = "#ID ID_chip filter xImage yImage ra dec z mag flag SNR "
......
......@@ -2,7 +2,7 @@ import galsim
import os
from astropy.time import Time as asTime
def ConfigDir(cat_dir=None, work_dir=None, data_dir=None, config_file_path=None):
def ConfigDir(config, work_dir=None, data_dir=None):
path_dict = {}
# Working directory
if work_dir == None:
......@@ -11,48 +11,35 @@ def ConfigDir(cat_dir=None, work_dir=None, data_dir=None, config_file_path=None)
else:
path_dict["work_dir"] = work_dir
# Configuration file
if config_file_path is not None:
path_dict["config_file"] = config_file_path
else:
path_dict["config_file"] = os.path.join(path_dict["work_dir"], "ObservationSim.cfg")
# Output directories
# path_dict["output_fig_dir"] = os.path.join(path_dict["work_dir"], "figure/")
# if not os.path.exists(path_dict["output_fig_dir"]):
# os.system("mkdir %s"%path_dict["output_fig_dir"])
# path_dict["output_cat_dir"] = os.path.join(path_dict["work_dir"], "scat/")
# if not os.path.exists(path_dict["output_cat_dir"]):
# os.system("mkdir %s"%path_dict["output_cat_dir"])
# path_dict["output_img_dir"] = os.path.join(path_dict["work_dir"], "simg/")
# if not os.path.exists(path_dict["output_img_dir"]):
# os.system("mkdir %s"%path_dict["output_img_dir"])
# Data directory
if data_dir == None:
# Assume all input datasets are in the work directory
path_dict["data_dir"] =os.path.join(path_dict["work_dir"], "data/")
else:
path_dict["data_dir"] = data_dir
# Data sub-catalogs
# Object catalog direcotry
# path_dict["cat_dir"] = os.path.join(path_dict["data_dir"], "catalog_points_7degree2/", cat_dir)
path_dict["cat_dir"] = os.path.join(path_dict["data_dir"], "Catalog_20210126")
path_dict["cat_dir"] = os.path.join(path_dict["data_dir"], config["input_path"]["cat_dir"])
# PSF data directory
path_dict["psf_dir"] = os.path.join(path_dict["data_dir"], "csstPSFdata/CSSOS_psf_20210108/CSST_psf_ciomp_2p5um_cycle3_ccr90_proc")
path_dict["psf_dir"] = os.path.join(path_dict["data_dir"], config["psf_setting"]["psf_dir"])
# SED catalog directory
# TODO: SED_dir is deprecated
path_dict["SED_dir"] = os.path.join(path_dict["data_dir"], "imageSims/Catalog/SEDObject")
path_dict["template_dir"] = path_dict["data_dir"] + "Templates/"
# path_dict["template_dir"] = path_dict["data_dir"] + "Templates/"
# path_dict["template_dir"] = os.path.join(path_dict["data_dir"], config["SED_templates_path"]["galaxy_SED"])
# Directories/files for instrument parameters, e.g. efficiency curves.
path_dict["filter_dir"] = os.path.join(path_dict["data_dir"], "Filters")
path_dict["ccd_dir"] = os.path.join(path_dict["data_dir"], "Filter_CCD_Mirror/ccd")
path_dict["mirror_file"] = os.path.join(path_dict["data_dir"], "Filter_CCD_Mirror/mirror_ccdnote.txt")
path_dict["filter_dir"] = os.path.join(path_dict["data_dir"], config["Efficiency_curve_path"]["filter_eff"])
path_dict["ccd_dir"] = os.path.join(path_dict["data_dir"], config["Efficiency_curve_path"]["ccd_eff"])
path_dict["mirror_file"] = os.path.join(path_dict["data_dir"], config["Efficiency_curve_path"]["mirror_eff"])
# Cosmic-ray data directory:
path_dict["CRdata_dir"] = os.path.join(path_dict["data_dir"], "CRdata")
path_dict["CRdata_dir"] = os.path.join(path_dict["data_dir"], config["CR_data_path"])
path_dict["sky_file"] = os.path.join(path_dict["data_dir"], config["sky_data_path"])
# Slitless spectroscopy realted
path_dict["sls_dir"] = os.path.join(path_dict["data_dir"], "CONF/")
path_dict["normalize_dir"] = os.path.join(path_dict["data_dir"], "normalize_filter/")
path_dict["sls_dir"] = os.path.join(path_dict["data_dir"], config["SLS_path"]["SLS_conf"])
path_dict["normalize_dir"] = os.path.join(path_dict["data_dir"], config["SLS_path"]["SLS_norm"])
return path_dict
......
......@@ -30,13 +30,13 @@ class Chip(FocalPlane):
self.read_noise = 5.0 # e/pix
self.dark_noise = 0.02 # e/pix/s
self.pix_scale = 0.074 # pixel scale
self.gain = float(config["gain"])
self.bias_level = float(config["bias_level"])
self.gain = float(config["ins_effects"]["gain"])
self.bias_level = float(config["ins_effects"]["bias_level"])
self.overscan = 1000
self.exptime = float(config["exp_time"]) # second
self.dark_exptime = float(config['dark_exptime'])
self.flat_exptime = float(config['flat_exptime'])
self.readout_time = float(config['readout_time'])
self.exptime = float(config["obs_setting"]["exp_time"]) # second
self.dark_exptime = float(config["ins_effects"]['dark_exptime'])
self.flat_exptime = float(config["ins_effects"]['flat_exptime'])
self.readout_time = float(config["ins_effects"]['readout_time'])
# A chip ID must be assigned
self.chipID = int(chipID)
......@@ -65,8 +65,8 @@ class Chip(FocalPlane):
self._getCRdata()
# Define the sensor
if config["bright_fatter"].lower() == "y":
self.sensor = galsim.SiliconSensor(strength=config["df_strength"], treering_func=treering_func)
if config["ins_effects"]["bright_fatter"] == True:
self.sensor = galsim.SiliconSensor(strength=config["ins_effects"]["df_strength"], treering_func=treering_func)
else:
self.sensor = galsim.Sensor()
......@@ -295,18 +295,18 @@ class Chip(FocalPlane):
hdu1.writeto(fname, output_verify='ignore', overwrite=True)
def addEffects(self, config, img, chip_output, filt, ra_cen, dec_cen, img_rot, exptime=150., pointing_ID=0, timestamp_obs=1621915200, pointing_type='MS', sky_map=None, tel=None):
SeedGainNonuni=int(config["seed_gainNonUniform"])
SeedBiasNonuni=int(config["seed_biasNonUniform"])
SeedRnNonuni = int(config["seed_rnNonUniform"])
SeedBadColumns = int(config["seed_badcolumns"])
SeedDefective = int(config["seed_defective"])
SeedCosmicRay = int(config["seed_CR"])
fullwell = int(config["full_well"])
if config["add_hotpixels"].lower() == "y":
SeedGainNonuni=int(config["random_seeds"]["seed_gainNonUniform"])
SeedBiasNonuni=int(config["random_seeds"]["seed_biasNonUniform"])
SeedRnNonuni = int(config["random_seeds"]["seed_rnNonUniform"])
SeedBadColumns = int(config["random_seeds"]["seed_badcolumns"])
SeedDefective = int(config["random_seeds"]["seed_defective"])
SeedCosmicRay = int(config["random_seeds"]["seed_CR"])
fullwell = int(config["ins_effects"]["full_well"])
if config["ins_effects"]["add_hotpixels"] == True:
BoolHotPix = True
else:
BoolHotPix = False
if config["add_deadpixels"].lower() == "y":
if config["ins_effects"]["add_deadpixels"]== True:
BoolDeadPix = True
else:
BoolDeadPix = False
......@@ -318,47 +318,47 @@ class Chip(FocalPlane):
raise ValueError("The shape img and sky_map must be equal.")
elif tel is not None: # If sky_map is given in flux
sky_map = sky_map * tel.pupil_area * self.exptime
if config["add_back"].lower() == "y":
if config["ins_effects"]["add_back"] == True:
img += sky_map
del sky_map
# Apply flat-field large scale structure for one chip
if config["flat_fielding"].lower() == "y":
if config["ins_effects"]["flat_fielding"] == True:
print(" Creating and applying Flat-Fielding", flush=True)
print(img.bounds, flush=True)
flat_img = effects.MakeFlatSmooth(
img.bounds,
int(config["seed_flat"]))
int(config["random_seeds"]["seed_flat"]))
flat_normal = flat_img / np.mean(flat_img.array)
img *= flat_normal
del flat_normal
if config["flat_output"].lower() == "n":
if config["output_setting"]["flat_output"] == False:
del flat_img
# Apply Shutter-effect for one chip
if config["shutter_effect"].lower() == "y":
if config["ins_effects"]["shutter_effect"] == True:
print(" Apply shutter effect", flush=True)
shuttimg = effects.ShutterEffectArr(img, t_shutter=1.3, dist_bearing=735, dt=1E-3) # shutter effect normalized image for this chip
img *= shuttimg
if config["shutter_output"].lower() == "y": # output 16-bit shutter effect image with pixel value <=65535
if config["output_setting"]["shutter_output"] == True: # output 16-bit shutter effect image with pixel value <=65535
shutt_gsimg = galsim.ImageUS(shuttimg*6E4)
shutt_gsimg.write("%s/ShutterEffect_%s_1.fits" % (chip_output.subdir, self.chipID))
del shutt_gsimg
del shuttimg
# Add Poisson noise
seed = int(config["seed_poisson"]) + pointing_ID*30 + self.chipID
seed = int(config["random_seeds"]["seed_poisson"]) + pointing_ID*30 + self.chipID
rng_poisson = galsim.BaseDeviate(seed)
poisson_noise = galsim.PoissonNoise(rng_poisson, sky_level=0.)
img.addNoise(poisson_noise)
# Add cosmic-rays
if config["cosmic_ray"].lower() == "y" and pointing_type=='MS':
if config["ins_effects"]["cosmic_ray"] == True and pointing_type=='MS':
print(" Adding Cosmic-Ray", flush=True)
cr_map = effects.produceCR_Map(
cr_map, cr_event_num = effects.produceCR_Map(
xLen=self.npix_x, yLen=self.npix_y,
exTime=self.exptime+0.5*self.readout_time,
cr_pixelRatio=0.003*(1+0.5*self.readout_time/self.exptime),
cr_pixelRatio=0.003*(self.exptime+0.5*self.readout_time)/150.,
gain=self.gain,
attachedSizes=self.attachedSizes,
seed=SeedCosmicRay+pointing_ID*30+self.chipID) # seed: obj-imaging:+0; bias:+1; dark:+2; flat:+3;
......@@ -382,25 +382,25 @@ class Chip(FocalPlane):
date_obs=date_obs,
time_obs=time_obs,
output_dir=chip_output.subdir,
exptime=150.)
exptime=self.exptime)
del crmap_gsimg
# Apply PRNU effect and output PRNU flat file:
if config["prnu_effect"].lower() == "y":
if config["ins_effects"]["prnu_effect"] == True:
print(" Applying PRNU effect", flush=True)
prnu_img = effects.PRNU_Img(
xsize=self.npix_x,
ysize=self.npix_y,
sigma=0.01,
seed=int(config["seed_prnu"]+self.chipID))
seed=int(config["random_seeds"]["seed_prnu"]+self.chipID))
img *= prnu_img
if config["prnu_output"].lower() == "y":
if config["output_setting"]["prnu_output"] == True:
prnu_img.write("%s/FlatImg_PRNU_%s.fits" % (chip_output.subdir,self.chipID))
if config["flat_output"].lower() == "n":
if config["output_setting"]["flat_output"] == False:
del prnu_img
# Add dark current
if config["add_dark"].lower() == "y":
if config["ins_effects"]["add_dark"] == True:
dark_noise = galsim.DeviateNoise(galsim.PoissonDeviate(rng_poisson, self.dark_noise*(self.exptime+0.5*self.readout_time)))
img.addNoise(dark_noise)
......@@ -410,35 +410,35 @@ class Chip(FocalPlane):
img = effects.DefectivePixels(img, IfHotPix=BoolHotPix, IfDeadPix=BoolDeadPix, fraction=badfraction, seed=SeedDefective+self.chipID, biaslevel=0)
# Apply Bad lines
if config["add_badcolumns"].lower() == "y":
if config["ins_effects"]["add_badcolumns"] == True:
img = effects.BadColumns(img, seed=SeedBadColumns, chipid=self.chipID)
# Add Bias level
if config["add_bias"].lower() == "y":
if config["ins_effects"]["add_bias"] == True:
print(" Adding Bias level and 16-channel non-uniformity")
img = effects.AddBiasNonUniform16(img,
bias_level=float(config["bias_level"]),
bias_level=float(config["ins_effects"]["bias_level"]),
nsecy = 2, nsecx=8,
seed=SeedBiasNonuni+self.chipID)
# Apply Nonlinearity on the chip image
if config["non_linear"].lower() == "y":
if config["ins_effects"]["non_linear"] == True:
print(" Applying Non-Linearity on the chip image", flush=True)
img = effects.NonLinearity(GSImage=img, beta1=5.e-7, beta2=0)
# Apply CCD Saturation & Blooming
if config["saturbloom"].lower() == "y":
if config["ins_effects"]["saturbloom"] == True:
print(" Applying CCD Saturation & Blooming")
img = effects.SaturBloom(GSImage=img, nsect_x=1, nsect_y=1, fullwell=fullwell)
# Apply CTE Effect
if config["cte_trail"].lower() == "y":
if config["ins_effects"]["cte_trail"] == True:
print(" Apply CTE Effect")
img = effects.CTE_Effect(GSImage=img, threshold=27)
# Add Read-out Noise
if config["add_readout"].lower() == "y":
seed = int(config["seed_readout"]) + pointing_ID*30 + self.chipID
if config["ins_effects"]["add_readout"] == True:
seed = int(config["random_seeds"]["seed_readout"]) + pointing_ID*30 + self.chipID
rng_readout = galsim.BaseDeviate(seed)
readout_noise = galsim.GaussianNoise(rng=rng_readout, sigma=self.read_noise)
img.addNoise(readout_noise)
......@@ -458,21 +458,21 @@ class Chip(FocalPlane):
# Output images for calibration pointing
######################################################################################
# Bias output
if config["bias_output"].lower() == "y" and pointing_type=='CAL':
if config["output_setting"]["bias_output"] == True and pointing_type=='CAL':
print(" Output N frame Bias files", flush=True)
NBias = int(config["NBias"])
NBias = int(config["ins_effects"]["NBias"])
for i in range(NBias):
BiasCombImg, BiasTag = effects.MakeBiasNcomb(
self.npix_x, self.npix_y,
bias_level=float(config["bias_level"]),
bias_level=float(config["ins_effects"]["bias_level"]),
ncombine=1, read_noise=self.read_noise, gain=1,
seed=SeedBiasNonuni+self.chipID)
if config["cosmic_ray"].lower() == "y":
if config["cray_differ"].lower() == "y":
cr_map = effects.produceCR_Map(
if config["ins_effects"]["cosmic_ray"] == True:
if config["ins_effects"]["cray_differ"] == True:
cr_map, cr_event_num = effects.produceCR_Map(
xLen=self.npix_x, yLen=self.npix_y,
exTime=0.01,
cr_pixelRatio=0.003*(0.01+0.5*self.readout_time)/(self.exptime+0.5*self.readout_time),
cr_pixelRatio=0.003*(0.01+0.5*self.readout_time)/150.,
gain=self.gain,
attachedSizes=self.attachedSizes,
seed=SeedCosmicRay+pointing_ID*30+self.chipID+1)
......@@ -481,20 +481,20 @@ class Chip(FocalPlane):
del cr_map
# Non-Linearity for Bias
if config["non_linear"].lower() == "y":
if config["ins_effects"]["non_linear"] == True:
print(" Applying Non-Linearity on the Bias image", flush=True)
BiasCombImg = effects.NonLinearity(GSImage=BiasCombImg, beta1=5.e-7, beta2=0)
# Apply Bad lines
if config["add_badcolumns"].lower() == "y":
BiasCombImg = effects.BadColumns(BiasCombImg-float(config["bias_level"])+5, seed=SeedBadColumns, chipid=self.chipID) + float(config["bias_level"])-5
if config["ins_effects"]["add_badcolumns"] == True:
BiasCombImg = effects.BadColumns(BiasCombImg-float(config["ins_effects"]["bias_level"])+5, seed=SeedBadColumns, chipid=self.chipID) + float(config["ins_effects"]["bias_level"])-5
BiasCombImg = effects.ApplyGainNonUniform16(BiasCombImg, gain=self.gain,
nsecy = 2, nsecx=8,
seed=SeedGainNonuni+self.chipID)
# BiasCombImg = effects.AddOverscan(
# BiasCombImg,
# overscan=float(config["bias_level"])-2, gain=self.gain,
# overscan=float(config["ins_effects"]["bias_level"])-2, gain=self.gain,
# widthl=27, widthr=27, widtht=8, widthb=8)
BiasCombImg.replaceNegative(replace_value=0)
BiasCombImg.quantize()
......@@ -518,13 +518,13 @@ class Chip(FocalPlane):
del BiasCombImg
# Export combined (ncombine, Vignetting + PRNU) & single vignetting flat-field file
if config["flat_output"].lower() == "y" and pointing_type=='CAL':
if config["output_setting"]["flat_output"] == True and pointing_type=='CAL':
print(" Output N frame Flat-Field files", flush=True)
NFlat = int(config["NFlat"])
if config["add_bias"].lower() == "y":
NFlat = int(config["ins_effects"]["NFlat"])
if config["ins_effects"]["add_bias"] == True:
biaslevel = self.bias_level
overscan = biaslevel-2
elif config["add_bias"].lower() == "n":
elif config["ins_effects"]["add_bias"] == True:
biaslevel = 0
overscan = 0
darklevel = self.dark_noise*(self.flat_exptime+0.5*self.readout_time)
......@@ -539,12 +539,12 @@ class Chip(FocalPlane):
biaslevel=0,
seed_bias=SeedDefective+self.chipID
)
if config["cosmic_ray"].lower() == "y":
if config["cray_differ"].lower() == "y":
cr_map = effects.produceCR_Map(
if config["ins_effects"]["cosmic_ray"] == True:
if config["ins_effects"]["cray_differ"] == True:
cr_map, cr_event_num = effects.produceCR_Map(
xLen=self.npix_x, yLen=self.npix_y,
exTime=self.flat_exptime+0.5*self.readout_time,
cr_pixelRatio=0.003*(self.flat_exptime+0.5*self.readout_time)/(self.exptime+0.5*self.readout_time),
cr_pixelRatio=0.003*(self.flat_exptime+0.5*self.readout_time)/150.,
gain=self.gain,
attachedSizes=self.attachedSizes,
seed=SeedCosmicRay+pointing_ID*30+self.chipID+3)
......@@ -552,11 +552,11 @@ class Chip(FocalPlane):
FlatCombImg += cr_map
del cr_map
if config["non_linear"].lower() == "y":
if config["ins_effects"]["non_linear"] == True:
print(" Applying Non-Linearity on the Flat image", flush=True)
FlatCombImg = effects.NonLinearity(GSImage=FlatCombImg, beta1=5.e-7, beta2=0)
if config["cte_trail"].lower() == "y":
if config["ins_effects"]["cte_trail"] == True:
FlatCombImg = effects.CTE_Effect(GSImage=FlatCombImg, threshold=3)
# Add Hot Pixels or/and Dead Pixels
......@@ -565,21 +565,21 @@ class Chip(FocalPlane):
FlatCombImg = effects.DefectivePixels(FlatCombImg, IfHotPix=BoolHotPix, IfDeadPix=BoolDeadPix, fraction=badfraction, seed=SeedDefective+self.chipID, biaslevel=0)
# Apply Bad lines
if config["add_badcolumns"].lower() == "y":
if config["ins_effects"]["add_badcolumns"] == True:
FlatCombImg = effects.BadColumns(FlatCombImg, seed=SeedBadColumns, chipid=self.chipID)
# Add Bias level
if config["add_bias"].lower() == "y":
if config["ins_effects"]["add_bias"] == True:
print(" Adding Bias level and 16-channel non-uniformity")
# img += float(config["bias_level"])
# img += float(config["ins_effects"]["bias_level"])
FlatCombImg = effects.AddBiasNonUniform16(FlatCombImg,
bias_level=biaslevel,
nsecy = 2, nsecx=8,
seed=SeedBiasNonuni+self.chipID)
# Add Read-out Noise
if config["add_readout"].lower() == "y":
seed = int(config["seed_readout"]) + pointing_ID*30 + self.chipID
if config["ins_effects"]["add_readout"] == True:
seed = int(config["random_seeds"]["seed_readout"]) + pointing_ID*30 + self.chipID
rng_readout = galsim.BaseDeviate(seed)
readout_noise = galsim.GaussianNoise(rng=rng_readout, sigma=self.read_noise)
FlatCombImg.addNoise(readout_noise)
......@@ -615,13 +615,13 @@ class Chip(FocalPlane):
del flat_img
# Export Dark current images
if config["dark_output"].lower() == "y" and pointing_type=='CAL':
if config["output_setting"]["dark_output"] == True and pointing_type=='CAL':
print(" Output N frame Dark Current files", flush=True)
NDark = int(config["NDark"])
if config["add_bias"].lower() == "y":
NDark = int(config["ins_effects"]["NDark"])
if config["ins_effects"]["add_bias"] == True:
biaslevel = self.bias_level
overscan = biaslevel-2
elif config["add_bias"].lower() == "n":
elif config["ins_effects"]["add_bias"] == True:
biaslevel = 0
overscan = 0
for i in range(NDark):
......@@ -630,12 +630,12 @@ class Chip(FocalPlane):
overscan=overscan, bias_level=0, darkpsec=0.02, exptime=self.dark_exptime+0.5*self.readout_time,
ncombine=1, read_noise=self.read_noise,
gain=1, seed_bias=SeedBiasNonuni+self.chipID)
if config["cosmic_ray"].lower() == "y":
if config["cray_differ"].lower() == "y":
cr_map = effects.produceCR_Map(
if config["ins_effects"]["cosmic_ray"] == True:
if config["ins_effects"]["cray_differ"] == True:
cr_map, cr_event_num = effects.produceCR_Map(
xLen=self.npix_x, yLen=self.npix_y,
exTime=self.dark_exptime+0.5*self.readout_time,
cr_pixelRatio=0.003*(self.dark_exptime+0.5*self.readout_time)/(self.exptime+0.5*self.readout_time),
cr_pixelRatio=0.003*(self.dark_exptime+0.5*self.readout_time)/150.,
gain=self.gain,
attachedSizes=self.attachedSizes,
seed=SeedCosmicRay+pointing_ID*30+self.chipID+2)
......@@ -662,11 +662,11 @@ class Chip(FocalPlane):
del crmap_gsimg
# Non-Linearity for Dark
if config["non_linear"].lower() == "y":
if config["ins_effects"]["non_linear"] == True:
print(" Applying Non-Linearity on the Dark image", flush=True)
DarkCombImg = effects.NonLinearity(GSImage=DarkCombImg, beta1=5.e-7, beta2=0)
if config["cte_trail"].lower() == "y":
if config["ins_effects"]["cte_trail"] == True:
DarkCombImg = effects.CTE_Effect(GSImage=DarkCombImg, threshold=3)
# Add Hot Pixels or/and Dead Pixels
......@@ -675,21 +675,21 @@ class Chip(FocalPlane):
DarkCombImg = effects.DefectivePixels(DarkCombImg, IfHotPix=BoolHotPix, IfDeadPix=BoolDeadPix, fraction=badfraction, seed=SeedDefective+self.chipID, biaslevel=0)
# Apply Bad lines
if config["add_badcolumns"].lower() == "y":
if config["ins_effects"]["add_badcolumns"] == True:
DarkCombImg = effects.BadColumns(DarkCombImg, seed=SeedBadColumns, chipid=self.chipID)
# Add Bias level
if config["add_bias"].lower() == "y":
if config["ins_effects"]["add_bias"] == True:
print(" Adding Bias level and 16-channel non-uniformity")
# img += float(config["bias_level"])
# img += float(config["ins_effects"]["bias_level"])
DarkCombImg = effects.AddBiasNonUniform16(DarkCombImg,
bias_level=biaslevel,
nsecy = 2, nsecx=8,
seed=SeedBiasNonuni+self.chipID)
# Add Read-out Noise
if config["add_readout"].lower() == "y":
seed = int(config["seed_readout"]) + pointing_ID*30 + self.chipID
if config["ins_effects"]["add_readout"] == True:
seed = int(config["random_seeds"]["seed_readout"]) + pointing_ID*30 + self.chipID
rng_readout = galsim.BaseDeviate(seed)
readout_noise = galsim.GaussianNoise(rng=rng_readout, sigma=self.read_noise)
DarkCombImg.addNoise(readout_noise)
......@@ -725,7 +725,7 @@ class Chip(FocalPlane):
# img = galsim.ImageUS(img)
# # 16 output channel, with each a single image file
# if config["readout16"].lower() == "y":
# if config["ins_effects"]["readout16"] == True:
# print(" 16 Output Channel simulation")
# for coli in [0, 1]:
# for rowi in range(8):
......
......@@ -669,7 +669,7 @@ def produceCR_Map(xLen, yLen, exTime, cr_pixelRatio, gain, attachedSizes, seed=2
CRmap[sly, slx] += crMatrix_n[oky,:][:,okx]
return CRmap.astype(np.int32);
return CRmap.astype(np.int32), cr_event_size
def ShutterEffectArr(GSImage, t_shutter=1.3, dist_bearing=735, dt=1E-3):
......
import numpy as np
import os
vc_A = 2.99792458e+18 # speed of light: A/s
vc_m = 2.99792458e+8 # speed of light: m/s
h_Plank = 6.626196e-27 # Plank constant: erg s
VC_A = 2.99792458e+18 # speed of light: A/s
VC_M = 2.99792458e+8 # speed of light: m/s
H_PLANK = 6.626196e-27 # Plank constant: erg s
def photonEnergy(lambd):
""" The energy of photon at a given wavelength
......@@ -13,6 +13,6 @@ def photonEnergy(lambd):
Return:
eph: energy of photon in unit of erg
"""
nu = vc_A / lambd
eph = h_Plank * nu
nu = VC_A / lambd
eph = H_PLANK * nu
return eph
\ No newline at end of file
......@@ -11,32 +11,43 @@ from ._util import seds, sed_assign, extAv
from astropy.table import Table
from astropy.coordinates import spherical_to_cartesian
nside = 128
NSIDE = 128
class Catalog(object):
def __init__(self, config, chip, cat_dir, sed_dir, pRa, pDec, rotation=None, template_dir=None):
def __init__(self, config, chip, cat_dir=None, pRa=None, pDec=None, sed_dir=None, rotation=None):
if cat_dir is not None:
self.cat_dir = cat_dir
else:
self.cat_dir = os.path.join(config["data_dir"], config["input_path"]["cat_dir"])
self.sed_dir = sed_dir
self.chip = chip
self.template_dir = template_dir
self.seed_Av = config["seed_Av"]
self.seed_Av = config["random_seeds"]["seed_Av"]
if pRa is not None:
self.pRa = float('{:8.4f}'.format(pRa))
if pDec is not None:
self.pDec = float('{:8.4f}'.format(pDec))
# star_file = 'stars_ccd' + chip.getChipLabel(chip.chipID) + '_p_RA'+str(self.pRa) + '_DE' + str(self.pDec) + '.hdf5'
# galaxy_file = 'galaxies_ccd' + chip.getChipLabel(chip.chipID) + '_p_RA'+str(self.pRa) + '_DE' + str(self.pDec) + '.hdf5'
# star_file = 'MMW_Cluster_D20_10_healpix.hdf5'
star_file = 'MMW_Cluster_D20_healpix_21.hdf5'
galaxy_file = 'galaxyCats_r_10.0_healpix.hdf5'
star_SED_file = 'SpecLib.hdf5'
self.star_path = os.path.join(cat_dir, star_file)
self.galaxy_path = os.path.join(cat_dir, galaxy_file)
self.star_SED_path = os.path.join(cat_dir, star_SED_file)
self.rotation = rotation
self._load_SED_lib_gals()
if "star_cat" in config["input_path"]:
star_file = config["input_path"]["star_cat"]
star_SED_file = config["SED_templates_path"]["star_SED"]
self.star_path = os.path.join(self.cat_dir, star_file)
self.star_SED_path = os.path.join(config["data_dir"], star_SED_file)
self._load_SED_lib_star()
if "galaxy_cat" in config["input_path"]:
galaxy_file = config["input_path"]["galaxy_cat"]
self.galaxy_path = os.path.join(self.cat_dir, galaxy_file)
self.galaxy_SED_path = os.path.join(config["data_dir"], config["SED_templates_path"]["galaxy_SED"])
self._load_SED_lib_gals()
if "rotateEll" in config["shear_setting"]:
self.rotation = float(int(config["shear_setting"]["rotateEll"]/45.))
else:
self.rotation = 0.
# self._load_SED_info()
self._get_healpix_list()
self._load()
......@@ -48,20 +59,20 @@ class Catalog(object):
ra = np.deg2rad(np.array([ra_min, ra_max, ra_max, ra_min]))
dec = np.deg2rad(np.array([dec_max, dec_max, dec_min, dec_min]))
# phi, theta = ra, np.pi/2. - dec
# vertices_pix = np.unique(hp.ang2pix(nside, theta, phi))
# vertices_pix = np.unique(hp.ang2pix(NSIDE, theta, phi))
# print(vertices_pix)
vertices = spherical_to_cartesian(1., dec, ra)
self.pix_list = hp.query_polygon(nside, np.array(vertices).T, inclusive=True)
self.pix_list = hp.query_polygon(NSIDE, np.array(vertices).T, inclusive=True)
print("HEALPix List: ", self.pix_list)
def _load_SED_lib_star(self):
self.tempSED_star = h5.File(self.star_SED_path,'r')
def _load_SED_lib_gals(self):
tempdir_gal = os.path.join(self.template_dir, "Galaxy/")
# tempdir_gal = os.path.join(self.template_dir, "Galaxy/")
# tempdir_star = os.path.join(self.template_dir, "PicklesStars/")
self.tempSed_gal, self.tempRed_gal = seds("galaxy.list", seddir=tempdir_gal)
# self.tempSed_star, self.tempRed_star = seds("star.list", seddir=tempdir_star)
self.tempSed_gal, self.tempRed_gal = seds("galaxy.list", seddir=self.galaxy_SED_path)
def _load_SED_info(self):
sed_info_file = os.path.join(self.sed_dir, "sed.info")
......
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