Beispiel #1
0
def rerunellipse(files, xcenter, ycenter, minr, initialr, maxr, nframe=1):
    repeatflag = 1
    while (repeatflag > 0.1):
        mfile = files[i]
        t = mfile.split('.')
        k = t[0].split('m')
        efile = k[1] + '.tab'
        s = 'rm ' + efile
        os.system(s)

        s = "ellipse input=%s output=%s x0=%.1f y0=%.1f hcenter+ sma0=%.1f minsma=%.1f maxsma=%.1f inter+ \n" % (
            mfile, efile, xcenter, ycenter, initialr, minr, maxr)
        #        s="ellipse(input=%s, output=%s, x0=%.1f, y0=%.1f, hcenter+, sma0=%.1f, minsma=%.1f, maxsma=%.1f, interactive=+) \n"%(mfile,efile,xcenter,ycenter,initialr,minr,maxr)

        iraf.ellipse(input=mfile,
                     output=efile,
                     x0=xcenter,
                     y0=ycenter,
                     hcenter='yes',
                     sma0=initialr,
                     minsma=minr,
                     maxsma=maxr,
                     interactive='yes')
        print 'Displaying isophotes.  Hit q to quit'
        iraf.isoexam(table=efile)
        flag = str(
            raw_input('Are you happy with the fit?  y=yes n=no x=quit '))
        flag = str(flag)
        print 'this is what I think you typed ', flag
        if flag.find('y') > -1:
            s = 'mv *' + t[0] + '* Finished/'
            os.system(s)
            repeatflag = 0
            print 'i think repeatflag = 0', repeatflag
        if flag.find('n') > -1:
            s = 'rm *' + t[0] + '*.tab'
            os.system(s)
            s = 'rm m' + t[0] + '*.fits'
            os.system(s)
            repeatflag = 1
            print 'i think repeatflag = 1', repeatflag
        if flag.find('x') > -1:
            repeatflag = 0
            print 'i think repeatflag = 0', repeatflag
            return
        print 'repeatflag = ', repeatflag
Beispiel #2
0
def runellipse(files, xcenter, ycenter, minr, initialr, maxr, nframe=1):
    for i in range(len(files)):
        #for i in range(5):
        mfile = files[i]
        repeatflag = 1
        while (repeatflag > 0.1):
            iraf.display(mfile, frame=nframe, fill='yes')
            outfile1 = 'm' + mfile
            print mfile
            print 'Running imedit to mask out other sources in the field:'
            print 'Enter b to mask out a circular region'
            print 'Enter a to mark the corners of a rectangle'
            print 'Enter q when finished'
            try:
                os.remove(outfile1)
            except OSError:
                print 'everything is ok'
            print 'running imedit ', mfile, outfile1
            iraf.imedit(mfile, outfile1)

            t = mfile.split('.')
            efile = t[0] + '.tab'
            print 'Running ellipse to fit isophotes to galaxy:'
            print 'Enter h to continue fitting'
            try:
                os.remove(efile)
            except OSError:
                print 'everything is ok'
            iraf.ellipse(input=outfile1,
                         output=efile,
                         x0=xcenter,
                         y0=ycenter,
                         hcenter='yes',
                         sma0=initialr,
                         minsma=minr,
                         maxsma=maxr)
            print 'Displaying isophotes.  Hit q to quit'
            iraf.isoexam(table=efile)
            #            try:
            #                iraf.ellipse(input=outfile1,output=efile,x0=xcenter,y0=ycenter,hcenter='yes',sma0=initialr,minsma=minr,maxsma=maxr)
            #            except:
            #                print efile," already exists so I am deleting it. Hit Cntrl-c if you don't want to delete"
            #                s='rm '+efile
            #                os.system(s)
            #                iraf.ellipse(input=outfile1,output=efile,x0=xcenter,y0=ycenter,hcenter='yes',sma0=initialr,minsma=minr,maxsma=maxr)

            flag = str(
                raw_input('Are you happy with the fit?  y=yes n=no x=quit '))
            flag = str(flag)
            print 'this is what I think you typed ', flag
            if flag.find('y') > -1:
                s = 'mv *' + t[0] + '* Finished/'
                os.system(s)
                repeatflag = 0
                print 'i think repeatflag = 0', repeatflag
            if flag.find('n') > -1:
                s = 'rm *' + t[0] + '*.tab'
                os.system(s)
                s = 'rm m' + t[0] + '*.fits'
                os.system(s)
                repeatflag = 1
                print 'i think repeatflag = 1', repeatflag
            if flag.find('x') > -1:
                repeatflag = 0
                print 'i think repeatflag = 0', repeatflag
                return
            print 'repeatflag = ', repeatflag
