Ejemplo n.º 1
0
def align_combine(fitsdir, myfilter, examine=True):
    from pyraf import iraf 
    
    iraf.noao(_doprint=0)
    iraf.digiphot(_doprint=0)
    iraf.apphot(_doprint=0)
    
    os.chdir(fitsdir)
    listfiles = glob.glob(myfilter)
    listfiles.sort()
    
    if (examine):
        print "Opening ",listfiles[0]," to examine."
        iraf.imexamine(input=listfiles[0], \
                    logfile="coords.dat", \
                    keeplog="yes")
        
        with open("align.list",'w') as f:
            for i in listfiles:
                f.write(i+"\n")
    
    print "Aligning with reference:",listfiles[0]
    iraf.imalign( input   =  "@align.list", referenc= listfiles[0], coords  =  "coords.dat", output  = "*****@*****.**")  
    
    listfiles = glob.glob("a_"+myfilter)
    listfiles.sort()
    with open("comb.list",'w') as f:
        for i in listfiles:
            f.write(i+"\n")
            
    print "Combining"        
    iraf.imcombine(input = "@comb.list",\
                   output = "out.fits",\
                   combine= "median")
Ejemplo n.º 2
0
def align_combine(fitsdir, myfilter, examine=True):
    from pyraf import iraf 
    
    iraf.noao(_doprint=0)
    iraf.digiphot(_doprint=0)
    iraf.apphot(_doprint=0)
    
    os.chdir(fitsdir)
    listfiles = glob.glob(myfilter)
    listfiles.sort()
    
    if (examine):
        print "Opening ",listfiles[0]," to examine."
        iraf.imexamine(input=listfiles[0], \
                    logfile="coords.dat", \
                    keeplog="yes")
        
        with open("align.list",'w') as f:
            for i in listfiles:
                f.write(i+"\n")
    
    print "Aligning with reference:",listfiles[0]
    iraf.imalign( input   =  "@align.list", referenc= listfiles[0], coords  =  "coords.dat", output  = "*****@*****.**")  
    
    listfiles = glob.glob("a_"+myfilter)
    listfiles.sort()
    with open("comb.list",'w') as f:
        for i in listfiles:
            f.write(i+"\n")
            
    print "Combining"        
    iraf.imcombine(input = "@comb.list",\
                   output = "out.fits",\
                   combine= "median")
Ejemplo n.º 3
0
def align(location):
    inputlist(location)
    outputlist(location)
    ref_image = glob.glob(location + "/*_ref_A_.fits")
    input_list = glob.glob(location + "/inputs*")
    output_list = glob.glob(location + "/outputs*")
    coordinates = glob.glob(location + "/*.coo")
    if input_list == []:
        print("no input list found")
    elif output_list == []:
        print("no output list found")
    elif coordinates == []:
        print("no coordinate list found")
    elif ref_image == []:
        print("no reference image found")
    elif len(input_list) > 1:
        print("too many input lists")
    elif len(output_list) > 1:
        print("too many ouptut lists")
    elif len(coordinates) > 1:
        print("too many coordinate lists")
    elif len(ref_image) > 1:
        print("too many reference images")
    else:
        try:
            ref_image = ref_image[0]
            input_list = "@" + input_list[0]
            output_list = "@" + output_list[0]
            coordinates = coordinates[0]
            iraf.imalign(input=input_list, reference=ref_image, coords=coordinates, output=output_list, boxsize = 20, bigbox = 30)
            images = glob.glob(location + "/*_N_.fits")
            for i in images:
                os.system("mv %s %s/sdi/archive/data" % (i, loc))
            print("alignment successful!")
            print("moved non-aligned _N_ images to sdi archive")
        except iraf.IrafError:
            print("alignment failed, check parameters")
