Exemple #1
0
def mk_image(galaxy):
    base = './../../images_v5/GS_2.5as_matched/gs_all_'

    i_img = pyf.getdata(base+str(galaxy)+'_I.fits')
    j_img = pyf.getdata(base+str(galaxy)+'_J.fits')
    h_img = pyf.getdata(base+str(galaxy)+'_H.fits')

    #include 90% of pixels
    x = pyl.hstack(i_img)
    i_lim = scoreatpercentile(x,99)
    x = pyl.hstack(j_img)
    j_lim = scoreatpercentile(x,99)
    x = pyl.hstack(h_img)
    h_lim = scoreatpercentile(x,99)

    print galaxy, i_lim, j_lim, h_lim

    img = pyl.zeros((h_img.shape[0], h_img.shape[1], 3), dtype=float)
    img[:,:,0] = img_scale.asinh(h_img, scale_min=-0.1*h_lim, scale_max=h_lim,
            non_linear=0.5)
    img[:,:,1] = img_scale.asinh(j_img, scale_min=-0.1*j_lim, scale_max=j_lim,
            non_linear=0.5)
    img[:,:,2] = img_scale.asinh(i_img, scale_min=-0.1*i_lim, scale_max=i_lim,
            non_linear=0.5)

    return img
Exemple #2
0
def mk_image(galaxy):
    base = './../../images_v5/GS_2.5as_matched/gs_all_'

    i_img = pyf.getdata(base + str(galaxy) + '_I.fits')
    j_img = pyf.getdata(base + str(galaxy) + '_J.fits')
    h_img = pyf.getdata(base + str(galaxy) + '_H.fits')

    #include 90% of pixels
    x = pyl.hstack(i_img)
    i_lim = scoreatpercentile(x, 99)
    x = pyl.hstack(j_img)
    j_lim = scoreatpercentile(x, 99)
    x = pyl.hstack(h_img)
    h_lim = scoreatpercentile(x, 99)

    print galaxy, i_lim, j_lim, h_lim

    img = pyl.zeros((h_img.shape[0], h_img.shape[1], 3), dtype=float)
    img[:, :, 0] = img_scale.asinh(h_img,
                                   scale_min=-0.1 * h_lim,
                                   scale_max=h_lim,
                                   non_linear=0.5)
    img[:, :, 1] = img_scale.asinh(j_img,
                                   scale_min=-0.1 * j_lim,
                                   scale_max=j_lim,
                                   non_linear=0.5)
    img[:, :, 2] = img_scale.asinh(i_img,
                                   scale_min=-0.1 * i_lim,
                                   scale_max=i_lim,
                                   non_linear=0.5)

    return img
Exemple #3
0
def mk_image(galaxy):
    base = './../../images_v5/GS_2.5as_matched/gs_all_'

    i_img = pyf.getdata(base + str(galaxy) + '_I.fits')
    j_img = pyf.getdata(base + str(galaxy) + '_J.fits')
    h_img = pyf.getdata(base + str(galaxy) + '_H.fits')

    img = pyl.zeros((h_img.shape[0], h_img.shape[1], 3), dtype=float)
    img[:, :, 0] = img_scale.asinh(h_img)
    img[:, :, 1] = img_scale.asinh(j_img)
    img[:, :, 2] = img_scale.asinh(i_img)

    return img
def mk_image(galaxy):
    base = './../../images_v5/GS_2.5as_matched/gs_all_'

    i_img = pyf.getdata(base+str(galaxy)+'_I.fits')
    j_img = pyf.getdata(base+str(galaxy)+'_J.fits')
    h_img = pyf.getdata(base+str(galaxy)+'_H.fits')

    img = pyl.zeros((h_img.shape[0], h_img.shape[1], 3), dtype=float)
    img[:,:,0] = img_scale.asinh(h_img)
    img[:,:,1] = img_scale.asinh(j_img)
    img[:,:,2] = img_scale.asinh(i_img)

    return img
