Пример #1
0
def convert_to_coordinates(ra, dec, evt, ctype):
    """
    convert ra dec to sky, det, or chip coordinates
    input:  ra      --- ra in degree
            dec     --- dec in degree
            evt     --- evt1 file 
            ctype   --- sky/det/chip
    output: [newx, newy]
    """
    
    cmd = 'dmcoords ' + evt + ' opt=cel ra=' + str(ra) + ' dec=' + str(dec) + ' verbose=1 > ' + zspace
    hcf.run_ascds(cmd)

    newx= ''
    newy= ''
#
#--- extract sky coordindats
#
    info = read_data(zspace, remove=1)
    info.reverse()
    for ent in info:
        if ctype == 'sky':
            mc = re.search('SKY\(X,Y\)', ent)
        elif ctype == 'det':
            mc = re.search('DETX,DETY',  ent)
        elif ctype == 'chip':
            mc = re.search('CHIP',       ent)
        if mc is not None:
            atemp = re.split('\s+', ent)
            newx = float(atemp[1])
            newy = float(atemp[2])

    return [newx, newy]
Пример #2
0
def select_letg_arm(ofits, outfile, include=1):
    """
    extract area defined by letg arm area either include or exclude
    input:  ofits   --- fits file name
            outfile --- output fits file name
            include --- if 1: include the area, 0: exclude the area
    output: outfile --- resulted fits file

    note: polygons are from:
        $CALDB/data/chandra/hrc/tgmask2/letgD1999-07-22regN0002.fits"[ROWID=SOURCE]"
    """
    #
    #--- letg polygon areas
    #
    if include == 1:
        area1 = '(-0.0057803997770,  0.000531000027 '
        area1 = area1 + ',-0.29866999387741, 0.000531000027       '
        area1 = area1 + ',-1.1548999548,     0.00211400003172     '
        area1 = area1 + ',-1.1548999548,    -0.00211400003172     '
        area1 = area1 + ',-0.29866999387741,-0.000531000027       '
        area1 = area1 + ',-0.0057803997770, -0.000531000027      '
        area1 = area1 + ',-0.0057803997770,  0.000531000027)      '

        area2 = '(0.0057803997770,   0.000531000027'
        area2 = area2 + ',0.29866999387741,  0.000531000027       '
        area2 = area2 + ',    1.1548999548,  0.00211400003172     '
        area2 = area2 + ',    1.1548999548, -0.00211400003172     '
        area2 = area2 + ',0.29866999387741, -0.000531000027       '
        area2 = area2 + ',0.0057803997770,  -0.000531000027      '
        area2 = area2 + ',0.0057803997770,   0.000531000027)'
#
#--- letg polygon background area
#
    else:
        area1 = '(-0.0057803997770,   0.00730999978259  '
        area1 = area1 + ',-0.29866999387741,   0.00730999978259  '
        area1 = area1 + ',-1.1548999548,       0.02314000017941  '
        area1 = area1 + ',-1.1548999548,       0.00200000009499  '
        area1 = area1 + ',-0.29866999387741,   0.00200000009499  '
        area1 = area1 + ',-0.0057803997770,    0.00200000009499  '
        area1 = area1 + ',-0.0057803997770,    0.00730999978259) '

        area2 = '(0.0057803997770,   -0.00730999978259          '
        area2 = area2 + ',0.29866999387741,  -0.00730999978259  '
        area2 = area2 + ',1.1548999548,      -0.02314000017941  '
        area2 = area2 + ',1.1548999548,      -0.00200000009499  '
        area2 = area2 + ',0.29866999387741,  -0.00200000009499  '
        area2 = area2 + ',0.0057803997770,   -0.00200000009499  '
        area2 = area2 + ',0.0057803997770,   -0.00730999978259) '
#
#--- create dmcopy command
#
    cmd = 'dmcopy "' + ofits + '[(tg_r,tg_d)='
    cmd = cmd + ' polygon' + area1
    cmd = cmd + '+polygon' + area2
    cmd = cmd + ']" outfile=' + outfile + ' clobber="yes"'

    hcf.run_ascds(cmd)
Пример #3
0
def filter_by_status(fits):
    """
    filter fits file by the status column
    input:  fits    --- fits file
    output: fits    --- status filtered fits file
    """

    filter = '0000xxxx000xxxxx'
    cmd = ' dmcopy "' + fits + '[status=0000xxxx000xxxxx]" outfile=zxc.fits clobber=yes'
    #run_ciao(cmd)
    hcf.run_ascds(cmd)
    #run_ascds(cmd)

    cmd = 'mv zxc.fits ' + fits
    os.system(cmd)
Пример #4
0
def get_target_data(obsid, evt1, clean, carea, barea, ra_targ, dec_targ, yoffset, zoffset, inst):
    """
    extract center part of the data and the background
    input:  obsid   --- obsid
            evt1    --- event 1 data fits file name
            clean   --- cleaned fits file name
            carea   --- extracted main area output fits file
            barea   --- txtracted background output  fits file
    output: carea /barea
    """
#
#--- set the radius around the source and the background area
#
    [radius, annul1, annul2, tarea, sarea, cx, cy] = set_radius(yoffset, zoffset, inst)
