Пример #1
0
def show_sn_on_image(nickname, imfilename,
                     datfile='candels_sn_hostphot.txt',
                     imsizearcsec=2.5, circleradarcsec=0.2,
                     color='red'):
    indat = ascii.read(datfile, format='commented_header',
                       header_start=-1, data_start=0)
    nicknamelist = np.array([nick.lower() for nick in indat['nickname']])
    isn = np.where(nicknamelist==nickname)[0]
    raHMS = indat['RA_SN'][isn]
    decDMS = indat['DEC_SN'][isn]
    raDD, decDD = convert_hmsdms_to_deg(raHMS, decDMS)

    cwd = os.path.abspath('.')
    sndir = os.path.join(cwd, nickname.lower())
    ax = pl.gca()
    combofile = os.path.join(sndir, imfilename )
    combodat = pyfits.getdata(combofile)
    xsn, ysn = hstphot.radec2xy(combofile, raDD, decDD)
    pixscale = imageops.getpixscale(combofile)
    imsizepix = imsizearcsec / pixscale
    halfimsizepix = round(imsizepix/2)
    imdatcenter = combodat[
                  int(ysn-halfimsizepix):int(ysn+halfimsizepix),
                  int(xsn-halfimsizepix):int(xsn+halfimsizepix)]

    ax.imshow(imdatcenter, aspect='equal', interpolation='nearest',
              vmin=-0.05, vmax=0.15, cmap=cm.Greys_r)
    circleradpix = circleradarcsec / pixscale
    c = Circle((halfimsizepix - 1 + (xsn % 1), halfimsizepix - 1 + (ysn % 1)),
                radius=circleradpix, edgecolor=color, facecolor='None')
    ax.add_patch(c)
    ax.set_xticks([])
    ax.set_yticks([])
    return
Пример #2
0
def show_sn_on_image(nickname,
                     imfilename,
                     datfile='candels_sn_hostphot.txt',
                     imsizearcsec=2.5,
                     circleradarcsec=0.2,
                     color='red'):
    indat = ascii.read(datfile,
                       format='commented_header',
                       header_start=-1,
                       data_start=0)
    nicknamelist = np.array([nick.lower() for nick in indat['nickname']])
    isn = np.where(nicknamelist == nickname)[0]
    raHMS = indat['RA_SN'][isn]
    decDMS = indat['DEC_SN'][isn]
    raDD, decDD = convert_hmsdms_to_deg(raHMS, decDMS)

    cwd = os.path.abspath('.')
    sndir = os.path.join(cwd, nickname.lower())
    ax = pl.gca()
    combofile = os.path.join(sndir, imfilename)
    combodat = pyfits.getdata(combofile)
    xsn, ysn = hstphot.radec2xy(combofile, raDD, decDD)
    pixscale = imageops.getpixscale(combofile)
    imsizepix = imsizearcsec / pixscale
    halfimsizepix = round(imsizepix / 2)
    imdatcenter = combodat[int(ysn - halfimsizepix):int(ysn + halfimsizepix),
                           int(xsn - halfimsizepix):int(xsn + halfimsizepix)]

    ax.imshow(imdatcenter,
              aspect='equal',
              interpolation='nearest',
              vmin=-0.05,
              vmax=0.15,
              cmap=cm.Greys_r)
    circleradpix = circleradarcsec / pixscale
    c = Circle((halfimsizepix - 1 + (xsn % 1), halfimsizepix - 1 + (ysn % 1)),
               radius=circleradpix,
               edgecolor=color,
               facecolor='None')
    ax.add_patch(c)
    ax.set_xticks([])
    ax.set_yticks([])
    return
