Commit 8b77095f authored by xin's avatar xin
Browse files

syn master code

parent 25dafa5a
...@@ -45,6 +45,7 @@ class Galaxy(MockObject): ...@@ -45,6 +45,7 @@ class Galaxy(MockObject):
full = integrate_sed_bandpass(sed=self.sed, bandpass=filt.bandpass_full) full = integrate_sed_bandpass(sed=self.sed, bandpass=filt.bandpass_full)
except Exception as e: except Exception as e:
print(e) print(e)
self.logger.error(e)
return -1 return -1
for i in range(len(bandpass_list)): for i in range(len(bandpass_list)):
bandpass = bandpass_list[i] bandpass = bandpass_list[i]
...@@ -52,6 +53,7 @@ class Galaxy(MockObject): ...@@ -52,6 +53,7 @@ class Galaxy(MockObject):
sub = integrate_sed_bandpass(sed=self.sed, bandpass=bandpass) sub = integrate_sed_bandpass(sed=self.sed, bandpass=bandpass)
except Exception as e: except Exception as e:
print(e) print(e)
self.logger.error(e)
return -1 return -1
ratio = sub/full ratio = sub/full
...@@ -86,6 +88,7 @@ class Galaxy(MockObject): ...@@ -86,6 +88,7 @@ class Galaxy(MockObject):
full = integrate_sed_bandpass(sed=self.sed, bandpass=filt.bandpass_full) full = integrate_sed_bandpass(sed=self.sed, bandpass=filt.bandpass_full)
except Exception as e: except Exception as e:
print(e) print(e)
self.logger.error(e)
return False return False
nphotons_sum = 0 nphotons_sum = 0
...@@ -111,6 +114,7 @@ class Galaxy(MockObject): ...@@ -111,6 +114,7 @@ class Galaxy(MockObject):
sub = integrate_sed_bandpass(sed=self.sed, bandpass=bandpass) sub = integrate_sed_bandpass(sed=self.sed, bandpass=bandpass)
except Exception as e: except Exception as e:
print(e) print(e)
self.logger.error(e)
# return False # return False
continue continue
......
...@@ -44,6 +44,7 @@ class MockObject(object): ...@@ -44,6 +44,7 @@ class MockObject(object):
self.hlr_bulge = self.param["hlr_bulge"] self.hlr_bulge = self.param["hlr_bulge"]
self.e1_disk, self.e2_disk = 0., 0. self.e1_disk, self.e2_disk = 0., 0.
self.e1_bulge, self.e2_bulge = 0., 0. self.e1_bulge, self.e2_bulge = 0., 0.
self.additional_output_str = ""
self.logger = logger self.logger = logger
...@@ -126,6 +127,7 @@ class MockObject(object): ...@@ -126,6 +127,7 @@ class MockObject(object):
full = integrate_sed_bandpass(sed=self.sed, bandpass=filt.bandpass_full) full = integrate_sed_bandpass(sed=self.sed, bandpass=filt.bandpass_full)
except Exception as e: except Exception as e:
print(e) print(e)
self.logger.error(e)
return False return False
nphotons_sum = 0 nphotons_sum = 0
...@@ -145,6 +147,7 @@ class MockObject(object): ...@@ -145,6 +147,7 @@ class MockObject(object):
sub = integrate_sed_bandpass(sed=self.sed, bandpass=bandpass) sub = integrate_sed_bandpass(sed=self.sed, bandpass=bandpass)
except Exception as e: except Exception as e:
print(e) print(e)
self.logger.error(e)
# return False # return False
continue continue
......
...@@ -135,15 +135,15 @@ class SpecDisperser(object): ...@@ -135,15 +135,15 @@ class SpecDisperser(object):
bean_thr_spec = beam_thr * spec_sample bean_thr_spec = beam_thr * spec_sample
###generate sensitivity file for aXe ###generate sensitivity file for aXe
# ysensitivity = lam_beam * 0 ysensitivity = lam_beam * 0
#
# ysensitivity[lam_index] = interp.interp_conserve_c(lam_beam[lam_index], lam_intep, ysensitivity[lam_index] = interp.interp_conserve_c(lam_beam[lam_index], lam_intep,
# beam_thr * math.pi * 100 * 100 * 1e-7 / ( beam_thr * math.pi * 100 * 100 * 1e-7 / (
# cons.h.value * cons.c.value / ( cons.h.value * cons.c.value / (
# lam_intep * 1e-10)), integrate=0, left=0, lam_intep * 1e-10)), integrate=0, left=0,
# right=0) right=0)
#
# self.writerSensitivityFile(conffile = self.grating_conf_file, beam = beam, w = lam_beam[lam_index], sens = ysensitivity[lam_index]) self.writerSensitivityFile(conffile = self.grating_conf_file, beam = beam, w = lam_beam[lam_index], sens = ysensitivity[lam_index])
ysens[lam_index] = interp.interp_conserve_c(lam_beam[lam_index], lam_intep, bean_thr_spec, integrate=1, left=0, ysens[lam_index] = interp.interp_conserve_c(lam_beam[lam_index], lam_intep, bean_thr_spec, integrate=1, left=0,
right=0) right=0)
...@@ -199,7 +199,7 @@ class SpecDisperser(object): ...@@ -199,7 +199,7 @@ class SpecDisperser(object):
def writerSensitivityFile(self, conffile = '', beam = '', w = None, sens = None): def writerSensitivityFile(self, conffile = '', beam = '', w = None, sens = None):
orders={'A':'1st','B':'0st','C':'2st','D':'-1st','E':'-2st'} orders={'A':'1st','B':'0st','C':'2st','D':'-1st','E':'-2st'}
sens_file_name = conffile[0:-5]+'_sensitivity_'+ orders[beam] + '.fits' sens_file_name = conffile[0:-6]+'_sensitivity_'+ orders[beam] + '.fits'
if not os.path.exists(sens_file_name) == True: if not os.path.exists(sens_file_name) == True:
senstivity_out = Table(array([w,sens]).T, names=('WAVELENGTH', 'SENSITIVITY')) senstivity_out = Table(array([w,sens]).T, names=('WAVELENGTH', 'SENSITIVITY'))
senstivity_out.write(sens_file_name, format='fits') senstivity_out.write(sens_file_name, format='fits')
......
...@@ -37,6 +37,7 @@ class Star(MockObject): ...@@ -37,6 +37,7 @@ class Star(MockObject):
full = integrate_sed_bandpass(sed=self.sed, bandpass=filt.bandpass_full) full = integrate_sed_bandpass(sed=self.sed, bandpass=filt.bandpass_full)
except Exception as e: except Exception as e:
print(e) print(e)
self.logger.error(e)
return -1 return -1
for i in range(len(bandpass_list)): for i in range(len(bandpass_list)):
...@@ -46,6 +47,7 @@ class Star(MockObject): ...@@ -46,6 +47,7 @@ class Star(MockObject):
sub = integrate_sed_bandpass(sed=self.sed, bandpass=bandpass) sub = integrate_sed_bandpass(sed=self.sed, bandpass=bandpass)
except Exception as e: except Exception as e:
print(e) print(e)
self.logger.error(e)
return -1 return -1
ratio = sub/full ratio = sub/full
......
...@@ -25,6 +25,7 @@ class Observation(object): ...@@ -25,6 +25,7 @@ class Observation(object):
self.filter_param = FilterParam() self.filter_param = FilterParam()
self.chip_list = [] self.chip_list = []
self.filter_list = [] self.filter_list = []
self.all_filter = []
self.Catalog = Catalog self.Catalog = Catalog
# if we want to apply field distortion? # if we want to apply field distortion?
...@@ -37,8 +38,6 @@ class Observation(object): ...@@ -37,8 +38,6 @@ class Observation(object):
nchips = self.focal_plane.nchip_x*self.focal_plane.nchip_y nchips = self.focal_plane.nchip_x*self.focal_plane.nchip_y
for i in range(nchips): for i in range(nchips):
chipID = i + 1 chipID = i + 1
if self.focal_plane.isIgnored(chipID=chipID):
continue
# Make Chip & Filter lists # Make Chip & Filter lists
chip = Chip( chip = Chip(
...@@ -47,10 +46,11 @@ class Observation(object): ...@@ -47,10 +46,11 @@ class Observation(object):
filter_id, filter_type = chip.getChipFilter() filter_id, filter_type = chip.getChipFilter()
filt = Filter(filter_id=filter_id, filt = Filter(filter_id=filter_id,
filter_type=filter_type, filter_type=filter_type,
filter_param=self.filter_param, filter_param=self.filter_param)
ccd_bandpass=chip.effCurve) if not self.focal_plane.isIgnored(chipID=chipID):
self.chip_list.append(chip) self.chip_list.append(chip)
self.filter_list.append(filt) self.filter_list.append(filt)
self.all_filter.append(filt)
# Read catalog and shear(s) # Read catalog and shear(s)
self.g1_field, self.g2_field, self.nshear = get_shear_field(config=self.config) self.g1_field, self.g2_field, self.nshear = get_shear_field(config=self.config)
...@@ -154,13 +154,25 @@ class Observation(object): ...@@ -154,13 +154,25 @@ class Observation(object):
conf=chip.sls_conf, conf=chip.sls_conf,
pixelSize=chip.pix_scale, pixelSize=chip.pix_scale,
isAlongY=0) isAlongY=0)
# fname = os.path.join(chip_output.subdir,'SkyMap_'+chip.filter_type+'_'+str(chip.chipID) + '.fits')
# fits.writeto(fname, sky_map, output_verify='ignore', overwrite=True)
del flat_normal del flat_normal
if pointing.pointing_type == 'MS': if pointing.pointing_type == 'MS':
# Load catalogues and templates # Load catalogues and templates
self.cat = self.Catalog(config=self.config, chip=chip, pointing=pointing, cat_dir=cat_dir, sed_dir=sed_dir, logger=chip_output.logger) self.cat = self.Catalog(config=self.config, chip=chip, pointing=pointing, cat_dir=cat_dir, sed_dir=sed_dir, chip_output=chip_output)
chip_output.create_output_file()
self.nobj = len(self.cat.objs) self.nobj = len(self.cat.objs)
for ifilt in range(len(self.all_filter)):
temp_filter = self.all_filter[ifilt]
# Update the limiting magnitude using exposure time in pointing
temp_filter.update_limit_saturation_mags(exptime=pointing.exp_time, chip=chip)
# Select cutting band filter for saturation/limiting magnitude
if temp_filter.filter_type.lower() == self.config["obs_setting"]["cut_in_band"].lower():
cut_filter = temp_filter
# Loop over objects # Loop over objects
missed_obj = 0 missed_obj = 0
bright_obj = 0 bright_obj = 0
...@@ -179,7 +191,7 @@ class Observation(object): ...@@ -179,7 +191,7 @@ class Observation(object):
elif obj.type == 'quasar' and self.config["run_option"]["star_only"]: elif obj.type == 'quasar' and self.config["run_option"]["star_only"]:
continue continue
# load SED # load and convert SED; also caculate object's magnitude in all CSST bands
try: try:
sed_data = self.cat.load_sed(obj) sed_data = self.cat.load_sed(obj)
norm_filt = self.cat.load_norm_filt(obj) norm_filt = self.cat.load_norm_filt(obj)
...@@ -189,25 +201,39 @@ class Observation(object): ...@@ -189,25 +201,39 @@ class Observation(object):
target_filt=filt, target_filt=filt,
norm_filt=norm_filt, norm_filt=norm_filt,
) )
_, obj.param["mag_%s"%cut_filter.filter_type] = self.cat.convert_sed(
mag=obj.param["mag_use_normal"],
sed=sed_data,
target_filt=cut_filter,
norm_filt=norm_filt,
)
except Exception as e: except Exception as e:
# print(e) print(e)
chip_output.logger.error(e) chip_output.logger.error(e)
continue continue
# chip_output.logger.info("debug point #1")
# Exclude very bright/dim objects (for now) # Exclude very bright/dim objects (for now)
if filt.is_too_bright(mag=obj.getMagFilter(filt)): # if filt.is_too_bright(mag=obj.getMagFilter(filt)):
# if filt.is_too_bright(mag=obj.mag_use_normal):
if cut_filter.is_too_bright(mag=obj.param["mag_%s"%self.config["obs_setting"]["cut_in_band"].lower()]):
# print("obj too birght!!", flush=True) # print("obj too birght!!", flush=True)
if obj.type != 'galaxy': if obj.type != 'galaxy':
bright_obj += 1 bright_obj += 1
obj.unload_SED() obj.unload_SED()
continue continue
if filt.is_too_dim(mag=obj.getMagFilter(filt)): if filt.is_too_dim(mag=obj.getMagFilter(filt)):
# if cut_filter.is_too_dim(mag=obj.param["mag_%s"%self.config["obs_setting"]["cut_in_band"].lower()]):
# print("obj too dim!!", flush=True) # print("obj too dim!!", flush=True)
dim_obj += 1 dim_obj += 1
obj.unload_SED() obj.unload_SED()
# print(obj.getMagFilter(filt)) # print(obj.getMagFilter(filt))
continue continue
# chip_output.logger.info("debug point #2")
if self.config["shear_setting"]["shear_type"] == "constant": if self.config["shear_setting"]["shear_type"] == "constant":
if obj.type == 'star': if obj.type == 'star':
obj.g1, obj.g2 = 0., 0. obj.g1, obj.g2 = 0., 0.
...@@ -221,12 +247,16 @@ class Observation(object): ...@@ -221,12 +247,16 @@ class Observation(object):
# print("failed to load external shear.") # print("failed to load external shear.")
chip_output.logger.error("failed to load external shear.") chip_output.logger.error("failed to load external shear.")
pass pass
# chip_output.logger.info("debug point #3")
elif self.config["shear_setting"]["shear_type"] == "catalog": elif self.config["shear_setting"]["shear_type"] == "catalog":
pass pass
else: else:
chip_output.logger.error("Unknown shear input") chip_output.logger.error("Unknown shear input")
raise ValueError("Unknown shear input") raise ValueError("Unknown shear input")
# chip_output.logger.info("debug point #4")
pos_img, offset, local_wcs = obj.getPosImg_Offset_WCS(img=chip.img, fdmodel=self.fd_model, chip=chip, verbose=False) pos_img, offset, local_wcs = obj.getPosImg_Offset_WCS(img=chip.img, fdmodel=self.fd_model, chip=chip, verbose=False)
if pos_img.x == -1 or pos_img.y == -1: if pos_img.x == -1 or pos_img.y == -1:
# Exclude object which is outside the chip area (after field distortion) # Exclude object which is outside the chip area (after field distortion)
...@@ -235,8 +265,12 @@ class Observation(object): ...@@ -235,8 +265,12 @@ class Observation(object):
obj.unload_SED() obj.unload_SED()
continue continue
# chip_output.logger.info("debug point #5")
# Draw object & update output catalog # Draw object & update output catalog
try: try:
# chip_output.logger.info("debug point #6")
# chip_output.logger.info("current filter type: %s"%filt.filter_type)
if self.config["run_option"]["out_cat_only"]: if self.config["run_option"]["out_cat_only"]:
isUpdated = True isUpdated = True
pos_shear = 0. pos_shear = 0.
...@@ -265,6 +299,7 @@ class Observation(object): ...@@ -265,6 +299,7 @@ class Observation(object):
exptime=pointing.exp_time, exptime=pointing.exp_time,
normFilter=norm_filt, normFilter=norm_filt,
) )
# chip_output.logger.info("debug point #7")
if isUpdated: if isUpdated:
# TODO: add up stats # TODO: add up stats
# print("updating output catalog...") # print("updating output catalog...")
...@@ -274,7 +309,7 @@ class Observation(object): ...@@ -274,7 +309,7 @@ class Observation(object):
# print("object omitted", flush=True) # print("object omitted", flush=True)
continue continue
except Exception as e: except Exception as e:
# print(e) print(e)
chip_output.logger.error(e) chip_output.logger.error(e)
pass pass
# Unload SED: # Unload SED:
......
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