예제 #1
0
파일: agnspecred.py 프로젝트: jsamu/AGNKEY
def correlate():
    scilist = glob.glob('AGN*EX.fits')
    stdlist = glob.glob('STD*EX.fits')
    lamps = glob.glob('LAMP*EX.fits')

    for img in lamps:
        hdu = pyfits.getheader(img)
        if hdu['HIERARCH ESO DPR TECH'] == 'SPECTRUM':
            specref = img.rsplit('.fits',1)[0]
        elif hdu['HIERARCH ESO DPR TECH'] == 'MOS':
            mosref = img.rsplit('.fits',1)[0]



    for spec in scilist:
        spec = spec.rsplit('.fits',1)[0]
        iraf.refspectra(spec,references=specref,sort='',group='',confirm='no',assign='yes')
        name = spec.rsplit('_EX',1)[0]+'_EL'
        iraf.dispcor(spec,output=name)

    for spec in stdlist:
        spec = spec.rsplit('.fits',1)[0]
        iraf.refspectra(spec,references=mosref,sort='',group='',confirm='no',assign='yes')
        name = spec.rsplit('_EX',1)[0]+'_EL'
        iraf.dispcor(spec,output=name)
예제 #2
0
def wl_cal(filename, outname, cals):
    print 'run wavelength calibration...'
    if os.path.isfile(outname):
        print 'file %s is already exist' % outname
    else:
        iraf.imred()
        iraf.specred()
        print 'The calibration file is listed below:'
        for i in xrange(len(cals)):
            print i, cals[i], get_fits_objname(cals[i])
        valget = 0
        if len(cals) > 1:
            valget = raw_input('Which one are you want to use?:')
            while type(eval(valget)) != int:
                valget = raw_input('input is not a int type, please reinput:')
            valget = int(valget)
        iraf.refspectra(input = filename
                , references = cals[valget], apertures = '', refaps = ''
                , ignoreaps = True, select = 'interp', sort = ''
                , group = '', time = False, timewrap = 17.0
                , override = False, confirm = True, assign = True
                , logfiles = 'STDOUT,logfile', verbose = False, answer = 'yes')
        print 'make file ' + outname + '...'
        iraf.dispcor(input = filename
                , output = outname, linearize = True, database = 'database'
                , table = '', w1 = 'INDEF', w2 = 'INDEF', dw = 'INDEF'
                , nw = 'INDEF', log = False, flux = True, blank = 0.0
                , samedisp = False, ignoreaps = True
                , confirm = False, listonly = False, verbose = True
                , logfile = '')
    print 'splot %s' % outname
    iraf.splot(images = outname)
예제 #3
0
def thar_ref(object_b_fn_ec, wave_ref, colour):
# Import IRAF modules:
  iraf.noao(_doprint=0)
  iraf.onedspec(_doprint=0)
#  iraf.echelle(_doprint=0)
  parList = "wavelength_calibration_refspectra.par"
  if os.path.isfile(object_b_fn_ec) == True:
    if os.path.isfile(wave_ref) == True:
      if os.path.isfile(parList) == True:
# Assign reference spectra to input object spectra using IRAF task refspectra:
        iraf.refspectra.setParList(ParList="wavelength_calibration_refspectra.par")
        iraf.refspectra(input=object_b_fn_ec, references=wave_ref)
        print ' '
        print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
        print colour.capitalize() + ' object spectrum             '
        print '(' + str(object_b_fn_ec) + ')                      '
        print 'assigned to ' + str(colour) + ' reference spectrum '
        print '(' + str(wave_ref) + ') successfully.              ' 
        print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
        print ' '
      else:
        print ' '
        print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
        print 'Wavelength reference IRAF .par file                ' 
        print str(parList)
        print 'does not exist. Exiting script.                    '
        print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
        print ' '
        print ' '
        sys.exit()
    else:
      print ' '
      print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
      print 'ThAr reference frame                               ' 
      print str(wave_ref)
      print 'does not exist. Exiting script.                    '
      print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
      print ' '
      print ' '
      sys.exit()
  else:
    print ' '
    print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    print 'Input frame                                        ' 
    print str(object_b_fn_ec)
    print 'does not exist. Exiting script.                    '
    print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    print ' '
    print ' '
    sys.exit()
def apply_wav_solution(WORK_DIR, include_cal=False):
  print '\n + Applying the wavelength solution\n'
  
  iraf.unlearn('dispcor')

  for i, obj in enumerate(observations[WORK_DIR]['objects']):
    cal = observations[WORK_DIR]['calibs'][i]+'.ec'
    # export wav calibrated spectra
    print 'Using cal:', cal
    for j in ['.ec', '.ec.nosky']:
      #iraf.hedit(images=obj, fields='refspec1', value=observations[WORK_DIR]['calibs'][0]+'.ec', add='yes', verify='no')
      iraf.refspectra(input=obj+j, referen=cal, sort='', group='', confirm='no', Stdout="/dev/null")
      iraf.dispcor(input=obj+j, output=obj+j, lineari='no', verbose='yes')
    if include_cal:
      os.remove(cal+'_wvl.fits')
      # export wav calibrated cal image
      iraf.refspectra(input=cal, referen=cal, sort='', group='', confirm='no', Stdout="/dev/null")
      iraf.dispcor(input=cal, output=cal+'_wvl', lineari='no', verbose='yes')