Пример #3
0
def update_sn_coordinates(nickname, datfile='candels_sn_hostphot.txt',
                          verbose=True, clobber=False):
    """ display IR diff image, let the user select the epochs where the SN is
    visible, make a stack, get an updated measurement of the SN position
    :return:
    """
    cwd = os.path.abspath('.')
    sndir = os.path.join(cwd, nickname.lower())
    if not os.path.isdir(sndir):
        raise exceptions.RuntimeError("No directory %s" % sndir)
    diffimlist = glob.glob(sndir+"/*f1*sub_masked.fits")
    combofile = os.path.join(sndir, '%s_composite_sub_masked.fits' %
                             nickname.lower())
    indat = ascii.read(datfile, format='commented_header',
                       header_start=-1, data_start=0)
    nicknamelist = np.array([nick.lower() for nick in indat['nickname']])
    isn = np.where(nicknamelist==nickname)[0]
    raHMS = indat['RA_SN'][isn]
    decDMS = indat['DEC_SN'][isn]
    raDD, decDD = convert_hmsdms_to_deg(raHMS, decDMS)

    if not os.path.isfile(combofile) or clobber:
        fig = pl.figure(1, figsize=[12, 4])
        fig.subplots_adjust(left=0.03, bottom=0.03, right=0.97, top=0.97)
        if verbose:
            print("Constructing composite image %s from: %s" % (
                combofile,
                str([os.path.basename(diffim) for diffim in combinelist])))
        fig.clf()
        fig.suptitle('%s Recentering' % nickname)
        iax = 0
        if verbose:
            print "plotting diff images to select for composite image"
        for diffim in diffimlist:
            imname = os.path.basename(diffim)
            imnameparts = imname.split('_')
            filter = imnameparts[1]
            epoch = imnameparts[2]
            iax += 1

            ax = fig.add_subplot(1, len(diffimlist), iax)
            show_sn_on_image(nickname, diffim, datfile=datfile,
                             imsizearcsec=1.0, circleradarcsec=0.2)
            ax.text(0.0, 1.2, '%i: %s \n%s' % (iax, filter, epoch),
                    transform=ax.transAxes, ha='left', va='bottom')
        pl.draw()
        iwithsn = input("Recentering for %s\n" % nickname +
                        "Enter a comma-sep'd list of image numbers in which"
                        " the SN is bright enough for centroiding:"
                        "\n   ")
        combinelist = np.array(diffimlist)[list(iwithsn)]
        combofile = imageops.imaverage(combinelist, combofile, clobber=True)
    elif os.path.isfile(combofile) and not clobber:
        print "%s exists.  Not clobbering." % combofile

    fig = pl.figure(10, figsize=[4, 4])
    fig.clf()
    ax = fig.add_subplot(1, 1, 1)
    show_sn_on_image(nickname, combofile, datfile=datfile,
                     imsizearcsec=1.0, circleradarcsec=0.2, color='cyan')

    # locate the sn centroid position
    xsn, ysn = hstphot.radec2xy(combofile, raDD, decDD)
    combodat = pyfits.getdata(combofile)
    xnew, ynew = cntrd.cntrd(combodat, xsn, ysn, 5)
    xnew += 1 # convert from iraf to python-style coordinates
    ynew += 1 # convert from iraf to python-style coordinates
    ranew, decnew = hstphot.xy2radec(combofile, xnew, ynew)
    ranew = ranew[0]
    decnew = decnew[0]
    raHMSnew, decDMSnew =  convert_deg_to_hmsdms(ranew, decnew)
    oldstr = '%-15s old(cyan): %11s %-11s  %10.6f %10.6f %9.3f %9.3f'%(
        nickname.lower(), raHMS[0], decDMS[0], raDD, decDD, xsn, ysn)
    newstr = '%-15s new(red) : %11s %-11s  %10.6f %10.6f %9.3f %9.3f'%(
        nickname.lower(), raHMSnew, decDMSnew, ranew, decnew, xnew, ynew)
    print oldstr
    print newstr

    # show the new position as a red circle
    pixscale = imageops.getpixscale(combofile)
    circleradpix = 0.2 / pixscale
    imsizepix = 1.0 / pixscale
    halfimsizepix = round(imsizepix/2)
    c = Circle((halfimsizepix - 1 + int(xnew)-int(xsn) + (xnew % 1),
                halfimsizepix - 1 + int(ynew)-int(ysn) + (ynew % 1)),
                radius=circleradpix, edgecolor='red', facecolor='None')
    ax.add_patch(c)
    fig.suptitle('%s : red=new position' % nickname)
    return raHMSnew, decDMSnew, ranew, decnew