Beispiel #3
0
def runellipse(files,
               xcenter,
               ycenter,
               minr,
               ipa,
               initialr,
               maxr,
               iellip,
               nframe=1,
               myradius=15):
    initialradius = myradius
    for i in range(len(files)):
        myradius = initialradius

        mfile = files[i]

        #mask image
        outfile1 = 'm' + mfile
        continueWithProgram, continueWithObject = runimedit(
            mfile, outfile1, nframe)
        if not continueWithProgram:
            print "quitting program"
            return
        if not continueWithObject:
            print "going on to next image"
            continue

        #run ellipse
        t = mfile.split('.')
        efile = t[0] + '.tab'
        imprefix = t[0]
        print mfile, imprefix
        print 'Running ellipse to fit isophotes to galaxy:'
        try:
            os.remove(efile)
        except OSError:
            print 'everything is ok'
        print "First pass, letting PA and e vary"
        iraf.ellipse(input=outfile1,
                     output=efile,
                     x0=xcenter,
                     y0=ycenter,
                     hcenter='no',
                     sma0=initialr,
                     minsma=minr,
                     maxsma=maxr,
                     pa=ipa,
                     hpa='no',
                     ellip=iellip,
                     hellip='no')
        print 'Displaying isophotes from first pass.  Hit q in DS9 window to quit'
        iraf.isoexam(table=efile)

        os.system('rm junk.txt')
        iraf.tprint(table=efile,
                    pwidth='INDEF',
                    showhdr='no',
                    Stdout='junk.txt')
        os.system("awk '{print $2, $7, $9, $11, $13}' < junk.txt > junk2.txt")
        #run ellipse a second time, keeping PA and ellip fixed
        #allow user to adjust the radius where PA and ellip are measured
        repeatflag = 1
        while (repeatflag > 0.1):
            infile = open('junk2.txt', 'r')
            for line in infile:
                t = line.split()
                if float(t[0]) > myradius:
                    newellip = float(t[1])
                    if newellip < .05:  #min value that ellipse can handle
                        newellip = .05
                    newPA = float(t[2])
                    if newPA < -90:
                        newPA = newPA + 180
                    elif newPA > 90:
                        newPA = newPA - 180
                    #11 - X0, 13 - Y0
                    newxcenter = float(t[3])
                    newycenter = float(t[4])
                    break
            s = 'rm ' + efile
            os.system(s)
            iraf.ellipse(input=outfile1,
                         output=efile,
                         x0=newxcenter,
                         y0=newycenter,
                         hcenter='yes',
                         sma0=initialr,
                         minsma=minr,
                         maxsma=maxr,
                         pa=newPA,
                         hpa='yes',
                         ellip=newellip,
                         hellip='yes')

            print 'Displaying isophotes from second pass using r = ', myradius
            print 'Hit q in the DS9 window to quit'
            iraf.isoexam(table=efile)

            flag = str(
                raw_input('Are you happy with the fit?  y=yes n=no x=quit '))
            flag = str(flag)
            print 'this is what I think you typed ', flag
            if flag.find('n') > -1:
                flag2 = str(
                    raw_input(
                        'What is the problem?  c=off-center r=set new radius x=quit '
                    ))
                flag2 = str(flag2)
                if flag2.find('r') > -1:
                    myr = input('Enter new radius to use ')
                    myradius = float(myr)
                    s = 'rm ' + efile
                    os.system(s)
                    repeatflag = 1
                elif flag2.find('x') > -1:
                    repeatflag = 0
                    return
                elif flag2.find('c') > -1:

                    s = 'mv *' + imprefix + '* OffCenter/'
                    print s
                    os.system(s)
                    repeatflag = 0
                    print "repeatflag = ", repeatflag
            elif flag.find('x') > -1:
                repeatflag = 0
                print 'i think repeatflag = 0', repeatflag
                return
            else:
                s = 'mv *' + imprefix + '* Finished/'
                os.system(s)
                repeatflag = 0
                print 'i think repeatflag = 0 ', repeatflag

            print 'repeatflag = ', repeatflag
