Commit b7f8c4fa authored by GZhao's avatar GZhao
Browse files

V2.0 developing initial

parent 6a5baa03
Pipeline #4230 failed with stage
in 0 seconds
This source diff could not be displayed because it is too large. You can view the blob instead.
%% Cell type:markdown id: tags:
# 观测效应仿真
%% Cell type:markdown id: tags:
观测效应仿真功能包括背景光仿真和宇宙线仿真两部分。
## 宇宙线仿真
使用CosmicRayFrameMaker()类可以生成宇宙线。在仿真中仅考虑由于mu子导致的宇宙线,这类宇宙线例子会在穿过CCD芯片时导致感光,产生长短不一的细线。
程序中假设宇宙线具有均匀且各项同性的分布。宇宙线事件的数目设置为1个事件/秒/平方厘米(参考WFPC2手册)。
能量、宽度、长度等参考Miles et al.2021、Fisher-Levine 2015等文章,分布如下图所示。
另外对于宇宙线沿路径方向的强度,我们也通过FFT的方式增加了随机性。
另外可以通过修改CosmicRayFrameMaker()类中的参数来调整宇宙线的事件几率、长度、宽度、强度分布等,具体参考代码中的注释。
%% Cell type:code id: tags:
``` python
from CpicImgSim import CosmicRayFrameMaker
cr_gen = CosmicRayFrameMaker()
crs = cr_gen.random_CR_parameter(10000, [1024, 1024])
```
%% Cell type:code id: tags:
``` python
flux = []
length = []
angle = []
sigma = []
for cr in crs:
flux.append(cr.flux)
length.append(cr.length)
angle.append(cr.angle)
sigma.append(cr.sigma)
import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
plt.figure(figsize=(10, 3))
plt.subplot(1,3,1)
plt.hist(flux, bins=np.linspace(0, 20000, 20))
plt.title('cosmic ray event energy')
plt.xlabel('electron number')
plt.subplot(1,3,2)
plt.hist(length, bins=np.linspace(0, 30, 10), log=True)
plt.title('path length of CRs')
plt.xlabel('pixels')
plt.subplot(1,3,3)
plt.hist(sigma)
plt.title('path width of CRs')
plt.xlabel('pixels')
plt.tight_layout()
```
%% Output
%% Cell type:markdown id: tags:
使用该类的make_cr_frame()方法可以生成宇宙线图像。
该方法包括两个参数,分别为相机芯片尺寸和曝光时间。下面的代码演示了如何生成宇宙线图像。生成的宇宙线图像为一个二维数组,单位为电子数。
图中仿真了分别为30s曝光和300s曝光的两幅宇宙线图像。
%% Cell type:code id: tags:
``` python
def psf_imshow(psf, vmin=1e-8, vmax=0.1):
focal_img = psf.copy()
focal_img = np.maximum(focal_img, vmin)
focal_img = np.minimum(focal_img, focal_img.max()*vmax)
# image_log = np.log10(focal_img)
image_log = focal_img
plt.imshow(image_log, origin='lower', cmap='gray')
plt.figure(figsize=(10, 6))
plt.subplot(1,2,1)
crframe = cr_gen.make_cr_frame([1032, 1056], 30)
psf_imshow(crframe, vmin=0, vmax=0.01)
plt.title('cosmic ray frame 30s')
plt.subplot(1,2,2)
crframe_300 = cr_gen.make_cr_frame([1056, 1032], 300)
psf_imshow(crframe_300, vmin=0, vmax=0.01)
plt.title('cosmic ray frame 300s')
fits.writeto('image_files/cr_frame_30s.fit', crframe, overwrite=True)
```
%% Output
%% Cell type:markdown id: tags:
sky_frame_maker()函数可以生成天空背景图像,输入参数为观测波段、对应波段的星等/平方角秒、焦面比例尺、图像大小。
程序中天空背景光谱按照太阳光谱估计、考虑仪器的整体光电效率。输出为一个二维数组,反应了焦面处的辐照密度,单位为电子数/秒/平方米。
注意需要乘上望远镜通光口径和曝光时间来得到电子数。
%% Cell type:code id: tags:
``` python
from CpicImgSim import sky_frame_maker
area = 3.14 * 100 ** 2
frame = sky_frame_maker('f661', 19, 0.01613, (1024, 1024)) * area
psf_imshow(frame)
plt.title('sky background frame, 19mag/arcsec$^2$@f661')
plt.text(40, 40, f'{frame[1,1]:.3f} photons/pixel/s', color='white')
```
%% Output
Text(40, 40, '0.029 photons/pixel/s')
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
使用教程
===========
仿真程序上手
-------------------------
.. toctree::
:maxdepth: 1
快速开始 </notebooks/0_main_example.ipynb>
程序模块使用说明
----------------------
.. toctree::
:maxdepth: 1
目标仿真模块 </notebooks/1_target_example.ipynb>
焦面模块 </notebooks/2_focus_example.ipynb>
观测效应仿真模块 </notebooks/3_obs_effect.ipynb>
相机仿真模块 </notebooks/4_camera_example.ipynb>
点扩散函数仿真模块 </notebooks/5_psf_example.ipynb>
import setuptools
import CpicImgSim
setuptools.setup(
name='csst_cpic_sim',
version='1.0.0',
name='CpicImgSim',
version=CpicImgSim.__version__,
author='CSST Team',
author_email='gzhao@niaot.ac.cn',
description='The CSST CPIC Simulation', # short description
......@@ -17,9 +18,9 @@ setuptools.setup(
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Scientific/Engineering :: Astronomy"
],
package_dir={'csst_cpic_sim': 'csst_cpic_sim'},
package_dir={'CpicImgSim': 'CpicImgSim'},
include_package_data=False,
install_requires=['numpy', 'scipy', 'astropy', 'pysynphot', 'hcipy', 'pandas'],
install_requires=['numpy', 'scipy', 'astropy', 'pysynphot', 'hcipy'],
python_requires='>=3.8',
)
[run]
branch = True
source = CpicImgSim
使用python运行unittest:
python -m unittest
使用coverage运行unittest
coverage run -m unittest
生成html报告
coverage html
\ No newline at end of file
import unittest
from csst_cpic_sim.camera import EMCCD
from CpicImgSim.camera import EMCCD
import numpy as np
......@@ -69,4 +69,17 @@ class TestEMCCD(unittest.TestCase):
if __name__ == '__main__':
unittest.main()
# unittest.main()
from CpicImgSim.camera import CPIC_VIS_EMCCD
emccd = CPIC_VIS_EMCCD()
emccd.emgain_fun(1023, -30)
bias_images = []
for _ in range(10):
bias = emccd.bias_frame(show=True)
bias_images.append(bias)
bias_images = np.array(bias_images)
from astropy.io import fits
fits.writeto("bias.fits", bias_images)
import unittest
from csst_cpic_sim.camera import CosmicRayFrameMaker, sky_frame_maker
from csst_cpic_sim.target import star_photlam
from csst_cpic_sim.optics import filter_throughput
from CpicImgSim.camera import CosmicRayFrameMaker, sky_frame_maker
from CpicImgSim.target import star_photlam
from CpicImgSim.optics import filter_throughput
import numpy as np
......
import unittest
from unittest import mock
from csst_cpic_sim.io import obsid_parser, primary_hdu, frame_header, save_fits_simple
import csst_cpic_sim.io as io
from CpicImgSim.io import obsid_parser, primary_hdu, frame_header, save_fits_simple
import CpicImgSim.io as io
from astropy.io import fits
import numpy as np
import yaml
......
import unittest
from csst_cpic_sim import observation_simulation, quick_run
from CpicImgSim import observation_simulation, quick_run
class TestMain(unittest.TestCase):
......
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