コード例 #1
0
ファイル: Quickimage.py プロジェクト: Zeklandia/quickimage
def make_RGB():

    Blue,header = pf.getdata('Blue.fit',0,header=True)
    Green,header = pf.getdata('Green.fit',0,header=True)
    Red,header = pf.getdata('Red.fit',0,header=True)

    G = h.pyfits.open('Green.fit')
    Gh = h.pyfits.getheader('Green.fit')
    
    B = h.pyfits.open('Blue.fit')
    Bh = h.pyfits.getheader('Blue.fit')
    
    R = h.pyfits.open('Red.fit')
    Rh = h.pyfits.getheader('Red.fit')

    Bnew = h.hcongrid(B[0].data,B[0].header,Gh)
    Rnew = h.hcongrid(R[0].data,R[0].header,Gh)
    
    Blue = Bnew
    Green,header = readimage('Green.fit')
    Red = Rnew

    bmed = np.median(Blue)
    gmed = np.median(Green)
    rmed = np.median(Red)
    
    bsig = rb.std(Blue)
    gsig = rb.std(Green)
    rsig = rb.std(Red)
    
    final = np.zeros((Blue.shape[0],Blue.shape[1],3),dtype=float)  
    
    sigmin = 1.25
    sigmax = 15
    
    final[:,:,0] = img_scale.sqrt(Red,scale_min=rmed+sigmin*rsig,scale_max=rmed+0.6*sigmax*rsig)
    final[:,:,1] = img_scale.sqrt(Green,scale_min=gmed+sigmin*gsig,scale_max=gmed+0.6*sigmax*gsig)
    final[:,:,2] = img_scale.sqrt(Blue,scale_min=bmed+sigmin*bsig,scale_max=bmed+0.6*sigmax*bsig)
    
    plt.ion()
    plt.figure(99)
    #plt.imshow(img,aspect='equal')
    plt.xlim(250,1550)
    plt.ylim(288,1588)
    plt.xticks([])
    plt.yticks([])
    plt.imshow(final,aspect='equal')

    return
コード例 #2
0
ファイル: Quickimage.py プロジェクト: Zeklandia/quickimage
def makeband(band='V'):
    
    files = glob.glob('Mantis*[0-9]'+band+'_cal.fit*')
    zsz = len(files)
    reffile = files[zsz/2]
    image0,header0 = readimage(reffile)
    ysz,xsz = np.shape(image0)
    
    refim = h.pyfits.open(reffile)
    refh = h.pyfits.getheader(reffile)
    
    stack = np.zeros((xsz,ysz,zsz))
    for i in range(zsz):
       im = h.pyfits.open(files[i])
       newim = h.hcongrid(im[0].data,im[0].header,refh)
       stack[:,:,i] = newim
       
    final = np.median(stack,axis=2)
    
    if band == 'V':
        tag = 'Blue'
        
    if band == 'R':
        tag = 'Green'
        
    if band == 'ip':
        tag = 'Red'
        
    test = glob.glob(tag+'.fit')
    if test:
        os.remove(tag+'.fit')
    pf.writeto(tag+'.fit',final,header0)
コード例 #3
0
def project_to_header(fitsfile,
                      header,
                      use_montage=True,
                      quiet=True,
                      **kwargs):
    """
    Light wrapper of montage with hcongrid as a backup

    kwargs will be passed to `~hcongrid.hcongrid` if ``use_montage==False``

    Parameters
    ----------
    fitsfile : string
        a FITS file name
    header : `~astropy.io.fits.Header`
        A fits Header instance with valid WCS to project to
    use_montage : bool
        Use montage or hcongrid (based on `~scipy.ndimage.interpolation.map_coordinates`)
    quiet : bool
        Silence Montage's output

    Returns
    -------
    image : `~numpy.ndarray`
        image projected to header's coordinates

    """
    try:
        import montage
        montageOK = True
    except ImportError:
        montageOK = False
    try:
        from hcongrid import hcongrid
        hcongridOK = True
    except ImportError:
        hcongridOK = False
    import tempfile

    if montageOK and use_montage:
        temp_headerfile = tempfile.NamedTemporaryFile()
        header.toTxtFile(temp_headerfile.name)

        outfile = tempfile.NamedTemporaryFile()
        montage.wrappers.reproject(fitsfile,
                                   outfile.name,
                                   temp_headerfile.name,
                                   exact_size=True,
                                   silent_cleanup=quiet)
        image = fits.getdata(outfile.name)

        outfile.close()
        temp_headerfile.close()
    elif hcongridOK:
        # only works for 2D images
        image = hcongrid(
            fits.getdata(fitsfile).squeeze(),
            flatten_header(fits.getheader(fitsfile)), header, **kwargs)

    return image
コード例 #4
0
def cal_image(filepath,plot = True,path=None,band='gp',source='BD710031',bias=None,dark=None,flat=None):
    
    if not path:
        path = set_path()

    if length(bias) == 1:
        bias = make_bias(path=path)

    if length(dark) == 1:
        dark = make_dark(path=path)

    if length(flat) == 1:
        flat = make_flat(path=path,band=band,bias=bias,dark=dark)
        
        
    image0, header0 = qi.readimage(filepath)
    refh = h.pyfits.getheader(filepath)
   
    im = h.pyfits.open(filepath)
    newim = h.hcongrid((im[0].data-dark-bias)/flat, im[0].header,refh)
    
    if plot:
        qi.display_image(newim)
        
    return newim,header0