Beispiel #4
0
def runellipseold(files,xcenter,ycenter,minr,ipa,initialr,maxr,iellip,nframe=1,myradius=15):
    initialradius=myradius
    for i in range(len(files)):
        myradius=initialradius
    
        mfile=files[i]

        #mask image
        outfile1='m'+mfile
        continueWithProgram,continueWithObject=runimedit(mfile,outfile1,nframe)
        if not continueWithProgram:
            print "quitting program"
            return
        if not continueWithObject:
            print "going on to next image"
            continue

        #run ellipse
        t=mfile.split('.')
        efile=t[0]+'.tab'
        imprefix=t[0]
        print mfile, imprefix
        print 'Running ellipse to fit isophotes to galaxy:'
        try:
            os.remove(efile)
        except OSError:
            print 'everything is ok'
        print "First pass, letting PA and e vary"
        iraf.ellipse(input=outfile1,output=efile,x0=xcenter,y0=ycenter,hcenter='no',sma0=initialr,minsma=minr,maxsma=maxr,pa=ipa,hpa='no',ellip=iellip,hellip='no')
        print 'Displaying isophotes from first pass.  Hit q in DS9 window to quit'
        iraf.isoexam(table=efile)

        os.system('rm junk.txt')
        iraf.tprint(table=efile,pwidth='INDEF',showhdr='no', Stdout='junk.txt')
        os.system("awk '{print $2, $7, $9, $11, $13}' < junk.txt > junk2.txt")
        #run ellipse a second time, keeping PA and ellip fixed
        #allow user to adjust the radius where PA and ellip are measured
        repeatflag=1
        while (repeatflag > 0.1):
            infile=open('junk2.txt','r')
            for line in infile:
                t=line.split()
                if float(t[0]) > myradius:
                    newellip=float(t[1])
                    if newellip < .05:#min value that ellipse can handle
                        newellip=.05
                    newPA=float(t[2])
                    if newPA < -90:
                        newPA=newPA+180
                    elif newPA > 90:
                        newPA = newPA-180
                    #11 - X0, 13 - Y0
                    newxcenter=float(t[3])
                    newycenter=float(t[4])
                    break
            s='rm '+efile
            os.system(s)
            iraf.ellipse(input=outfile1,output=efile,x0=newxcenter,y0=newycenter,hcenter='yes',sma0=initialr,minsma=minr,maxsma=maxr,pa=newPA,hpa='yes',ellip=newellip,hellip='yes')

            print 'Displaying isophotes from second pass using r = ',myradius
            print 'Hit q in the DS9 window to quit'
            iraf.isoexam(table=efile)
                
            flag=str(raw_input('Are you happy with the fit?  y=yes n=no x=quit '))
            flag=str(flag)
            print 'this is what I think you typed ',flag
            if flag.find('n') > -1:
                flag2=str(raw_input('What is the problem?  c=off-center r=set new radius x=quit '))
                flag2=str(flag2)
                if flag2.find('r') > -1:
                    myr=input('Enter new radius to use ')
                    myradius=float(myr)
                    s='rm '+efile
                    os.system(s)
                    repeatflag=1
                elif flag2.find('x') > -1:
                    repeatflag=0
                    return
                elif flag2.find('c') > -1:

                    s='mv *'+imprefix+'* OffCenter/'
                    print s
                    os.system(s)
                    repeatflag=0
                    print "repeatflag = ",repeatflag
            elif flag.find('x') > -1:
                repeatflag=0
                print 'i think repeatflag = 0', repeatflag
                return
            else:
                s='mv *'+imprefix+'* Finished/'
                os.system(s)
                repeatflag=0
                print 'i think repeatflag = 0 ', repeatflag

            print 'repeatflag = ',repeatflag
