Generate PSF and do photometry for CSST MBI L1 pipeline.
Generate PSF using PSFEx and do photometry using SExtractor. If psf_ccds_path is set, use CCDS PSF, else get PSF with PSFEx and then do photometry. If get_psf_flag is set true, force get PSF with PSFEx.
Parameters
----------
image_path : str
Path of image, defaulting to "/path/to/image".
weight_path : str
Path of weight, defaulting to "/path/to/weight".
flag_path : str
Path of flag, defaulting to "/path/to/flag".
psf_ccds_path : str, optional
Path of psf_ccds, optional, defaulting to None.
psf_local_path : str
Path of psf_local, defaulting to "/path/to/psf_local".
flux_path : str
Path of flux adu, defaulting to "/path/to/flux".
cat_path : str
Path of catalog, defaulting to "/path/to/cat".
seg_path : str
Path of segmentation, defaulting to "/path/to/seg".
sky_path : str
Path of sky map, defaulting to "/path/to/sky".
plot_flag : bool
Wether output some diagnostic plots, default False.
getpsf_flag : bool
Force to get PSF, default False.
Returns
-------
CsstResult
Result containing `status`, `file_list`, and `output`.
"""
time0=time.time()
# generate psf
ifpsf_ccds_pathisNoneorgetpsf_flag:
print("get PSF model for "+image_path)
pflag=generate_psf(image_path,weight_path,
flag_path,psf_local_path)
time1=time.time()
psftime=time1-time0
# pick a PSF
ifpsf_ccds_pathisNone:
# use psf_path
psf_path=psf_local_path
else:
psf_path=psf_ccds_path
ifos.path.isfile(psf_path):
# photometry
print('do photometry for '+image_path)
do_photometry(
image_path,
weight_path,
flag_path,
psf_path,
flux_path,
cat_path,
sky_path,
seg_path,
plot_flag,
)
time2=time.time()
if'time1'invars().keys():
phottime=time2-time1
else:
phottime=time2-time0
print('Total time for '+image_path+': ',time2-time0)
ifos.path.isfile(cat_path):
f=fits.open(cat_path,mode='update')
if'psftime'invars().keys():
f[1].header['PSF_PATH']=psf_path
f[1].header['PSFTIME']=(psftime,'seconds')
f[1].header['PHOTTIME']=(phottime,'seconds')
f.flush(output_verify='fix+warn')
f.close()
# # construct CsstResult
# result = CsstResult(
# status=CsstStatus(0 if os.path.exists(cat_path) else 2),
# files=[
# psf_path,
# flux_path,
# cat_path,
# seg_path,
# sky_path,
# ],
# )
# return result
defgenerate_psf(
image_path:str="/path/to/image",
weight_path:str="/path/to/weight",
flag_path:str="/path/to/flag",
psf_local_path:str="/path/to/psf_local",
)->None:
"""
Generate psf for csst image.
Parameters
----------
image_path : str
Path of image, defaulting to "/path/to/image".
weight_path : str
Path of weight, defaulting to "/path/to/weight".
flag_path : str
Path of flag, defaulting to "/path/to/flag".
psf_local_path : str
Path of psf_local..., defaulting to "/path/to/psf_local".