Пример #4
0
def update_sn_coordinates(nickname,
                          datfile='candels_sn_hostphot.txt',
                          verbose=True,
                          clobber=False):
    """ display IR diff image, let the user select the epochs where the SN is
    visible, make a stack, get an updated measurement of the SN position
    :return:
    """
    cwd = os.path.abspath('.')
    sndir = os.path.join(cwd, nickname.lower())
    if not os.path.isdir(sndir):
        raise exceptions.RuntimeError("No directory %s" % sndir)
    diffimlist = glob.glob(sndir + "/*f1*sub_masked.fits")
    combofile = os.path.join(sndir,
                             '%s_composite_sub_masked.fits' % nickname.lower())
    indat = ascii.read(datfile,
                       format='commented_header',
                       header_start=-1,
                       data_start=0)
    nicknamelist = np.array([nick.lower() for nick in indat['nickname']])
    isn = np.where(nicknamelist == nickname)[0]
    raHMS = indat['RA_SN'][isn]
    decDMS = indat['DEC_SN'][isn]
    raDD, decDD = convert_hmsdms_to_deg(raHMS, decDMS)

    if not os.path.isfile(combofile) or clobber:
        fig = pl.figure(1, figsize=[12, 4])
        fig.subplots_adjust(left=0.03, bottom=0.03, right=0.97, top=0.97)
        if verbose:
            print("Constructing composite image %s from: %s" %
                  (combofile,
                   str([os.path.basename(diffim) for diffim in combinelist])))
        fig.clf()
        fig.suptitle('%s Recentering' % nickname)
        iax = 0
        if verbose:
            print "plotting diff images to select for composite image"
        for diffim in diffimlist:
            imname = os.path.basename(diffim)
            imnameparts = imname.split('_')
            filter = imnameparts[1]
            epoch = imnameparts[2]
            iax += 1

            ax = fig.add_subplot(1, len(diffimlist), iax)
            show_sn_on_image(nickname,
                             diffim,
                             datfile=datfile,
                             imsizearcsec=1.0,
                             circleradarcsec=0.2)
            ax.text(0.0,
                    1.2,
                    '%i: %s \n%s' % (iax, filter, epoch),
                    transform=ax.transAxes,
                    ha='left',
                    va='bottom')
        pl.draw()
        iwithsn = input("Recentering for %s\n" % nickname +
                        "Enter a comma-sep'd list of image numbers in which"
                        " the SN is bright enough for centroiding:"
                        "\n   ")
        combinelist = np.array(diffimlist)[list(iwithsn)]
        combofile = imageops.imaverage(combinelist, combofile, clobber=True)
    elif os.path.isfile(combofile) and not clobber:
        print "%s exists.  Not clobbering." % combofile

    fig = pl.figure(10, figsize=[4, 4])
    fig.clf()
    ax = fig.add_subplot(1, 1, 1)
    show_sn_on_image(nickname,
                     combofile,
                     datfile=datfile,
                     imsizearcsec=1.0,
                     circleradarcsec=0.2,
                     color='cyan')

    # locate the sn centroid position
    xsn, ysn = hstphot.radec2xy(combofile, raDD, decDD)
    combodat = pyfits.getdata(combofile)
    xnew, ynew = cntrd.cntrd(combodat, xsn, ysn, 5)
    xnew += 1  # convert from iraf to python-style coordinates
    ynew += 1  # convert from iraf to python-style coordinates
    ranew, decnew = hstphot.xy2radec(combofile, xnew, ynew)
    ranew = ranew[0]
    decnew = decnew[0]
    raHMSnew, decDMSnew = convert_deg_to_hmsdms(ranew, decnew)
    oldstr = '%-15s old(cyan): %11s %-11s  %10.6f %10.6f %9.3f %9.3f' % (
        nickname.lower(), raHMS[0], decDMS[0], raDD, decDD, xsn, ysn)
    newstr = '%-15s new(red) : %11s %-11s  %10.6f %10.6f %9.3f %9.3f' % (
        nickname.lower(), raHMSnew, decDMSnew, ranew, decnew, xnew, ynew)
    print oldstr
    print newstr

    # show the new position as a red circle
    pixscale = imageops.getpixscale(combofile)
    circleradpix = 0.2 / pixscale
    imsizepix = 1.0 / pixscale
    halfimsizepix = round(imsizepix / 2)
    c = Circle(
        (halfimsizepix - 1 + int(xnew) - int(xsn) +
         (xnew % 1), halfimsizepix - 1 + int(ynew) - int(ysn) + (ynew % 1)),
        radius=circleradpix,
        edgecolor='red',
        facecolor='None')
    ax.add_patch(c)
    fig.suptitle('%s : red=new position' % nickname)
    return raHMSnew, decDMSnew, ranew, decnew