def runellipse(files,xcenter,ycenter,minr,ipa,initialr,maxr,iellip,nframe=1,myradius=15):
    initialradius=myradius
    #print 'got here'
    #print files
    for i in range(len(files)):
        myradius=initialradius
    
        mfile=files[i]

        #mask image
        
        outfile1='m'+mfile
        if os.path.isfile(outfile1):
            print "found masked file ",outfile1
            print "skipping imedit and running ellipse interactively"
            continueWithProgram=1
            continueWithObject=1

        else:
            print "can't find masked file ",outfile1
            print "running imedit"
            continueWithProgram,continueWithObject=runimedit(mfile,outfile1,nframe)

        if not continueWithProgram:
            print "quitting program"
            return
        if not continueWithObject:
            print "going on to next image"
            continue

        #run ellipse
        t=mfile.split('.')
        efile=t[0]+'.tab'
        imprefix=t[0]
        try:
            os.remove(efile)
        except OSError:
            print 'everything is ok'
            #continue

        print "First pass through ellipse to find center"
        iraf.ellipse(input=outfile1,output=efile,x0=xcenter,y0=ycenter,hcenter='no',sma0=initialr,minsma=minr,maxsma=maxr,pa=ipa,hpa='no',ellip=iellip,hellip='no',interactive='no')
        #print 'Displaying isophotes from first pass.  Hit q in DS9 window to quit'
        #iraf.isoexam(table=efile)

        os.system('rm junk.txt')
        iraf.tprint(table=efile,pwidth='INDEF',showhdr='no', Stdout='junk.txt')
        os.system("awk '{print $2, $7, $9, $11, $13}' < junk.txt > junk2.txt")
        #run ellipse a second time, keeping PA and ellip fixed
        #allow user to adjust the radius where PA and ellip are measured
        infile=open('junk2.txt','r')
        for line in infile:
            t=line.split()
            if float(t[0]) > myradius:
                newxcenter=float(t[3])
                newycenter=float(t[4])
                break
        s='rm '+efile
        os.system(s)

        #draw ellipse with ds9
        iraf.display(outfile1,1)
        (myellip,mypa)=findellipse(outfile1,newxcenter,newycenter)
        flag2=str(raw_input('Do you want to skip this one?  y=skip, any other key to continue '))
        if flag2.find('y') > -1:
            s='mv *'+imprefix+'* ../PeculiarGalaxies/'
            print s
            os.system(s)
            continue
        #run ellipse interactively
        #allow user to repeat until satisfied with script
        repeatflag=1
        while repeatflag:
            s='rm '+efile
            os.system(s)
            iraf.ellipse(input=outfile1,output=efile,x0=newxcenter,y0=newycenter,hcenter='yes',sma0=initialr,minsma=minr,maxsma=maxr,pa0=mypa,hpa='yes',ellip0=myellip,hellip='yes',interactive='no')

            print 'Displaying isophotes from second pass using r = ',myradius
            print 'Hit q in the DS9 window to quit'
            iraf.isoexam(table=efile)
                
            flag=str(raw_input('Are you happy with the fit?  y=yes n=no x=quit '))
            flag=str(flag)
            print 'this is what I think you typed ',flag
            if flag.find('n') > -1:
                s='rm '+efile
                os.system(s)
                repeatflag=1
            elif flag.find('x') > -1:
                repeatflag=0
                print 'i think repeatflag = 0', repeatflag
                return
            else:
                s='mv *'+imprefix+'* ../Finished/'
                os.system(s)
                repeatflag=0
                print 'i think repeatflag = 0 ', repeatflag

            print 'repeatflag = ',repeatflag