def makeRGB(rimg,gimg,bimg,minsigma=1.,maxpercentile=99.9,color_scaling=None,sigmaclip=3,iters=20,nonlinear=8.):
    ''' minsigma -- black level is set this many clipped-sigma below sky
       maxpercentile -- white level is set at this percentile of the pixel levels
       color_scaling -- list or array: maximum value is divided by this; 
                        so if you want the brightest pixels to be reddish, try, say 1.0,0.2, 0.1
       sigmaclip -- clipping threshold for iterative sky determination
       iters -- number of iterations for iterative sky determination
    '''
    bands = ['r','g','b']
    # Color scaling
    if color_scaling == None:
        cfactor = {'r':1.,'g':1.0,'b':1.0}
    else:
        cfactor = {}
        for i,b in enumerate(bands):
            cfactor[b] = color_scaling[i]
    images = {'r':rimg, 'g':gimg, 'b':bimg}
    rescaled_img = {}
    for b in ['r','g','b']:
        mean, median, stddev = astats.sigma_clipped_stats(images[b],sigma=sigmaclip,iters=iters)
        imin = median-minsigma*stddev
        imax = np.percentile(images[b],maxpercentile)
        rescaled_img[b] = img_scale.asinh(images[b],scale_min=imin,scale_max=imax/cfactor[b],non_linear=nonlinear)
        print imin,imax
    rgbimg = np.zeros((rescaled_img['r'].shape[0],rescaled_img['r'].shape[1],3),dtype=np.float64)
    rgbimg[:,:,0]=rescaled_img['r']
    rgbimg[:,:,1]=rescaled_img['g']
    rgbimg[:,:,2]=rescaled_img['b']
    return rgbimg
Exemple #6
0
def return_stellar_mass_img(filename, camera=0, scale_min=1e8, scale_max=1e10, size_scale=1.0, non_linear=1e8):
    image = sunpy__load.load_stellar_mass_map(filename, camera=camera)
    n_pixels = image.shape[0]
    img = np.zeros((n_pixels, n_pixels), dtype=float)
    img[:,:] = img_scale.asinh(image, scale_min=scale_min, scale_max=scale_max, non_linear=non_linear)
    img[img<0] = 0
    return img
Exemple #7
0
def return_johnson_uvk_img(filename,
                           camera=0,
                           scale_min=0.1,
                           scale_max=50,
                           size_scale=1.0):
    if (not os.path.exists(filename)):
        print "file not found:", filename
        sys.exit()

    b_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths(
        filename, band="U_Johnson.res")
    g_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths(
        filename, band="V_Johnson.res")
    r_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths(
        filename, band="K_Johnson.res")

    b_image = sunpy__load.load_broadband_image(
        filename, band='U_Johnson.res',
        camera=camera) * b_effective_wavelength / g_effective_wavelength * 2.5
    g_image = sunpy__load.load_broadband_image(
        filename, band='V_Johnson.res',
        camera=camera) * g_effective_wavelength / g_effective_wavelength
    r_image = sunpy__load.load_broadband_image(
        filename, band='K_Johnson.res',
        camera=camera) * r_effective_wavelength / g_effective_wavelength * 1.5

    n_pixels
    img = np.zeros((n_pixels, n_pixels, 3), dtype=float)
    img[:, :, 0] = img_scale.asinh(r_image,
                                   scale_min=scale_min,
                                   scale_max=scale_max,
                                   non_linear=0.5)
    img[:, :, 1] = img_scale.asinh(g_image,
                                   scale_min=scale_min,
                                   scale_max=scale_max,
                                   non_linear=0.5)
    img[:, :, 2] = img_scale.asinh(b_image,
                                   scale_min=scale_min,
                                   scale_max=scale_max,
                                   non_linear=0.5)
    img[img < 0] = 0
    return img
Exemple #8
0
def return_johnson_uvk_img(filename,camera=0,scale_min=0.1,scale_max=50,size_scale=1.0):
    if (not os.path.exists(filename)):
        print "file not found:", filename
        sys.exit()

    b_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths(filename,band="U_Johnson.res")
    g_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths(filename,band="V_Johnson.res")
    r_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths(filename,band="K_Johnson.res")

    b_image = sunpy__load.load_broadband_image(filename,band='U_Johnson.res',camera=camera) * b_effective_wavelength / g_effective_wavelength * 2.5
    g_image = sunpy__load.load_broadband_image(filename,band='V_Johnson.res',camera=camera) * g_effective_wavelength / g_effective_wavelength 
    r_image = sunpy__load.load_broadband_image(filename,band='K_Johnson.res',camera=camera) * r_effective_wavelength / g_effective_wavelength * 1.5 

    n_pixels
    img = np.zeros((n_pixels, n_pixels, 3), dtype=float)
    img[:,:,0] = img_scale.asinh(r_image, scale_min=scale_min, scale_max=scale_max,non_linear=0.5)
    img[:,:,1] = img_scale.asinh(g_image, scale_min=scale_min, scale_max=scale_max,non_linear=0.5)
    img[:,:,2] = img_scale.asinh(b_image, scale_min=scale_min, scale_max=scale_max,non_linear=0.5)
    img[img<0] = 0
    return img