#
#--- check whether manually determined sky coordinates are available 
#
    #cmd = ' tgdetect ' + evt1 + ' none  zo_pos_x=' + ra_targ + ' zo_pos_y=' + dec_targ + ' outfile=zinfo.fits clobber=yes'
    cmd = ' celldetect ' + evt1 + ' outfile=zinfo.fits clobber=yes'
    hcf.run_ascds(cmd)

    t     = pyfits.open('zinfo.fits')
    tdata = t[1].data

    data  = tdata['net_counts']
    dmax  = 0
    pos   = 0
    for k in range(0, len(data)):
        val = float(data[k])
        if val > dmax:
            dmax = val
            pos  = k

    psave = []
    for ent in ('x', 'y', 'net_counts', 'net_counts_err', 'bkg_counts', 'bkg_counts_err', 'net_rate',\
                 'net_rate_err', 'bkg_rate', 'bkg_rate_err'):
        try:
            data  = tdata.field(ent)
            out   = data[pos]
            psave.append(out)
        except:
            pass
    t.close()

    x = psave[0]
    y = psave[1]

    mcf.rm_file('zinfo.fits')
#
#--- center part
#
    cmd   = 'dmcopy "' + clean + '[(x,y)=circle(' + str(x) + ',' + str(y) 
    cmd   = cmd + ',' + str(radius) + ')]" outfile=' + carea + ' clobber=yes'
    hcf.run_ascds(cmd)

#
#--- background area; annulus around the source position
#
    if cx == 0:     #--- hrc s case and hrc i offset < 13.6 arcmin
        px = x
        py = y
    else:           #--- hrc i with offset > 13.6 arcmin
        px = cx
        py = cy

    cmd   = 'dmcopy "' + clean + '[(x,y)=annulus(' + str(px) + ',' + str(py)  
    cmd   = cmd + ',' +  str(annul1) + ',' + str(annul2)
    cmd   = cmd + ')]" outfile=' + barea + ' clobber=yes'
    hcf.run_ascds(cmd)
    
    line  = str(psave[0])
    for  k in range(1, len(psave)):
        line  = line + '\t'  + str(psave[k])

    line = line + '\n'

    ofile = data_dir + 'Fittings/' + str(obsid) + '/center_info'
    fo    = open(ofile, 'w')
    fo.write(line)
    fo.close()

    return [float(x), float(y), tarea, sarea]
Пример #5
0
def get_center_data(obsid, evt1, clean, carea, barea):
    """
    extract center part of the data and the background
    input:  obsid   --- obsid
            evt1    --- event 1 data fits file name
            clean   --- cleaned fits file name
            carea   --- extracted main area output fits file
            barea   --- txtracted background output  fits file
    output: carea /barea
    """
    #
    #--- check whether manually determined sky coordinates are available
    #
    [skyx, skyy] = check_sky_coord_list(obsid)
    #
    #--- try tgdetect to find the center part first
    #
    try:
        cmd = ' tgdetect ' + evt1 + ' none outfile=zinfo.fits clobber=yes'
        hcf.run_ascds(cmd)

        t = pyfits.open('zinfo.fits')
        tdata = t[1].data
        t.close()
        pos = 0
        test = tdata.field('x')[0]
        dchk = 1
#
#--- if tgdetect does not work try celldetect
#
    except:
        cmd = ' celldetect ' + evt1 + ' outfile=zinfo.fits clobber=yes'
        hcf.run_ascds(cmd)
        t = pyfits.open('zinfo.fits')
        tdata = t[1].data
        data = tdata['net_counts']
        if len(data) > 0:
            dmax = 0
            pos = 0
            for k in range(0, len(data)):
                val = float(data[k])
                if val > dmax:
                    dmax = val
                    pos = k
            dchk = 2
        else:
            if skyx == '':
                return False
            else:
                dchk = 3
#
#--- get the information about the center source area
#
    if dchk == 1 or dchk == 2:
        psave = []
        for ent in ('x', 'y', 'net_counts', 'net_counts_err', 'bkg_counts', 'bkg_counts_err', 'net_rate',\
                    'net_rate_err', 'bkg_rate', 'bkg_rate_err'):
            try:
                data = tdata.field(ent)
                out = data[pos]
                psave.append(out)
            except:
                if skyx == '':
                    return False

    mcf.rm_file('zinfo.fits')
    #
    #--- center part
    #
    if skyx != '':
        cmd = 'dmcopy "' + clean + '[(x,y)=circle(' + str(skyx) + ',' + str(
            skyy)
    else:
        cmd = 'dmcopy "' + clean + '[(x,y)=circle(' + str(
            psave[0]) + ',' + str(psave[1])
    cmd = cmd + ',200)]" outfile=' + carea + ' clobber=yes'
    hcf.run_ascds(cmd)
    #
    #--- background area; 400 pix above the center area
    #
    ypos = float(psave[1]) + 400
    cmd = 'dmcopy "' + clean + '[(x,y)=circle(' + str(
        psave[0]) + ',' + str(ypos)
    cmd = cmd + ', 200)]" outfile=' + barea + ' clobber=yes'
    hcf.run_ascds(cmd)

    line = str(psave[0])
    for k in range(1, len(psave)):
        line = line + '\t' + str(psave[k])

    line = line + '\n'

    ofile = data_dir + 'Fittings/' + str(obsid) + '/center_info'
    fo = open(ofile, 'w')
    fo.write(line)
    fo.close()

    return True