Beispiel #6
0
def measure_disk(input_image,
                 xcenter,
                 ycenter,
                 ipa,
                 iellip,
                 initialr,
                 minr,
                 maxr,
                 zp,
                 band=0,
                 nframe=1,
                 myradius=25,
                 keepfixed=0,
                 einteractive=0,
                 mask_image=None):
    print 'inside measure disk'
    print 'mask image = ', mask_image
    myradius = initialr
    recentervalue = 'yes'
    interactivevalue = 'no'

    print '\n Running ellipse on ', input_image, '\n'
    mfile = input_image

    xcenter_cutout = xcenter
    ycenter_cutout = ycenter

    t = mfile.split('.')
    efile = t[0] + '.tab'
    efile_ascii = t[0] + '.dat'
    imprefix = t[0]
    print 'Running ellipse to fit isophotes to galaxy:', mfile
    if os.path.exists(efile):
        os.remove(efile)
    if keepfixed:
        print input_image, efile, xcenter_cutout, ycenter_cutout, initialr, minr, maxr, ipa
        iraf.ellipse(input=input_image,
                     output=efile,
                     dqf=mask_image,
                     x0=xcenter_cutout,
                     y0=ycenter_cutout,
                     hcenter='yes',
                     recenter=recentervalue,
                     sma0=initialr,
                     minsma=minr,
                     maxsma=maxr,
                     pa=ipa,
                     hpa='yes',
                     ellip=iellip,
                     hellip='yes',
                     interactive='yes',
                     step=0.1,
                     linear='no')

    else:
        print "First pass, letting PA and e vary"
        print input_image, efile, xcenter_cutout, ycenter_cutout, initialr, minr, maxr, ipa,
        if mask_image == None:
            iraf.ellipse(input=input_image,
                         output=efile,
                         x0=xcenter_cutout,
                         y0=ycenter_cutout,
                         hcenter='no',
                         recenter=0,
                         sma0=initialr,
                         minsma=minr,
                         maxsma=maxr,
                         pa=ipa,
                         hpa='no',
                         ellip=iellip,
                         hellip='no',
                         interactive=einteractive,
                         step=0.1,
                         linear='no')
        else:
            iraf.ellipse(input=input_image,
                         output=efile,
                         dqf=mask_image,
                         x0=xcenter_cutout,
                         y0=ycenter_cutout,
                         hcenter='no',
                         recenter=0,
                         sma0=initialr,
                         minsma=minr,
                         maxsma=maxr,
                         pa=ipa,
                         hpa='no',
                         ellip=iellip,
                         hellip='no',
                         interactive='yes',
                         step=0.1,
                         linear='no')
    print 'Displaying isophotes from first pass.  Hit q in DS9 window to quit'
    iraf.isoexam(table=efile)
    try:
        os.system('rm tp.00*')
    except:
        print 'no tp.00? files to remove'
    iraf.isoimap(input_image, table=efile)
    # get final ellipse parameters to return to the user
    if os.path.exists('junk.txt'):
        os.remove('junk.txt')
    iraf.tprint(table=efile, pwidth='INDEF', showhdr='no', Stdout='junk.txt')
    s = "awk '{print $2, $7, $9, $11, $13}' < " + "junk.txt > " + "junk2.txt"
    os.system(s)
    infile = open('junk2.txt', 'r')
    for line in infile:
        t = line.split()
        if float(t[0]) > myradius:

            newellip = float(t[1])
            if newellip < .05:  # min value that ellipse can handle
                newellip = .05
            newPA = float(t[2])
            if newPA < -90:
                newPA = newPA + 180
            elif newPA > 90:
                newPA = newPA - 180

            newxcenter = float(t[3])
            newycenter = float(t[4])

    if os.path.exists(efile_ascii):
        os.remove(efile_ascii)
    iraf.tprint(table=efile, pwidth='INDEF', showhdr='no', Stdout=efile_ascii)
    return newxcenter, newycenter, newellip, newPA
