Commit c04f055f authored by Shuai Feng's avatar Shuai Feng
Browse files

add example

parent 179474ef
Pipeline #7815 passed with stage
in 0 seconds
%% Cell type:markdown id:ba724066 tags:
# 三维数据立方模拟(`cube3d`)
%% Cell type:code id:8b12b69e tags:
``` python
import sys
sys.path.append("..")
from csst_ifs_gehong import spec1d as s
from csst_ifs_gehong import map2d as m
from csst_ifs_gehong import cube3d as b
from csst_ifs_gehong import config as c
import numpy as np
import matplotlib.pyplot as plt
```
%% Cell type:markdown id:8d20f84d tags:
### 光谱格式配置项
`config`模块用来配置模拟光谱的格式,包括波长方向配置(波长范围、波长间隔)和空间方向配置(像素数、像素大小)。默认配置下模拟得到的三维数据立方可直接用于`csst-ifs-etc`的计算。
%% Cell type:code id:6603f0ff tags:
``` python
config = c.config(nx=30, ny=30, dpix=0.3)
```
%% Cell type:markdown id:9bf2f575 tags:
## 模拟TNG星系的积分视场光谱
%% Cell type:markdown id:3007c0f0 tags:
### 数据读取
%% Cell type:code id:37995ee9 tags:
``` python
from astropy.io import fits
hdulist = fits.open('Example.fits')
print(hdulist.info())
```
%% Output
Filename: Example.fits
No. Name Ver Type Cards Dimensions Format
0 PRIMARY 1 PrimaryHDU 4 ()
1 SURFACE_BRIGHT 1 ImageHDU 8 (100, 100) float64
2 AGE_STAR 1 ImageHDU 8 (100, 100) float64
3 FEH_STAR 1 ImageHDU 8 (100, 100) float64
4 E(B-V) 1 ImageHDU 8 (100, 100) float64
5 VEL_STAR 1 ImageHDU 8 (100, 100) float64
6 SIG_STAR 1 ImageHDU 8 (100, 100) float64
7 HA_FLUX 1 ImageHDU 8 (100, 100) float64
8 ZH_GAS 1 ImageHDU 8 (100, 100) float64
9 VEL_GAS 1 ImageHDU 8 (100, 100) float64
10 SIG_GAS 1 ImageHDU 8 (100, 100) float64
None
%% Cell type:markdown id:9d8d82de tags:
### 分别导入数据
%% Cell type:code id:10e00021 tags:
``` python
# 恒星星族相关Map
stellar_sbmap = m.Map2d(config)
stellar_sbmap.load_map(hdulist[1].data)
stellar_agemap = m.Map2d(config)
stellar_agemap.load_map(np.log10(hdulist[2].data*1e9))
stellar_fehmap = m.Map2d(config)
stellar_fehmap.load_map(hdulist[4].data)
stellar_velmap = m.Map2d(config)
stellar_velmap.load_map(hdulist[5].data)
stellar_vdispmap = m.Map2d(config)
stellar_vdispmap.load_map(hdulist[6].data)
# 气体相关Map
gas_hamap = m.Map2d(config)
gas_hamap.load_map(hdulist[7].data)
gas_zhmap = m.Map2d(config)
gas_zhmap.load_map(hdulist[8].data)
gas_velmap = m.Map2d(config)
gas_velmap.load_map(hdulist[9].data)
gas_vdispmap = m.Map2d(config)
gas_vdispmap.load_map(hdulist[10].data)
# 尘埃消光
ebvmap = m.Map2d(config)
ebvmap.load_map(hdulist[3].data)
stellarcontinuum = m.StellarPopulationMap(config, sbright = stellar_sbmap,
logage = stellar_agemap, feh = stellar_fehmap,
vel = stellar_velmap, vdisp = stellar_vdispmap,
ebv = ebvmap)
ionizedgas = m.IonizedGasMap(config, halpha = gas_hamap,
zh = gas_zhmap, vel = gas_velmap,
vdisp = gas_vdispmap, ebv = ebvmap)
```
%% Output
Notice: Spaxel with < 0 mag in the input ebv map will be automatically adjusted to 0 mag.
%% Cell type:markdown id:5b6fa973 tags:
### 配置cube3d的基本参数
模拟的数据立方类的形式进行操作(`cube3d.Cube3D`)。在开始模拟之前需先对模拟参数进行配置,包括数据立方的格式`config`,恒星成分物理参数分布`stellar_map`和气体成分物理参数分布`gas_map`
%% Cell type:code id:9b0057d3 tags:
``` python
u = b.Cube3D(config, stellar_map = stellarcontinuum, gas_map = ionizedgas)
```
%% Cell type:markdown id:d377ed48 tags:
### 配置模拟光谱所需要的模板
包括恒星连续谱模板和电离气体发射线模板
%% Cell type:code id:61bc3c17 tags:
``` python
gas_tem = s.EmissionLineTemplate(config, model = 'hii')
stellar_tem = s.StellarContinuumTemplate(config)
```
%% Cell type:markdown id:018f8779 tags:
### 开始进行光谱模拟
%% Cell type:code id:e8b6943f tags:
``` python
u.make_cube(stellar_tem = stellar_tem, hii_tem = gas_tem)
```
%% Cell type:markdown id:d1a8443c tags:
### 展示模拟光谱
%% Cell type:code id:f4177775 tags:
``` python
x1, y1 = 14, 14
x2, y2 = 12, 12
plt.figure(figsize=(15,3.5))
plt.subplot(121)
plt.imshow(np.log10(np.mean(u.flux[:,:,(u.wave>4900)&(u.wave<5100)],axis=2)),cmap='gray_r')
plt.colorbar(label=r'$\log (10^{-17} erg/s/\AA/cm^2)$')
plt.scatter(x1,y1,marker='o',s=100,color='red',alpha=0.5)
plt.scatter(x2,y2,marker='o',s=100,color='blue',alpha=0.5)
plt.xticks([])
plt.yticks([])
plt.subplot(122)
idx=(u.wave>3800)&(u.wave<7000)
plt.plot(u.wave[idx],u.flux[x1,y1,:][idx],lw=2,color='red')
plt.plot(u.wave[idx],u.flux[x2,y2,:][idx],lw=2,color='blue')
plt.xlim(3800,7000)
plt.yscale('log')
plt.xlabel(r'$Wavelength(\AA)$')
plt.ylabel(r'$Flux (10^{-17} erg/s/\AA/cm^2)$')
plt.tight_layout()
plt.show()
```
%% Output
%% Cell type:markdown id:103590a5 tags:
### 数据立方存储
%% Cell type:code id:a36e8322 tags:
``` python
u.savefits('result.fits')
```
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.
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