예제 #1
0
	def getSize(self, file):
		'''
		This function can be used to get the size of the image. It actually
		returns a simple information found from the image header, however,
		when parsed correctly the image size is available.
		'''
		self.file = file

		head = I.imheader(self.file, Stdout=1)
		return head
예제 #2
0
파일: Photometry.py 프로젝트: RainW7/SamPy
    def getSize(self, file):
        '''
		This function can be used to get the size of the image. It actually
		returns a simple information found from the image header, however,
		when parsed correctly the image size is available.
		'''
        self.file = file

        head = I.imheader(self.file, Stdout=1)
        return head
예제 #3
0
def get_image_size(images):
    result = iraf.imheader(images=images, longheader=0, Stdout=1)
    if result[0] == '':
        return None
    array = {}
    for item in result:
        res = re.search(r'(.*)\[([0-9]+),([0-9]+)\]', item)
        array[res.group(1)] = [int(res.group(2)), int(res.group(3))]

    if len(array.keys()) == 1:
        return array[array.keys()[0]]
    else:
        return array
예제 #4
0
def find_param_with_comment(filename, comment):
    header_long = iraf.imheader(filename, lo=True, Stdout=True)
    for header_val in header_long:
        trimmed = header_val.replace(' = ',
                                     '!^!^!').replace(' / ',
                                                      '!^!^!').split('!^!^!')
        if len(trimmed) < 3:
            continue
        elif trimmed[2] == comment:
            return trimmed[0]
        else:
            pass
    return 'NullReturn'
예제 #5
0
def get_comment(filename, paramname):
    header_long = iraf.imheader(filename, lo=True, Stdout=True)
    for header_val in header_long:
        trimmed = header_val.replace(' = ',
                                     '!^!^!').replace(' / ',
                                                      '!^!^!').split('!^!^!')
        if len(trimmed) < 3:
            continue
        elif trimmed[1].strip() == paramname:
            return trimmed[2].strip()
        else:
            pass
    return 'NullReturn'
예제 #6
0
def getCenter(imgs):
    ''' 
        getCenter: Uses the Iraf imcntr task to find the centers of a list of objects
        Inputs:    a list of image filenames <imgs> (see getIter()) to find the centers of.
        Outputs:   a numpy array with shape (len(imgs), 3), of the form
                                   ...         ...         ...
                                <img_name>  <center_x>  <center_y>
                                   ...         ...         ...
                   where all three fields are strings.
    '''
    out = np.full((len(imgs),3),"-1",dtype=object)
    shape_re = re.compile(r"\[(?P<rows>\d+),(?P<cols>\d+)\]")
    center_re = re.compile(r"x:\s+(?P<center_x>\d+\.\d*)\s+y:\s+(?P<center_y>\d+\.\d*)")
    for i in range(0,len(imgs)):
        header_string = iraf.imheader(imgs[i],Stdout=1)[0]
        shape = shape_re.search(header_string)
        rows,cols = -1,-1
        if shape:
            rows = int(shape.group("rows"))
            cols = int(shape.group("cols"))
        else:
            sys.exit(1)
        #end if
        center_string = iraf.imcntr(imgs[i],rows/2,cols/2,cboxsize=31, Stdout=1)[0]
        center = center_re.search(center_string)
        center_x,center_y = "-1","-1"
        if center:
            center_x = str(int(float(center.group("center_x"))))
            center_y = str(int(float(center.group("center_y"))))
        else:
            sys.exit(1)
        #end if
        out[i,0] = imgs[i]
        out[i,1] = center_x
        out[i,2] = center_y
    #end loop
    return out
예제 #7
0
             z22 = float(z22)
         _z11, _z22, goon = agnkey.util.display_image(
             'original.fits', 1, z11, z22, False)
         answ = raw_input(">>>>> Cuts OK [y/n] [y]?")
         if not answ:
             answ = 'y'
         elif answ == 'no':
             answ = 'n'
         z11 = float(_z11)
         z22 = float(_z22)
     #        else:
     #            z11=float(_z11)
     #            z22=float(_z22)
 if not _interactive and xx0:
     _dimension = string.split((string.split(
         iraf.imheader('original', Stdout=1)[0], ']')[0]),
                               '[')[1]
     aa, bb = string.split(_dimension, ',')
     aa, bb = float(aa) / 2, float(bb) / 2
     _vec = str(aa) + '  ' + str(bb) + '  1'
     vector = [_vec]
     ff = open('tmplabel', 'w')
     for i in vector:
         ff.write(i + ' \n')
     ff.close()
     if _show:
         iraf.tvmark(1, 'tmplabel', autol='no', mark="circle", radii=10, inter='no', label='no',
                     number='yes', \
                     pointsize=20, txsize=2, color=204)
     os.system('cp tmplabel ' + img + '.sn.coo')
 else:
예제 #8
0
파일: trace.py 프로젝트: georgezhou/hsfu23
def extract(image,trace,sigma,bk):

    if sigma < 1.:
        sigma = 1.

    #sigma = sigma*2
    #print sigma,"sigma"

    original_file = pyfits.open(image)
    original_header = iraf.imheader(images=image,longheader=1,Stdout=1)

    image = pyfits.getdata(image)
    image = transpose(image)

    line = []
    peak = []

    step = 200

    i = 0
    while i < len(image):
        crop = image[i]

        bk_i = []
        signal_i = []

        ### uncomment this to see where the extraction is taking place

        # plt.plot(crop)
        # plt.axvline(x=trace[i])
        # plt.show()

        x = arange(0,len(crop)+0.1-1,0.1)
        y = interpolate.interp1d(arange(0,len(crop)),crop)
        y = y(x)
        weights = []

        for j in range(len(x)):
            for n in bk:
                if x[j] > n[0] and x[j] < n[1]:
                    bk_i.append(y[j])
            
            if x[j] > trace[i] - sigma and x[j] < trace[i] + sigma:
                signal_i.append(y[j])

                weights.append(gaussian([1,trace[i],sigma,0],x[j]))

        if len(bk_i) > 0:
            bk_i = median(bk_i)
        else:
            bk_i = 0

        if len(signal_i) > 0:
            pass
        else:
            signal_i = [0]
            weights = [1]

        signal_i = array(signal_i)
        weights = array(weights)

        line.append(i+1)
        peak.append(sum(signal_i)-bk_i*len(signal_i))
        #peak.append(sum(signal_i*weights)-sum(bk_i*weights))

        i = i + 1    

    ### Uncomment to plot spectrum
    # plt.clf()
    # plt.plot(line,peak)
    # plt.show()

    data = transpose(array([line,peak]))
    f = open("spectrum.flux","w")
    functions.write_table(data,f)
    f.close()

    os.system("rm spectrum.fits")
    iraf.rspectext(
        input = "spectrum.flux",\
        output = "spectrum.fits",\
        title = "",\
        flux = 0,\
        dtype = "interp")
    
    update_fitsheader(original_header,original_file,"spectrum.fits")
    original_file.close()
예제 #9
0
iraf.hedit('master$dark', 'EXPTIME,EXPOSURE', 1, update='yes', ver='no')

###############################################################################
# Make comment

if not noReduce:
    iraf.hedit('master$dark',
               'OBS_I',
               'Combined darks, bias removed',
               add='yes',
               ver='no')

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

print
iraf.imstat.unlearn()
iraf.imstat.setParam('fields', 'image,npix,mean,midpt,mode,stddev,min,max')
iraf.imstat('RAW$@list$dark,T$@list$dark,master$dark-uns,master$dark')

###############################################################################
# Dump the relevant information to the log

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

print 'darkcombine parameters'
print
iraf.ccdred.darkcombine.lParam()
print
iraf.imheader('master$dark', longheader='yes')
예제 #10
0
iraf.ccdred.zerocombine('RAW$@list$bias', output='master$bias')

###############################################################################
# Make comment

iraf.hedit('master$bias',
           'OBS_I',
           'Combined biases 1, 2 and 3',
           add='yes',
           ver='no')

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

print
iraf.imstat.unlearn()
iraf.imstat.setParam('fields', 'image,npix,mean,midpt,mode,stddev,min,max')
iraf.imstat('RAW$@list$bias,master$bias')

###############################################################################
# Dump the relevant information to the log

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

