Example #1
0
    def getOverscanInfo():
        if 'INSTRUMENT' not in os.environ:
            raise NoInstrumentException

        instrumentFile = '%s.ini' % os.environ['INSTRUMENT']

        return OverscanInfo(bashreader.parseFile(instrumentFile))
Example #2
0
def calcNearestNeighborCut(options, cat, psfsize, ldaclensing):

    curdir = os.getcwd()

    os.chdir(ldaclensing)

    progs = bashreader.parseFile('progs.ini')
    
    temp_inputcatfile = utilities.getTempFile(dir=progs.tempdir, suffix='.cat')
    temp_outputcatfile = utilities.getTempFile(dir=progs.tempdir, suffix='.cat')
    print cat.sourcefile
    hdulist = pyfits.open(cat.sourcefile)
    newhdus = [pyfits.PrimaryHDU()]
    for hdu in hdulist[1:]:
        if hdu.header['EXTNAME'] == 'OBJECTS':
            newhdus.append(cat.hdu)
        elif hdu.header['EXTNAME'] == 'FIELDS':
            fieldstable = ldac.LDACCat(hdu)
            fieldstable['OBJECT_COUNT'][:] = np.array([len(cat)])
            newhdus.append(fieldstable.hdu)
    hdulist = pyfits.HDUList(newhdus)
    hdulist.writeto(temp_inputcatfile, clobber=True)
    
    stringvals = copy.copy(options)
    stringvals.inputcatfile = temp_inputcatfile
    stringvals.outputcatfile = temp_outputcatfile

    #BASH script hardcodes what the comparison catalog is. Bewarned!
    command = './cut_nearest_neighbours_cc.sh %(cluster)s %(filter)s %(image)s %(inputcatfile)s %(outputcatfile)s %(psfsize)2.4f' % stringvals


    try:

        subprocess.check_call(command.split())

        outputcat = ldac.openObjectFile(temp_outputcatfile)

        ids = {}
        for id in cat['SeqNr']:
            ids[id] = False
        for id in outputcat['SeqNr']:
            ids[id] = True

        nearest_neighbor_cut = np.array([ids[id] for id in cat['SeqNr']])

    finally:
    
#        if os.path.exists(temp_inputcatfile):
#            os.remove(temp_inputcatfile)
#        if os.path.exists(temp_outputcatfile):
#            os.remove(temp_outputcatfile)
        os.chdir(curdir)

    return nearest_neighbor_cut
