Commit de080ed4 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

add ccds.convert_slsconf()

parent a45b0e9c
Pipeline #2688 failed with stage
in 0 seconds
......@@ -8,10 +8,10 @@ Modified-History:
2023-07-08, Bo Zhang, created
2023-12-15, Bo Zhang, add module header
"""
import functools
import os
from ccds import client
from .slsconf import convert_slsconf
class CCDS:
......@@ -97,6 +97,14 @@ class CCDS:
# 'ledflat': '/ccds_root/references/msc/csst_msc_ms_ledflat_10_000001.fits'}
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"
......
"""
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 os
from astropy.io import fits
def convert_slsconf(
extract1d_json_path: str,
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
import astropy.io.fits as pyfits
# return dict(zip(conf_names, conf_paths)), dict(
# zip(sensitivity_order_names, sensitivity_order_paths)
# )
return slsconf
# 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]
def readjson(file_json_path):
with open(file_json_path) as f:
......@@ -13,18 +69,6 @@ def readjson(file_json_path):
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):
fsx.write("INSTRUMENT CSSTSLS" + "\n")
fsx.write("CAMERA " + flt + "\n")
......@@ -46,22 +90,22 @@ def fwriteKEY(fsx, flt):
def fwriteBEAM(
fsx,
extract1d_json_path,
sensitivity_order_name,
GRATINGLR,
BEAMX,
SENSITIVITY_X,
MMAG_EXTRACT_X,
MMAG_MARK_X,
DYDX_ORDER_X,
DYDX_X_0,
DYDX_X_1,
XOFF_X,
YOFF_X,
DISP_ORDER_X,
DLDP_X_0,
DLDP_X_1,
fsx,
extract1d_json_path,
sensitivity_order_name,
GRATINGLR,
BEAMX,
SENSITIVITY_X,
MMAG_EXTRACT_X,
MMAG_MARK_X,
DYDX_ORDER_X,
DYDX_X_0,
DYDX_X_1,
XOFF_X,
YOFF_X,
DISP_ORDER_X,
DLDP_X_0,
DLDP_X_1,
):
d = readjson(extract1d_json_path)
fsx.write(BEAMX), [
......@@ -104,13 +148,15 @@ def fwriteBEAM(
for j in range(len(d[GRATINGLR][DLDP_X_1]))
], 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")
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
flt = readjson(extract1d_json_path)['FILTER']
flt = readjson(extract1d_json_path)["FILTER"]
os.system("> " + c)
fs = open(c, "a")
......@@ -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):
h = pyfits.open(sensitivity_fits_path)
for extname in ['L0st', 'LP1st', 'LM1st', 'LP2st', 'LM2st']:
hdu0 = pyfits.PrimaryHDU()
hdu1 = pyfits.BinTableHDU(h[extname].data)
hdul = pyfits.HDUList([hdu0, hdu1])
h = fits.open(sensitivity_fits_path)
for extname in ["L0st", "LP1st", "LM1st", "LP2st", "LM2st"]:
hdu0 = fits.PrimaryHDU()
hdu1 = fits.BinTableHDU(h[extname].data)
hdul = fits.HDUList([hdu0, hdu1])
hdul.writeto(sensitivity_order_path, overwrite=True, checksum=True)
hdul.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))
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