예제 #1
0
파일: muse.py 프로젝트: ntejos/mypython
    def mpdaf_process(self,
                      refpath='./esocombine/',
                      deepwhite='./esocombine/IMAGE_FOV_0001.fits',
                      extmask=None,
                      extmaskonly=False,
                      nproc=24):
        """

        Produces final cubes optimised for fields that are relatively 
        empty in continuum sources using the GTO/MPDAF procedures

        refpath -> where the reference cubes for wcs resempling are 
                     otherwise the cube itself is used 
                   
        deepwhite -> the best white image available to mask sources
        
	skymask -> mask this region in the mpdaf reduction (selfcalibrate and zap) Format: ds9 region in image units
	
	extmaskonly -> if true ose only the skymask supplied externally, if false merge sextractor and skymasks

        nproc -> number of processors 


        """

        import os
        import glob
        import subprocess
        import muse_redux_mpdaf as ex

        #first, list how many OBs are there
        listob = glob.glob('OB*')
        listob.sort()
        nobs = len(listob)
        print('Process {} OBs'.format(nobs))

        #now make space as needed for final products
        if not os.path.exists('mpdafcombine'):
            os.makedirs('mpdafcombine')

        #rerun pipe enabling resampling on final ESO cube
        ex.individual_resample(listob, refpath=refpath)

        #now perform self-calibration on pixel table
        ex.selfcalibrate(listob,
                         deepwhite,
                         refpath=refpath,
                         extmask=extmask,
                         extmaskonly=extmaskonly,
                         nproc=nproc)

        #now perform sky subtraction on cubes with zap
        ex.zapskysub(listob, extmask=extmask, extmaskonly=extmaskonly)

        #finally, coadd data
        ex.coaddcubes(listob)

        print("All done!")
예제 #2
0
파일: muse.py 프로젝트: ntejos/mypython
    def line_process(self,
                     skymode='internal',
                     refpath='./esocombine/',
                     skymask=None,
                     lmin=4900,
                     lmax=9000,
                     deepwhite=None):
        """

        Produces final cubes optimised for fields that are relatively 
        empty in continuum sources but that may have very extended 
        emission lines.

        lmin -> the minimum wavelength to consider
        lmax -> the maximum wavelength to consider
        refpath -> where the reference cubes for wcs resempling are 
        skymask -> a skymask to be used for identify good regions for skysubtraction 
                   (expected in image coordinates)
        skymode -> internal: use good pixels (i.e. not containing sources or defined in skymask) to perform 
                   skysubtraction plus run ZAP on it.
        deepwhite -> if set to an image, this is used to mask sources during sky subtraction.
                     otherwise the cube itself is used 
                   
        """

        import os
        import glob
        import subprocess
        import muse_redux_line as ex

        #first, list how many OBs are there
        listob = glob.glob('OB*')
        listob.sort()
        nobs = len(listob)
        print('Process {} OBs'.format(nobs))

        #now make space as needed for final products
        if not os.path.exists('linecombine'):
            os.makedirs('linecombine')

        #rerun pipe enabling resampling on final ESO cube
        ex.individual_resample(listob, refpath=refpath)

        #next construct the ifu mask for each exposure
        ex.make_ifumasks(listob, refpath=refpath)

        #compute illumination correction
        ex.make_illcorr(listob)

        #now do background subtraction
        if ('internal' in skymode):
            ex.internalskysub(listob, skymask, deepwhite=deepwhite)
        else:
            print("Sky subtraction mode {} not supported".format(skymode))

        #change dir
        currdir = os.getcwd()
        os.chdir('linecombine')
        print('Changing dir to linecombine...')

        fl1 = open('cubes.lst', 'w')
        fl2 = open('masks.lst', 'w')

        #loop over OBs
        for oob in range(nobs):
            #count how many science exposures
            nsci = len(
                glob.glob("../{}/Proc/Basic/OBJECT_RED_0*.fits*".format(
                    listob[oob])))
            #reconstruct names
            for ll in range(nsci):
                fl1.write(
                    '../{}/Proc/Line/DATACUBE_FINAL_LINEWCS_EXP{}_zapsky.fits\n'
                    .format(listob[oob], ll + 1))
                fl2.write(
                    '../{}/Proc/Line/MASK_EXP{}_ILLCORR_edges.fits\n'.format(
                        listob[oob], ll + 1))
        fl1.close()
        fl2.close()

        #make the temp combine
        ex.combine_cubes("cubes.lst", "masks.lst")
        os.chdir(currdir)

        print("All done!")