Example #3
0
def sextract(filter):
    from config_bonn import appendix, cluster, tag, arc, filter_root
    import utilities
    import os, re, bashreader, sys, string
    from glob import glob
    from copy import copy

    dict = bashreader.parseFile('progs.ini')
    for key in dict.keys():
        os.environ[key] = str(dict[key])

    TEMPDIR = '/tmp/'
    PHOTCONF = './photconf/'

    path = '/nfs/slac/g/ki/ki05/anja/SUBARU/%(cluster)s/' % {
        'cluster': cluster
    }

    search_params = {
        'path': path,
        'cluster': cluster,
        'filter': filter,
        'appendix': appendix,
        'PHOTCONF': PHOTCONF,
        'tag': tag,
        'DATACONF': os.environ['DATACONF'],
        'TEMPDIR': TEMPDIR,
        'fwhm': 1.00
    }

    searchstr = "/%(path)s/*%(filter)s*/SCIENCE/*1*fits" % search_params
    print searchstr
    files = glob(searchstr)
    files.sort()
    print files
    exposures = {}
    # first 30 files
    print files[0:30]
    for file in files:  #[0:30]:
        if string.find(file, 'wcs') == -1 and string.find(file,
                                                          '.sub.fits') == -1:
            res = re.split('_', re.split('/', file)[-1])
            print res
            if not exposures.has_key(res[0]): exposures[res[0]] = {}
            if not exposures[res[0]].has_key('images'):
                exposures[res[0]]['images'] = []
            if not exposures[res[0]].has_key('keywords'):
                exposures[res[0]]['keywords'] = {}
            exposures[res[0]]['images'].append(
                file)  # res[0] is the root of the image name
            print 'hey', file
            reload(utilities)

            if not exposures[res[0]]['keywords'].has_key(
                    'ROTATION'
            ):  #if exposure does not have keywords yet, then get them

                exposures[res[0]]['keywords']['filter'] = filter

                res2 = re.split('/', file)
                for r in res2:
                    if string.find(r, filter) != -1:
                        print r
                        exposures[res[0]]['keywords']['date'] = r.replace(
                            filter + '_', '')
                        exposures[res[0]]['keywords']['fil_directory'] = r
                        search_params['fil_directory'] = r

                kws = utilities.get_header_kw(
                    file, ['ROTATION'])  # return KEY/NA if not SUBARU
                for kw in kws.keys():
                    exposures[res[0]]['keywords'][kw] = kws[kw]

    print 'hey2!!!!!!'
    print exposures
    #raw_input()
    #first = exposures[exposures.keys()[0]]
    #first['images'] = [first['images'][0]]
    #exposures = {exposures.keys()[0]: first}
    exposures = {exposures.keys()[0]: exposures[exposures.keys()[0]]}
    print exposures

    print 'stop1'
    #temporary method

    for kw in exposures.keys():  # now go through exposure by exposure
        exposure = exposures[kw]
        print kw, exposure['images']
        children = []
        print exposure['images']
        print 'hey!!!!!!'
        for image in exposure['images']:
            child = os.fork()
            if child:
                children.append(child)
            else:

                params = copy(search_params)
                params['GAIN'] = 1.000  #float(exposure['keywords']['GAIN'])
                params['PIXSCALE'] = float(exposure['keywords']['PIXSCALE'])

                ROOT = re.split('\.', re.split('\/', image)[-1])[0]
                params['ROOT'] = ROOT
                NUM = re.split('O', re.split('\_', ROOT)[1])[0]
                params['NUM'] = NUM
                print ROOT

                weightim = "/%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits" % params
                #flagim = "/%(path)s/%(fil_directory)s/WEIGHTS/globalflag_%(NUM)s.fits" % params
                #finalflagim = TEMPDIR + "flag_%(ROOT)s.fits" % params
                params['finalflagim'] = weightim
                #os.system('rm ' + finalflagim)
                #command = "ic -p 16 '1 %2 %1 0 == ?' " + weightim + " " + flagim + " > " + finalflagim
                #print command
                #raw_input()
                #utilities.run(command)

                command = "sex /%(path)s/%(fil_directory)s/SCIENCE/%(ROOT)s.fits -c %(PHOTCONF)s/singleastrom.conf.sex \
                            -FLAG_IMAGE ''\
                            -FLAG_TYPE MAX\
                            -CATALOG_NAME %(TEMPDIR)s/seeing_%(ROOT)s.cat \
                            -FILTER_NAME %(PHOTCONF)s/default.conv\
                            -CATALOG_TYPE 'ASCII' \
                            -DETECT_MINAREA 5 -DETECT_THRESH 5.\
                            -ANALYSIS_THRESH 5 \
                            -WEIGHT_IMAGE /%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits\
                            -WEIGHT_TYPE MAP_WEIGHT\
                            -PARAMETERS_NAME %(PHOTCONF)s/singleastrom.ascii.flag.sex" % params

                print command
                os.system(command)

                sys.exit(0)
        for child in children:
            os.waitpid(child, 0)

        command = 'cat ' + TEMPDIR + 'seeing_' + kw + '*cat > ' + TEMPDIR + 'paste_seeing_' + kw + '.cat'
        utilities.run(command)

        file_seeing = TEMPDIR + '/paste_seeing_' + kw + '.cat'
        PIXSCALE = float(exposure['keywords']['PIXSCALE'])
        reload(utilities)
        print file_seeing, kw, PIXSCALE, exposure['keywords']['PIXSCALE']
        fwhm = utilities.calc_seeing(file_seeing, 10, PIXSCALE)

        # get the CRPIX values for
        #image = exposure['images'][0]
        start = 1
        for image in exposure['images']:
            print image
            res = re.split('\_\d+', re.split('\/', image)[-1])
            #print res
            imroot = "/%(path)s/%(fil_directory)s/SCIENCE/" % search_params
            im = imroot + res[0] + '_1' + res[1]
            #print im
            crpix = utilities.get_header_kw(
                image, ['CRPIX1', 'CRPIX2', 'NAXIS1', 'NAXIS2'])
            if start == 1:
                crpixzero = copy(crpix)
                crpixhigh = copy(crpix)
                start = 0
            from copy import copy
            if float(crpix['CRPIX1']) > float(crpixzero['CRPIX1']) and float(
                    crpix['CRPIX2']) > float(crpixzero['CRPIX2']):
                crpixzero = copy(crpix)

            if float(crpix['CRPIX1']) < float(crpixhigh['CRPIX1']) and float(
                    crpix['CRPIX2']) < float(crpixhigh['CRPIX2']):
                crpixhigh = copy(crpix)

            print crpix, crpixzero, crpixhigh

        LENGTH1 = abs(float(crpixhigh['CRPIX1']) -
                      float(crpixzero['CRPIX1'])) + float(crpix['NAXIS1'])
        LENGTH2 = abs(float(crpixhigh['CRPIX2']) -
                      float(crpixzero['CRPIX2'])) + float(crpix['NAXIS2'])

        print crpixhigh['CRPIX1'], crpixzero['CRPIX1'], crpix['NAXIS1'], crpix[
            'NAXIS2']

        children = []
        for image in exposure['images']:
            child = os.fork()
            if child:
                children.append(child)
            else:

                params = copy(search_params)
                params['fwhm'] = fwhm
                params['GAIN'] = 1.000  #float(exposure['keywords']['GAIN'])
                params['PIXSCALE'] = float(exposure['keywords']['PIXSCALE'])

                ROOT = re.split('\.', re.split('\/', image)[-1])[0]
                params['ROOT'] = ROOT
                NUM = re.split('O', re.split('\_', ROOT)[1])[0]
                params['NUM'] = NUM
                print ROOT

                finalflagim = TEMPDIR + "flag_%(ROOT)s.fits" % params

                weightim = "/%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits" % params
                #flagim = "/%(path)s/%(fil_directory)s/WEIGHTS/globalflag_%(NUM)s.fits" % params
                #finalflagim = TEMPDIR + "flag_%(ROOT)s.fits" % params
                params['finalflagim'] = weightim
                im = "/%(path)s/%(fil_directory)s/SCIENCE/%(ROOT)s.fits" % params
                crpix = utilities.get_header_kw(im, ['CRPIX1', 'CRPIX2'])

                command = "sex /%(path)s/%(fil_directory)s/SCIENCE/%(ROOT)s.fits -c %(PHOTCONF)s/phot.conf.sex \
                -PARAMETERS_NAME %(PHOTCONF)s/phot.param.sex \
                -CATALOG_NAME %(TEMPDIR)s/%(ROOT)s.cat \
                -FILTER_NAME %(DATACONF)s/default.conv\
                -FILTER  Y \
                -FLAG_TYPE MAX\
                -FLAG_IMAGE ''\
                -SEEING_FWHM %(fwhm).3f \
                -DETECT_MINAREA 5 -DETECT_THRESH 5 -ANALYSIS_THRESH 5 \
                -MAG_ZEROPOINT 27.0 \
                -GAIN %(GAIN).3f \
                -WEIGHT_IMAGE /%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits\
                -WEIGHT_TYPE MAP_WEIGHT" % params
                #-CHECKIMAGE_TYPE BACKGROUND,APERTURES,SEGMENTATION\
                #-CHECKIMAGE_NAME /%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.background.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.apertures.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.segmentation.fits\

                catname = "%(TEMPDIR)s/%(ROOT)s.cat" % params
                print command
                utilities.run(command, [catname])

                import commands
                lines = commands.getoutput('ldactoasc -s -b -i ' + catname +
                                           ' -t LDAC_OBJECTS | wc -l')
                import re
                res = re.split('\n', lines)
                print lines

                if int(res[-1]) == 0:
                    print 'NO OBJECTS, exiting...'
                    sys.exit(0)

                poscatname = "%(TEMPDIR)s/%(ROOT)s.pos.cat" % params
                command = 'ldaccalc -i ' + catname + ' -o ' + TEMPDIR + params[
                    'ROOT'] + '.scamp.cata -t LDAC_OBJECTS -c "(XWIN_IMAGE + ' + str(
                        float(crpixzero['CRPIX1']) - float(crpix['CRPIX1'])
                    ) + ');" -k FLOAT -n XWIN_IMAGE_TEMP "" -c "(YWIN_IMAGE + ' + str(
                        float(crpixzero['CRPIX2']) - float(crpix['CRPIX2'])
                    ) + ');" -k FLOAT -n YWIN_IMAGE_TEMP "" -c "(YWIN_IMAGE*0 + ' + str(
                        params['NUM']) + ');" -k FLOAT -n CHIP "" '
                print command
                utilities.run(command)

                command = 'ldacdelkey -i ' + TEMPDIR + params[
                    'ROOT'] + '.scamp.cata -t LDAC_OBJECTS -o ' + TEMPDIR + params[
                        'ROOT'] + '.scamp.catb -k XWIN_IMAGE YWIN_IMAGE'
                utilities.run(command)

                command = 'ldacrenkey -i ' + TEMPDIR + params[
                    'ROOT'] + '.scamp.catb -t LDAC_OBJECTS -o ' + TEMPDIR + params[
                        'ROOT'] + '.scamp.catc -k XWIN_IMAGE_TEMP XWIN_IMAGE YWIN_IMAGE_TEMP YWIN_IMAGE'
                utilities.run(command)

                #command = 'ldacrenkey
                sys.exit(0)

        for child in children:
            #print 'waiting for' child
            os.waitpid(child, 0)
        ''' run SCAMP on entire image '''
        newposlist = glob(TEMPDIR + kw + '*scamp.catc')

        outcatscamp = TEMPDIR + 'tmppaste_' + kw + '.scampall.cat'

        outheadscamp = TEMPDIR + 'tmppaste_' + kw + '.scampall.head'
        print newposlist
        if len(newposlist) > 1:
            command = 'ldacpaste -i ' + TEMPDIR + kw + '*scamp.cat -o ' + outcatscamp
            print command
        else:
            command = 'cp ' + newposlist[0] + ' ' + outcatscamp
        utilities.run(command)

        command = 'scamp ' + outcatscamp + " -SOLVE_PHOTOM N -ASTREF_CATALOG SDSS-R6 -CHECKPLOT_TYPE NONE -WRITE_XML N "

        print command
        utilities.run(command)

        headfile = outheadscamp
        print headfile
        #raw_input()

        children = []
        for image in exposure['images']:
            child = os.fork()
            if child:
                children.append(child)
            else:
                params = copy(search_params)
                params['fwhm'] = fwhm
                params['GAIN'] = 1.000  #float(exposure['keywords']['GAIN'])
                params['PIXSCALE'] = float(exposure['keywords']['PIXSCALE'])

                ROOT = re.split('\.', re.split('\/', image)[-1])[0]
                params['ROOT'] = ROOT
                NUM = re.split('O', re.split('\_', ROOT)[1])[0]
                params['NUM'] = NUM
                print ROOT

                finalflagim = TEMPDIR + "flag_%(ROOT)s.fits" % params

                weightim = "/%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits" % params
                #flagim = "/%(path)s/%(fil_directory)s/WEIGHTS/globalflag_%(NUM)s.fits" % params
                #finalflagim = TEMPDIR + "flag_%(ROOT)s.fits" % params
                params['finalflagim'] = weightim
                im = "/%(path)s/%(fil_directory)s/SCIENCE/%(ROOT)s.fits" % params
                crpix = utilities.get_header_kw(im, ['CRPIX1', 'CRPIX2'])

                hf = open(headfile, 'r').readlines()
                hdict = {}
                for line in hf:
                    import re
                    if string.find(line, '=') != -1:
                        res = re.split('=', line)
                        name = res[0].replace(' ', '')
                        res = re.split('/', res[1])
                        value = res[0].replace(' ', '')
                        print name, value
                        hdict[name] = value

                imfix = "/tmp/%(ROOT)s.fixwcs.fits" % params

                command = "cp " + im + " " + imfix
                utilities.run(command)

                for name in [
                        'CRVAL1', 'CRVAL2', 'CD1_1', 'CD1_2', 'CD2_1', 'CD2_2'
                ]:  #,'CRPIX1','CRPIX1']:
                    command = 'sethead ' + imfix + ' ' + name + '=' + hdict[
                        name]
                    print command
                    os.system(command)

                crpix = utilities.get_header_kw(im, ['CRPIX1', 'CRPIX2'])

                command = "sex /tmp/%(ROOT)s.fixwcs.fits -c %(PHOTCONF)s/phot.conf.sex \
                -PARAMETERS_NAME %(PHOTCONF)s/phot.param.sex \
                -CATALOG_NAME %(TEMPDIR)s/%(ROOT)s.fixwcs.cat \
                -FILTER_NAME %(DATACONF)s/default.conv\
                -FILTER  Y \
                -FLAG_TYPE MAX\
                -FLAG_IMAGE ''\
                -SEEING_FWHM %(fwhm).3f \
                -DETECT_MINAREA 5 -DETECT_THRESH 5 -ANALYSIS_THRESH 5 \
                -MAG_ZEROPOINT 27.0 \
                -GAIN %(GAIN).3f \
                -WEIGHT_IMAGE /%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits\
                -WEIGHT_TYPE MAP_WEIGHT" % params
                #-CHECKIMAGE_TYPE BACKGROUND,APERTURES,SEGMENTATION\
                #-CHECKIMAGE_NAME /%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.background.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.apertures.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.segmentation.fits\
                catname = "%(TEMPDIR)s/%(ROOT)s.cat" % params
                print command
                utilities.run(command, [catname])

                catname = "%(TEMPDIR)s/%(ROOT)s.cat" % params
                print command
                utilities.run(command, [catname])
                import commands
                lines = commands.getoutput('ldactoasc -s -b -i ' + catname +
                                           ' -t LDAC_OBJECTS | wc -l')
                import re
                res = re.split('\n', lines)
                print lines
                if int(res[-1]) == 0: sys.exit(0)
                command = 'scamp ' + catname + " -SOLVE_PHOTOM N -ASTREF_CATALOG SDSS-R6 -CHECKPLOT_TYPE NONE -WRITE_XML N "
                print command
                utilities.run(command)

                headfile = "%(TEMPDIR)s/%(ROOT)s.head" % params
                hf = open(headfile, 'r').readlines()
                hdict = {}
                for line in hf:
                    import re
                    if string.find(line, '=') != -1:
                        res = re.split('=', line)
                        name = res[0].replace(' ', '')
                        res = re.split('/', res[1])
                        value = res[0].replace(' ', '')
                        print name, value
                        hdict[name] = value

                imfix = "/tmp/%(ROOT)s.fixwcs.fits" % params

                command = "cp " + im + " " + imfix
                utilities.run(command)

                for name in [
                        'CRVAL1', 'CRVAL2', 'CD1_1', 'CD1_2', 'CD2_1', 'CD2_2',
                        'CRPIX1', 'CRPIX1'
                ]:
                    command = 'sethead ' + imfix + ' ' + name + '=' + hdict[
                        name]
                    print command
                    os.system(command)

                command = "sex /tmp/%(ROOT)s.fixwcs.fits -c %(PHOTCONF)s/phot.conf.sex \
                -PARAMETERS_NAME %(PHOTCONF)s/phot.param.sex \
                -CATALOG_NAME %(TEMPDIR)s/%(ROOT)s.fixwcs.cat \
                -FILTER_NAME %(DATACONF)s/default.conv\
                -FILTER  Y \
                -FLAG_TYPE MAX\
                -FLAG_IMAGE ''\
                -SEEING_FWHM %(fwhm).3f \
                -DETECT_MINAREA 5 -DETECT_THRESH 5 -ANALYSIS_THRESH 5 \
                -MAG_ZEROPOINT 27.0 \
                -GAIN %(GAIN).3f \
                -WEIGHT_IMAGE /%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits\
                -WEIGHT_TYPE MAP_WEIGHT" % params
                #-CHECKIMAGE_TYPE BACKGROUND,APERTURES,SEGMENTATION\
                #-CHECKIMAGE_NAME /%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.background.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.apertures.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.segmentation.fits\
                catname = "%(TEMPDIR)s/%(ROOT)s.cat" % params
                print command
                utilities.run(command, [catname])

                command = 'ldacconv -b 1 -c R -i ' + TEMPDIR + params[
                    'ROOT'] + '.fixwcs.cat -o ' + TEMPDIR + params[
                        'ROOT'] + '.conv'
                print command
                utilities.run(command)
                # Xpos_ABS is difference of CRPIX and zero CRPIX
                command = 'ldaccalc -i ' + TEMPDIR + params[
                    'ROOT'] + '.conv -o ' + TEMPDIR + params[
                        'ROOT'] + '.newpos -t OBJECTS -c "(Xpos + ' + str(
                            float(crpixzero['CRPIX1']) - float(crpix['CRPIX1'])
                        ) + ');" -k FLOAT -n Xpos_ABS "" -c "(Ypos + ' + str(
                            float(crpixzero['CRPIX2']) - float(crpix['CRPIX2'])
                        ) + ');" -k FLOAT -n Ypos_ABS "" -c "(Ypos*0 + ' + str(
                            params['NUM']) + ');" -k FLOAT -n CHIP "" '

                #command = 'ldaccalc -i ' + TEMPDIR + params['ROOT'] + '.conv -o ' + TEMPDIR + params['ROOT'] + '.newpos -t OBJECTS -c "(' + str(crpix['CRPIX1']) + ' - Xpos);" -k FLOAT -n Xpos_ABS "" -c "(' + str(crpix['CRPIX2']) + ' - Ypos);" -k FLOAT -n Ypos_ABS "" -c "(Ypos*0 + ' + str(params['NUM']) + ');" -k FLOAT -n CHIP "" '
                print command
                utilities.run(command)
                sys.exit(0)
        for child in children:
            #print 'waiting for' child
            os.waitpid(child, 0)

        from glob import glob
        outcat = TEMPDIR + 'tmppaste_' + kw + '.cat'

        newposlist = glob(TEMPDIR + kw + '*newpos')
        if len(newposlist) > 1:
            command = 'ldacpaste -i ' + TEMPDIR + kw + '*newpos -o ' + outcat
            print command
        else:
            command = 'cp ' + newposlist[0] + ' ' + outcat

        utilities.run(command)

        os.system('ldactoasc -i ' + outcat +
                  ' -b -s -k MAG_APER MAGERR_APER -t OBJECTS > /tmp/' + kw +
                  'aper')
        os.system('asctoldac -i /tmp/' + kw + 'aper -o /tmp/' + kw +
                  'cat1 -t OBJECTS -c ./photconf/MAG_APER.conf')

        outfinal = TEMPDIR + 'paste_' + kw + '.cat'
        os.system('ldacjoinkey -i ' + outcat + ' -p /tmp/' + kw + 'cat1 -o ' +
                  outfinal +
                  ' -k MAG_APER1 MAG_APER2 MAGERR_APER1 MAGERR_APER2')

        exposures[kw]['pasted_cat'] = outfinal

    return exposures, LENGTH1, LENGTH2
