Commit aaf98bf9 authored by Fang Yuedong's avatar Fang Yuedong
Browse files

add option to specify logger name

parent 23ec8465
...@@ -3,8 +3,9 @@ import logging ...@@ -3,8 +3,9 @@ import logging
import ObservationSim.Config._util as _util import ObservationSim.Config._util as _util
from ObservationSim.Config.Header import generatePrimaryHeader from ObservationSim.Config.Header import generatePrimaryHeader
class ChipOutput(object): class ChipOutput(object):
def __init__(self, config, chip, filt, pointing): def __init__(self, config, chip, filt, pointing, logger_filename=None):
self.config = config self.config = config
self.chip = chip self.chip = chip
self.filt = filt self.filt = filt
...@@ -15,12 +16,12 @@ class ChipOutput(object): ...@@ -15,12 +16,12 @@ class ChipOutput(object):
self.h_prim = generatePrimaryHeader( self.h_prim = generatePrimaryHeader(
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
pointing_id = pointing.obs_id, pointing_id=pointing.obs_id,
pointing_type_code = pointing.pointing_type_code, pointing_type_code=pointing.pointing_type_code,
ra=pointing.ra, ra=pointing.ra,
dec=pointing.dec, dec=pointing.dec,
pixel_scale=chip.pix_scale, pixel_scale=chip.pix_scale,
time_pt = pointing.timestamp, time_pt=pointing.timestamp,
exptime=pointing.exp_time, exptime=pointing.exp_time,
im_type=pointing.pointing_type, im_type=pointing.pointing_type,
sat_pos=[pointing.sat_x, pointing.sat_y, pointing.sat_z], sat_pos=[pointing.sat_x, pointing.sat_y, pointing.sat_z],
...@@ -29,18 +30,22 @@ class ChipOutput(object): ...@@ -29,18 +30,22 @@ class ChipOutput(object):
run_counter=self.config["run_counter"], run_counter=self.config["run_counter"],
chip_name=self.chip_label) chip_name=self.chip_label)
obs_id = _util.get_obs_id(img_type=self.pointing_type, project_cycle=config["project_cycle"], run_counter=config["run_counter"], pointing_id=pointing.obs_id, pointing_type_code = pointing.pointing_type_code) obs_id = _util.get_obs_id(img_type=self.pointing_type, project_cycle=config["project_cycle"], run_counter=config[
"run_counter"], pointing_id=pointing.obs_id, pointing_type_code=pointing.pointing_type_code)
self.subdir = pointing.output_dir self.subdir = pointing.output_dir
self.cat_name = self.h_prim['FILENAME'] + '.cat' self.cat_name = self.h_prim['FILENAME'] + '.cat'
if logger_filename is None:
logger_filename = self.h_prim['FILENAME'] + '.log' logger_filename = self.h_prim['FILENAME'] + '.log'
self.logger = logging.getLogger() self.logger = logging.getLogger()
fh = logging.FileHandler(os.path.join(self.subdir, logger_filename), mode='w+', encoding='utf-8') fh = logging.FileHandler(os.path.join(
self.subdir, logger_filename), mode='w+', encoding='utf-8')
fh.setLevel(logging.DEBUG) fh.setLevel(logging.DEBUG)
self.logger.setLevel(logging.DEBUG) self.logger.setLevel(logging.DEBUG)
logging.getLogger('numba').setLevel(logging.WARNING) logging.getLogger('numba').setLevel(logging.WARNING)
formatter = logging.Formatter('%(asctime)s - %(msecs)d - %(levelname)-8s - [%(filename)s:%(lineno)d] - %(message)s') formatter = logging.Formatter(
'%(asctime)s - %(msecs)d - %(levelname)-8s - [%(filename)s:%(lineno)d] - %(message)s')
fh.setFormatter(formatter) fh.setFormatter(formatter)
self.logger.addHandler(fh) self.logger.addHandler(fh)
...@@ -51,7 +56,7 @@ class ChipOutput(object): ...@@ -51,7 +56,7 @@ class ChipOutput(object):
self.hdr = hdr1 + hdr2 self.hdr = hdr1 + hdr2
self.fmt = fmt1 + fmt2 self.fmt = fmt1 + fmt2
self.logger.info("pointing_type = %s\n"%(self.pointing_type)) self.logger.info("pointing_type = %s\n" % (self.pointing_type))
def Log_info(self, message): def Log_info(self, message):
print(message) print(message)
...@@ -67,7 +72,8 @@ class ChipOutput(object): ...@@ -67,7 +72,8 @@ class ChipOutput(object):
def create_output_file(self): def create_output_file(self):
if self.pointing_type == 'SCI': if self.pointing_type == 'SCI':
self.cat = open(os.path.join(self.subdir, self.cat_name), "w") self.cat = open(os.path.join(self.subdir, self.cat_name), "w")
self.logger.info("Creating catalog file %s ...\n"%(os.path.join(self.subdir, self.cat_name))) self.logger.info("Creating catalog file %s ...\n" %
(os.path.join(self.subdir, self.cat_name)))
if not self.hdr.endswith("\n"): if not self.hdr.endswith("\n"):
self.hdr += "\n" self.hdr += "\n"
self.cat.write(self.hdr) self.cat.write(self.hdr)
...@@ -76,8 +82,9 @@ class ChipOutput(object): ...@@ -76,8 +82,9 @@ class ChipOutput(object):
ximg = obj.real_pos.x + 1.0 ximg = obj.real_pos.x + 1.0
yimg = obj.real_pos.y + 1.0 yimg = obj.real_pos.y + 1.0
line = self.fmt%( line = self.fmt % (
obj.id, int(self.chip_label), self.filt.filter_type, ximg, yimg, obj.ra, obj.dec, obj.ra_orig, obj.dec_orig, obj.z, obj.getMagFilter(self.filt), obj.type, obj.id, int(self.chip_label), self.filt.filter_type, ximg, yimg, obj.ra, obj.dec, obj.ra_orig, obj.dec_orig, obj.z, obj.getMagFilter(
self.filt), obj.type,
obj.pmra, obj.pmdec, obj.rv, obj.parallax) obj.pmra, obj.pmdec, obj.rv, obj.parallax)
line += obj.additional_output_str line += obj.additional_output_str
if not line.endswith("\n"): if not line.endswith("\n"):
......
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