首次运行时跳过python raw_input提示符

时间:2014-05-09 13:42:17

标签: python raw-input

我试着通过论坛寻找答案,但我认为这对我的案例来说太具体了。

我正在使用python和pyraf编写图像缩小脚本。它会提示用户是否需要使用raw_input(“Question”)完成某些IRAF任务。我有一行,粘贴在下面,在我第一次运行脚本时跳过。如果我在之后立即重新运行脚本,则不会跳过它。该脚本会跳过此提示并立即转到下一个提示,因此完全错过了缩减中的这一步骤。

有谁知道为什么会这样?或者如果已经在其他地方回答了这个问题,我就错过了它?

skyslit=input("Which slit is for sky? Enter 0 if no sky slit: ")-1

for i in range(len(rows)/2):
    if raw_input("Need to combine flats, normalize response and divide from comparisons and science frames?: ") == 'yes':
        ####Making lists of individual slit files and normalized files
        szflat,junk,szflats=listfiles(flats[0][5:-5]+'_s'+str(i+1),beg='z*.')
        szcomp,nszcomp,szcomps=listfiles(comps[0][5:-5]+'_s'+str(i+1),beg='z*.',bias='yes',append='n')
        scrzsci,nscrzsci,scrzscis=listfiles(scis[0][5:-5]+'_s'+str(i+1),beg='crz*.',bias='yes',append='n')
        ####Combine flats into master file
        iraf.unlearn(iraf.flatcombine)
        iraf.flatcombine(szflat,output='sz'+flats[0][5:-5]+'_s'+str(i+1),combine='average',reject='minmax',ccdtype='none',process='no',subsets='no',delete ='no',rdnoise='RDNOISE',gain='GAIN')
        print 'Created Master Flat file: sz'+flats[0][5:-5]+'_s'+str(i+1)+'.fits'
        ####Normalize flat response for each slit
        iraf.noao.twodspec.longslit.response('sz'+flats[0][5:-5]+'_s'+str(i+1)+'.fits','sz'+flats[0][5:-5]+'_s'+str(i+1)+'.fits','Res_sz'+flats[0][5:-5]+'_s'+str(i+1)+'.fits', interac='yes', functio='chebyshev', order='30')
        print 'Normalized Flat response for each slit'
        ####Divide Comps and Science frames by Normalized Flat
        ####Make lists for extracted files
        ccdproc(szcomp,nszcomp,szcomps,flat='yes',flatfile='Res_sz'+flats[0][5:-5]+'_s'+str(i+1)+'.fits')
        ccdproc(scrzsci,nscrzsci,scrzscis,flat='yes',flatfile='Res_sz'+flats[0][5:-5]+'_s'+str(i+1)+'.fits')
        print 'Divided Comp and Science frames by Normalized Flat'

    ####Combine consecutive, normalized Comparison spectra in batches
    c_comps=sorted(glob.glob('nz*.'+comps[0][5:-5]+'_s'+str(i+1)+'.fits'))
    num=[]
    for c in c_comps: num.append(float(c[3:6]))
    sets=[]
    lis=[num[0]]
    n=1
    while n < len(num):
        if num[n]-num[n-1] == 1.: lis.append(num[n])
        if num[n]-num[n-1] > 1.:
            sets.append(lis)
            lis=[num[n]]
        if n == len(num)-1: sets.append(lis)
        n+=1
    l=0
    ####Creating file lists
    complist=''
    compfiles=[]
    while l < len(sets):
        ind=[num.index(n) for n in sets[l]]
        comblist=''
        for n in ind: comblist+=c_comps[n]+','
        iraf.imcombine(comblist[:-1],'nzComp'+str(l)+'_'+comps[0][5:comps[0].index('_')]+'_s'+str(i+1)+'.fits',combine='average',reject='minmax')
        data,h=py.getdata('nzComp'+str(l)+'_'+comps[0][5:comps[0].index('_')]+'_s'+str(i+1)+'.fits',header=True)
        del h['CCDSEC']
        py.writeto('nzComp'+str(l)+'_'+comps[0][5:comps[0].index('_')]+'_s'+str(i+1)+'.fits',data,h,clobber=True)
        complist+='nzComp'+str(l)+'_'+comps[0][5:comps[0].index('_')]+'_s'+str(i+1)+'.fits,'
        compfiles.append('nzComp'+str(l)+'_'+comps[0][5:comps[0].index('_')]+'_s'+str(i+1)+'.fits')
        l+=1

    ####Find wavelength solution
    ####Using the combined comparison files
    if raw_input("Need to find wavelength solution?: ") == 'yes': ##THIS IS WHAT IS SKIPPED!
        for im in compfiles:
            iraf.noao.twodspec.longslit.identify(im,coordli='goodman_hgar.dat',match=10,fwidth=7,thresho=10,niter=1)                iraf.noao.twodspec.longslit.reidentify(im,im,interac='no',coordli='goodman_hgar.dat',nlost=5,thresho=10,match=10,trace='no',overrid='yes',verbose='yes')
            iraf.noao.twodspec.longslit.fitcoords(im[:-5])
            scifiles=sorted(glob.glob('ncrz*.'+scis[0][5:-5]+'_s'+str(i+1)+'.fits'))
            imnum=[]
            for s in scifiles: imnum.append(s[5:8])
            first,last=input("First and last number of science frames that correspond to this Comparison (string). Do not include leading 0.: ")
            for s in scifiles[imnum.index(first):imnum.index(last)+1]: iraf.noao.twodspec.longslit.transform(s,'f'+s,fitname=im[:-5],flux='no')

    ####Subtract sky background if in slit
    if i != skyslit:
        if raw_input("Is sky background present in slit?: ") == 'yes': ##THIS IS WHERE IT SKIPS TO!!

这个if语句位于for循环中,迭代我正在减少的图像。以上是跳过的行周围的相关代码。对不起,这么久了。

提前感谢您的任何帮助!

0 个答案:

没有答案