Example #4
0
    max = 0
    k = 0
    for i in range(nbins):
        if bin[i] > max:
            k = i
            max = bin[i]
    fwhm = 0.3 + k * binsize

    print 'fwhm', fwhm
    return fwhm


import os, sys, bashreader, commands
from utilities import *

dict = bashreader.parseFile('progs.ini')
for key in dict.keys():
    os.environ[key] = str(dict[key])

cluster = 'MACS2243-09'
appendix = '_all'  #_good'
TEMPDIR = '/tmp/'
PHOTCONF = './photconf/'
tag = 'local50'
path = '/nfs/slac/g/ki/ki05/anja/SUBARU/%(cluster)s/' % {'cluster': cluster}
type = 'all'

filters = ['B', 'W-J-V', 'W-C-RC', 'W-C-IC', 'W-S-Z+']

filter_root = 'W-J-V'
Example #5
0
def doit():
    usage = '''
get_seeing.py

    gets the seeing for all exposures

usage:

   get_seeing.py [maindir] [cluster] [ending] [list of filters:optional]

   example:
        ./get_seeing.py ${SUBARUDIR} MACS1427+44 
        ./get_seeing.py ${SUBARUDIR} MACS1427+44 "_t1"
        ./get_seeing.py ${SUBARUDIR} MACS1427+44 "" W-J-V W-J-B 

    If no filters given, all filters will be included, otherwinse only the listed filters will be considered.
    
    result:
         file seeing_[clustername].cat in local directory with list of exposures and seeing.


options:
    -h       this

    '''
    # if -h called, or not enough args, show usage and quit
    if ('-h' in sys.argv) or len(sys.argv) <3:
        print usage
        exit(0)



    # set up directory structure:
    maindir=sys.argv[1]       # this should be ${SUBARUDIR} 
    cluster=sys.argv[2]       # full cluster name    

    if (len(sys.argv) == 3):
        filterlist=['all']
    else:
        filterlist = sys.argv[3:]

        
    # get the progs from prog.ini
    dict = bashreader.parseFile('progs.ini')

    # definitions...
    path=maindir+'/'+cluster


    TEMPDIR = tempfile.mkdtemp(dir='/tmp')
    PHOTCONF = './photconf/'

    # different filters...
    subarufilters=['W-J-B','W-J-V','W-C-RC','W-C-IC','W-S-I+','W-S-Z+']
    cfhtfilters=['u','g','r','i','z']

    # for the case of all filters
    if filterlist[0]=='all':
         list_of_images = glob.glob(path+'/W-?-??/SCIENCE/coadd_'+cluster+'_SUPA*/coadd.fits')
         list_of_images.extend(glob.glob(path+'/W-?-??/SCIENCE/coadd_'+cluster+'_all/coadd.fits'))
         list_of_images.extend(glob.glob(path+'/W-?-?/SCIENCE/coadd_'+cluster+'_SUPA*/coadd.fits'))
         list_of_images.extend(glob.glob(path+'/W-?-?/SCIENCE/coadd_'+cluster+'_all/coadd.fits'))
         list_of_images.extend(glob.glob(path+'/?/SCIENCE/coadd_'+cluster+'_*p/coadd.fits'))
         list_of_images.extend(glob.glob(path+'/?/SCIENCE/coadd_'+cluster+'_all/coadd.fits'))
         list_of_images.extend(glob.glob(path+'/W-?-?_*_CALIB/SCIENCE/coadd_'+cluster+'_all/coadd.fits'))
         list_of_images.extend(glob.glob(path+'/W-?-??_*_CALIB/SCIENCE/coadd_'+cluster+'_all/coadd.fits'))
         

             
         

    else : # for specific filters
        list_of_images=[]
        for f in filterlist:
            thislist = glob.glob(path+'/'+f+'/SCIENCE/coadd_'+cluster+'_SUPA*/coadd.fits')
            thislist.append(path+'/'+f+'/SCIENCE/coadd_'+cluster+'_all/coadd.fits')
            thislist.extend(glob.glob(path+'/'+f+'/SCIENCE/coadd_'+cluster+'_*p/coadd.fits'))


            list_of_images = list_of_images + thislist

            
    print "Measuring the seeing of ..."
    for image in list_of_images:
        print image

    # if no images, quit
    if len(list_of_images)==0:
        print 'no images '
        exit(1)

    
    children = []   # this is supposed to make it faster
    #                 its the parallel mechanism
    for image in list_of_images:        
        child = os.fork()  # forking!
        if child:
            children.append(child)  # children processes.
        else:            
            flagimage=image[:-4]+'flag.fits' # assumes the flag file is coadd.flag.fits
            if len(flagimage) == 0:          # if we can't find it
                print 'Can not find '+flagimage
                exit(1)

            tag = findImageTag(image)

            params = {'path':path, 
                      'cluster':cluster, 
                      'PHOTCONF':PHOTCONF, 
                      'TEMPDIR': TEMPDIR,
                      'image':image,
                      'flagimage':flagimage,
                      'tag':tag}

                            
            # now run sextractor to determine the seeing:              
            command = 'sex %(image)s \
            -c %(PHOTCONF)s/singleastrom.conf.sex \
            -FLAG_IMAGE %(flagimage)s \
            -FLAG_TYPE MAX \
            -CATALOG_NAME %(TEMPDIR)s/seeing_%(tag)s.cat \
            -FILTER_NAME %(PHOTCONF)s/default.conv \
            -CATALOG_TYPE "ASCII" \
            -DETECT_MINAREA 10 -DETECT_THRESH 10. \
            -ANALYSIS_THRESH 5 \
            -PARAMETERS_NAME %(PHOTCONF)s/singleastrom.ascii.param.sex' %  params 


            print command
            sys.stderr.write(command + '\n')
            os.system(command)
            sys.exit(0)

            
    for child in children: 
        os.waitpid(child,0)
    
    # Got seeing
    
