I am performing aperture photometry over thousands of images and have this piece of code in my module.
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)
This works fine on most of the images but in some of the images it triggers following error;
> <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'}
This error usually happens when the variables are not defined but I have checked that the variable here "masked_img_aper" is defined and looks like a normal image. The mask "b_ap_pix_mask" also look normal like other masks on previous images. So, I am not sure what's going on and how to fix this. My code runs in a loop over thousands of images and this is only happening for a few images which breaks down the code. I would like to circumvent this issue (possibly by using "if" statement) or fix it.
I tried following but it didn't work;
if (isinstance(np.array(b_ap_pix_mask.apply(masked_img_aper)), NoneType) == False;
Any ideas would be appreciated. Best, Abhi