コード例 #5
0
def stack_ims(path=None,band='gp',source='NGC188',bias=None,dark=None,flat=None):

    
    if not path:
        path = set_path()

    if length(bias) == 1:
        bias = make_bias(path=path)

    if length(dark) == 1:
        dark = make_dark(path=path)

    if length(flat) == 1:
        flat = make_flat(path=path,band=band,bias=bias,dark=dark)

        
    files,sz = tp.get_files(dir=path, tag=source+'.'+band)

    # Designate reference file 
    reffile = files[sz/2]
    image0, header0 = qi.readimage(reffile)
    ysz, xsz = np.shape(image0)
    refim = h.pyfits.open(reffile)
    refh = h.pyfits.getheader(reffile)
    stack = np.zeros((xsz,ysz,sz))
    
    for i in range(sz):
        im = h.pyfits.open(files[i])
        newim = h.hcongrid((im[0].data-dark-bias)/flat, im[0].header,refh)
        stack[:,:,i] = newim
    
    final = np.median(stack, axis=2)


    return final,refh
コード例 #6
0
ファイル: match_images.py プロジェクト: keflavich/FITS_tools
def project_to_header(fitsfile, header, use_montage=True, quiet=True,
                      **kwargs):
    """
    Light wrapper of montage with hcongrid as a backup

    kwargs will be passed to `~hcongrid.hcongrid` if ``use_montage==False``

    Parameters
    ----------
    fitsfile : string
        a FITS file name
    header : `~astropy.io.fits.Header`
        A fits Header instance with valid WCS to project to
    use_montage : bool
        Use montage or hcongrid (based on `~scipy.ndimage.interpolation.map_coordinates`)
    quiet : bool
        Silence Montage's output

    Returns
    -------
    image : `~numpy.ndarray`
        image projected to header's coordinates

    """
    try:
        import montage
        montageOK=True
    except ImportError:
        montageOK=False
    try:
        from hcongrid import hcongrid
        hcongridOK=True
    except ImportError:
        hcongridOK=False
    import tempfile

    if montageOK and use_montage:
        temp_headerfile = tempfile.NamedTemporaryFile()
        header.toTxtFile(temp_headerfile.name)

        outfile = tempfile.NamedTemporaryFile()
        montage.wrappers.reproject(fitsfile, outfile.name,
                temp_headerfile.name, exact_size=True,
                silent_cleanup=quiet)
        image = fits.getdata(outfile.name)
        
        outfile.close()
        temp_headerfile.close()
    elif hcongridOK:
        # only works for 2D images
        image = hcongrid(fits.getdata(fitsfile).squeeze(),
                         flatten_header(fits.getheader(fitsfile)),
                         header,
                         **kwargs)

    return image
コード例 #7
0
def project_to_header(fitsfile,
                      header,
                      use_montage=True,
                      quiet=True,
                      **kwargs):
    """
    Light wrapper of montage with hcongrid as a backup

    Parameters
    ----------
        fitsfile : string
            a FITS file name
        header : pyfits.Header
            A pyfits Header instance with valid WCS to project to
        use_montage : bool
            Use montage or hcongrid (scipy's map_coordinates)
        quiet : bool
            Silence Montage's output

    Returns
    -------
        np.ndarray image projected to header's coordinates

    """
    try:
        import montage
        montageOK = True
    except ImportError:
        montageOK = False
    try:
        from hcongrid import hcongrid
        hcongridOK = True
    except ImportError:
        hcongridOK = False
    import tempfile

    if montageOK and use_montage:
        temp_headerfile = tempfile.NamedTemporaryFile()
        header.toTxtFile(temp_headerfile.name)

        outfile = tempfile.NamedTemporaryFile()
        montage.wrappers.reproject(fitsfile,
                                   outfile.name,
                                   temp_headerfile.name,
                                   exact_size=True,
                                   silent_cleanup=quiet)
        image = pyfits.getdata(outfile.name)

        outfile.close()
        temp_headerfile.close()
    elif hcongridOK:
        image = hcongrid(load_data(fitsfile), load_header(fitsfile), header)

    return image
コード例 #8
0
def project_to_header(fitsfile, header, use_montage=True, quiet=True, **kwargs):
    """
    Light wrapper of montage with hcongrid as a backup

    Parameters
    ----------
        fitsfile : string
            a FITS file name
        header : pyfits.Header
            A pyfits Header instance with valid WCS to project to
        use_montage : bool
            Use montage or hcongrid (scipy's map_coordinates)
        quiet : bool
            Silence Montage's output

    Returns
    -------
        np.ndarray image projected to header's coordinates

    """
    try:
        import montage
        montageOK=True
    except ImportError:
        montageOK=False
    try:
        from hcongrid import hcongrid
        hcongridOK=True
    except ImportError:
        hcongridOK=False
    import tempfile

    if montageOK and use_montage:
        temp_headerfile = tempfile.NamedTemporaryFile()
        header.toTxtFile(temp_headerfile.name)

        outfile = tempfile.NamedTemporaryFile()
        montage.wrappers.reproject(fitsfile,
                                   outfile.name,
                                   temp_headerfile.name,
                                   exact_size=True,
                                   silent_cleanup=quiet)
        image = pyfits.getdata(outfile.name)
        
        outfile.close()
        temp_headerfile.close()
    elif hcongridOK:
        image = hcongrid(load_data(fitsfile),
                         load_header(fitsfile),
                         header)

    return image