Beispiel #7
0
def measure_disk(input_image,xcenter,ycenter,ipa,iellip,initialr,minr,maxr,zp,band=0,nframe=1,myradius=20,keepfixed=0,einteractive=0,mask_image=None):
    print 'inside measure disk'
    print 'mask image = ',mask_image
    #myradius=initialr
    recentervalue='yes'
    interactivevalue='yes'

    print '\n Running ellipse on ',input_image,'\n'
    print ' Enter ? for a list of options \n'
    print ' Enter c to continue fitting ellipses automatically \n'
    mfile=input_image
    
    xcenter_cutout=xcenter
    ycenter_cutout=ycenter
    
    t=mfile.split('.')
    efile=t[0]+'.tab'
    efile_ascii=t[0]+'.dat'
    imprefix=t[0]
    print 'Running ellipse to fit isophotes to galaxy:',mfile
    if os.path.exists(efile):
        os.remove(efile)
    if keepfixed:
        print input_image,efile,xcenter_cutout,ycenter_cutout,initialr,minr,maxr,ipa
        iraf.ellipse(input=input_image,output=efile,dqf=mask_image,x0=xcenter_cutout,y0=ycenter_cutout,hcenter='yes',recenter=recentervalue,sma0=initialr,minsma=minr,maxsma=maxr,pa=ipa,hpa='yes',ellip=iellip,hellip='yes',interactive='yes',step=0.1,linear='no')
                
    else:
        print "First pass, letting PA and e vary"
        print input_image,efile,xcenter_cutout,ycenter_cutout,initialr,minr,maxr,ipa,
        if mask_image == None:
            iraf.ellipse(input=input_image,output=efile,x0=xcenter_cutout,y0=ycenter_cutout,hcenter='no',recenter='yes',sma0=initialr,minsma=minr,maxsma=maxr,pa=ipa,hpa='no',ellip=iellip,hellip='no',interactive='yes',step=0.1,linear='no')
        else:
            iraf.ellipse(input=input_image,output=efile,dqf=mask_image,x0=xcenter_cutout,y0=ycenter_cutout,hcenter='no',recenter=0,sma0=initialr,minsma=minr,maxsma=maxr,pa=ipa,hpa='no',ellip=iellip,hellip='no',interactive='yes',step=0.1,linear='no')
    print 'Displaying isophotes from first pass.  Hit q in DS9 window to quit'
    iraf.isoexam(table=efile)
    try:
        os.system('rm tp.00*')
    except:
        print 'no tp.00? files to remove'
    iraf.isoimap(input_image,table=efile)
    # get final ellipse parameters to return to the user

    if os.path.exists('junk.txt'):
        os.remove('junk.txt')
    iraf.tprint(table=efile,pwidth='INDEF',showhdr='no', Stdout='junk.txt')
    s="awk '{print $2, $7, $9, $11, $13}' < "+"junk.txt > "+"junk2.txt"
    os.system(s)
    redo = 1
    while redo:

        infile=open('junk2.txt','r')
        print 'within redo loop'
        for line in infile:
            t=line.split()
            if float(t[0]) > myradius:
                #print 'got here',myradius, t[0]
                newellip=float(t[1])
                if newellip < .05: # min value that ellipse can handle
                    newellip=.05
                newPA=float(t[2])
                if newPA < -90:
                    newPA=newPA+180
                elif newPA > 90:
                    newPA = newPA-180
                
                newxcenter=float(t[3])
                newycenter=float(t[4])
                break
        infile.close()
        print 'ellipse values at r = ',myradius
        print '    ellip = ',newellip
        print '    PA = ',newPA
        t=raw_input('are you happy? (n = no, enter to continue) ')
        if t.find('n') >-1:
            newr=raw_input('Enter radius where ellipse best represents galaxy ')
            myradius=float(newr)        
        else:
            redo = 0
            continue

    if os.path.exists(efile_ascii):
        os.remove(efile_ascii)
    iraf.tprint(table=efile,pwidth='INDEF',showhdr='no', Stdout=efile_ascii)
    return newxcenter,newycenter,newellip,newPA
