Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Liu Dezi
csst_msc_sim
Commits
aaf98bf9
Commit
aaf98bf9
authored
Apr 22, 2024
by
Fang Yuedong
Browse files
add option to specify logger name
parent
23ec8465
Changes
1
Show whitespace changes
Inline
Side-by-side
ObservationSim/Config/ChipOutput.py
View file @
aaf98bf9
...
...
@@ -3,8 +3,9 @@ import logging
import
ObservationSim.Config._util
as
_util
from
ObservationSim.Config.Header
import
generatePrimaryHeader
class
ChipOutput
(
object
):
def
__init__
(
self
,
config
,
chip
,
filt
,
pointing
):
def
__init__
(
self
,
config
,
chip
,
filt
,
pointing
,
logger_filename
=
None
):
self
.
config
=
config
self
.
chip
=
chip
self
.
filt
=
filt
...
...
@@ -15,12 +16,12 @@ class ChipOutput(object):
self
.
h_prim
=
generatePrimaryHeader
(
xlen
=
chip
.
npix_x
,
ylen
=
chip
.
npix_y
,
pointing_id
=
pointing
.
obs_id
,
pointing_type_code
=
pointing
.
pointing_type_code
,
pointing_id
=
pointing
.
obs_id
,
pointing_type_code
=
pointing
.
pointing_type_code
,
ra
=
pointing
.
ra
,
dec
=
pointing
.
dec
,
pixel_scale
=
chip
.
pix_scale
,
time_pt
=
pointing
.
timestamp
,
time_pt
=
pointing
.
timestamp
,
exptime
=
pointing
.
exp_time
,
im_type
=
pointing
.
pointing_type
,
sat_pos
=
[
pointing
.
sat_x
,
pointing
.
sat_y
,
pointing
.
sat_z
],
...
...
@@ -29,18 +30,22 @@ class ChipOutput(object):
run_counter
=
self
.
config
[
"run_counter"
],
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
.
cat_name
=
self
.
h_prim
[
'FILENAME'
]
+
'.cat'
if
logger_filename
is
None
:
logger_filename
=
self
.
h_prim
[
'FILENAME'
]
+
'.log'
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
)
self
.
logger
.
setLevel
(
logging
.
DEBUG
)
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
)
self
.
logger
.
addHandler
(
fh
)
...
...
@@ -51,7 +56,7 @@ class ChipOutput(object):
self
.
hdr
=
hdr1
+
hdr2
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
):
print
(
message
)
...
...
@@ -67,7 +72,8 @@ class ChipOutput(object):
def
create_output_file
(
self
):
if
self
.
pointing_type
==
'SCI'
:
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
"
):
self
.
hdr
+=
"
\n
"
self
.
cat
.
write
(
self
.
hdr
)
...
...
@@ -76,8 +82,9 @@ class ChipOutput(object):
ximg
=
obj
.
real_pos
.
x
+
1.0
yimg
=
obj
.
real_pos
.
y
+
1.0
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
,
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
.
pmra
,
obj
.
pmdec
,
obj
.
rv
,
obj
.
parallax
)
line
+=
obj
.
additional_output_str
if
not
line
.
endswith
(
"
\n
"
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment