Commit 568d0740 authored by Fang Yuedong's avatar Fang Yuedong
Browse files

add deep_cr module

parent 3b9f0e28
This diff is collapsed.
...@@ -24,6 +24,7 @@ from astropy.stats import sigma_clipped_stats ...@@ -24,6 +24,7 @@ from astropy.stats import sigma_clipped_stats
# FlagConfig, # FlagConfig,
# ) # )
from L1_pipeline.csst_msc_instrument.image import ( from L1_pipeline.csst_msc_instrument.image import (
remove_cr_deepcr,
subtract_bias, subtract_bias,
subtract_dark, subtract_dark,
FlagConfig, FlagConfig,
...@@ -46,7 +47,7 @@ def core_msc_l1_mbi_instrument( ...@@ -46,7 +47,7 @@ def core_msc_l1_mbi_instrument(
config_ccd_info: Optional[str] = None, config_ccd_info: Optional[str] = None,
config_bad_pixel: Optional[str] = None, config_bad_pixel: Optional[str] = None,
device: Optional[str] = "CPU", device: Optional[str] = "CPU",
): #-> CsstResult: ): # -> CsstResult:
""" """
Make the instrument correction for one chip of CSST data. Make the instrument correction for one chip of CSST data.
...@@ -91,7 +92,8 @@ def core_msc_l1_mbi_instrument( ...@@ -91,7 +92,8 @@ def core_msc_l1_mbi_instrument(
hdu = fits.HDUList( hdu = fits.HDUList(
[ [
fits.PrimaryHDU(header=raw[0].header.copy()), fits.PrimaryHDU(header=raw[0].header.copy()),
fits.ImageHDU(header=raw[1].header.copy(), data=raw[1].data.copy()), fits.ImageHDU(header=raw[1].header.copy(),
data=raw[1].data.copy()),
] ]
) )
# 创建wht[1].data hdulist # 创建wht[1].data hdulist
...@@ -153,8 +155,10 @@ def core_msc_l1_mbi_instrument( ...@@ -153,8 +155,10 @@ def core_msc_l1_mbi_instrument(
) )
# 过饱和检测 # 过饱和检测
saturate = SATURATE saturate = SATURATE
flg[1].data = _check_over_saturation(flg[1].data, hdu[1].data, saturate) flg[1].data = _check_over_saturation(
saturate = saturate * hdu[1].header["GAIN01"] / hdu[0].header["EXPTIME"] flg[1].data, hdu[1].data, saturate)
saturate = saturate * \
hdu[1].header["GAIN01"] / hdu[0].header["EXPTIME"]
status_header.set("SATURATE", saturate) status_header.set("SATURATE", saturate)
# 时间归一 # 时间归一
hdu[1].data = hdu[1].data / hdu[0].header["EXPTIME"] hdu[1].data = hdu[1].data / hdu[0].header["EXPTIME"]
...@@ -163,17 +167,18 @@ def core_msc_l1_mbi_instrument( ...@@ -163,17 +167,18 @@ def core_msc_l1_mbi_instrument(
# hdu[1].header.set('BUNIT', 'electron/s') # hdu[1].header.set('BUNIT', 'electron/s')
status_header.set("BUNIT", "electron/s") status_header.set("BUNIT", "electron/s")
# 检测宇宙线 # 检测宇宙线
# hdu[1].data, flg[1].data, cr_count = remove_cr_deepcr( hdu[1].data, flg[1].data, cr_count = remove_cr_deepcr(
# hdu[1].data, hdu[1].data,
# flg[1].data, flg[1].data,
# device, device,
# hdu[1].header["CHIPID"], hdu[1].header["CHIPID"],
# ) )
# status_header.set("S_CRS", 0) status_header.set("S_CRS", 0)
# status_header.set("CRCOUNT", cr_count) status_header.set("CRCOUNT", cr_count)
# 记录BKG与RMS # 记录BKG与RMS
_, bkg, rms = sigma_clipped_stats(data=hdu[1].data, mask=(flg[1].data == 16)) _, bkg, rms = sigma_clipped_stats(
data=hdu[1].data, mask=(flg[1].data == 16))
status_header.set("SKY_BKG", bkg) status_header.set("SKY_BKG", bkg)
status_header.set("SKY_RMS", rms) status_header.set("SKY_RMS", rms)
# 检测卫星拖尾 # 检测卫星拖尾
...@@ -185,7 +190,7 @@ def core_msc_l1_mbi_instrument( ...@@ -185,7 +190,7 @@ def core_msc_l1_mbi_instrument(
) )
# 数据类型 # 数据类型
hdu[1].data = hdu[1].data.astype(np.float32) hdu[1].data = hdu[1].data.astype(np.float32)
# # 快门改正 # # 快门改正
# hdu[1].data = _fix_shutter(hdu[1].data, shutter, hdu[0].header["EXPTIME"]) # hdu[1].data = _fix_shutter(hdu[1].data, shutter, hdu[0].header["EXPTIME"])
# status_header.set("S_SHUT", 0) # status_header.set("S_SHUT", 0)
...@@ -243,7 +248,8 @@ def _set_status_header(): ...@@ -243,7 +248,8 @@ def _set_status_header():
status_header = fits.Header() # template Header status_header = fits.Header() # template Header
status_header.append(("COMMENT", "=" * 66), bottom=True) status_header.append(("COMMENT", "=" * 66), bottom=True)
status_header.append(("COMMENT", "INSTRUMENT CORRECTION INFORMATION"), bottom=True) status_header.append(
("COMMENT", "INSTRUMENT CORRECTION INFORMATION"), bottom=True)
status_header.append(("COMMENT", "=" * 66), bottom=True) status_header.append(("COMMENT", "=" * 66), bottom=True)
for card in demo_header.cards: for card in demo_header.cards:
...@@ -369,8 +375,10 @@ def _dilation(array_orig: np.ndarray, iterations: int = 1): ...@@ -369,8 +375,10 @@ def _dilation(array_orig: np.ndarray, iterations: int = 1):
""" """
from scipy import ndimage from scipy import ndimage
struct1 = ndimage.generate_binary_structure(2, 1) # give a saturate structure struct1 = ndimage.generate_binary_structure(
struct_ext = ndimage.iterate_structure(struct1, iterations) # make a dilation 2, 1) # give a saturate structure
struct_ext = ndimage.iterate_structure(
struct1, iterations) # make a dilation
if iterations == 0: if iterations == 0:
array_out = array_orig array_out = array_orig
else: else:
......
...@@ -15,6 +15,9 @@ from .gain import apply_gain ...@@ -15,6 +15,9 @@ from .gain import apply_gain
from .overscan import correct_overscan from .overscan import correct_overscan
from .config import FlagConfig, CameraConfig, CCDArrayConfig, get_array_config from .config import FlagConfig, CameraConfig, CCDArrayConfig, get_array_config
from .format import convert_format from .format import convert_format
from .cosmicray.deepcr import remove_cr_deepcr
from .cosmicray.lacosmic import remove_cr_la
__all__ = ['correct_overscan', 'apply_gain', 'subtract_bias', 'remove_crosstalk', 'subtract_dark',
'FlagConfig', 'CameraConfig', 'CCDArrayConfig', 'get_array_config','convert_format', ] __all__ = ['correct_overscan', 'apply_gain', 'subtract_bias', 'remove_crosstalk', 'subtract_dark',
\ No newline at end of file 'FlagConfig', 'CameraConfig', 'CCDArrayConfig', 'get_array_config', 'convert_format', 'remove_cr_deepcr', 'remove_cr_la']
"""
Identifier: csst-l1/msc/csst_msc_common/csst_msc_common/cosmicray/__init__.py
Name: __init__.py
Description: Cosmic ray module.
Author: Li Shao (shaoli@nao.cas.cn)
Created: 2023-11-27
Modified-History:
2023-11-27, Li Shao, created
"""
from .deepcr import remove_cr_deepcr
from .lacosmic import remove_cr_la
__all__ = ['remove_cr_deepcr', 'remove_cr_la', ]
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