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-pipeline
csst_common
Commits
de080ed4
Commit
de080ed4
authored
Dec 22, 2023
by
BO ZHANG
🏀
Browse files
add ccds.convert_slsconf()
parent
a45b0e9c
Pipeline
#2688
failed with stage
in 0 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
csst_common/ccds/ccds.py
View file @
de080ed4
...
@@ -8,10 +8,10 @@ Modified-History:
...
@@ -8,10 +8,10 @@ Modified-History:
2023-07-08, Bo Zhang, created
2023-07-08, Bo Zhang, created
2023-12-15, Bo Zhang, add module header
2023-12-15, Bo Zhang, add module header
"""
"""
import
functools
import
os
import
os
from
ccds
import
client
from
ccds
import
client
from
.slsconf
import
convert_slsconf
class
CCDS
:
class
CCDS
:
...
@@ -97,6 +97,14 @@ class CCDS:
...
@@ -97,6 +97,14 @@ class CCDS:
# 'ledflat': '/ccds_root/references/msc/csst_msc_ms_ledflat_10_000001.fits'}
# 'ledflat': '/ccds_root/references/msc/csst_msc_ms_ledflat_10_000001.fits'}
return
refs_fp
return
refs_fp
@
staticmethod
def
convert_slsconf
(
refs
:
dict
,
dir_output
:
str
)
->
dict
:
return
convert_slsconf
(
extract1d_json_path
=
refs
[
"extract1d"
],
sensitivity_fits_path
=
refs
[
"sensitivity"
],
dir_output
=
dir_output
,
)
"""
"""
file_path="/dfsroot/L0/MSC/SCIE/62030/10160000105/MS/CSST_MSC_MS_SCIE_20280916072059_20280916072329_10160000105_10_L0_V01.fits"
file_path="/dfsroot/L0/MSC/SCIE/62030/10160000105/MS/CSST_MSC_MS_SCIE_20280916072059_20280916072329_10160000105_10_L0_V01.fits"
...
...
csst_common/ccds/slsconf.py
View file @
de080ed4
"""
Identifier: csst_common/dfs.py
Name: dfs.py
Description: DFS wrapper
Author: Bo Zhang
Created: 2023-07-08
Modified-History:
2023-12-22, Bowei Zhao, implemented convert_slsconf
2023-12-22, Bo Zhang, tweaks
Details:
chipid: [01, 02, 03, 04, 05, 10, 21, 26, 27, 28, 29, 30]
filter: [GI, GV, GU, GU, GV, GI, GI, GV, GU, GU, GV, GI]
clabel: [GI-1, GV-1, GU-1, GU-2, GV-2, GI-2, GI-3, GV-3, GU-3, GU-4, GV-4, GI-4]
keys = ['BEAMA', 'MMAG_EXTRACT_A', 'MMAG_MARK_A', 'DYDX_ORDER_A', 'DYDX_A_0', 'DYDX_A_1', 'XOFF_A', 'YOFF_A',
'DISP_ORDER_A', 'DLDP_A_0', 'DLDP_A_1', 'BEAMB', 'MMAG_EXTRACT_B', 'MMAG_MARK_B', 'DYDX_ORDER_B', 'DYDX_B_0',
'XOFF_B', 'YOFF_B', 'DISP_ORDER_B', 'DLDP_B_0', 'DLDP_B_1', 'BEAMC', 'MMAG_EXTRACT_C', 'MMAG_MARK_C',
'DYDX_ORDER_C', 'DYDX_C_0', 'DYDX_C_1', 'XOFF_C', 'YOFF_C', 'DISP_ORDER_C', 'DLDP_C_0', 'DLDP_C_1', 'BEAMD',
'MMAG_EXTRACT_D', 'MMAG_MARK_D', 'DYDX_ORDER_D', 'DYDX_D_0', 'DYDX_D_1', 'XOFF_D', 'YOFF_D', 'DISP_ORDER_D',
'DLDP_D_0', 'DLDP_D_1', 'BEAME', 'MMAG_EXTRACT_E', 'MMAG_MARK_E', 'DYDX_ORDER_E', 'DYDX_E_0', 'DYDX_E_1',
'XOFF_E', 'YOFF_E', 'DISP_ORDER_E', 'DLDP_E_0', 'DLDP_E_1']
"""
import
json
import
json
import
os
import
os
from
astropy.io
import
fits
import
astropy.io.fits
as
pyfits
# chipid: [01, 02, 03, 04, 05, 10, 21, 26, 27, 28, 29, 30]
def
convert_slsconf
(
# filter: [GI, GV, GU, GU, GV, GI, GI, GV, GU, GU, GV, GI]
extract1d_json_path
:
str
,
# clabel: [GI-1, GV-1, GU-1, GU-2, GV-2, GI-2, GI-3, GV-3, GU-3, GU-4, GV-4, GI-4]
sensitivity_fits_path
:
str
,
dir_output
:
str
,
)
->
dict
:
extract1d_name
=
os
.
path
.
basename
(
extract1d_json_path
)
sensitivity_name
=
os
.
path
.
basename
(
sensitivity_fits_path
)
slsconf
=
dict
()
# conf_names = []
# conf_paths = []
sensitivity_order_names
=
[]
# sensitivity_order_paths = []
# save CSST_MSC_MS_SENSITIVITY_{CHIPID}_{VERSION}_{ORDER}.conf
for
order
in
[
"0st"
,
"+1st"
,
"-1st"
,
"+2st"
,
"-2st"
]:
sensitivity_order_name
=
sensitivity_name
.
replace
(
".fits"
,
f
"_
{
order
}
.fits"
)
sensitivity_order_path
=
os
.
path
.
join
(
dir_output
,
sensitivity_order_name
)
resave_sensitivity
(
sensitivity_fits_path
,
sensitivity_order_path
)
sensitivity_order_names
.
append
(
sensitivity_order_name
)
# sensitivity_order_paths.append(sensitivity_order_path)
slsconf
[
f
"sensitivity_
{
order
}
"
]
=
sensitivity_order_path
# save CSST_MSC_MS_EXTRACT1D_{CHIPID}_{VERSION}_{DIRECTION}.conf
for
direction
,
GRATINGLR
in
zip
([
"left"
,
"right"
],
[
"GRATINGL"
,
"GRATINGR"
]):
conf_name
=
extract1d_name
.
replace
(
".json"
,
f
"_
{
direction
}
.conf"
)
conf_path
=
os
.
path
.
join
(
dir_output
,
conf_name
)
fsave_conf
(
extract1d_json_path
,
conf_path
,
sensitivity_order_names
,
GRATINGLR
)
# conf_names.append(conf_name)
# conf_paths.append(conf_path)
slsconf
[
f
"conf_
{
direction
}
"
]
=
conf_path
# return dict(zip(conf_names, conf_paths)), dict(
# zip(sensitivity_order_names, sensitivity_order_paths)
# )
return
slsconf
def
readjson
(
file_json_path
):
def
readjson
(
file_json_path
):
with
open
(
file_json_path
)
as
f
:
with
open
(
file_json_path
)
as
f
:
...
@@ -13,18 +69,6 @@ def readjson(file_json_path):
...
@@ -13,18 +69,6 @@ def readjson(file_json_path):
return
d
return
d
##################################################################################
##################################################################################
# keys = ['BEAMA', 'MMAG_EXTRACT_A', 'MMAG_MARK_A', 'DYDX_ORDER_A', 'DYDX_A_0', 'DYDX_A_1', 'XOFF_A', 'YOFF_A',
# 'DISP_ORDER_A', 'DLDP_A_0', 'DLDP_A_1', 'BEAMB', 'MMAG_EXTRACT_B', 'MMAG_MARK_B', 'DYDX_ORDER_B', 'DYDX_B_0',
# 'XOFF_B', 'YOFF_B', 'DISP_ORDER_B', 'DLDP_B_0', 'DLDP_B_1', 'BEAMC', 'MMAG_EXTRACT_C', 'MMAG_MARK_C',
# 'DYDX_ORDER_C', 'DYDX_C_0', 'DYDX_C_1', 'XOFF_C', 'YOFF_C', 'DISP_ORDER_C', 'DLDP_C_0', 'DLDP_C_1', 'BEAMD',
# 'MMAG_EXTRACT_D', 'MMAG_MARK_D', 'DYDX_ORDER_D', 'DYDX_D_0', 'DYDX_D_1', 'XOFF_D', 'YOFF_D', 'DISP_ORDER_D',
# 'DLDP_D_0', 'DLDP_D_1', 'BEAME', 'MMAG_EXTRACT_E', 'MMAG_MARK_E', 'DYDX_ORDER_E', 'DYDX_E_0', 'DYDX_E_1',
# 'XOFF_E', 'YOFF_E', 'DISP_ORDER_E', 'DLDP_E_0', 'DLDP_E_1']
def
fwriteKEY
(
fsx
,
flt
):
def
fwriteKEY
(
fsx
,
flt
):
fsx
.
write
(
"INSTRUMENT CSSTSLS"
+
"
\n
"
)
fsx
.
write
(
"INSTRUMENT CSSTSLS"
+
"
\n
"
)
fsx
.
write
(
"CAMERA "
+
flt
+
"
\n
"
)
fsx
.
write
(
"CAMERA "
+
flt
+
"
\n
"
)
...
@@ -104,13 +148,15 @@ def fwriteBEAM(
...
@@ -104,13 +148,15 @@ def fwriteBEAM(
for
j
in
range
(
len
(
d
[
GRATINGLR
][
DLDP_X_1
]))
for
j
in
range
(
len
(
d
[
GRATINGLR
][
DLDP_X_1
]))
],
fsx
.
write
(
"
\n
"
)
],
fsx
.
write
(
"
\n
"
)
fsx
.
write
(
"# "
+
"
\n
"
)
fsx
.
write
(
"# "
+
"
\n
"
)
fsx
.
write
(
SENSITIVITY_X
+
" "
+
sensitivity_order_name
+
'
\n
'
)
fsx
.
write
(
SENSITIVITY_X
+
" "
+
sensitivity_order_name
+
"
\n
"
)
fsx
.
write
(
"# "
+
"
\n
"
+
"
\n
"
)
fsx
.
write
(
"# "
+
"
\n
"
+
"
\n
"
)
def
fsave_conf
(
extract1d_json_path
,
extract1d_conf_path
,
sensitivity_order_names
,
GRATINGLR
):
def
fsave_conf
(
extract1d_json_path
,
extract1d_conf_path
,
sensitivity_order_names
,
GRATINGLR
):
c
=
extract1d_conf_path
c
=
extract1d_conf_path
flt
=
readjson
(
extract1d_json_path
)[
'
FILTER
'
]
flt
=
readjson
(
extract1d_json_path
)[
"
FILTER
"
]
os
.
system
(
"> "
+
c
)
os
.
system
(
"> "
+
c
)
fs
=
open
(
c
,
"a"
)
fs
=
open
(
c
,
"a"
)
...
@@ -215,38 +261,12 @@ def fsave_conf(extract1d_json_path, extract1d_conf_path, sensitivity_order_names
...
@@ -215,38 +261,12 @@ def fsave_conf(extract1d_json_path, extract1d_conf_path, sensitivity_order_names
def
resave_sensitivity
(
sensitivity_fits_path
,
sensitivity_order_path
):
def
resave_sensitivity
(
sensitivity_fits_path
,
sensitivity_order_path
):
h
=
py
fits
.
open
(
sensitivity_fits_path
)
h
=
fits
.
open
(
sensitivity_fits_path
)
for
extname
in
[
'
L0st
'
,
'
LP1st
'
,
'
LM1st
'
,
'
LP2st
'
,
'
LM2st
'
]:
for
extname
in
[
"
L0st
"
,
"
LP1st
"
,
"
LM1st
"
,
"
LP2st
"
,
"
LM2st
"
]:
hdu0
=
py
fits
.
PrimaryHDU
()
hdu0
=
fits
.
PrimaryHDU
()
hdu1
=
py
fits
.
BinTableHDU
(
h
[
extname
].
data
)
hdu1
=
fits
.
BinTableHDU
(
h
[
extname
].
data
)
hdul
=
py
fits
.
HDUList
([
hdu0
,
hdu1
])
hdul
=
fits
.
HDUList
([
hdu0
,
hdu1
])
hdul
.
writeto
(
sensitivity_order_path
,
overwrite
=
True
,
checksum
=
True
)
hdul
.
writeto
(
sensitivity_order_path
,
overwrite
=
True
,
checksum
=
True
)
hdul
.
close
()
hdul
.
close
()
h
.
close
()
h
.
close
()
def
convert_slsconf
(
extract1d_json_path
,
sensitivity_fits_path
,
dir_output
):
extract1d_name
=
os
.
path
.
basename
(
extract1d_json_path
)
sensitivity_name
=
os
.
path
.
basename
(
sensitivity_fits_path
)
conf_names
=
[]
conf_paths
=
[]
sensitivity_order_names
=
[]
sensitivity_order_paths
=
[]
# save CSST_MSC_MS_SENSITIVITY_CHIPID_VERSION_ORDER.conf
for
order
in
[
'+1st'
,
'0st'
,
'-1st'
,
'+2st'
,
'-2st'
]:
sensitivity_order_name
=
sensitivity_name
.
replace
(
".fits"
,
''
.
join
([
"_"
,
order
,
".fits"
]))
sensitivity_order_path
=
os
.
path
.
join
(
dir_output
,
sensitivity_order_name
)
resave_sensitivity
(
sensitivity_fits_path
,
sensitivity_order_path
)
sensitivity_order_names
.
append
(
sensitivity_order_name
)
sensitivity_order_paths
.
append
(
sensitivity_order_path
)
# save CSST_MSC_MS_EXTRACT1D_CHIPID_VERSION_DIRECTION.conf
for
direction
,
GRATINGLR
in
zip
([
'left'
,
'right'
],
[
'GRATINGL'
,
'GRATINGR'
]):
conf_name
=
extract1d_name
.
replace
(
".json"
,
''
.
join
([
"_"
,
direction
,
".conf"
]))
conf_path
=
os
.
path
.
join
(
dir_output
,
conf_name
)
fsave_conf
(
extract1d_json_path
,
conf_path
,
sensitivity_order_names
,
GRATINGLR
)
conf_names
.
append
(
conf_name
)
conf_paths
.
append
(
conf_path
)
return
dict
(
zip
(
conf_names
,
conf_paths
)),
dict
(
zip
(
sensitivity_order_names
,
sensitivity_order_paths
))
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