Ejemplo n.º 4
0
def alignImages(imageName, imageName_Ha):
    #Read the fwhm and seeing from the image file
    imageHeader = fits.open(imageName + ".fits")[0]
    fwhm = imageHeader.header['SEEING']
    annul = 5.0 * fwhm
    aper = 3.0 * fwhm
    sigma = imageHeader.header['SKYSIGMA']
    iraf.daophot(_doprint=0)
    #Do 'daofind' on the image to locate the stars
    print("1. Find stars using 'daofind'")

    #Configure 'datapars', 'findpars', and 'daofind'

    iraf.datapars.fwhmpsf = fwhm
    iraf.datapars.sigma = sigma
    iraf.datapars.datamin = -10
    iraf.datapars.ccdread = "RDNOISE"
    iraf.datapars.gain = "GAIN"
    iraf.datapars.exposure = "EXPTIME"
    iraf.datapars.airmass = "AIRMASS"
    iraf.datapars.filter = "FILTER"
    iraf.datapars.obstime = "TIME-OBS"

    iraf.findpars.threshold = 20 * sigma
    iraf.findpars.sharplo = 0.2
    iraf.findpars.sharphi = 1.0
    iraf.findpars.roundlo = -1.0
    iraf.findpars.roundhi = 1.0
    iraf.daofind.verify = 'no'
    iraf.daofind.verbose = 'no'

    #Delete exisiting coordinate,output files of 'phot',file containg data of 'good' stars, old images
    for f in ("coord", "mag", "psel", "R_final.fits", "Ha_final.fits"):
        silentDelete(f)

    iraf.daofind(imageName, 'coord')

    print("File containing the coordinates of the stars is coord")

    print(" ")
    #Configure 'centerpars', 'fitskypars','photpars'
    iraf.datapars.datamax = 150000
    iraf.centerpars.calgorithm = "centroid"
    iraf.centerpars.cbox = 16
    iraf.centerpars.maxshift = 3

    iraf.fitskypars.salgorithm = "mode"
    iraf.fitskypars.annulus = annul
    iraf.fitskypars.dannulus = 10

    iraf.photpars.apertures = aper

    iraf.phot.verify = 'no'
    iraf.phot.verbose = 'no'

    print("2. Obtain data of stars using 'phot'")
    #Call 'phot' to get the data of the stars
    iraf.phot(imageName, 'coord', 'mag')

    #sort in order of increasing magnitude of stars
    iraf.psort('mag', "mag")
    boundsig = sigma + 2
    boexpr = "CIER==0 && PIER==0 && STDEV <=" + str(boundsig)
    print(
        "File containing the data of the stars in order of decreasing brightness is mag"
    )

    print(" ")

    print("3. Select stars with low error, no bad pixels")
    #Select stars that have no centering error, skyerror <sig+2 and no bad pixels
    iraf.pselect("mag", "psel", boexpr)

    print(
        "File containing stars with low sky error,low centering error is psel")
    print(" ")

    #Renumber the ID number of the stars in order of increasing magnitude
    iraf.prenumber("psel")

    #Delete existing files
    for f in ("pdump.file", "stars25", 'alR.fits', 'rIn.fits', 'haIn.fits'):
        silentDelete(f)

    print("4. Select the 25 brightest stars")
    iraf.pselect("psel", "stars25", "ID <=25")

    print("File containing the brightest 25 'good' stars is stars25")
    print(" ")

    #Pick out only the required data of stars from the .25 file
    sys.stdout = open("pdump.file", "w")
    iraf.pdump("stars25", "xcenter,ycenter,flux", "yes")
    sys.stdout = sys.__stdout__

    print("The coordinates and flux are stored in pdump.file")

    #Align images
    iraf.imcopy(imageName, 'rIn')
    iraf.imcopy(imageName_Ha, 'haIn')
    print("Aligning images")
    #iraf.imalign.verbose='no'
    iraf.imalign("rIn,haIn", "rIn", "pdump.file", "R_final,Ha_final")