def measure_disk(input_image,
                 xcenter,
                 ycenter,
                 ipa,
                 iellip,
                 initialr,
                 minr,
                 maxr,
                 zp,
                 band=0,
                 nframe=1,
                 myradius=20,
                 keepfixed=0,
                 einteractive=0,
                 mask_image=None):
    print 'inside measure disk'
    print 'mask image = ', mask_image
    #myradius=initialr
    recentervalue = 'yes'
    interactivevalue = 'yes'

    print '\n Running ellipse on ', input_image, '\n'
    print ' Enter ? for a list of options \n'
    print ' Enter c to continue fitting ellipses automatically \n'
    mfile = input_image

    xcenter_cutout = xcenter
    ycenter_cutout = ycenter

    t = mfile.split('.')
    efile = t[0] + '.tab'
    efile_ascii = t[0] + '.dat'
    imprefix = t[0]
    print 'Running ellipse to fit isophotes to galaxy:', mfile
    if os.path.exists(efile):
        os.remove(efile)
    if keepfixed:
        print input_image, efile, xcenter_cutout, ycenter_cutout, initialr, minr, maxr, ipa
        iraf.ellipse(input=input_image,
                     output=efile,
                     dqf=mask_image,
                     x0=xcenter_cutout,
                     y0=ycenter_cutout,
                     hcenter='yes',
                     recenter=recentervalue,
                     sma0=initialr,
                     minsma=minr,
                     maxsma=maxr,
                     pa=ipa,
                     hpa='yes',
                     ellip=iellip,
                     hellip='yes',
                     interactive='yes',
                     step=0.1,
                     linear='no')

    else:
        print "First pass, letting PA and e vary"
        print input_image, efile, xcenter_cutout, ycenter_cutout, initialr, minr, maxr, ipa,
        if mask_image == None:
            iraf.ellipse(input=input_image,
                         output=efile,
                         x0=xcenter_cutout,
                         y0=ycenter_cutout,
                         hcenter='no',
                         recenter='yes',
                         sma0=initialr,
                         minsma=minr,
                         maxsma=maxr,
                         pa=ipa,
                         hpa='no',
                         ellip=iellip,
                         hellip='no',
                         interactive='yes',
                         step=0.1,
                         linear='no')
        else:
            iraf.ellipse(input=input_image,
                         output=efile,
                         dqf=mask_image,
                         x0=xcenter_cutout,
                         y0=ycenter_cutout,
                         hcenter='no',
                         recenter=0,
                         sma0=initialr,
                         minsma=minr,
                         maxsma=maxr,
                         pa=ipa,
                         hpa='no',
                         ellip=iellip,
                         hellip='no',
                         interactive='yes',
                         step=0.1,
                         linear='no')
    print 'Displaying isophotes from first pass.  Hit q in DS9 window to quit'
    iraf.isoexam(table=efile)
    try:
        os.system('rm tp.00*')
    except:
        print 'no tp.00? files to remove'
    iraf.isoimap(input_image, table=efile)
    # get final ellipse parameters to return to the user

    if os.path.exists('junk.txt'):
        os.remove('junk.txt')
    iraf.tprint(table=efile, pwidth='INDEF', showhdr='no', Stdout='junk.txt')
    s = "awk '{print $2, $7, $9, $11, $13}' < " + "junk.txt > " + "junk2.txt"
    os.system(s)
    redo = 1
    while redo:

        infile = open('junk2.txt', 'r')
        print 'within redo loop'
        for line in infile:
            t = line.split()
            if float(t[0]) > myradius:
                #print 'got here',myradius, t[0]
                newellip = float(t[1])
                if newellip < .05:  # min value that ellipse can handle
                    newellip = .05
                newPA = float(t[2])
                if newPA < -90:
                    newPA = newPA + 180
                elif newPA > 90:
                    newPA = newPA - 180

                newxcenter = float(t[3])
                newycenter = float(t[4])
                break
        infile.close()
        print 'ellipse values at r = ', myradius
        print '    ellip = ', newellip
        print '    PA = ', newPA
        t = raw_input('are you happy? (n = no, enter to continue) ')
        if t.find('n') > -1:
            newr = raw_input(
                'Enter radius where ellipse best represents galaxy ')
            myradius = float(newr)
        else:
            redo = 0
            continue

    if os.path.exists(efile_ascii):
        os.remove(efile_ascii)
    iraf.tprint(table=efile, pwidth='INDEF', showhdr='no', Stdout=efile_ascii)
    return newxcenter, newycenter, newellip, newPA
