Exemplo n.º 1
0
def do_pedsub( pedparname, Trl, pedtrlname, file_1, file_2, kwpars, saapername):
    """ Call pedsub

    @param pedparname: parameter file name
    @type pedparname: string
    @param Trl: trailer file name
    @type Trl: string
    @param pedtrlname: pedsub's trailer file name
    @type pedtrlname: string
    @param file_1: name of input cal file
    @type file_1: string
    @param file_2: name of output ped file
    @type file_2: string
    @param kwpars: keyword params for pedsub
    @type kwpars: dict
    @param saapername: name of file for SAA persistence image
    @type saapername: string
    """
    pedsub_complete='=== PEDSUB finished'

    # Timestamp the trailer file
    Trl.write(_timestamp('PEDSUB starting with paramas from %s'%pedparname))

    # Run pedsub with output directed to special file
    iraf.flprcache()
    iraf.pedsub.unlearn()
    iraf.pedsub(input = file_1, output = file_2, Stdout = pedtrlname, **kwpars)

    # Examine task output & append to trailer file
    pedout = open( pedtrlname )

    for line in pedout:
            Trl.write( line )
    pedout.close()

    os.remove(pedtrlname)

    if not line.startswith(pedsub_complete):
        raise PedsubError
Exemplo n.º 2
0
def imgets(img, field):
    iraf.flprcache()
    iraf.flprcache()
    iraf.imgets(img, field)
    return iraf.imgets.value
Exemplo n.º 3
0
def imgets(img,field):
   iraf.flprcache()
   iraf.flprcache()
   iraf.imgets(img,field)
   return iraf.imgets.value
Exemplo n.º 4
0
def coaddImages(workdir, coaddfile=None, method='median'):
    '''
    Combine aligned images, masking out bad pixels using transformed
    masks

    @parameter coaddfile path to output coadded file to be produced by
    this method. None defaults to the workdir.
    
    @parameter method Method for combining images. See IRAF's imcombine
    for additional options
    '''

    print "Reading database..."
    db = readpickle(os.path.join(workdir, "db.pkl"))
    rejectimages = []
    for image in db:
        ## reject images with unphysical transformations.
        ##  e.g., those rotated too much
        if image['geomapangle'] > 15. and image['geomapangle'] < 345:
            image['okforalignment'] = False
            rejectimages.append(image['rawimgname'])

    db = [image for image in db if image['okforalignment'] == True]
    if len(db) == 0:
        print "Cannot continue, no matching images!"
        return

    print "Ok, we have %i images to combine." % len(db)

    curdir = os.getcwd()
    os.chdir(workdir)

    if coaddfile is None:
        coaddfile = 'coadd.fits'

    starttime = datetime.now()

    iraf.images()
    iraf.immatch()
    inputimages = []
    outnames = []

    ## sub-grouping the files
    numberofGroups = int(len(db) / 30.) + 1
    for i in range(numberofGroups - 1):
        inputimages.append(','.join(
            [image['aliimgname'] for image in db[i * 30:(i + 1) * 30]]))
        outnames.append(coaddfile + '_{0}.fits'.format(i))

    if len(db) % 30 != 0:
        ## handling the remaining not-grouped files
        inputimages.append(','.join(
            [image['aliimgname'] for image in db[(numberofGroups - 1) * 30:]]))
        outnames.append(coaddfile + '_{0}.fits'.format(numberofGroups - 1))
    print "divied the images in {} groups".format(numberofGroups)

    for i in range(len(inputimages)):
        iraf.flprcache()
        iraf.imcombine(input=inputimages[i],
                       output=outnames[i],
                       combine=method,
                       masktype='goodvalue')
    iraf.flprcache()
    iraf.imcombine(input=outnames[i],
                   output=coaddfile,
                   combine=method,
                   masktype='goodvalue')

    print "- " * 40
    endtime = datetime.now()
    timetaken = nicetimediff(endtime - starttime)

    os.chdir(curdir)

    print "Dear user, I'm done with the alignment. I did it in %s." % timetaken
    print "The following are rejected: \n{0}".format(rejectimages)
    ## Update the db :
    writepickle(db, os.path.join(workdir, "db.pkl"))
Exemplo n.º 5
0
			print "Central reference pixel is: ", central_pixel

			shift = peak_pos - central_pixel
			print "Shift between two images is: ",shift

			if shift != 0: #this should always be the case bc we know it's tilted but I ran into this when the sample size was small
				slope = (line2y2 - line1y2) / shift 
			


			#this is where I will be copying the image over row-by-row; the iterator is moving up in rows
			#now I can't actually 'slide' a row, since the image section I have to put it into needs to be the same size. I'll have to select only the part of the image I need (not-selecting the amount determined from the tilt) and copy that over to the full sized row <-- hopefully this will automatically pad it with 0's, otherwise I may have to make it up some how? Otherwise, when the skyline is straight the slit as a whole will be tilted, and I don't think I can go past the already existing boundaries of the slit I'm copying into. 

			#The y_expansion factor is here because the slit_width doesn't reflect the iraf.blkrep change
			for row in range(2,int(mod_slit_width)+2): #that range bc IRAF starts at 1 and need to reach slit end
				iraf.flprcache()
				new_y1 = row-1
				new_y2 = row
				try:
#If there is a negative slope, I correct the tilt by altering the x1 from image2. In this case, as I increase in y, the correction needs to push the rows to the right. To do that I can copy the full row from image1 to start at the corrected position in image2.

		#the correction is just inverting the slope-intercept form of y = mx + b to solve for x (which is (y-b)/m = x)
					if slope < 0:
						correction = row / -slope
						corrected_x1 = round(secx1 + correction) #coordinate x1 position of where row goes to in image2
						#corrected_x2 = secx2 - corrected_x1 #so the image end fits just to the end of image2
						image1 = '%s[%d][%d:%d,%d:%d]' % (filename,ext_num,secx1,mod_secx2,new_y1,new_y2)
						image2 = '%s[%d][%d:%d,%d:%d]' % (corrected_file,ext_num,corrected_x1,mod_secx2,new_y1,new_y2)
						imcopy_output = iraf.imcopy(image1,image2, Stdout=1)
						imcopy_log.write('%s\n' % imcopy_output)
						#does this make the x-dimension of the corrected slit less than 6218?