Ejemplo n.º 5
0
            imgs2align=open('imgs2align.list','w')
            imgs2alignOUT=open('imgs2alignOUT.list','w')
            for j in imgINP:
                imgs2align.write(images[j]+'\n')
                imgs2alignOUT.write('s'+images[j]+'\n')
        #       inVAR=inVAR+','+images[j]
        #       outVAR=outVAR+',s'+images[j]
            imgs2align.close()
            imgs2alignOUT.close()
     #      inVAR=inVAR[1:]    # To remove leading comma
     #      outVAR=outVAR[1:]
            inVAR="@imgs2align.list"
            outVAR="@imgs2alignOUT.list"

            try :
                iraf.imalign(input=inVAR, reference=Refimage, coords=Refimage+".coo", output=outVAR, shifts="shifts.in", interp_type="nearest",boundary_type="constant",trimimages="no")
                ask=raw_input('Do you want to combine these images? [Enter _y_ for yes]: ')
                if ask == "y" : 
                    name=raw_input('Enter name for the combined image without .fits extension: ')
                    iraf.imcombine(input=Refimage+','+outVAR, output=name+'.fits',combine="average")
                else : print ("No combining done..\n")
            except iraf.IrafError, e :
                print ('IRAF ERROR : Some image might be having problem. Remove it and try')
                print e
                print('-'*60)
                traceback.print_exc(file=sys.stdout)
                print('-'*60)



    print ('Moving to next directory\n')
Ejemplo n.º 6
0
        else:
            listfile.write(j + "\n")
            comfile.write('shifted_' + j + "\n")
            shiftfile.write('%d\t%d\n' %
                            (im_info[i][j]['dx'], im_info[i][j]['dy']))
            mjds.append(im_info[i][j]['mjd'])

    im_info[i]['mjd'] = np.mean(mjd)

    listfile.close()
    shiftfile.close()
    comfile.close()

    iraf.imalign(input='@imagelist.txt',
                 reference=refim,
                 coords='refcoords.txt',
                 output='shifted_//@imagelist.txt',
                 shifts='shifts.txt')

    iraf.imcombine(input='@comlist.txt',
                   output='stack_' + refim,
                   combine='median',
                   offsets='none')

######################################

#
# for i in im_info:
#
#     filtername = i
#
Ejemplo n.º 7
0
                    imgs2align.write(images[j] + '\n')
                    imgs2alignOUT.write('s' + images[j] + '\n')
#                   inVAR=inVAR+','+images[j]
#                   outVAR=outVAR+',s'+images[j]
                imgs2align.close()
                imgs2alignOUT.close()
                #                inVAR=inVAR[1:]    # To remove leading comma
                #                outVAR=outVAR[1:]
                inVAR = "@imgs2align.list"
                outVAR = "@imgs2alignOUT.list"

                try:
                    iraf.imalign(input=inVAR,
                                 reference=Refimage,
                                 coords=Refimage + ".coo",
                                 output=outVAR,
                                 shifts="shifts.in",
                                 interp_type="nearest",
                                 boundary_type="constant",
                                 trimimages="no")
                    ask = raw_input(
                        'Do you want to combine these images? [Enter _y_ for yes]: '
                    )
                    if ask == "y":
                        name = raw_input(
                            'Enter name for the combined image without .fits extension: '
                        )
                        iraf.imcombine(input=Refimage + ',' + outVAR,
                                       output=name + '.fits',
                                       combine="average")
                    else:
                        print("No combining done..\n")
print l1
f.close()

santinizeOut('bdfa')
import stsci.tools.irafglobals

cnt = 0
boxsize = 11
bigbox = 15
maxcnt = 8
while cnt < maxcnt:
    try:
        iraf.imalign(input='@llist//-bdf',
                     reference=l1,
                     coords='images.coord',
                     output='@llist//-bdfa',
                     shifts='coord.shift',
                     boxsize=boxsize,
                     bigbox=bigbox)
    except stsci.tools.irafglobals.IrafError:
        cnt += 1
        boxsize += 10 + 3 * cnt
        bigbox += 10 + 3 * cnt
    else:
        break

if cnt >= maxcnt:
    sys.exit(1)