############################################
#  Now we are just going to organize it a bit
#  
############################################    
    openfile =  open('seeing_'+cluster+'.cat','w')
    # now we order the seeings, find which is the worst.    
    fwhms = {} 
    for image in list_of_images:
        # get some info
        try:
            GAIN, PIXSCALE, EXPTIME = utilities.get_header_info(image) 
        except Exception:
            sys.stderr.write('Skipping %s!' % image)
            continue

        tag = findImageTag(image)

        # get all the info together in one array
        fwhms[tag] = {'IMAGE':image,'GAIN':GAIN,'PIXSCALE':PIXSCALE, 'EXPTIME': EXPTIME}

        # the output cat from above
        file_seeing = '%(TEMPDIR)s/seeing_%(tag)s.cat' % {'TEMPDIR': TEMPDIR,'tag':tag}

        # gets seeing
        fwhms[tag]['SEEING'] = utilities.calc_seeing(file_seeing,PIXSCALE)  
        print 'image', tag, fwhms[tag]['SEEING'] 

        openfile.write(tag+' '+ str(fwhms[tag]['SEEING']) + ' \n')

    fwhms_comp=[fwhms[x] for x in fwhms.keys()] # list of fwhm's 
    fwhms_comp.sort(utilities.compare)                    # sort
    seeing_worst = fwhms_comp[0]['SEEING']      # worst
    image_worst = fwhms_comp[0]['IMAGE']        # worst image

    
    print ' worst SEEING', image_worst, seeing_worst

    [ os.remove('%s/%s' % (TEMPDIR,file)) for file in os.listdir(TEMPDIR) ]
    os.rmdir(TEMPDIR)
