我正在对数以千计的图像执行光圈测光,并且在我的模块中有这段代码。
b_aperture = SkyCircularAperture(b_position, r= r*u.arcsec)
b_annulus_aperture = SkyCircularAnnulus(b_position, r_in= r_in* u.arcsec, r_out= r_out* u.arcsec)
b_ap_pix = b_aperture.to_pixel(w_n)
b_ap_pix_mask= b_ap_pix.to_mask(method='exact')[0]
c_img_data = b_ap_pix_mask.apply(masked_img_aper)这在大多数图像上工作得很好,但在一些图像中,它会触发以下错误;
> <ipython-input-41-d3d69b9fd615> in <module>()
51 b_ap_pix = b_aperture.to_pixel(w_n)
52 b_ap_pix_mask= b_ap_pix.to_mask(method='exact')[0]
53 c_img_data = b_ap_pix_mask.apply(masked_img_aper)
55 b_phot_table = aperture_photometry(masked_img_aper, b_aperture, method ='exact', wcs =w_n )
/Users/aprakash/Library/Enthought/Canopy/edm/envs/User/lib/python3.5/site-packages/photutils/aperture/core.py in apply(self, data, fill_value)
719 """
721 return self.cutout(data, fill_value=fill_value) * self.data
722
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'}这个错误通常发生在变量没有定义的时候,但是我已经检查了这里的变量"masked_img_aper“是定义的并且看起来像一个正常的图像。遮罩"b_ap_pix_mask“看起来也和之前图像中的其他遮罩一样正常。所以,我不确定发生了什么以及如何解决这个问题。我的代码在数千张图片上循环运行,这种情况只发生在少数几张图片上,这会分解代码。我想绕过这个问题(可能通过使用"if“语句)或修复它。
我试着跟随它,但它不起作用;
if (isinstance(np.array(b_ap_pix_mask.apply(masked_img_aper)), NoneType) == False;任何想法都将不胜感激。最好的,阿比
发布于 2018-04-29 00:28:53
看起来这是一个在开发中的当前版本中修复的错误:https://github.com/astropy/photutils/pull/646
发布于 2018-04-29 07:53:54
好的,我已经找到了一种方法来规避这个问题,使用下面的方法;
try:
c_img_data = b_ap_pix_mask.multiply(masked_img_aper)
except:
print('Error calling b_ap_pix_mask.multiply(), ignoring')
pass这将跳过循环中的图像。因为,我正在处理数以千计的图像,去掉一些图像不会有太大的不同。
https://stackoverflow.com/questions/50072617
复制相似问题