Exemple #9
0
def return_h_band_img(filename,camera=0,scale_min=0.1,scale_max=50,size_scale=1.0):
    if (not os.path.exists(filename)):
        print "file not found:", filename
        sys.exit()

    image = sunpy__load.load_broadband_image(filename,band='H_Johnson.res', camera=camera) 
    n_pixels = image.shape[0]
    img = np.zeros((n_pixels, n_pixels), dtype=float)
    img[:,:] = img_scale.asinh(image, scale_min=scale_min, scale_max=scale_max,non_linear=0.5)
    img[img<0] = 0
    return img
Exemple #10
0
def return_sdss_gri_img(filename,camera=0,scale_min=0.1,scale_max=50,size_scale=1.0, non_linear=0.5):
    if (not os.path.exists(filename)):
        print "file not found:", filename
        sys.exit()

    b_image = sunpy__load.load_broadband_image(filename,band='g_SDSS.res',camera=camera) * 0.7
    g_image = sunpy__load.load_broadband_image(filename,band='r_SDSS.res',camera=camera) * 1.0
    r_image = sunpy__load.load_broadband_image(filename,band='i_SDSS.res',camera=camera) * 1.4
    n_pixels = r_image.shape[0]
    img = np.zeros((n_pixels, n_pixels, 3), dtype=float)

    img[:,:,0] = img_scale.asinh(r_image, scale_min=scale_min, scale_max=scale_max,non_linear=non_linear)
    img[:,:,1] = img_scale.asinh(g_image, scale_min=scale_min, scale_max=scale_max,non_linear=non_linear)
    img[:,:,2] = img_scale.asinh(b_image, scale_min=scale_min, scale_max=scale_max,non_linear=non_linear)
    img[img<0] = 0

    del b_image, g_image, r_image
    gc.collect()

    return img
Exemple #11
0
def return_sdss_gri_img(filename,
                        camera=0,
                        scale_min=0.1,
                        scale_max=50,
                        size_scale=1.0,
                        non_linear=0.5):
    if (not os.path.exists(filename)):
        print "file not found:", filename
        sys.exit()

    b_image = sunpy__load.load_broadband_image(
        filename, band='g_SDSS.res', camera=camera) * 0.7
    g_image = sunpy__load.load_broadband_image(
        filename, band='r_SDSS.res', camera=camera) * 1.0
    r_image = sunpy__load.load_broadband_image(
        filename, band='i_SDSS.res', camera=camera) * 1.4
    n_pixels = r_image.shape[0]
    img = np.zeros((n_pixels, n_pixels, 3), dtype=float)

    img[:, :, 0] = img_scale.asinh(r_image,
                                   scale_min=scale_min,
                                   scale_max=scale_max,
                                   non_linear=non_linear)
    img[:, :, 1] = img_scale.asinh(g_image,
                                   scale_min=scale_min,
                                   scale_max=scale_max,
                                   non_linear=non_linear)
    img[:, :, 2] = img_scale.asinh(b_image,
                                   scale_min=scale_min,
                                   scale_max=scale_max,
                                   non_linear=non_linear)
    img[img < 0] = 0

    del b_image, g_image, r_image
    gc.collect()

    return img
Exemple #12
0
def return_stellar_mass_img(filename,
                            camera=0,
                            scale_min=1e8,
                            scale_max=1e10,
                            size_scale=1.0,
                            non_linear=1e8):
    image = sunpy__load.load_stellar_mass_map(filename, camera=camera)
    n_pixels = image.shape[0]
    img = np.zeros((n_pixels, n_pixels), dtype=float)
    img[:, :] = img_scale.asinh(image,
                                scale_min=scale_min,
                                scale_max=scale_max,
                                non_linear=non_linear)
    img[img < 0] = 0
    return img
