我真的快要完成一大段代码了,但它的最后一部分似乎失败了,我不知道为什么。我在这里尝试做的是取一个图像数组,将它与不同的图像数组进行比较,在初始图像数组等于1的地方,我想在第二个图像数组中屏蔽这一部分。然而,我得到了一个奇怪的错误:
代码:
maskimg='omask'+str(inimgs)[5:16]+'.fits'
newmaskimg=pf.getdata(maskimg)
oimg=pf.getdata(inimgs)
for i in range (newmaskimg.shape[0]):
for j in range (newmaskimg.shape[1]):
if newmaskimg[i,j]==1:
oimg[i,j]=0
pf.writeto('newestmask'+str(inimgs)[5:16]+'.fits',newmaskimg)错误:
/home/vidur/se_files/fetch_swarp10.py in objmask(inimgs, inwhts, thresh1, thresh2, tfdel, xceng, yceng, outdir, tmpdir)
122 if newmaskimg[i,j]==1:
123 oimg[i,j]=0
--> 124 pf.writeto('newestmask'+str(inimgs)[5:16]+'.fits',newmaskimg)
125
126
/usr/local/lib/python2.7/dist-packages/pyfits/convenience.pyc in writeto(filename, data, header, output_verify, clobber, checksum)
396 hdu = PrimaryHDU(data, header=header)
397 hdu.writeto(filename, clobber=clobber, output_verify=output_verify,
--> 398 checksum=checksum)
399
400
/usr/local/lib/python2.7/dist-packages/pyfits/hdu/base.pyc in writeto(self, name, output_verify, clobber, checksum)
348 hdulist = HDUList([self])
349 hdulist.writeto(name, output_verify, clobber=clobber,
--> 350 checksum=checksum)
351
352 def _get_raw_data(self, shape, code, offset):
/usr/local/lib/python2.7/dist-packages/pyfits/hdu/hdulist.pyc in writeto(self, fileobj, output_verify, clobber, checksum)
651 os.remove(filename)
652 else:
--> 653 raise IOError("File '%s' already exists." % filename)
654 elif (hasattr(fileobj, 'len') and fileobj.len > 0):
655 if clobber:
IOError: File 'newestmaskPHOTOf105w0.fits' already exists.发布于 2013-08-15 02:37:31
如果您不关心覆盖现有文件,pyfits.writeto将接受clobber参数以自动覆盖现有文件(它仍将输出警告):
pyfits.writeto(..., clobber=True)顺便说一句,让我强调一下,您在上面发布的代码并不是使用Numpy的正确方式。代码中的循环可以在一行中编写,速度会快几个数量级。例如,许多可能性之一是这样写它:
oimg[newmaskimg == 1] = 0发布于 2014-08-17 02:42:07
是,添加clobber = True。我以前在我的代码中使用过它,它工作得很好。或者,只需执行sudo rm path/to/file并删除它们,这样您就可以再次运行它。
发布于 2020-02-21 20:36:50
我遇到了同样的问题,事实证明,使用参数clobber仍然有效,但在未来的AstroPy版本中将不再支持。
参数overwrite做了同样的事情,并且没有输出错误消息。
https://stackoverflow.com/questions/17712913
复制相似问题