print
print 'zerocombine parameters'
print
iraf.ccdred.zerocombine.lParam()
print
iraf.imheader('master$bias', longheader='yes')
예제 #11
0
    ###########################################################################
    # Make comment

    if not config.noReduce:
        iraf.hedit('master$norm-flat-' + filter,
                   'OBS_I',
                   'Combined flats, bias removed',
                   add='yes',
                   ver='no')

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

    print
    iraf.imstat('RAW$@list$flat-' + filter + ',' + 'T$@list$flat-' + filter +
                ',' + 'master$flat-' + filter + ',' + 'master$norm-flat-' +
                filter,
                fields='image,npix,mean,midpt,mode,stddev,min,max')

    ###########################################################################
    # Dump the relevant information to the log

    sys.stdout = open('log/4.' + filter + '.log', 'w')

    print 'flatcombine parameters'
    print
    iraf.ccdred.flatcombine.lParam()
    print
    iraf.imheader('master$norm-flat-' + filter, longheader='yes')

    sys.stdout = oldstdout
예제 #12
0
파일: agnsn.py 프로젝트: svalenti/agnkey
             z22 = _z22
         else:
             z22 = float(z22)
         _z11, _z22, goon = agnkey.util.display_image('original.fits', 1, z11, z22, False)
         answ = raw_input(">>>>> Cuts OK [y/n] [y]?")
         if not answ:
             answ = 'y'
         elif answ == 'no':
             answ = 'n'
         z11 = float(_z11)
         z22 = float(_z22)
     #        else:
     #            z11=float(_z11)
     #            z22=float(_z22)
 if not _interactive and xx0:
     _dimension = string.split((string.split(iraf.imheader('original', Stdout=1)[0], ']')[0]), '[')[1]
     aa, bb = string.split(_dimension, ',')
     aa, bb = float(aa) / 2, float(bb) / 2
     _vec = str(aa) + '  ' + str(bb) + '  1'
     vector = [_vec]
     ff = open('tmplabel', 'w')
     for i in vector:
         ff.write(i + ' \n')
     ff.close()
     if _show:
         iraf.tvmark(1, 'tmplabel', autol='no', mark="circle", radii=10, inter='no', label='no',
                     number='yes', \
                     pointsize=20, txsize=2, color=204)
     os.system('cp tmplabel ' + img + '.sn.coo')
 else:
     answ0 = 'n'
예제 #13
0
""" This file is meant to be run by itself, demonstrating the Python-to-IRAF
API for use in testing, starting with the very simplest of function calls.
This test is useful in special installations, such as one without IRAF. """

import sys
print("Simple #1 - about to: from pyraf import iraf ...")
from pyraf import iraf
print("Simple #2 - about to import pyraf ...")  # should be essentially a no-op
import pyraf
print("Simple #3 - ver is ...")
print(pyraf.__version__)
print("Simple #4 - pwd is ...")
iraf.pwd()  # will print
print("Simple #5 - has IRAF is ...")
from pyraf import irafinst
print(str(irafinst.EXISTS))
if not irafinst.EXISTS:
    sys.exit(0)

print("Simple #6 - files output is ... (the rest require IRAF)")
iraf.files('file_a.txt,file-b.txt,file.c.txt,,filed.txt')
print("Simple #7 - loading imutil")
iraf.images(_doprint=0)  # load images
iraf.imutil(_doprint=0)  # load imutil
print("Simple #8 - imaccess to dev$pix is ...")
print(iraf.imaccess("dev$pix"))
print("Simple #9 - imheader of dev$pix is ...")
iraf.imheader("dev$pix")

sys.exit(0)
예제 #14
0
    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')

sys.stdout = oldstdout
예제 #15
0
""" This file is meant to be run by itself, demonstrating the Python-to-IRAF
API for use in testing, starting with the very simplest of function calls.
This test is useful in special installations, such as one without IRAF. """

import sys
print("Simple #1 - about to: from pyraf import iraf ...")
from pyraf import iraf
print("Simple #2 - about to import pyraf ...") # should be essentially a no-op
import pyraf
print("Simple #3 - ver is ...")
print(pyraf.__version__)
print("Simple #4 - pwd is ...")
iraf.pwd() # will print
print("Simple #5 - has IRAF is ...")
from pyraf import irafinst
print(str(irafinst.EXISTS))
if not irafinst.EXISTS:
   sys.exit(0)

print("Simple #6 - files output is ... (the rest require IRAF)")
iraf.files('file_a.txt,file-b.txt,file.c.txt,,filed.txt')
print("Simple #7 - loading imutil")
iraf.images(_doprint=0) # load images
iraf.imutil(_doprint=0) # load imutil
print("Simple #8 - imaccess to dev$pix is ...")
print(iraf.imaccess("dev$pix"))
print("Simple #9 - imheader of dev$pix is ...")
iraf.imheader("dev$pix")

sys.exit(0)