test.py 1.27 KB
Newer Older
Zheng Gaoshan's avatar
Zheng Gaoshan committed
1
2
3
4
5
from astroquery.mast import Observations
from astropy.io import fits
from astropy.visualization import simple_norm
import matplotlib.pyplot as plt
from ccdproc import CCDData
Zheng Gaoshan's avatar
Zheng Gaoshan committed
6

Zheng Gaoshan's avatar
Zheng Gaoshan committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 查询并下载观测数据
obs_table = Observations.query_criteria(dataproduct_type=["image"], obs_collection="HST", instrument_name="ACS/WFC")
data_products_by_obs = Observations.get_product_list(obs_table[0])
download_info = Observations.download_products(data_products_by_obs[:1], productType="SCIENCE")

# 加载FITS文件
fits_file_path = download_info['obs_id', 'local_path'][0]['local_path']
hdu_list = fits.open(fits_file_path)
hdu = hdu_list[0]

# 将HDU对象转换为CCDData对象,便于后续处理
ccd_image = CCDData(hdu.data, unit="adu")

# 使用ccdproc进行基本处理,比如减去平均值
processed_image = ccd_image.subtract(ccd_image.mean())

# 显示处理前后的图像
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 7))
norm = simple_norm(hdu.data, 'sqrt', percent=99)
ax1.imshow(hdu.data, norm=norm, origin='lower')
ax1.set_title('原始图像')
norm_processed = simple_norm(processed_image.data, 'sqrt', percent=99)
ax2.imshow(processed_image.data, norm=norm_processed, origin='lower')
ax2.set_title('处理后图像')
plt.show()

# 关闭fits文件以释放资源
hdu_list.close()