Example #6
0
#!/usr/bin/env python

import sys, pyfits, bashreader, ldac, math, os, re, numpy

inputfile = sys.argv[1]
outputfile = sys.argv[2]
image = sys.argv[3]

config = bashreader.parseFile('./progs.ini')
npara =int(config.npara)

inputcat = pyfits.open(inputfile)
if inputcat is None:
    print 'Cannot open %s' % inputfile
    sys.exit(1)

root, ext = os.path.splitext(inputfile)


objects = None
hfindpeaks = None
fields = None
for hdu in inputcat:
    try:
        if 'OBJECTS' == hdu.header['EXTNAME']:
            objects = ldac.LDACCat(hdu)
        elif 'HFINDPEAKS' == hdu.header['EXTNAME']:
            hfindpeaks = hdu
        elif 'FIELDS' == hdu.header['EXTNAME']:
            fields = hdu
    except KeyError:
Example #7
0
 def sextract(self,exposures):
     #from config_bonn import appendix, cluster, tag, arc, filter_root
     import utilities
     import os, re, bashreader, sys, string
     from glob import glob
     from copy import copy
 
     dict = bashreader.parseFile('progs.ini')
     for key in dict.keys():
         os.environ[key] = str(dict[key])
 
 
     TEMPDIR = '/tmp/'
     PHOTCONF = './photconf/'
 
     path='/nfs/slac/g/ki/ki05/anja/SUBARU/%(cluster)s/' % {'cluster':cluster}
 
     
     print exposures.keys()
     print exposures_zero.keys()
     print exposures_one.keys()
                 
     print 'hey2!!!!!!'
     print exposures
     first = exposures[exposures.keys()[0]]
     first['images'] = first['images']
     exposures = {exposures.keys()[0]: first}
 
 
 
 
     #exp_tmp = {}
     #for exposure in exposures.keys()[2:4]:
     #    exp_tmp[exposure] = exposures[exposure]
     #exposures = exp_tmp
 
 
     #exposures = {exposures.keys()[0]: exposures[exposures.keys()[0:4]]}
     print exposures
 
 
     print 'stop1'
     #temporary method
 
     measure_fwhm = 1
 
     for kw in exposures.keys(): # now go through exposure by exposure
         exposure = exposures[kw]
         print kw, exposure['images']
         print exposure['images']
         
         ''' get the CRPIX values '''
         start = 1
         for image in exposure['images']:
             print image                                                 
             res = re.split('\_\d+',re.split('\/',image)[-1])
             #print res
             imroot = "/%(path)s/%(fil_directory)s/SCIENCE/" % search_params
             im = imroot + res[0] + '_1' + res[1] 
             #print im
             crpix = utilities.get_header_kw(image,['CRPIX1','CRPIX2','NAXIS1','NAXIS2'])
             if start == 1:
                 crpixzero = copy(crpix)
                 crpixhigh = copy(crpix)
                 start = 0
             from copy import copy 
             if float(crpix['CRPIX1'])  > float(crpixzero['CRPIX1']) and float(crpix['CRPIX2'])  > float(crpixzero['CRPIX2']):
                 crpixzero = copy(crpix)
 
             if float(crpix['CRPIX1'])  < float(crpixhigh['CRPIX1']) and float(crpix['CRPIX2'])  < float(crpixhigh['CRPIX2']):
                 crpixhigh = copy(crpix)
 
             print crpix, crpixzero, crpixhigh
         LENGTH1 =  abs(float(crpixhigh['CRPIX1']) - float(crpixzero['CRPIX1'])) + float(crpix['NAXIS1']) 
         LENGTH2 =  abs(float(crpixhigh['CRPIX2']) - float(crpixzero['CRPIX2'])) + float(crpix['NAXIS2']) 
         print crpixhigh['CRPIX1'], crpixzero['CRPIX1'], crpix['NAXIS1'], crpix['NAXIS2']
 
 
 
         print exposure['images']
         'exposures'
 
         children = []
         for image in exposure['images']:
             child = os.fork()
             if child:
                 children.append(child)
             else:
                 print fwhm 
                 params = copy(search_params)  
                 
                 finalflagim = TEMPDIR + "flag_%(ROOT)s.fits" % params 
 
                 weightim = "/%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits" % params
                 #flagim = "/%(path)s/%(fil_directory)s/WEIGHTS/globalflag_%(NUM)s.fits" % params
                 #finalflagim = TEMPDIR + "flag_%(ROOT)s.fits" % params 
                 params['finalflagim'] = weightim
                 im = "/%(path)s/%(fil_directory)s/SCIENCE/%(ROOT)s.fits" % params
                 crpix = utilities.get_header_kw(im,['CRPIX1','CRPIX2'])
 
                 command = "sex /%(path)s/%(fil_directory)s/SCIENCE/%(ROOT)s.fits -c %(PHOTCONF)s/phot.conf.sex \
                 -PARAMETERS_NAME %(PHOTCONF)s/phot.param.sex \
                 -CATALOG_NAME %(TEMPDIR)s/%(ROOT)s.cat \
                 -FILTER_NAME %(DATACONF)s/default.conv\
                 -FILTER  Y \
                 -FLAG_TYPE MAX\
                 -FLAG_IMAGE ''\
                 -SEEING_FWHM %(fwhm).3f \
                 -DETECT_MINAREA 10 -DETECT_THRESH 10 -ANALYSIS_THRESH 10 \
                 -MAG_ZEROPOINT 27.0 \
                 -GAIN %(GAIN).3f \
                 -WEIGHT_IMAGE /%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits\
                 -WEIGHT_TYPE MAP_WEIGHT" % params
                 #-CHECKIMAGE_TYPE BACKGROUND,APERTURES,SEGMENTATION\
                 #-CHECKIMAGE_NAME /%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.background.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.apertures.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.segmentation.fits\
                                                                                                                                                                                                       
                 catname = "%(TEMPDIR)s/%(ROOT)s.cat" % params
                 filtcatname = "%(TEMPDIR)s/%(ROOT)s.filt.cat" % params
                 print command
                 utilities.run(command,[catname])
 
                 utilities.run('ldacfilter -i ' + catname + ' -o ' + filtcatname + ' -t LDAC_OBJECTS\
                             -c "(CLASS_STAR > 0.5);"',[filtcatname])
 
                 import commands
                 lines = commands.getoutput('ldactoasc -s -b -i ' + filtcatname + ' -t LDAC_OBJECTS | wc -l')
                 import re
                 res = re.split('\n',lines)
                 print lines
                 if int(res[-1]) == 0: sys.exit(0)
 
                 command = 'scamp ' + filtcatname + " -SOLVE_PHOTOM N -ASTREF_CATALOG SDSS-R6 -CHECKPLOT_TYPE NONE -WRITE_XML N "  
 
                 print command
                 utilities.run(command)
 
 
                 #headfile = "%(TEMPDIR)s/%(ROOT)s.head" % params
 
                 headfile = "%(TEMPDIR)s/%(ROOT)s.filt.head" % params
                 hf = open(headfile,'r').readlines() 
                 hdict = {}
                 for line in hf:
                     import re
                     if string.find(line,'=') != -1:
                         res = re.split('=',line)
                         name = res[0].replace(' ','')
                         res = re.split('/',res[1])
                         value = res[0].replace(' ','')
                         print name, value
                         hdict[name] = value
                
                 imfix = "/tmp/%(ROOT)s.fixwcs.fits" % params
 
                 command = "cp " + im + " " + imfix
                 utilities.run(command)
 
                 for name in ['CRVAL1','CRVAL2','CD1_1','CD1_2','CD2_1','CD2_2','CRPIX1','CRPIX1']:
                     command = 'sethead ' + imfix + ' ' + name + '=' + hdict[name]
                     print command
                     os.system(command)
 
                 command = "sex /tmp/%(ROOT)s.fixwcs.fits -c %(PHOTCONF)s/phot.conf.sex \
                 -PARAMETERS_NAME %(PHOTCONF)s/phot.param.sex \
                 -CATALOG_NAME %(TEMPDIR)s/%(ROOT)s.fixwcs.cat \
                 -FILTER_NAME %(DATACONF)s/default.conv\
                 -FILTER  Y \
                 -FLAG_TYPE MAX\
                 -FLAG_IMAGE ''\
                 -SEEING_FWHM %(fwhm).3f \
                 -DETECT_MINAREA 5 -DETECT_THRESH 5 -ANALYSIS_THRESH 5 \
                 -MAG_ZEROPOINT 27.0 \
                 -GAIN %(GAIN).3f \
                 -WEIGHT_IMAGE /%(path)s/%(fil_directory)s/WEIGHTS/%(ROOT)s.weight.fits\
                 -WEIGHT_TYPE MAP_WEIGHT" % params
                 #-CHECKIMAGE_TYPE BACKGROUND,APERTURES,SEGMENTATION\
                 #-CHECKIMAGE_NAME /%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.background.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.apertures.fits,/%(path)s/%(fil_directory)s/PHOTOMETRY/coadd.segmentation.fits\
                 catname = "%(TEMPDIR)s/%(ROOT)s.cat" % params
                 print command
                 utilities.run(command,[catname])
 
                 command = 'ldacconv -b 1 -c R -i ' + TEMPDIR + params['ROOT'] + '.fixwcs.cat -o ' + TEMPDIR + params['ROOT'] + '.conv'
                 print command
                 utilities.run(command)
                 # Xpos_ABS is difference of CRPIX and zero CRPIX
                 command = 'ldaccalc -i ' + TEMPDIR + params['ROOT'] + '.conv -o ' + TEMPDIR + params['ROOT'] + '.newpos -t OBJECTS -c "(Xpos + ' + str(float(crpixzero['CRPIX1']) - float(crpix['CRPIX1'])) + ');" -k FLOAT -n Xpos_ABS "" -c "(Ypos + ' + str(float(crpixzero['CRPIX2']) - float(crpix['CRPIX2'])) + ');" -k FLOAT -n Ypos_ABS "" -c "(Ypos*0 + ' + str(params['NUM']) + ');" -k FLOAT -n CHIP "" ' 
 
                 #command = 'ldaccalc -i ' + TEMPDIR + params['ROOT'] + '.conv -o ' + TEMPDIR + params['ROOT'] + '.newpos -t OBJECTS -c "(' + str(crpix['CRPIX1']) + ' - Xpos);" -k FLOAT -n Xpos_ABS "" -c "(' + str(crpix['CRPIX2']) + ' - Ypos);" -k FLOAT -n Ypos_ABS "" -c "(Ypos*0 + ' + str(params['NUM']) + ');" -k FLOAT -n CHIP "" ' 
                 print command
                 utilities.run(command)
                 sys.exit(0)
         for child in children:  
             #print 'waiting for' child
             os.waitpid(child,0)
 
 
         from glob import glob
         outcat = TEMPDIR + 'tmppaste_' + kw + '.cat'
 
         newposlist = glob(TEMPDIR + kw + '*newpos')
         if len(newposlist) > 1:
             command = 'ldacpaste -i ' + TEMPDIR + kw + '*newpos -o ' + outcat 
             print command
         else:
             command = 'cp ' + newposlist[0] + ' ' + outcat 
 
         utilities.run(command)
 
 
         os.system('ldactoasc -i ' + outcat + ' -b -s -k MAG_APER MAGERR_APER -t OBJECTS > /tmp/' + kw + 'aper')
         os.system('asctoldac -i /tmp/' + kw + 'aper -o /tmp/' + kw + 'cat1 -t OBJECTS -c ./photconf/MAG_APER.conf')
 
         outfinal = TEMPDIR + 'paste_' + kw + '.cat'
         os.system('ldacjoinkey -i ' + outcat + ' -p /tmp/' + kw + 'cat1 -o ' + outfinal + ' -k MAG_APER1 MAG_APER2 MAGERR_APER1 MAGERR_APER2')
 
         exposures[kw]['pasted_cat'] = outfinal
 
     return exposures, LENGTH1, LENGTH2 
