理解Python错误消息?

时间:2013-07-13 06:07:25

标签: python debugging

我需要帮助理解此错误消息和/或它的来源。我很困惑,至于我,我无法确定错误是什么。

这是我正在尝试运行的代码:

def objmask(inimgs, inwhts, thresh1='20.0', thresh2='2.0', tfdel=True, 
            xceng=3001., yceng=3001., outdir='.', tmpdir='tmp'):
# initial detection of main galaxy with SExtractor for re-centering purposes
    if outdir!='.':
        if not os.path.exists(outdir):
            os.makedirs(outdir)

    if not os.path.exists(tmpdir):
        os.makedirs(tmpdir)
    for c in range(np.size(inimgs)):
        print 'Creating Aperture Run:', c
        subprocess.call(['sex',inimgs[c],'-c','./se_files/gccg.sex',
                         '-CATALOG_NAME','./se_files/_tmp_seobj'+str(c)+'.cat',
                         '-PARAMETERS_NAME','./se_files/gccg_ell.param',
                         '-FILTER_NAME','./se_files/gccg.conv',
                         '-STARNNW_NAME','./se_files/gccg.nnw',
                         '-CHECKIMAGE_TYPE','APERTURES',
                         '-VERBOSE_TYPE','QUIET',
                         '-DETECT_THRESH',thresh1,
                         '-ANALYSIS_THRESH',thresh2,
                         '-WEIGHT_IMAGE',inwhts[c]],
                         )

# extract catalog and identify central galaxy
        secat=asciitable.read('./se_files/_tmp_seobj'+str(c)+'.cat',
                              names=['flux','ferr','xmin','ymin','xmax','ymax',
                                     'xc','yc','cxx','cyy','cxy'])
        robj = np.sqrt((secat['xc']-xceng)**2.0+(secat['yc']-yceng)**2.0)
        rmin = (robj==np.min(robj))
        wrmin = np.where(robj==np.min(robj))
        xc_min,yc_min = secat['xc'][rmin],secat['yc'][rmin]
        print 'extract catalog complete'

# shift images and masks to a common center
        hdu=pf.open(inimgs[c])
        img=hdu[0].data

        xdel=xceng-xc_min
        ydel=yceng-yc_min
        img_sh=shift(img,[ydel,xdel])

        hdu2=pf.open(inwhts[c])
        mask=hdu2[0].data
        mask_sh=shift(mask,[yceng-yc_min,xceng-xc_min])

        xmin=np.delete(secat['xmin']+xdel,wrmin)
        xmax=np.delete(secat['xmax']+xdel,wrmin)
        xcen=np.delete(secat['xc']+xdel,wrmin)
        ymin=np.delete(secat['ymin']+ydel,wrmin)
        ymax=np.delete(secat['ymax']+ydel,wrmin)
        ycen=np.delete(secat['yc']+ydel,wrmin)
    print 'shift complete'

# mask detected objects and write mask file
        #retgen.pbar ((float(c)*ncols+1.0)/18.0)
        omask=tgen.semask(img.shape,xmin,xmax,ymin,ymax,xcen,ycen,
                          np.delete(secat['cxx'],wrmin),
                          np.delete(secat['cyy'],wrmin),
                          np.delete(secat['cxy'],wrmin),2.0)

        hdimsh=pf.PrimaryHDU(img_sh)
        hdmsh=pf.PrimaryHDU(omask)
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            hdimsh.writeto(outdir+'/sh_img_'+str(c)+'.fits',
                           clobber=True)
            hdmsh.writeto(tmpdir+'/_omask.fits',clobber=True)
    print 'mask file complete'

这是我通过终端运行时收到的错误消息:

>>> fetch_swarp2.objmask(['sciPHOTOf105w0.fits'],['whtPHOTOf105w0.fits'])
Creating Aperture Run: 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "fetch_swarp2.py", line 110, in objmask
    '-WEIGHT_IMAGE',inwhts[c]],
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

所以。 。 。问题在哪里,我该如何解决?

2 个答案:

答案 0 :(得分:0)

使用subprocess.call关键字参数调用shell=True

    subprocess.call([...], shell=True)

或指定sex的完整路径:

subprocess.call(['/path/to/sex', ...], shell=True)

答案 1 :(得分:0)

该代码运行带有一些参数的名为sex的命令。 Python无法找到该命令;确保已安装它。注释似乎表明该命令由SExtractor提供。