Exemple #13
0
def IMG_pull(field, galaxy, smin = -0.1, smax = 0.3):
    if field[1] == 'S':
        seg = fits.open('/Volumes/Vince_CLEAR/gsd_img/goodss_3dhst.v4.0.F160W_seg.fits')[0].data
        f160 = fits.open('/Volumes/Vince_CLEAR/gsd_img/goodss_3dhst.v4.0.F160W_orig_sci.fits')[0].data
        f125 = fits.open('/Volumes/Vince_CLEAR/gsd_img/goodss_3dhst.v4.0.F125W_orig_sci.fits')[0].data
        f105 = fits.open('/Volumes/Vince_CLEAR/gsd_img/goodss-F105W-astrodrizzle-v4.4_drz_sci.fits')[0].data

    if field[1] == 'N':
        seg = fits.open('/Volumes/Vince_CLEAR/gnd_img/goodsn_3dhst.v4.0.F160W_seg.fits')[0].data
        f160 = fits.open('/Volumes/Vince_CLEAR/gnd_img/goodsn_3dhst.v4.0.F160W_orig_sci.fits')[0].data
        f125 = fits.open('/Volumes/Vince_CLEAR/gnd_img/goodsn_3dhst.v4.0.F125W_orig_sci.fits')[0].data
        f105 = fits.open('/Volumes/Vince_CLEAR/gnd_img/goodsn-F105W-astrodrizzle-v4.4_drz_sci.fits')[0].data
        
    ###############img plot################
    idx = np.argwhere(seg == galaxy)

    ylist = np.arange(min(idx.T[0]), max(idx.T[0]) + 1, 1)
    xlist = np.arange(min(idx.T[1]), max(idx.T[1]) + 1, 1)

    segimg = seg[min(idx.T[0]): max(idx.T[0]), min(idx.T[1]): max(idx.T[1])]
    f105img = f105[min(idx.T[0]): max(idx.T[0]), min(idx.T[1]): max(idx.T[1])]
    f105img[segimg != galaxy] = 0
    maxloc = np.argwhere(f105img == np.max(f105img))[0]

    ycnt = ylist[maxloc[0]]
    xcnt = xlist[maxloc[1]]

    f105img = f105[ycnt - 40: ycnt + 41, xcnt - 40: xcnt + 41]
    f125img = f125[ycnt - 40: ycnt + 41, xcnt - 40: xcnt + 41]
    f160img = f160[ycnt - 40: ycnt + 41, xcnt - 40: xcnt + 41]

    img = np.zeros((f125img.shape[0], f125img.shape[1], 3), dtype=float)
    img[:,:,0] = img_scale.asinh(f160img, scale_min = smin, scale_max = smax)
    img[:,:,1] = img_scale.asinh(f125img, scale_min = smin, scale_max = smax)
    img[:,:,2] = img_scale.asinh(f105img, scale_min = smin, scale_max = smax)
    return img
Exemple #14
0
def return_h_band_img(filename,
                      camera=0,
                      scale_min=0.1,
                      scale_max=50,
                      size_scale=1.0):
    if (not os.path.exists(filename)):
        print "file not found:", filename
        sys.exit()

    image = sunpy__load.load_broadband_image(filename,
                                             band='H_Johnson.res',
                                             camera=camera)
    n_pixels = image.shape[0]
    img = np.zeros((n_pixels, n_pixels), dtype=float)
    img[:, :] = img_scale.asinh(image,
                                scale_min=scale_min,
                                scale_max=scale_max,
                                non_linear=0.5)
    img[img < 0] = 0
    return img
Exemple #15
0
 def doScaling(self, img, rgb):
     for j in range(3):
         smin, it = img_scale.sky_mean_sig_clip(rgb[j], self.SKY_SIGMA,
                                                self.SKY_CONVERGENCE)
         pxmax = max(rgb[j].flatten())
         smax = int(self.wb[j] *
                    (self.SCALE_RANGE / self.opt['scaling'] + smin))
         #            smax = int((self.SCALE_RANGE + smin) / self.wb[j])
         if self.SCALE_METHOD == self.scaleMethods[0]:
             img[:, :, j] = img_scale.linear(rgb[j],
                                             scale_min=smin,
                                             scale_max=smax)
         elif self.SCALE_METHOD == self.scaleMethods[1]:
             img[:, :, j] = img_scale.sqrt(rgb[j],
                                           scale_min=smin,
                                           scale_max=smax)
         elif self.SCALE_METHOD == self.scaleMethods[2]:
             img[:, :, j] = img_scale.log(rgb[j],
                                          scale_min=smin,
                                          scale_max=smax)
         elif self.SCALE_METHOD == self.scaleMethods[3]:
             img[:, :, j] = img_scale.asinh(rgb[j],
                                            scale_min=smin,
                                            scale_max=smax)
             cmap=pylab.cm.hot)