Beispiel #9
0
    def runEllipse24UsingSDSS(self):
        agcnumber=self.agcnumber[self.ellipseflag]
        #mcutoutpath='/home/rfinn/research/LocalClusters/MaskedCutouts/'+self.prefix+'/'
        mcutoutpath='/home/rfinn/research/LocalClusters/MaskedCutouts/'+self.prefix+'/'
        os.chdir(mcutoutpath)
        s=outpathroot+'research/LocalClusters/Ellipse24UsingSDSS/'+self.prefix
        try:
            os.mkdir(s)
        except OSError:
            pass
        for i in range(len(agcnumber)):
            print agcnumber[i]
        
            sdssEllipseTable= '/home/rfinn/research/LocalClusters/EllipseTables/'+self.prefix+'/'+self.prefix+'-'+str(agcnumber[i])+'-cutout-sdss.tab'
            #mipsImage=mcutoutpath+'m'+self.prefix+'-'+str(agcnumber[i])+'-cutout-24-rot.fits'
            mipsImage='m'+self.prefix+'-'+str(agcnumber[i])+'-cutout-24-rot.fits'
            #outim=cutoutpath+self.prefix+'-'+str(agcSpiral[i])+'-cutout-sdss.fits \n'
            os.system('rm junk.txt')
            if os.path.isfile(sdssEllipseTable):
                iraf.tprint(table=sdssEllipseTable,pwidth='INDEF',showhdr='no', Stdout='junk.txt')
                os.system("awk '{print $2, $7, $9, $11, $13}' < junk.txt > junk2.txt")
            else:
                print 'Warning: ',sdssEllipseTable,' does not exist'
                sdssEllipseTable= '/home/rfinn/research/LocalClusters/EllipseTables/'+self.prefix+'/'+self.prefix+'-'+str(agcnumber[i])+'-cutout-sdss.dat'
                s="awk '{print $2, $7, $9, $11, $13}' <"+sdssEllipseTable+" > junk2.txt"
                os.system(s)
            #run ellipse a second time, keeping PA and ellip fixed
            infile=open('junk2.txt','r')
            for line in infile:
                t=line.split()
                if float(t[0]) > myradius:
                    newellip=float(t[1])
                    if newellip < .05:#min value that ellipse can handle
                        newellip=.05
                    newPA=float(t[2])
                    if newPA < -90:
                        newPA=newPA+180
                    elif newPA > 90:
                        newPA = newPA-180
                    #11 - X0, 13 - Y0
                    newxcenter=float(t[3])
                    newycenter=float(t[4])


            t=mipsImage.split('.')
            efile=self.prefix+'-'+str(agcnumber[i])+'.24UsingSDSS.tab'
            copyefile=outpathroot+'research/LocalClusters/Ellipse24UsingSDSS/'+self.prefix+'/'+self.prefix+'-'+str(agcnumber[i])+'.24UsingSDSS.tab'


            #iraf.ellipse(input=mipsImage,output=efile,inellip=sdssEllipseTable)#trying to use sdss input
            if os.path.exists(efile):
                s=efile+' exists.  Rerun?  (y=yes, any key to skip)'
                rerunFlag=raw_input(s)
                if rerunFlag.find('y') > -1:
                    os.remove(efile)
                    iraf.ellipse(input=mipsImage,output=efile,x0=xcenter,y0=ycenter,hcenter='yes',recenter='no',sma0=initialr,minsma=minr,maxsma=maxr,pa=newPA,hpa='yes',ellip=newellip,hellip='yes')

                else:
                    continue
            else:
                iraf.ellipse(input=mipsImage,output=efile,x0=xcenter,y0=ycenter,hcenter='yes',recenter='no',sma0=initialr,minsma=minr,maxsma=maxr,pa=newPA,hpa='yes',ellip=newellip,hellip='yes')
            #outfile24=homedir+'research/LocalClusters/EllipseTables/'+self.prefix+'/'+self.prefix+'-'+str(agcSpiral[i])+'-cutout-24-rot.dat \n'

            print 'Displaying isophotes from ellipse fit.  Hit q in DS9 window to quit'
            iraf.isoexam(table=efile)
            s='cp '+efile+' '+copyefile
            print s
            os.system(s)