问题描述
我写了用于校准图像(暗框和平坦场)的脚本...这里是代码的一部分
I write script for calibration of image (dark frame and flat field)...Here is part of code
for n in range(len(img)):
with pyfits.open(img[n], mode='update', memmap=True) as im:
imgg = im[0].data
header = im[0].header
imgg.astype(float)
imgg = (imgg - dd) / df
imgg[np.isnan(imgg)] = 1
imgg.astype(int)
plt.imshow(imgg, cmap=plt.cm.Greys_r, vmin=0.5, vmax=1.5)
plt.show()
这部分代码使用暗框和平坦场对图像进行校准...当我在绘制vmin
和vmax
时使用时,可以获得正确的图片,但我不知道vmin
和vmax
工作.我需要将其应用于图像数据(imgg
),因为当我保存数据时,我得到的图像没有vmin
和vmax
...
This part of code make calibration of image with dark frame and flat field... When I use at the plotting vmin
and vmax
, I get the right picture but I don't know how vmin
and vmax
work. I need to apply this on image data (imgg
) because when I save data I get images without vmin
and vmax
...
有什么建议吗?
第二个问题...如何保存拟合文件中的数据更改?当我使用im.close()
时,此功能仅对一个文件有效,但不能循环工作.
And the second question... How I can save data changes in fits files? When I used im.close()
this work only on one file but don't work in loop.
谢谢
编辑
好的,这是完整的脚本
import numpy as np
import pyfits
from matplotlib import pyplot as plt
import glob
dark=glob.glob('.../ha/dark/*.fits')
flat=glob.glob('.../ha/flat/*.fits')
img=glob.glob('.../ha/*.fits')
sumd0 = pyfits.open(dark[0])
sumdd=sumd0[0].data
sumdd.astype(float)
for i in range(1,len(dark)):
sumdi=pyfits.open(dark[i])
sumdi=sumdi[0].data
sumdd=sumdd.astype(float)+sumdi.astype(float)
dd=sumdd/len(dark)
sumf0 = pyfits.open(flat[0])
sumff=sumf0[0].data
sumff.astype(float)
for i in range(1,len(flat)):
sumfi=pyfits.open(flat[i])
sumfi=sumfi[0].data
sumff=sumff.astype(float)+sumfi.astype(float)
ff=sumff/len(flat)
df=(ff-dd)
for n in range(len(img)):
with pyfits.open(img[n],mode='update',memmap=True) as im:
imgg=im[0].data
header=im[0].header
imgg.astype(float)
imgg=(imgg-dd)/df
imgg.astype(int)
plt.imshow(imgg,cmap=plt.cm.Greys_r,vmin=0.5,vmax=1.5)
plt.show()
推荐答案
有点重复的问题,但我认为这可以满足您的要求(来自其他答案的评论).
A bit ofuscated question but I think this does what you want (from your comment in the other answer).
要以与vmin
和vmax
相同的行为钳制数据,请使用 np.clip
:
To clamp the data with the same behaviour as vmin
and vmax
, use np.clip
:
np.clip(data, min, max)
在您的情况下:
data = np.clip(data, 0.5, 1.5)
这篇关于vmin vmax算法matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!