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
csst-sims
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
Hide 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
...
...
@@ -13,14 +14,14 @@ class ChipOutput(object):
# Get primary header based on chip and pointing
self
.
h_prim
=
generatePrimaryHeader
(
xlen
=
chip
.
npix_x
,
ylen
=
chip
.
npix_y
,
pointing_id
=
pointing
.
obs_id
,
pointing_type_code
=
pointing
.
pointing_type_code
,
ra
=
pointing
.
ra
,
dec
=
pointing
.
dec
,
xlen
=
chip
.
npix_x
,
ylen
=
chip
.
npix_y
,
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,45 +30,50 @@ 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'
logger_filename
=
self
.
h_prim
[
'FILENAME'
]
+
'.log'
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
)
hdr1
=
"# obj_ID ID_chip filter xImage yImage ra dec ra_orig dec_orig z mag obj_type "
hdr1
=
"# obj_ID ID_chip filter xImage yImage ra dec ra_orig dec_orig z mag obj_type "
hdr2
=
"pm_ra pm_dec RV parallax"
fmt1
=
"%20s %4d %5s %10.3f %10.3f %15.8f %15.8f %15.8f %15.8f %7.4f %8.4f %15s "
fmt1
=
"%20s %4d %5s %10.3f %10.3f %15.8f %15.8f %15.8f %15.8f %7.4f %8.4f %15s "
fmt2
=
"%15.8f %15.8f %15.8f %15.8f"
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
)
self
.
logger
.
info
(
message
)
def
Log_error
(
self
,
message
):
print
(
message
)
self
.
logger
.
error
(
message
)
def
update_output_header
(
self
,
additional_column_names
=
""
):
self
.
hdr
+=
additional_column_names
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
)
...
...
@@ -75,9 +81,10 @@ class ChipOutput(object):
def
cat_add_obj
(
self
,
obj
,
pos_img
,
pos_shear
):
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