예제 #5
0
def reduce_data(filelist_new, filelist_masterflats, filelist_masterthars):
    if len(filelist_new) == 0:
        print("Please, choose science files to reduce first!")
    elif len(filelist_masterflats) == 0:
        print("Please, choose masterflat files first!")
    elif len(filelist_masterthars) == 0:
        print("Please, choose Thorium-Argon reference files first!")
    else:
        print("Starting reduction process...")
        extracted_science_files = []
        current_directory = os.getcwd()

        years = [
            '{:04d}'.format(year) for year in range(2005,
                                                    date.today().year + 1)
        ]
        month = ['{:02d}'.format(mon) for mon in range(1, 13)]

        for i in range(len(filelist_new)):
            trim = trim_remove_bias(filelist_new[i])
            chosen_masterflat = None

            dummyI = trim.replace(".trim_will_be_removed.fits", ".dummyI.fits")
            dummyII = trim.replace(".trim_will_be_removed.fits",
                                   ".dummyII.fits")

            if os.path.exists(dummyI):
                os.remove(dummyI)
            if os.path.exists(dummyII):
                os.remove(dummyII)

            for y in years:
                for mon in month:
                    date_check_1 = y + "_" + mon
                    date_check_2 = y + "-" + mon
                    if ((date_check_1 in trim)
                            or (date_check_2 in trim)) == True:
                        for masterflat in filelist_masterflats:
                            if ((date_check_1 in masterflat)
                                    or (date_check_2 in masterflat)) == True:
                                chosen_masterflat = masterflat

            if chosen_masterflat is None:
                print("Masterflat File not found!!")
                continue

            iraf.imarith(trim, "/", chosen_masterflat, dummyI)

            iraf.apscatter(dummyI,
                           output=dummyII,
                           interactive="No",
                           apertures="1-51",
                           references="find_orders.fits")

            clean = trim.replace(".trim_will_be_removed.fits", ".clean.fits")
            mask = trim.replace(".trim_will_be_removed.fits", ".mask.fits")

            mean_image = iraf.imstat(dummyII,
                                     Stdout=1,
                                     fields="mean",
                                     format="no")
            print(mean_image)

            if float(mean_image[0]) > 5000:
                array, header = cosmics.fromfits(dummyII)

                sigclip = 50.0
                objlim = 50.0

                c = cosmics.cosmicsimage(array,
                                         gain=0.368,
                                         readnoise=3.7,
                                         sigclip=sigclip,
                                         sigfrac=10.0,
                                         objlim=objlim)

                c.run(maxiter=0)
                cosmics.tofits(clean, c.cleanarray, header)
                cosmics.tofits(mask, c.mask, header)

            elif 5000 > float(mean_image[0]) > 1000:
                array, header = cosmics.fromfits(dummyII)
                sigclip = 20.0
                objlim = 20.0
                c = cosmics.cosmicsimage(array,
                                         gain=0.368,
                                         readnoise=3.7,
                                         sigclip=sigclip,
                                         sigfrac=4.0,
                                         objlim=objlim)

                c.run(maxiter=2)
                cosmics.tofits(clean, c.cleanarray, header)
                cosmics.tofits(mask, c.mask, header)
            else:
                array, header = cosmics.fromfits(dummyII)

                sigclip = 5.0
                objlim = 5.0

                c = cosmics.cosmicsimage(array,
                                         gain=0.368,
                                         readnoise=3.7,
                                         sigclip=sigclip,
                                         sigfrac=1.8,
                                         objlim=objlim)

                c.run(maxiter=2)
                cosmics.tofits(clean, c.cleanarray, header)
                cosmics.tofits(mask, c.mask, header)

            extract = trim.replace(".trim_will_be_removed.fits",
                                   ".extracted.fits")
            extracted_science_files.append(extract)

            iraf.apall(clean,
                       output=extract,
                       references="find_orders",
                       profiles="find_orders",
                       apertures="1-51")
            #    iraf.apall(clean, output=extract, references= "find_orders", profiles= "find_orders", apertures = "3-50" )
            #    iraf.apall(clean, output=extract, references= "find_orders", profiles= "find_orders", apertures = "3-50" )
            os.remove(dummyI)
            os.remove(dummyII)
            os.remove(trim)

        write_reftable(filelist_new, filelist_masterthars)

        thar_directory = os.path.dirname(filelist_masterthars[0])

        if thar_directory == os.path.dirname(filelist_new[0]):
            pass
        else:
            remove_file(thar_directory, "science.lis")
            remove_file(thar_directory, "reftable.dat")

            shutil.move("science.lis", thar_directory)
            shutil.move("reftable.dat", thar_directory)
        os.chdir(thar_directory)

        iraf.refspectra("@science.lis",
                        references="reftable.dat",
                        ignoreaps="Yes",
                        sort="",
                        group="",
                        override="yes",
                        confirm="no",
                        assign="yes")
        iraf.dispcor("@science.lis", output="@science.lis")

        if thar_directory == os.path.dirname(filelist_new[0]):
            pass
        else:
            remove_file(current_directory, "science.lis")
            remove_file(current_directory, "reftable.dat")

            shutil.move("science.lis", current_directory)
            shutil.move("reftable.dat", current_directory)
        os.chdir(current_directory)

        normalize_and_merge(extracted_science_files)

        print("Success! Reduction process complete.")
예제 #6
0
#                  threshold=50,shift=INDEF)
iraf.ecreidentify(images='@arcs_extracted',
                  reference='arcnewref.ec',
                  shift=INDEF,
                  cradius=2,
                  threshold=45,
                  refit=yes)

# ASSIGN WAVECALS TO OBJECT SPECTRA
# Assign comparison spectra to object images based on times the images were
# made, with weights for later dispersion solution assignment
iraf.refspectra('@targets_extracted',
                references='@arcs_extracted',
                select='interp',
                sort='utmiddle',
                group='observat',
                time=yes,
                confirm=no,
                override=yes,
                assign=yes)

iraf.refspectra('sig_//@targets_extracted',
                references='@arcs_extracted',
                select='interp',
                sort='utmiddle',
                group='observat',
                time=yes,
                confirm=no,
                override=yes,
                assign=yes)