import numpy as np
import pyfits
import pywcs
import sys
import os
import multiprocessing
import bashreader as bash

dir = sys.argv[1]
filter = sys.argv[2]
coaddvers = sys.argv[3]
fsources = sys.argv[4]
pixscale = float(sys.argv[5])
survey = sys.argv[6]
outdir = sys.argv[7]
usedcpus = bash.parseFile('progs.ini')['npara']

sources = np.genfromtxt(fsources, dtype='str')

fzero = open(outdir + '/' + survey + '_pointings_available_sum_zero.txt', 'w')
fnotzero = open(outdir + '/' + survey + '_pointings_available_sum_not_zero.txt', 'w')

allpointings = sources[:,0]
unique = []
[unique.append(item) for item in allpointings if item not in unique]


def check_coords(pointing):
  sumzerolist = []
  sumnotzerolist = []
usage = \
'''createExclusion.py FILE
     FILE   a txt file with IMAGE    1,2,5,7-9
'''

if len(sys.argv) != 2:
    print usage
#    BonnLogger.updateStatus(__bonn_logger_id__, 1)
    sys.exit(1)

if 'INSTRUMENT' not in os.environ:
    print "INSTRUMENT not set!"
    sys.exit(1)


config = bashreader.parseFile('%s.ini' % os.environ['INSTRUMENT'])
if config is None:
    print "Cannot read %s.ini!" % os.environ['INSTRUMENT']
    sys.exit(1)


filePrefix = config.prefix
nchips = int(config.nchips)


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