pylab.axis('off')
pylab.savefig(image)
pylab.clf()

sys.exit()

new_img = img_scale.linear(img_data, scale_min=min_val)
pylab.imshow(new_img,
             interpolation='nearest',
             origin='lower',
             cmap=pylab.cm.hot)
pylab.axis('off')
pylab.savefig(image)
pylab.clf()
new_img = img_scale.asinh(img_data, scale_min=min_val, non_linear=0.01)
pylab.imshow(new_img,
             interpolation='nearest',
             origin='lower',
             cmap=pylab.cm.hot)
pylab.axis('off')
pylab.savefig(image)
pylab.clf()
new_img = img_scale.asinh(img_data, scale_min=min_val, non_linear=0.5)
pylab.imshow(new_img,
             interpolation='nearest',
             origin='lower',
             cmap=pylab.cm.hot)
pylab.axis('off')
pylab.savefig(image)
pylab.clf()
Exemple #17
0
    w = wcs.WCS(f125[0].header)

    pos = w.wcs_world2pix(np.array([G_DF.ra,G_DF.dec]).T, 1)

    G_DF['x'] = pos.T[0]
    G_DF['y'] = pos.T[1]

    xlims = np.array([min(pos.T[0]) - 20, max(pos.T[0]) + 20]).astype(int)
    ylims = np.array([min(pos.T[1])- 20, max(pos.T[1])+ 20]).astype(int) 

    f105img = f105[0].data[ylims[0]:ylims[1],xlims[0]:xlims[1]]
    f125img = f125[0].data[ylims[0]:ylims[1],xlims[0]:xlims[1]]
    f160img = f160[0].data[ylims[0]:ylims[1],xlims[0]:xlims[1]]

    img = np.zeros((f125img.shape[0], f125img.shape[1], 3), dtype=float)
    img[:,:,0] = img_scale.asinh(f160img, scale_min=-0.1, scale_max=0.5)
    img[:,:,1] = img_scale.asinh(f125img, scale_min=-0.1, scale_max=0.5)
    img[:,:,2] = img_scale.asinh(f105img, scale_min=-0.1, scale_max=0.5)

    fig = plt.gcf()
    DPI = fig.get_dpi()
    fig.set_size_inches(img.shape[1] / float(DPI), img.shape[0] / float(DPI))

    plt.imshow(img,aspect='equal')
    plt.xticks([])
    plt.yticks([])
    plt.savefig('../data/website_data/{0}_img.jpg'.format(field))#, bbox_inches = 'tight')