"""

iraf.noao.imred()
Ejemplo n.º 9
0
def alignImages(imageName,imageName_Ha):
  #Read the fwhm and seeing from the image file
  imageHeader = fits.open(imageName+".fits")[0]
  fwhm = imageHeader.header['SEEING']
  annul = 5.0 * fwhm
  aper=3.0 * fwhm
  sigma = imageHeader.header['SKYSIGMA']
  iraf.daophot(_doprint=0)
  #Do 'daofind' on the image to locate the stars
  print("1. Find stars using 'daofind'")
  
  #Configure 'datapars', 'findpars', and 'daofind'
  
  iraf.datapars.fwhmpsf=fwhm
  iraf.datapars.sigma=sigma
  iraf.datapars.datamin=-10
  iraf.datapars.ccdread="RDNOISE"
  iraf.datapars.gain="GAIN"
  iraf.datapars.exposure="EXPTIME"
  iraf.datapars.airmass="AIRMASS"
  iraf.datapars.filter="FILTER"
  iraf.datapars.obstime="TIME-OBS"

  iraf.findpars.threshold=20*sigma
  iraf.findpars.sharplo=0.2
  iraf.findpars.sharphi=1.0
  iraf.findpars.roundlo=-1.0
  iraf.findpars.roundhi=1.0
  iraf.daofind.verify='no'
  iraf.daofind.verbose='no'

  #Delete exisiting coordinate,output files of 'phot',file containg data of 'good' stars, old images
  for f in("coord","mag","psel","R_final.fits","Ha_final.fits"):
    silentDelete(f)

  iraf.daofind(imageName,'coord')

  print("File containing the coordinates of the stars is coord")


  print(" ")
  #Configure 'centerpars', 'fitskypars','photpars'
  iraf.datapars.datamax=150000
  iraf.centerpars.calgorithm="centroid"
  iraf.centerpars.cbox=16
  iraf.centerpars.maxshift=3

  iraf.fitskypars.salgorithm="mode"
  iraf.fitskypars.annulus=annul
  iraf.fitskypars.dannulus=10

  iraf.photpars.apertures=aper

  iraf.phot.verify='no'
  iraf.phot.verbose='no'

  print("2. Obtain data of stars using 'phot'")
  #Call 'phot' to get the data of the stars 
  iraf.phot (imageName,'coord','mag')

  #sort in order of increasing magnitude of stars
  iraf.psort('mag',"mag")
  boundsig=sigma+2
  boexpr="CIER==0 && PIER==0 && STDEV <="+str(boundsig)  
  print("File containing the data of the stars in order of decreasing brightness is mag")

  print (" ")

  print("3. Select stars with low error, no bad pixels")
  #Select stars that have no centering error, skyerror <sig+2 and no bad pixels
  iraf.pselect ("mag" ,"psel" ,boexpr)

  print("File containing stars with low sky error,low centering error is psel")
  print(" ")

  #Renumber the ID number of the stars in order of increasing magnitude
  iraf.prenumber ("psel")


  #Delete existing files
  for f in ("pdump.file","stars25",'alR.fits','rIn.fits','haIn.fits'):
    silentDelete(f)

  print("4. Select the 25 brightest stars")
  iraf.pselect ("psel","stars25", "ID <=25")

  print("File containing the brightest 25 'good' stars is stars25")
  print(" ")

  #Pick out only the required data of stars from the .25 file
  sys.stdout=open("pdump.file","w")
  iraf.pdump ("stars25","xcenter,ycenter,flux","yes")
  sys.stdout = sys.__stdout__
  
  print("The coordinates and flux are stored in pdump.file")
  
  #Align images
  iraf.imcopy(imageName,'rIn')
  iraf.imcopy(imageName_Ha,'haIn')
  print("Aligning images")
  #iraf.imalign.verbose='no'
  iraf.imalign("rIn,haIn", "rIn","pdump.file","R_final,Ha_final")
Ejemplo n.º 10
0
for line in open(config.root + 'list/science.comb', 'r').readlines():

    fn = line.rstrip()
    ref = open(config.root + 'list/' + fn).readline().rstrip()

    print
    print "Aligning science frames for " + fn + " relto " + ref + "..."

    iraf.imdelete("OUT$@list$" + fn)

    iraf.imalign(input='INP$@list$' + fn,
                 reference='INP$' + ref,
                 coords='align$' + fn + '.coords',
                 output='OUT$@list$' + fn,
                 shifts='align$' + fn + '.shift',
                 niterate=config.align_niter,
                 trimimages=config.align_trim,
                 boxsize=config.align_boxsize,
                 bigbox=config.align_bigbox,
                 interp_type=config.align_interp)

###############################################################################
# Show what we have done

sys.stdout = open('log/5.log', 'w')

print 'imalign parameters'
print
iraf.imalign.lParam()
print
iraf.imheader('OUT$*', longheader='yes')
Ejemplo n.º 11
0
def align_images():
    """Search directories for data images and align them using pyraf imalin.
    
    The images aligned correspond to the same object.
    One of the images belonging to the set along with the set of x,y 
    coordinates of the images are used to perform the alignment.
    The images aligned are stored in new files to keep the original ones.
    
    """
    
    logging.info("Aligning images ...")
    
    # Set the parameters needed to perform imalign.
    set_align_pars()

    # Variable to count the total number of images and the image aligned
    number_of_images = 0
    number_of_images_aligned = 0

    # Walk from current directory.
    for path,dirs,files in os.walk('.'):

        # Inspect only directories without subdirectories.
        if len(dirs) == 0:
            split_path = path.split(os.sep)

            # Check if current directory is for data images.
            # Only files in these directories are processed.
            if split_path[-2] == DATA_DIRECTORY:
                
                # Get the full path of the directory.                
                full_dir = path
                
                logging.debug("Found a directory for data images: " + full_dir)

                # Get the list of catalog files ignoring hidden files.
                files_full_path = \
                    [f for f in glob.glob(os.path.join(full_dir, "*." + \
                                                       CATALOG_FILE_EXT)) \
                    if not os.path.basename(f).startswith('.')]
                    
                logging.debug("Found " + str(len(files_full_path)) + 
                              " catalog files")
                
                # Get the list of unique catalog names.
                # Each object could have several images, each one with a
                # catalog file, only a catalog file is needed by object,
                # so get a generic catalog name for each object.
                catalog_names = \
                    [ os.path.basename(f[0:f.find(DATANAME_CHAR_SEP)]) \
                     for f in files_full_path ]

                logging.debug("Catalogs: " + str(catalog_names))

                # Align the images corresponding to each catalog.
                for cn in catalog_names:
                    data_images = \
                        [f for f in glob.glob(os.path.join(full_dir, \
                        cn + "*" + DATA_FINAL_PATTERN)) \
                        if not os.path.basename(f).startswith('.')]

                    if len(data_images) > 1:
                        
                        # Count all these images.
                        number_of_images += len(data_images)

                        # Sort the images by name.
                        data_images.sort()

                        # The reference image is the first one.
                        reference_image = data_images[0]
                        
                        # Remove the first image from the list to align.
                        data_images = data_images[1:]

                        # Get the names of the aligned images.
                        align_images = \
                            [s.replace(DATA_FINAL_PATTERN, DATA_ALIGN_PATTERN) \
                             for s in data_images ]

                        catalog = reference_image.replace(DATA_FINAL_PATTERN, \
                                                          "." + \
                                                          CATALOG_FILE_EXT)
                        
                        # Perform imalign on images one by one.
                        for i in range(len(data_images)):
                            
                            image = data_images[i]
                            aligned_image = align_images[i]

                            try:
                                iraf.imalign(image, reference_image, catalog, \
                                             aligned_image, Stdout=1)
                                
                                # Count this image as successfully aligned.
                                number_of_images_aligned += 1
                                
                            except iraf.IrafError as exc:
                                logging.error("Error executing imalign " + \
                                              "on image: " + image)
                                logging.error("Iraf error is: " + str(exc))   
                    else:
                        logging.debug("Only 1 data image, alignment is not " + \
                                      "necessary.")

    logging.info("Align - Total number of images: " + str(number_of_images))
    logging.info("Align - Number of images successfully aligned: " + \
                 str(number_of_images_aligned))