def parseChipList(chipList):
    
    chips = []
    for entry in filter(lambda x: x != '',
Example #10
0
def do_multiple(OBJNAME):
    #!/usr/bin/env python
    import os, sys, bashreader, commands
    from utilities import *
    from config_bonn import appendix, cluster, tag, arc, filters, filter_root, appendix_root

    dict = bashreader.parseFile('progs.ini')
    for key in dict.keys():
        os.environ[key] = str(dict[key])

    TEMPDIR = '/tmp/'
    PHOTCONF = './photconf/'
    path = '/nfs/slac/g/ki/ki05/anja/SUBARU/%s/' % cluster
    #type='each'
    type = 'all'

    filecommand = open('record.analysis', 'w')

    BASE = "coadd"
    image = BASE + '.fits'

    print 'Finished Loading Config, utils'

    if type == 'all' or type == 'each':
        children = []
        for filter in filters:
            child = os.fork()
            if child:
                children.append(child)
            else:
                params = {
                    'path': path,
                    'filter_root': filter_root,
                    'cluster': cluster,
                    'filter': filter,
                    'appendix': appendix,
                    'PHOTCONF': PHOTCONF,
                    'TEMPDIR': TEMPDIR
                }
                print params
                # now run sextractor to determine the seeing:
                command = 'sex %(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.fits -c %(PHOTCONF)s/singleastrom.conf.sex \
                            -FLAG_IMAGE /%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.flag.fits \
                            -FLAG_TYPE MAX\
                            -CATALOG_NAME %(TEMPDIR)s/seeing_%(filter)s.cat \
                            -FILTER_NAME %(PHOTCONF)s/default.conv\
                            -CATALOG_TYPE "ASCII" \
                            -DETECT_MINAREA 10 -DETECT_THRESH 10.\
                            -ANALYSIS_THRESH 5 \
                            -PARAMETERS_NAME %(PHOTCONF)s/singleastrom.ascii.param.sex' % params
                print command
                os.system(command)
                sys.exit(0)
        for child in children:
            os.waitpid(child, 0)

        print 'DONE W/ SEEING'

    fwhms = {}
    for filter in filters:
        file_header = '/%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.fits' % {
            'TEMPDIR': TEMPDIR,
            'filter': filter,
            'path': path,
            'cluster': cluster,
            'appendix': appendix
        }
        GAIN, PIXSCALE, EXPTIME = get_header_info(file_header)
        print GAIN, PIXSCALE

        fwhms[filter] = {
            'FILTER': filter,
            'GAIN': GAIN,
            'PIXSCALE': PIXSCALE,
            'EXPTIME': EXPTIME
        }

        if type == 'all' or type == 'each':
            file_seeing = '%(TEMPDIR)s/seeing_%(filter)s.cat' % {
                'TEMPDIR': TEMPDIR,
                'filter': filter
            }
            NLINES = 50
            print 'filter', filter
            fwhms[filter]['SEEING'] = calc_seeing(file_seeing, NLINES,
                                                  PIXSCALE)

    if type == 'all' or type == 'each':
        fwhms_comp = [fwhms[x] for x in fwhms.keys()]
        fwhms_comp.sort(compare)
        seeing_worst = fwhms_comp[0]['SEEING']
        filter_worst = fwhms_comp[0]['FILTER']
        print fwhms
        print 'SEEING', filter_worst, seeing_worst
        for x in fwhms.keys():
            print x, fwhms[x]

        import commands

        for filter in filters:
            print filter

            params = {
                'seeing_orig': float(fwhms[filter]['SEEING']),
                'seeing_new': float(seeing_worst),
                'PIXSCALE': float(PIXSCALE),
                'path': path,
                'cluster': cluster,
                'appendix': appendix,
                'filter': filter,
                'path': path,
                'DATACONF': os.environ['DATACONF']
            }

            command = 'mkdir %(DATACONF)s/default.conv %(path)s/%(filter)s/PHOTOMETRY/' % params
            os.system(command)
            if filter != filter_worst:
                print params
                command = 'python create_gausssmoothing_kernel.py %(seeing_orig).3f %(seeing_new).3f %(PIXSCALE).3f %(path)s/%(filter)s/PHOTOMETRY/' % params
                print command
                os.system(command)
            else:
                command = 'cp %(DATACONF)s/default.conv %(path)s/%(filter)s/PHOTOMETRY/gauss.conv' % params
                os.system(command)

    children = []
    for filter in filters:
        os.system("mkdir /" + path + "/" + filter + "/PHOTOMETRY/")
        os.system("rm /" + path + "/" + filter + "/PHOTOMETRY/" + BASE +
                  ".all" + tag + ".cat")

        child = os.fork()
        if child:
            children.append(child)
        else:

            command = "rm /%(path)s/%(filter)s/PHOTOMETRY/%(filter)s.all.cat" % {
                'path': path,
                'filter': filter
            }
            print command
            os.system(command)

            if type == 'all':

                params = {
                    'path': path,
                    'filter_root': filter_root,
                    'appendix_root': appendix_root,
                    'cluster': cluster,
                    'filter': filter,
                    'appendix': appendix,
                    'PHOTCONF': PHOTCONF,
                    'fwhm': seeing_worst,
                    'BASE': BASE,
                    'GAIN': float(fwhms[filter]['GAIN']),
                    'DATACONF': os.environ['DATACONF'],
                    'tag': tag
                }

                if filter != filter_worst:
                    ''' convolve image -- no background subtraction -- high detection threshold -- no dual detection '''
                    command = "sex /%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.fits -c %(PHOTCONF)s/phot.conf.sex \
                    -PARAMETERS_NAME %(PHOTCONF)s/phot.param.short.sex \
                    -CATALOG_NAME /%(path)s/%(filter)s/PHOTOMETRY/%(filter)s.all%(tag)s.cat \
                    -FILTER_NAME /%(path)s/%(filter)s/PHOTOMETRY/gauss.conv \
                    -FILTER  Y \
                    -SEEING_FWHM %(fwhm).3f \
                    -DETECT_MINAREA 3 -DETECT_THRESH 10000 -ANALYSIS_THRESH 10000 \
                    -MAG_ZEROPOINT 27.0 \
                    -FLAG_TYPE OR\
                    -FLAG_IMAGE /%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.flag.fits \
                    -GAIN %(GAIN).3f \
                    -CHECKIMAGE_NAME /%(path)s/%(filter)s/PHOTOMETRY/coadd.filtered.fits\
                    -CHECKIMAGE_TYPE FILTERED\
                    -BACK_TYPE MANUAL\
                    -BACK_VALUE 0.0\
                    -WEIGHT_IMAGE /%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.weight.fits \
                    -WEIGHT_TYPE MAP_WEIGHT" % params
                else:
                    command = 'cp /%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.fits /%(path)s/%(filter)s/PHOTOMETRY/coadd.filtered.fits' % params

                print command
                print 'making filtered image'
                os.system(command)
                ''' detection images -- one flag image --- one filter -- detect on lensing band '''
                command = "sex /%(path)s/%(filter_root)s/SCIENCE/coadd_%(cluster)s%(appendix_root)s/coadd.fits,/%(path)s/%(filter)s/PHOTOMETRY/coadd.filtered.fits -c %(PHOTCONF)s/phot.conf.sex \
                -PARAMETERS_NAME %(PHOTCONF)s/phot.param.short.sex \
                -CATALOG_NAME /%(path)s/%(filter)s/PHOTOMETRY/%(filter)s.all%(tag)s.cat \
                -FILTER_NAME %(DATACONF)s/default.conv \
                -FILTER  Y \
                -SEEING_FWHM %(fwhm).3f \
                -DETECT_MINAREA 3 -DETECT_THRESH 1.5 -ANALYSIS_THRESH 1.5 \
                -MAG_ZEROPOINT 27.0 \
                -FLAG_TYPE OR\
                -FLAG_IMAGE /%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.flag.fits \
                -GAIN %(GAIN).3f \
                -CHECKIMAGE_NAME /%(path)s/%(filter)s/PHOTOMETRY/coadd.background.fits,/%(path)s/%(filter)s/PHOTOMETRY/coadd.apertures.fits,/%(path)s/%(filter)s/PHOTOMETRY/coadd.segmentation.fits\
                -CHECKIMAGE_TYPE BACKGROUND,APERTURES,SEGMENTATION\
                -WEIGHT_IMAGE /%(path)s/%(filter_root)s/SCIENCE/coadd_%(cluster)s%(appendix_root)s/coadd.weight.fits,/%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.weight.fits \
                -WEIGHT_TYPE MAP_WEIGHT" % params

                print command
                print 'measuring filtered image'
                os.system(command)

                #command = "sex /%(path)s/%(filter_root)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.fits,/%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.fits -c %(PHOTCONF)s/phot.conf.sex \
                #-PARAMETERS_NAME %(PHOTCONF)s/phot.param.sex \
                #-CATALOG_NAME /%(path)s/%(filter)s/PHOTOMETRY/%(filter)s.all%(tag)s.cat \
                #-DETECT_MINAREA 10 -DETECT_THRESH 10 -ANALYSIS_THRESH 10 \
                #-MAG_ZEROPOINT 27.0 \
                #-FLAG_TYPE MAX\
                #-FLAG_IMAGE '' \
                #-GAIN %(GAIN).3f \
                #-WEIGHT_IMAGE /%(path)s/%(filter_root)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.weight.fits,'' \
                #-WEIGHT_TYPE MAP_WEIGHT" % params

            elif type == 'each':
                params = {
                    'path': path,
                    'filter_root': filter_root,
                    'cluster': cluster,
                    'filter': filter,
                    'appendix': appendix,
                    'PHOTCONF': PHOTCONF,
                    'fwhm': seeing_worst,
                    'BASE': BASE,
                    'GAIN': float(fwhms[filter]['GAIN']),
                    'DATACONF': os.environ['DATACONF'],
                    'tag': tag
                }

                command = "sex /%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.fits -c %(PHOTCONF)s/phot.conf.sex \
                -PARAMETERS_NAME %(PHOTCONF)s/phot.param.sex \
                -CATALOG_NAME /%(path)s/%(filter)s/PHOTOMETRY/%(filter)s.each%(tag)s.cat \
                -FILTER_NAME %(DATACONF)s/default.conv \
                -FILTER  Y \
                -SEEING_FWHM %(fwhm).3f \
                -DETECT_MINAREA 3 -DETECT_THRESH 3 -ANALYSIS_THRESH 3 \
                -MAG_ZEROPOINT 27.0 \
                -FLAG_TYPE OR\
                -FLAG_IMAGE /%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.flag.fits \
                -GAIN %(GAIN).3f \
                -WEIGHT_IMAGE /%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.weight.fits \
                -WEIGHT_TYPE MAP_WEIGHT" % params

            elif type == 'arc':

                params = {
                    'path': path,
                    'filter_root': filter_root,
                    'cluster': cluster,
                    'filter': filter,
                    'appendix': appendix,
                    'PHOTCONF': PHOTCONF,
                    'BASE': BASE,
                    'GAIN': float(fwhms[filter]['GAIN']),
                    'DATACONF': os.environ['DATACONF'],
                    'tag': tag
                }

                #command = "sex /%(path)s/%(filter_root)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.fits,/%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.fits -c %(PHOTCONF)s/phot.conf.sex \

                commandA = "sex /%(path)s/%(filter_root)s/PHOTOMETRY/coadd.small.fits,/%(path)s/%(filter)s/PHOTOMETRY/coadd.small.fits -c %(PHOTCONF)s/phot.conf.sex \
                -PHOT_APERTURES 70,100 \
                -BACK_SIZE 10 \
                -BACK_FILTERSIZE 2 \
                -BACKPHOTO_TYPE GLOBAL \
                -BACK_TYPE AUTO \
                -PARAMETERS_NAME %(PHOTCONF)s/phot.param.sex \
                -CATALOG_NAME /%(path)s/%(filter)s/PHOTOMETRY/%(filter)s.arc.all%(tag)s.cat \
                -FILTER_NAME %(DATACONF)s/default.conv,%(DATACONF)s/default.conv\
                -FILTER  Y \
                -DETECT_MINAREA 3 -DETECT_THRESH 0.5 -ANALYSIS_THRESH 0.5  \
                -MAG_ZEROPOINT 27.0 \
                -INTERP-TYPE NONE\
                -FLAG_TYPE MAX\
                -FLAG_IMAGE \"\"\
                -SATUR_LEVEL 30000.0  \
                -MAG_ZEROPOINT 27.0 \
                -GAIN %(GAIN).3f \
                -CHECKIMAGE_NAME /%(path)s/%(filter)s/PHOTOMETRY/coadd.arc.background.fits,/%(path)s/%(filter)s/PHOTOMETRY/coadd.arc.apertures.fits,/%(path)s/%(filter)s/PHOTOMETRY/coadd.arc.segmentation.fits\
                -CHECKIMAGE_TYPE BACKGROUND,APERTURES,SEGMENTATION\
                -WEIGHT_IMAGE /%(path)s/%(filter_root)s/PHOTOMETRY/coadd.weight.arc.small.fits,%(path)s/%(filter)s/PHOTOMETRY/coadd.weight.arc.small.fits\
                -WEIGHT_TYPE NONE" % params

                params['BACK_VALUE'] = 0
                if filter == 'W-J-V':
                    params['BACK_VALUE'] = -0.02

                commandB = "sex /%(path)s/%(filter_root)s/PHOTOMETRY/coadd_small.sub.fits,/%(path)s/%(filter)s/PHOTOMETRY/coadd_small.sub.fits -c %(PHOTCONF)s/phot.conf.sex \
                -PHOT_APERTURES 70,100 \
                -BACK_SIZE 64 \
                -BACK_FILTERSIZE 3 \
                -BACKPHOTO_TYPE GLOBAL \
                -BACK_TYPE MANUAL \
                -BACK_VALUE -0.02 \
                -PARAMETERS_NAME %(PHOTCONF)s/phot.param.sex \
                -CATALOG_NAME /%(path)s/%(filter)s/PHOTOMETRY/%(filter)s.arc.all%(tag)s.cat \
                -FILTER_NAME %(DATACONF)s/default.conv,%(DATACONF)s/default.conv\
                -FILTER  Y \
                -DETECT_MINAREA 3 -DETECT_THRESH 0.5 -ANALYSIS_THRESH 0.5  \
                -MAG_ZEROPOINT 27.0 \
                -INTERP-TYPE NONE\
                -FLAG_TYPE MAX\
                -FLAG_IMAGE \"\"\
                -SATUR_LEVEL 30000.0  \
                -MAG_ZEROPOINT 27.0 \
                -GAIN %(GAIN).3f \
                -CHECKIMAGE_NAME /%(path)s/%(filter)s/PHOTOMETRY/coadd.arc.apertures.fits,/%(path)s/%(filter)s/PHOTOMETRY/coadd.arc.segmentation.fits\
                -CHECKIMAGE_TYPE APERTURES,SEGMENTATION\
                -WEIGHT_IMAGE /%(path)s/%(filter_root)s/PHOTOMETRY/coadd.weight.arc.small.fits,%(path)s/%(filter)s/PHOTOMETRY/coadd.weight.arc.small.fits\
                -WEIGHT_TYPE MAP_WEIGHT" % params

                command = commandB

            #-WEIGHT_IMAGE /%(path)s/%(filter_root)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.weight.fits,%(path)s/%(filter)s/SCIENCE/coadd_%(cluster)s%(appendix)s/coadd.weight.fits\
            print command
            filecommand.write(command + '\n')
            sys.exit(0)

    for child in children:
        os.waitpid(child, 0)

    print 'DONE!!!!'
Example #11
0
    def setUp(self):

        progs = bashreader.parseFile('progs.ini')

        self.sex_command = progs['p_sex']
Example #12
0
'''
######################

import sys, unittest, os, subprocess, glob, shutil, optparse, difflib
import numpy, astropy, astropy.io.fits as pyfits
import ldac, bashreader

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

__cvs_id__ = "$Id: extract_object_cats.py,v 1.10 2010-11-12 20:33:56 dapple Exp $"

#######################
# GLOBAL CONSTANTS
#######################

PROGS = bashreader.parseFile('progs.ini')
PHOTCONF = './photconf'
DATACONF = PROGS['dataconf']
DETECT_OBJS_CONFIG = './photconf/detect.objs.conf.sex'
SMOOTH_IMAGE_CONFIG = './photconf/smooth.image.conf.sex'
DEFAULT_CONV = '%s/default.conv' % DATACONF

os.environ['DATACONF'] = DATACONF

#######################
# USER FUNCTIONS
#######################


def sextractor(image,
               detect=None,