"""
    xarray = np.arange(1,img.shape[1] + 1)
    yarray = np.arange(1,img.shape[0] + 1)
new_img = img_scale.power(img_data, power_index=3.0, scale_min=min_val)
pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot)
pylab.axis("off")
pylab.savefig("power.png")
pylab.clf()
new_img = img_scale.log(img_data, scale_min=min_val)
pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot)
pylab.axis("off")
pylab.savefig("log.png")
pylab.clf()
new_img = img_scale.linear(img_data, scale_min=min_val)
pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot)
pylab.axis("off")
pylab.savefig("linear.png")
pylab.clf()
new_img = img_scale.asinh(img_data, scale_min=min_val, non_linear=0.01)
pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot)
pylab.axis("off")
pylab.savefig("asinh_beta_01.png")
pylab.clf()
new_img = img_scale.asinh(img_data, scale_min=min_val, non_linear=0.5)
pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot)
pylab.axis("off")
pylab.savefig("asinh_beta_05.png")
pylab.clf()
new_img = img_scale.asinh(img_data, scale_min=min_val, non_linear=2.0)
pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot)
pylab.axis("off")
pylab.savefig("asinh_beta_20.png")
pylab.clf()
new_img = img_scale.histeq(img_data_raw, num_bins=256)
Exemple #19
0
d = [[galaxy.ICD_IH*100, galaxy.Mass, galaxy.ID] for galaxy in galaxies if\
        galaxy.Mass > 11]
d = pyl.asarray(d)

d = colsort(d)

d1 = d[:3]
d2 = d[3:7]
d3 = d[7:]

for i, (icd, mass, ID) in enumerate(zip(d1[:, 0], d1[:, 1], d1[:, 2])):
    print icd, mass, ID
    H = pyf.getdata(base + str(int(ID)) + '_H.fits')
    I = pyf.getdata(base + str(int(ID)) + '_I.fits')

    H = img_scale.asinh(H, non_linear=0.5)
    I = img_scale.asinh(I, non_linear=0.5)

    grid[i * 3].imshow(I, origin='lower', cmap='PuBu_r')
    grid[i * 3 + 1].imshow(H, origin='lower', cmap='PuBu_r')
    grid[i * 3 + 2].imshow(I - H, origin='lower', cmap='PuBu_r')

    grid[i * 3].set_xticks([])
    grid[i * 3].set_yticks([])
    grid[i * 3 + 1].set_xticks([])
    grid[i * 3 + 1].set_yticks([])
    grid[i * 3 + 2].set_xticks([])
    grid[i * 3 + 2].set_yticks([])

    grid[i * 3].text(1, 0, str(int(ID)), color='white', fontsize=10)
    grid[i * 3].text(1, 35, 'I', color='white', fontsize=10)
Exemple #20
0
img_data = hdulist[0].data
hdulist.close()
width = img_data.shape[0]
height = img_data.shape[1]
print "Blue file = ", blue_fn, "(", width, ",", height, ")"
img_data_b = numpy.array(img_data, dtype=float)
#sky = numpy.median(numpy.ravel(img_data_b))
#sky = numpy.mean(numpy.ravel(img_data_b))
sky, num_iter = img_scale.sky_median_sig_clip(img_data_b, sig_fract, per_fract,
                                              max_iter)
print "sky = ", sky, "(", num_iter, ") for blue image \
(", numpy.max(img_data_b), ",", numpy.min(img_data_b), ")"
img_data_b = img_data_b - sky

# Apply scaling relations
r = red_factor * img_scale.asinh(
    img_data_r, scale_min=min_val, non_linear=red_non_linear_fact)
g = green_factor * img_scale.asinh(
    img_data_g, scale_min=min_val, non_linear=green_non_linear_fact)
b = blue_factor * img_scale.asinh(
    img_data_b, scale_min=min_val, non_linear=blue_non_linear_fact)

# RGB image with SciPy
print "image size ", width, height
rgba_array = numpy.empty((width, height, 4),
                         numpy.uint8)  # assuming 8 bits per channnel
rgba_array[:, :, 0] = scipy.misc.bytescale(r)  # red
rgba_array[:, :, 1] = scipy.misc.bytescale(g)  # green
rgba_array[:, :, 2] = scipy.misc.bytescale(b)  # blue
rgba_array[:, :, 3] = 255  # Alpha transparency
scipy.misc.imsave('rgb.png', rgba_array)
d = pyl.asarray(d)
print len(d)
grid = axes_grid.ImageGrid(F, 111, nrows_ncols=(3,len(d)), axes_pad=0.05,
        add_all=True, share_all=True, aspect=True, direction='column')
d = colsort(d)

d1 = d
#d1 = d[:5]
#d2 = d[5:]

for i, (icd, mass, ID, s) in enumerate(zip(d1[:,0], d1[:,1], d1[:,2], d1[:,3])):
    print icd, mass, ID
    H = pyf.getdata(base+str(int(ID))+'_H.fits')
    I = pyf.getdata(base+str(int(ID))+'_I.fits')

    H = img_scale.asinh(H, non_linear=0.5)
    I = img_scale.asinh(I, non_linear=0.5)

    grid[i*3].imshow(I, origin='lower', cmap='PuBu_r')
    grid[i*3+1].imshow(H, origin='lower', cmap='PuBu_r')
    grid[i*3+2].imshow(I-H, origin='lower', cmap='PuBu_r')

    grid[i*3].set_xticks([])
    grid[i*3].set_yticks([])
    grid[i*3+1].set_xticks([])
    grid[i*3+1].set_yticks([])
    grid[i*3+2].set_xticks([])
    grid[i*3+2].set_yticks([])

    #grid[i*3].text(1, 0, str(int(ID)), color='white', fontsize=10)
    grid[i*3].text(1, 0, '{0:.2f}'.format(s), color='white', fontsize=10)
hdulist = pyfits.open(blue_fn)
img_header = hdulist[0].header
img_data = hdulist[0].data
hdulist.close()
width=img_data.shape[0]
height=img_data.shape[1]
print "Blue file = ", blue_fn, "(", width, ",", height, ")"
img_data_b = numpy.array(img_data, dtype=float)
rgb_array = numpy.empty((width,height,3), dtype=float)
#sky = numpy.median(numpy.ravel(img_data_b))
#sky = numpy.mean(numpy.ravel(img_data_b))
sky, num_iter = img_scale.sky_median_sig_clip(img_data_b, sig_fract, per_fract, max_iter)
print "sky = ", sky, "(", num_iter, ") for blue image \
(", numpy.max(img_data_b), ",", numpy.min(img_data_b), ")"
img_data_b = img_data_b - sky
b = img_scale.asinh(img_data_b, scale_min = min_val, non_linear=non_linear_fact)

# Green image
hdulist = pyfits.open(green_fn)
img_header = hdulist[0].header
img_data = hdulist[0].data
hdulist.close()
width=img_data.shape[0]
height=img_data.shape[1]
print "Green file = ", green_fn, "(", width, ",", height, ")"
img_data_g = numpy.array(img_data, dtype=float)
#sky = numpy.median(numpy.ravel(img_data_g))
#sky = numpy.mean(numpy.ravel(img_data_g))
sky, num_iter = img_scale.sky_median_sig_clip(img_data_g, sig_fract, per_fract, max_iter)
print "sky = ", sky, "(", num_iter, ") for green image \
(", numpy.max(img_data_g), ",", numpy.min(img_data_g), ")"
hdulist.close()
width=img_data.shape[0]
height=img_data.shape[1]
print "Blue file = ", blue_fn, "(", width, ",", height, ")"
img_data_b = numpy.array(img_data, dtype=float)
#sky = numpy.median(numpy.ravel(img_data_b))
#sky = numpy.mean(numpy.ravel(img_data_b))
#sky, num_iter = img_scale.sky_median_sig_clip(img_data_b, sig_fract, per_fract, max_iter)
sky, num_iter = img_scale.sky_median_sig_clip(img_data_b, sig_fract, per_fract, max_iter, low_cut=False, high_cut=True)
print "sky = ", sky, "(", num_iter, ") for blue image \
(", numpy.max(img_data_b), ",", numpy.min(img_data_b), ")"
img_data_b = img_data_b - sky


# Apply scaling relations
r = red_factor * img_scale.asinh(img_data_r, scale_min = min_val, non_linear=red_non_linear_fact)
g = green_factor * img_scale.asinh(img_data_g, scale_min = min_val, non_linear=green_non_linear_fact)
b = blue_factor * img_scale.asinh(img_data_b, scale_min = min_val, non_linear=blue_non_linear_fact)


# RGB image with SciPy
print "image size ", width, height
rgb_array = numpy.array( [numpy.ravel(scipy.misc.bytescale(r)), numpy.ravel(scipy.misc.bytescale(g)), numpy.ravel(scipy.misc.bytescale(b))] )
rgb_array = numpy.transpose(rgb_array)
rgb_array.astype(numpy.int)
PIL_data = []
for elm in rgb_array:
	PIL_data.append(tuple(elm))
use_image = Image.new('RGB', size=(height, width))
use_image.putdata(PIL_data)
use_image.save('rgb.png')
import pyfits
import numpy as np
import pylab as py
import img_scale

u_img = pyfits.getdata('0596.u.fits')
g_img = pyfits.getdata('0596.g.fits')
i_img = pyfits.getdata('0596.i.fits')

img = np.zeros((u_img.shape[0] , g_img.shape[1] , 3 ), dtype = float)
img[:,:,0]=img_scale.asinh(u_img)
img[:,:,1]=img_scale.asinh(g_img)
img[:,:,2]=img_scale.asinh(i_img)

py.clf()
py.imshow(img , aspect = 'equal')
py.title('0596')
py.savefig('0596.jpeg')