infofile.close()

################################################################
# proc=4 runs after proc=3. It updates and sorts the previous
#        files according to the observational dates.
################################################################
if proc == 4:

    globalist = U.get_str(
        '/Volumes/amb4/ALHAMBRA/images/individuals/globalist/global.list', 0)
    nl = len(globalist)
    for ii in range(nl):
        # imas = U.get_str(globalist[ii],0)
        # ni = len(imas)
        infofile_name = globalist[ii][:-4] + 'info.txt'
        fi, da, ti, ex, ix = U.get_data(infofile_name, (0, 1, 2, 3, 5))
        im, ti2 = U.get_str(infofile_name, (4, 2))
        ni = len(im)

        infofile_name_sorted = globalist[ii][:-4] + 'info.sort.txt'
        print 'Creating ', infofile_name_sorted
        infofile = open(infofile_name_sorted, 'w')
        header = '#  FILTER  DATE  TIME  EXPTIME  NAME  INDEX   PERIOD [min]   PERIOD [hours]   PERIOD [days]     PERIOD [years] \n'
        infofile.write(header)

        newdate = U.zeros(ni, 'int')
        for ii in range(ni):
            uno = int(da[ii])
            dos = ti2[ii]
            ll = '%s%s' % (uno, dos)
            newdate[ii] = float(ll)
Example #2
0
# General root to codes
root2codes = '/Users/albertomolino/Postdoc/T80S_Pipeline/Commisioning/codes/'

# BPZ-related files and roots.
root2bpz = '/Users/albertomolino/codigos/bpz-1.99.2/'
#spectra = 'COSMOSeB11new_recal'
spectra = 'eB11'

# J-PLUS related data
mainroot = '/Users/albertomolino/Postdoc/T80S_Pipeline/Commisioning/S82/Dec2017/'
root2cats = mainroot + 'splus_cats_NGSL/JPLUS_specz_sample_March2018/'

jplus_spz_cat = root2cats + 'jplus2sdssdr12_z05.cat'
jplus_spz_columns = root2cats + 'jplus2sdssdr12_z05.columns'
tiles = U.get_data(jplus_spz_cat, 1)
single_tiles = N.unique(tiles).astype(int)
n_single_tiles = len(single_tiles)

# Reading entire catalogue.
header_jplus = C.loadheader(jplus_spz_cat)
data_jplus = C.loaddata(jplus_spz_cat)
#C.savedata(data1[sample,:],outname,dir="",header=head1)

#n_single_tiles = 1
for ii in range(n_single_tiles):
    tile_jplus_spz_upl_cat = root2cats + 'tile_%i_jplus2sdssdr12_z05.ecor.upp.cat' % (
        single_tiles[ii])
    good = N.equal(tiles, single_tiles[ii])
    n_gals = len(data_jplus[good, 0])
    if n_gals > 50:
Example #3
0
out_file.write('#   7 F0410_auto \n')
out_file.write('#   8 F0430_auto  \n')
out_file.write('#   9 G_auto    \n')
out_file.write('#  10 F0515_auto  \n')
out_file.write('#  11 R_auto  \n')
out_file.write('#  12 F0660_auto  \n')
out_file.write('#  13 I_auto    \n')
out_file.write('#  14 F0861_auto  \n')
out_file.write('#  15 z_auto  \n')
out_file.write('# ID RA Dec U_auto F0378_auto F0395_auto '
               'F0410_auto F0430_auto G_auto F0515_auto '
               'R_auto F0660_auto I_auto F0861_auto z_auto'\n)

for ii in range(n_cats):
    print 'reading catalogue %i '%(ii+1)
    ids,ra,dec,u,f378,f395,f410,f430 = U.get_data(cats[ii],(0,1,2,15,24,33,42,51))
    g,f515,r,f660,i,f861,z,ps = U.get_data(cats[ii],(60,69,78,87,96,105,114,132))
    #Selecting good stars
    good  = N.greater_equal(ps,0.9)
    good *= N.less_equal(abs(u),30) * N.less_equal(abs(g),30)
    good *= N.less_equal(abs(r),30) * N.less_equal(abs(i),30)
    good *= N.less_equal(abs(z),30) * N.less_equal(abs(f378),30)
    good *= N.less_equal(abs(f395),30) * N.less_equal(abs(f410),30)
    good *= N.less_equal(abs(f430),30) * N.less_equal(abs(f515),30)
    good *= N.less_equal(abs(f660),30) * N.less_equal(abs(f861),30)
    # Compressing.
    ids,ra,dec,u,f378,f395,f410,f430 = U.multicompress(good,(ids,ra,dec,u,f378,f395,f410,f430))
    g,f515,r,f660,i,f861,z = U.multicompress(good,(g,f515,r,f660,i,f861,z))
    # Writing data into new catalogue.
    n_stars = len(ids)
    for ss in range(n_stars):
__author__ = 'albertomolino'

import sys
sys.path.append('/Users/albertomolino/doctorado/photo/programas/')
import useful as U
import matplotlib.pyplot as plt
import numpy as N

# Root to data
mainroot = '/Users/albertomolino/Postdoc/T80S_Pipeline/Commisioning/S82/Dec2017/'
root2cats = mainroot + 'splus_cats_NGSL/COSMOSeB11new_recal/'
bpz_cat = root2cats + 'master.STRIPE82_Photometry.m21_COSMOSeB11new_recal_redu.bpz'

# Reading data
zb,mo,od,zs,chi2,tb = U.get_data(bpz_cat,(1,10,5,9,8,4))

# Doing some cleaning
good = N.less(chi2,30) * N.greater_equal(mo,14)
good *= N.greater_equal(od,0.05) * N.greater_equal(zs,0.001)
zb,mo,od,zs,chi2,tb = U.multicompress(good,(zb,mo,od,zs,chi2,tb))
dz = (zs-zb)/(1.+zs)

#base magnitudes
basem  = N.arange(14,22,1.)
basem2 = basem[:-1]+((basem[1]-basem[0])/2.)

# base templates
baset  = N.arange(1,max(tb)+1,3)
baset2 = baset[:-1]+((baset[1]-baset[0])/2.)

# base redshift
Example #5
0
def globalimage_zb(image, cat, posx, posy, posarea, poszb, shape, save,
                   outfile):
    """
============
from alhambra_webpage import *
image = '/Users/albertomolino/Desktop/emss2137/emss2137.png'
cat = '/Volumes/amb2/SUBARU/emss2137/catalogs/MS2137_Subaru.bpz.2.cat'
posx = 3
posy = 4
posarea = 5
poszb = 17
shape = 'circle'
save = 'yes'
outfile = '/Users/albertomolino/Desktop/emss2137/emss2137_22.png'
globalimage_zb(image,cat,posx,posy,posarea,poszb,shape,save,outfile)
-----------------
import alhambra_photools
from alhambra_photools import *
import alhambra_webpage
from alhambra_webpage import *
image = '/Users/albertomolino/Desktop/macs1206/macs1206.color.png'
cat = '/Users/albertomolino/Desktop/UDF/Molino12/catalogs/ColorPro/macs1206_UDFconf_NIR_July2012_ISO_RS.cat'
posx = 3
posy = 4
shape = 'circle'
save = 'yes'
posarea = 5
poszb = 0
outfile = '/Users/albertomolino/Desktop/macs1206/macs1206.color.RS.purged.png'
globalimage_zb(image,cat,posx,posy,posarea,poszb,shape,save,outfile)
--------
import alhambra_photools
from alhambra_photools import *
import alhambra_webpage
from alhambra_webpage import *
image = '/Users/albertomolino/Desktop/rxj2248/HST/rxj2248_acs.png'
cat = '/Users/albertomolino/Desktop/rxj2248/HST/catalogs/rxj2248_IR_RedSeq.cat'
posx = 3
posy = 4
shape = 'circle'
save = 'yes'
posarea = 5
poszb = 0
outfile = '/Users/albertomolino/Desktop/rxj2248/HST/rxj2248_acs.RS.png'
globalimage_zb(image,cat,posx,posy,posarea,poszb,shape,save,outfile)
--------

    """
    colorfile = image
    im = Image.open(colorfile)
    imsize = nx, ny = im.size
    stamp = im.crop((0, 0, nx, ny))
    draw = ImageDraw.Draw(stamp)

    try:
        x, y, area, zb = U.get_data(cat, (posx, posy, posarea, poszb))
        sf = U.get_data(cat, 74)
        # good = greater(zb,0.28) * less(zb,0.34)
        good = U.greater(zb, 0.001) * U.less(sf, 0.7)
        x, y, area, zb = U.multicompress(good, (x, y, area, zb))
    except:
        print 'Impossible to read the data from catalog. Check it out!!'

    for ii in range(len(x)):
        xx = x[ii]
        yy = y[ii]
        aa = area[ii]
        zzb = zb[ii]
        zbval = ' %.2f ' % (zzb)
        # print 'x,y',xx,yy
        # print 'zbval',zbval
        # print 'ii',ii
        # dx = dy = 1.5 * aa
        shapesize = 20  # aa * 1.05
        # print 'shapesize',shapesize
        # dxo = dyo = 0

        colores = (255, 255, 1)
        # if zzb < 0.1  : colores = (255,1,1)   # red
        # elif zzb >= 0.1 and zzb < 0.3 : colores = (255,255,1) # yellow
        # elif zzb >= 0.3 and zzb < 1.  : colores = (1,255,1)   # Green
        # elif zzb >= 1.  and zzb < 3.  : colores = (1,255,255) # Blue
        # else: colores = (255,1,255) # Purple

        if shape != 'None':
            if shape == 'circle':
                draw.ellipse((xx - shapesize, ny - yy - shapesize,
                              xx + shapesize, ny - yy + shapesize),
                             fill=None)
            elif shape == 'crosshair':
                draw.line((xx + shapesize, yy, xx + shapesize - 10, yy),
                          fill=None,
                          width=3)
                draw.line((xx - shapesize, yy, xx - shapesize + 10, yy),
                          fill=None,
                          width=3)
                draw.line((xx, yy + shapesize, xx, yy + shapesize - 10),
                          fill=None,
                          width=3)
                draw.line((xx, yy - shapesize, xx, yy - shapesize + 10),
                          fill=None,
                          width=3)
            elif shape == 'rectangle':
                draw.rectangle((dx - shapesize, dy - shapesize, dx + shapesize,
                                dy + shapesize),
                               fill=colores)  # fill=None)
            else:
                print 'Shape not found!. It will not be overlaid...'

        draw.text((xx - (shapesize / 2.), ny - yy - (shapesize / 2.)),
                  zbval,
                  fill=(255, 255, 1))
        # draw.text((xx-(1.5*shapesize),ny-yy-(2.*shapesize)),zbval,fill=(255,255,255))
        # # draw.text((xx-(1.5*shapesize),ny-yy-(2.*shapesize)),zbval,fill=colores)

    if save == 'yes':
        if outfile != 'None':
            stamp.save(outfile)
        else:
            stamp.save('imcutoff.png')
z_min = 0.005
z_max = 0.5
delta_z = 0.01
base_z = N.arange(z_min, z_max + delta_z, delta_z)
base_z2 = base_z[:-1] + ((base_z[1] - base_z[0]) / 2.)
base_m = N.arange(m_min, m_max + delta_m, delta_m)
base_m2 = base_m[:-1] + ((base_m[1] - base_m[0]) / 2.)
base_o = N.array([0.0, 0.36, 0.54, 0.8])  # for z<0.5
colores = [
    'blue',
    'green',
    'red',
    'purple',
]

zb_all, odds_all, mo_all, chi2_all = U.get_data(master_bpz_auto, (1, 5, 9, 8))
zb_spz, zs, odds_spz, mo_spz, chi2_spz = U.get_data(master_spz_auto,
                                                    (1, 9, 5, 10, 8))

valor_auto_m_spz = N.zeros((len(base_o), (len(base_m) - 1)), float)
valor_auto_m_all = N.zeros((len(base_o), (len(base_m) - 1)), float)
valor_auto_z_spz = N.zeros((len(base_o), (len(base_z) - 1)), float)

plt.figure(1, figsize=(9, 8), dpi=80, facecolor='w', edgecolor='k')
plt.clf()
plt.subplot(121)
# As a function of AB
for jj in range(len(base_o)):
    for ii in range(len(base_m) - 1):
        ##all
        good = N.greater_equal(mo_all, base_m[ii]) * N.less(chi2_all, 5.)
Example #7
0
models = U.get_str(root_to_cat + 'ngsl_pick_wd.list', 0)
new_catalog = catalog[:-3] + 'extended_gr.cat'

# display information?
verbose = 0

# Reading the general catalogue.
datos_main = C.loaddata(catalog)
head_main = C.loadheader(catalog)

# gr synthetic models
#gr_models = datos_main[:,6]-datos_main[:,8] #SPLUS
gr_models = datos_main[:, 16] - datos_main[:, 17]  #SDSS

# Reading the SDSS_color catalog.
sdss_gr, density_gr = U.get_data(catalog_sdss_colors, (0, 1))
n_color_bins = len(sdss_gr) - 1

# Reading catalog dimensions.
n_stars_ori = N.shape(datos_main)[0]
n_cols = N.shape(datos_main)[1]
n_filters = n_cols - 1  #12 #20  #####################################

# Magnitude range we want to expand.
m_min = 12  ####################################
m_max = 22.0  ####################################
delta_m = 0.01  ####################################
base_m = N.arange(m_min, m_max + delta_m, delta_m)
n_m_ele = len(base_m)

# Number of stars per magnitude-bin.
Example #8
0
# catalogues parameters
header_cat = '# 1.tile_id 2.object_id 3.ra 4.dec 5.fwhm 6.uJAVA 7.uJAVA_err 8.gSDSS \
 9.gSDSS_err 10.rSDSS 11.rSDSS_err 12.iSDSS 13.iSDSS_err 14.zSDSS 15.zSDSS_err \
 16.J0395 17.J0395_err 18.J0410 19.J0410_err 20.J0430 21.J0430_err \
 17.J0515 18.J0515_err 19.J0660 20.J0660_err 21.J0861 22.J0861_err \
 23.zs_SDSS '

# BPZCAL parameters
columns11 = root2maincat+'jplus11.columns' #ID==Tile
columns11b = root2maincat+'jplus11b.columns' #ID==ID
ngal_min = 25
#FixFilters = ["jplus_r_sdss.res"]

# Opening main.cat and generate tile.cat
tile_num,obj_id,ra,dec,fw = U.get_data(maincat,(0,1,2,3,4))
u_m, u_em, g_m, g_em, r_m, r_em = U.get_data(maincat,(5,6,7,8,9,10))
i_m, i_em, z_m, z_em, f395_m, f395_em = U.get_data(maincat,(11,12,13,14,15,16))
f410_m, f410_em, f430_m, f430_em, f515_m, f515_em = U.get_data(maincat,(17,18,19,20,21,22))
f660_m, f660_em, f861_m, f861_em, zpec = U.get_data(maincat,(23,24,25,26,28))

only_tiles = jct.num_tiles(tile_num) # tiles w/o duplications
n_tiles = len(only_tiles) # number of Tiles
print 'Total number of Tiles to calibrate: ',n_tiles

for ii in range(n_tiles):
    ref_tile = only_tiles[ii]
    gs = N.less(abs(tile_num-ref_tile),1)# GoodSample
    tile_cat = tile_root+'%i.cat'%(ref_tile)
    U.put_data(tile_cat,
               (tile_num[gs],obj_id[gs],ra[gs],dec[gs],fw[gs],
Example #9
0
m_min = 14.
m_max = 19.
delta_m = 0.2
base_m = N.arange(m_min, m_max + delta_m, delta_m)
base_m2 = base_m[:-1] + ((base_m[1] - base_m[0]) / 2.)
z_min = 0.005
z_max = 0.4
delta_z = 0.01
base_z = N.arange(z_min, z_max + delta_z, delta_z)
base_z2 = base_z[:-1] + ((base_z[1] - base_z[0]) / 2.)

#All bands
ruta = '/Users/albertomolino/Postdoc/T80S_Pipeline/Commisioning/S82/Dec2017/splus_cats_NGSL/'
b0 = ruta + 'COSMOSeB11new_recal/master.STRIPE82_Photometry.m21_COSMOSeB11new_recal_redu.bpz'
zb0, zs0, m0, chi0, od0, tb0 = U.get_data(b0, (1, 9, 10, 8, 5, 4))
good0 = N.greater_equal(od0, 0.1) * N.less(chi0, 10)
zb0, zs0, m0, tb0 = U.multicompress(good0, (zb0, zs0, m0, tb0))
dz0 = (zb0 - zs0) / (1. + zs0)
valor0 = N.zeros(len(base_m) - 1)
for ii in range(len(valor0)):
    good = N.greater_equal(m0, base_m[ii])
    good *= N.less_equal(m0, base_m[ii + 1])
    valor0[ii] = U.std_mad(dz0[good])
#valor0[2]=0.0039
valor0[1] = 0.0052

#5-bands
b1 = ruta + 'using_5sdss_bands/master.STRIPE82_Photometry.m21_COSMOSeB11new_recal_5bands.bpz'
zb1, zs1, m1, chi1, od1, tb1 = U.get_data(b1, (1, 9, 10, 8, 5, 4))
good1 = N.greater_equal(od1, 0.1) * N.less(chi1, 10)
Example #10
0
    '/Users/albertomolino/Postdoc/T80S_Pipeline/Commisioning/codes/')
import useful as U
import numpy as N
import matplotlib.pyplot as plt
from matplotlib.pyplot import cm
#import bpz_tools as B

# Paths
root = '/Volumes/CLASH/S82/specz/AbsMag/analysis/'
catalog = root + 'specz_vs_photoz_MassMr.cat'

# Colors for data
scolors = list(cm.RdBu_r(N.linspace(0, 1, 12)))

# Reading data
Mr_sp, Mr_ph, Mas_sp, Mas_ph, zs, SpT = U.get_data(catalog, (2, 8, 3, 9, 4, 5))

## Plots
# Stellar_Mass
plt.figure(1, figsize=(8.5, 6.7), dpi=70, facecolor='w', edgecolor='k')
plt.clf()
plt.scatter(zs[::3] - 100.,
            Mas_sp[::3],
            s=100,
            c=SpT[::3],
            marker=u'.',
            cmap=cm.RdBu,
            alpha=0.5)
cb = plt.colorbar(pad=0., format='%i', ticks=N.arange(1., 17, 1))
cb.set_label(label='Spectral-type', size=20)
#cb.yticks(fontsize=20)
Example #11
0
root = '/Users/albertomolino/Postdoc/T80S_Pipeline/Commisioning/S82/Dec2017/'
columns = root + 'splus_auto.columns'
fluxcomparison = root + 'splus_cats_NGSL/COSMOSeB11new_recal_OT/masterOT_COSMOSeB11new_recal_SM.flux_comparison'

mmin = 14.
mmax = 18.
basem_high = N.arange(-1.0, 1.0, 0.01)
basem_med = N.arange(-3.0, 3.0, 0.02)
basem_low = N.arange(-3.0, 3.0, 0.08)
#basem2_high = basem_high[:-1]+((basem_high[1]-basem_high[0])/2.)
#basem2_low  = basem_low[:-1]+((basem_low[1]-basem_low[0])/2.)

# Reading data from catalogs.
ft1, fob1, efob1 = P.getinfo4_mosaic_uncert_obsvsmod(columns, fluxcomparison)
mag1 = U.get_data(fluxcomparison, 1)

#emob = B.e_frac2mag(efob1[ii][:])/float(fob1[ii][:])

plt.figure(1, figsize=(24, 12), dpi=80, facecolor='w', edgecolor='k')
plt.clf()

bin_labels = [0, 6]
base_x = N.linspace(-3.0, 3.0, 300)

for ss in range(12):
    plt.subplot(2, 6, ss + 1)
    if ss == 0:
        g_1 = U.greater_equal(mag1, mmin) * U.less_equal(mag1, mmax + 3)
    else:
        g_1 = U.greater_equal(mag1, mmin) * U.less_equal(mag1, mmax)
Example #12
0
colores[:, 3] = (0.00, 0.50, 0.00)
colores[:, 4] = (0.85, 0.65, 0.00)
colores[:, 5] = (0.75, 0.50, 0.00)
colores[:, 6] = (0.80, 0.25, 0.00)
colores[:, 7] = (1.00, 0.00, 0.00)
colores[:, 8] = (0.85, 0.00, 0.00)
colores[:, 9] = (0.65, 0.00, 0.00)
colores[:, 10] = (0.35, 0.00, 0.00)
colores[:, 11] = (0.25, 0.00, 0.00)
NB = N.array([1, 2, 3, 4, 6, 8, 10])

plt.figure(1, figsize=(11.5, 8.7), dpi=70, facecolor='w', edgecolor='k')
plt.clf()
#plt.subplot(211)
for ii in range(12):
    x, y = U.get_data(ruta + filtros[ii], (0, 1))
    plt.plot(x * 1000., y, '-', lw=10, color=colores[:, ii], alpha=0.5)

for ii in range(12):
    x, y = U.get_data(ruta + filtros[ii], (0, 1))
    #plt.plot(x*1.,y,'--',lw=2,color=colores[:,ii],alpha=0.7)
    if ii in NB:
        plt.fill_between(x * 1., y, 0, alpha=0.4, color=colores[:, ii], lw=4)
    else:
        plt.fill_between(x * 1., y, 0, alpha=0.2, color=colores[:, ii], lw=2)

plt.xlabel('Wavelength [$\AA$]', size=30, labelpad=5)
plt.ylabel('Throughput', size=30, labelpad=10)
plt.grid()

lab = [
Example #13
0
base_mlim = N.arange(15, 30, 0.25)
base_mlim2 = base_mlim[:-1] + ((base_mlim[1] - base_mlim[0]) / 2.)

## Defining variables where to store info.
fwhm_values = N.zeros((n_cats, 12), float)
boa_values = N.zeros((n_cats, 12), float)
zps_values = N.zeros((n_cats, 12), float)
mlim_values = N.zeros((n_cats, 12), float)
#seeing_values = N.zeros((n_cats,12),float)

## Reading data from catalogues
for sss in range(n_cats):
    field = os.path.basename(cats[sss])[9:-15]
    master_cat = root_to_cats + 'STRIPE82-%s_Photometry.cat' % (field)  ##
    print 'reading catalog %i out of %i ' % (sss + 1, n_cats)
    fwhm, mr = U.get_data(master_cat, (8, 84))
    fwhm_master, stars = sct.get_seeing_from_data_pro(fwhm, mr)
    for hhh in range(12):
        ind_catalog = root_to_ind + 'sex_STRIPE82-%s_%s_swp.cat' % (
            field, filters[hhh])  ##
        fwhm_ind = U.get_data(ind_catalog, 6)
        fwhm_redu = fwhm_ind[stars]
        good_stars = N.greater_equal(fwhm_redu, 1.)
        fwhm_values[sss, hhh] = U.mean_robust(fwhm_redu[good_stars]) * 0.55
        # aa & bb have to be picked from other catalogues.
        #aa,bb = U.get_data(ind_catalog,(11,12))
        #pausa = raw_input('paused in filter: %s'%(filters[hhh]))
        #boa_values[sss,hhh] = U.mean_robust((bb/aa)[stars])

        # Reading s/n from master for each filter
        mp, s2n = U.get_data(master_cat, (mag_pos[hhh], s2n_pos[hhh]))
Example #14
0
final_path = root + 'data_quality/'
lista_cats = root_to_cats + 'photometry.list'
cats = U.get_str(lista_cats, 0)
n_cats = len(cats)

# Creating the file where to save the data.
file_out_name = final_path + 'psf.Rband_centeref.cat'
file_out = open(file_out_name, 'w')
file_out.write('# x y fwhm \n')

# Starting the game...
for sss in range(n_cats):
    field = os.path.basename(cats[sss])[9:-15]
    master_cat = root_to_cats + 'STRIPE82-%s_Photometry.cat' % (field)  ##
    print 'reading catalog %i out of %i ' % (sss + 1, n_cats)
    x, y, fwhm, mr = U.get_data(master_cat, (3, 4, 8, 84))
    fwhm_master, stars = sct.get_seeing_from_data_pro(fwhm, mr)
    # Reading FWHM from Individual R images.
    ind_catalog = root_to_ind + 'sex_STRIPE82-%s_R_swp.cat' % (field)  ##
    fwhm_indiv = U.get_data(ind_catalog, 6)
    x_stars, y_stars, fw_stars = U.multicompress(stars, (x, y, fwhm_indiv))
    center_pos_x = N.less(abs(x_stars - N.mean(x_stars)), 1000.)
    center_pos_y = N.less(abs(y_stars - N.mean(y_stars)), 1000.)
    fw_stars_center = fw_stars[center_pos_x * center_pos_y]
    for ii in range(len(x_stars)):
        linea = '%i  %i ' % (x_stars[ii], y_stars[ii])
        mean_value_center = U.mean_robust(fw_stars_center)
        #valor = (fw_stars[ii]*fw_stars[ii])-(mean_value_center*mean_value_center)
        valor = (fw_stars[ii] - mean_value_center)
        linea += '%.2f \n' % (valor)
        file_out.write(linea)
Example #15
0
fov = 1.4 * n_cats

# Base to define the plot
base = N.arange(12, 30, .25)
base2 = base[:-1] + ((base[1] - base[0]) / 2.)
base3 = N.arange(1, 1.0e+6, 1)

final_a10 = N.zeros(len(base2))
final_a11 = N.zeros(len(base2))
final_a12 = N.zeros(len(base2))
final_a13 = N.zeros(len(base2))

for ii in range(12):
    print 'Analyzing filter: ', filters[ii]
    for hhh in range(n_cats):
        mr, s2n = U.get_data(catalogues[hhh], (mag_pos[ii], s2n_pos[ii]))
        mr += 0.083

        c0 = N.greater_equal(s2n, 3.) * N.less(mr, 30)
        c1 = N.greater_equal(s2n, 5.) * N.less(mr, 30)
        c2 = N.greater_equal(s2n, 10.) * N.less(mr, 30)
        c3 = N.greater_equal(s2n, 50.) * N.less(mr, 30)

        plt.figure(12)
        plt.clf()
        a10, a20, a30 = plt.hist(mr[c0], base, alpha=0.5, color='blue')
        a11, a21, a31 = plt.hist(mr[c1], base, alpha=0.5, color='green')
        a12, a22, a32 = plt.hist(mr[c2], base, alpha=0.5, color='orange')
        a13, a23, a33 = plt.hist(mr[c3], base, alpha=0.5, color='red')

        final_a10[:] += a10[:]
Example #16
0
    'uJAVA', 'J0378', 'J0395', 'J0410', 'J0430', 'gSDSS', 'J0515', 'rSDSS',
    'J0660', 'iSDSS', 'J0861', 'zSDSS'
]

# Field-of-View
fov = 1.4 * 11.

# Base to define the plot
base = N.arange(12, 30, .25)
base2 = base[:-1] + ((base[1] - base[0]) / 2.)
base3 = N.arange(1, 1.0e+6, 1)

# Generating figures
for ii in range(12):
    #ii=5
    mr, s2n = U.get_data(filename, (mag_pos[ii], s2n_pos[ii]))
    mr += 0.083

    c0 = N.greater_equal(s2n, 0.) * N.less(mr, 30)
    c1 = N.greater_equal(s2n, 1.) * N.less(mr, 30)
    c2 = N.greater_equal(s2n, 3.) * N.less(mr, 30)
    c3 = N.greater_equal(s2n, 5.) * N.less(mr, 30)
    # c4 = N.greater_equal(s2n,100.)*N.less(mr,30)

    plt.figure(12)
    plt.clf()

    a10, a20, a30 = plt.hist(mr[c0], base, alpha=0.5, color='blue')
    a11, a21, a31 = plt.hist(mr[c1], base, alpha=0.5, color='green')
    a12, a22, a32 = plt.hist(mr[c2], base, alpha=0.5, color='orange')
    a13, a23, a33 = plt.hist(mr[c3], base, alpha=0.5, color='red')
Example #17
0
def getsample_4_alhambra_multiple_mosaic(pepe):
    """
import os,sys
import useful as U
import alhambra_photools as alh
import alhambra_mosaics as alhmos
import pyfits
alhmos.getsample_4_alhambra_multiple_mosaic(4)


    """
    manual = 0
    pepa = open('mosaico.list', 'w')
    for ii in range(7):
        for jj in range(4):
            for kk in range(4):
                catalog = root_catalogs + 'f0%i/alhambra.f0%ip0%ic0%i.ColorProBPZ.Prior1Peak.cat' % (
                    ii + 2, ii + 2, jj + 1, kk + 1)
                colorimage = root_images + 'f0%i/color_images/f0%ip0%i_OPTICAL_%i.png' % (
                    ii + 2, ii + 2, jj + 1, kk + 1)
                if os.path.exists(catalog):
                    ids = U.get_str(catalog, 0)
                    xx, yy = U.get_data(catalog, (3, 4))
                    area, mm = U.get_data(catalog, (5, 62))
                    sf = U.get_data(
                        '/Volumes/amb22/catalogos/reduction_v4e/f0%i/f0%ip0%i_colorproext_%i_ISO.cat'
                        % (ii + 2, ii + 2, jj + 1, kk + 1), 71)
                    g = U.greater_equal(area, 100) * U.less_equal(
                        area, 500) * U.greater_equal(mm, 17) * U.less_equal(
                            mm, 21) * U.less(sf, 0.2)
                    # g = U.greater_equal(area,10000) * U.less_equal(mm,17) * U.less(sf,0.1)
                    # g = U.less_equal(mm,23.) * U.greater_equal(mm,18) * U.greater_equal(sf,0.8)
                    if manual != 1:
                        for ss in range(len(ids)):
                            if g[ss] == True:
                                linea = '%s \n' % (ids[ss])
                                pepa.write(linea)
                    else:
                        for ss in range(len(ids)):
                            if g[ss] == True:
                                print xx[ss], yy[ss]
                                print round(xx[ss]), round(yy[ss])
                                x = int(round(xx[ss]))
                                y = int(round(yy[ss]))
                                colorfile = colorimage
                                im = Image.open(colorfile)
                                imsize = nx, ny = im.size
                                dx = 70
                                dy = 70
                                dxo = dyo = 0
                                stamp = im.crop(
                                    (x - dx - dxo, ny - y - dy + dyo,
                                     x + dx - dxo, ny - y + dy + dyo))
                                draw = ImageDraw.Draw(stamp)
                                ressize = 300
                                stamp2 = stamp.resize((ressize, ressize),
                                                      Image.NEAREST)
                                stamp2.show()
                                buena = raw_input(
                                    'Include this source in the mosaic? [y/n]')
                                if buena == 'y':
                                    linea = '%s \n' % (ids[ss])
                                    pepa.write(linea)

    pepa.close()
Example #18
0
def overlaygalaxies(image,
                    cat,
                    posid,
                    posx,
                    posy,
                    cond,
                    shape,
                    save,
                    outfile,
                    extra=None):
    """
    This serves to create a color image with just stars.
============
import alhambra_webpage as alhw
import useful as U
image = '/Volumes/amb22/imagenes/f02/color_images/f02p01_OPTICAL_1.png'
cat = '/Volumes/amb22/catalogos/reduction_v4e/f02/f02p01_colorproext_1_ISO.cat'
posid = 0
posx = 3
posy = 4
sf = U.get_data(cat,71)
cond = U.greater_equal(sf,0.7)
shape = 'circle'
save = 'yes'
outfile = '/Volumes/amb22/catalogos/reduction_v4e/stars/f02/f02p01_stars_1.png'
alhw.overlaygalaxies(image,cat,posid,posx,posy,cond,shape,save,outfile)

    """
    colorfile = image
    im = Image.open(colorfile)
    imsize = nx, ny = im.size
    stamp = im.crop((0, 0, nx, ny))
    draw = ImageDraw.Draw(stamp)

    ids, x, y = U.get_data(cat, (posid, posx, posy))
    ids, x, y = U.multicompress(cond, (ids, x, y))

    for ii in range(len(x)):
        iid = ids[ii]
        xx = x[ii]
        yy = y[ii]
        shapesize = 10  # aa * 1.05
        colores = (255, 255, 1)

        if shape != 'None':
            if shape == 'circle':
                draw.ellipse((xx - shapesize, ny - yy - shapesize,
                              xx + shapesize, ny - yy + shapesize),
                             fill=None)
            elif shape == 'crosshair':
                draw.line((xx + shapesize, yy, xx + shapesize - 10, yy),
                          fill=None,
                          width=3)
                draw.line((xx - shapesize, yy, xx - shapesize + 10, yy),
                          fill=None,
                          width=3)
                draw.line((xx, yy + shapesize, xx, yy + shapesize - 10),
                          fill=None,
                          width=3)
                draw.line((xx, yy - shapesize, xx, yy - shapesize + 10),
                          fill=None,
                          width=3)
            elif shape == 'rectangle':
                draw.rectangle((dx - shapesize, dy - shapesize, dx + shapesize,
                                dy + shapesize),
                               fill=colores)  # fill=None)
            else:
                print 'Shape not found!. It will not be overlaid...'

        if extra == None:
            label = 'ID:814%i' % (iid)
        else:
            uno = int(int(extra) + iid)
            label = 'ID:%i' % (uno)
        draw.text((xx - (shapesize / 2.), ny - yy - (shapesize / 2.) - 15),
                  label,
                  fill=(255, 255, 1))

    if save == 'yes':
        if outfile != 'None':
            stamp.save(outfile)
        else:
            stamp.save('imcutoff.png')
Example #19
0
def alhambra_multiple_mosaic(listaids):
    """


----------
import os,sys
import useful as U
import alhambra_photools as alh
import alhambra_mosaics as alhmos
idlist = '/Users/albertomolino/doctorado/photo/programas/mosaico.list'
alhmos.alhambra_multiple_mosaic(idlist)

    """
    size = 20  # 100 # cell's size for mosaic image
    resol = 1
    single = 1
    wavel = 0

    ids0 = U.get_str(listaids, 0)
    ids = ids0[::resol]
    print 'Starting with the sample selection...'
    dim = len(ids)
    print 'dimension: ', dim

    file1name = alh.decapfile(listaids) + 'Bcolor.list'
    file2name = alh.decapfile(listaids) + 'Rcolor.list'
    file3name = alh.decapfile(listaids) + 'zcolor.list'
    if not os.path.exists(file1name) and not os.path.exists(
            file2name) and not os.path.exists(file3name):
        file1 = open(file1name, 'w')
        file2 = open(file2name, 'w')
        file3 = open(file3name, 'w')

        ff = 0
        pp = 0
        cc = 0
        for ii in range(dim):

            idi = ids[ii]
            field = int(idi[3:4])
            pointing = int(idi[4:5])
            ccd = int(idi[5:6])
            yo = int(idi[6:]) * 1
            # print 'Looking for ID: %s'%ids[ii]
            image1 = root_images + 'f0%i/f0%ip0%i_B_Subaru_%i.swp.fits' % (
                field, field, pointing, ccd)
            image2 = root_images + 'f0%i/f0%ip0%i_R_Subaru_%i.swp.fits' % (
                field, field, pointing, ccd)
            image3 = root_images + 'f0%i/f0%ip0%i_F814W_%i.swp.fits' % (
                field, field, pointing, ccd)
            # print field,ff
            # print pointing,pp
            # print ccd,cc

            if field != ff and pointing != pp and ccd != cc:
                # print 'reading new catalog'
                # catalog = '/Users/albertomolino/doctorado/photo/catalogos/reduction_v4f/alhambra.F0%iP0%iC0%i.ColorProBPZ.cat'%(field,field,pointing,ccd)
                catalog = root_catalogs + 'f0%i/alhambra.F0%iP0%iC0%i.ColorProBPZ.cat' % (
                    field, field, pointing, ccd)
                # print catalog
                idd = U.get_str(catalog, 0)
                ne = len(idd)
                x, y, mo = U.get_data(catalog, (6, 7, 65))
                # Sorting detections by magnitude.
                idd, x, y = U.multisort(mo, (idd, x, y))

            pos = N.where(idd == idi)[0][0]
            # for ss in range(ne):
            #     # print idd[ss]
            #     # if idd[ss]==idi:
            #     if idi[0] in idd:
            #        pos = ss

            if pos != -1:
                xx = int(round(x[pos]))
                yy = int(round(y[pos]))
                line1 = '%s  %i  %i  %i  %i  %i\n' % (image1, xx, yy, field,
                                                      pointing, ccd)
                # print line1
                file1.write(line1)
                line2 = '%s  %i  %i  %i  %i  %i\n' % (image2, xx, yy, field,
                                                      pointing, ccd)
                # print line2
                file2.write(line2)
                line3 = '%s  %i  %i  %i  %i  %i\n' % (image3, xx, yy, field,
                                                      pointing, ccd)
                # print line3
                file3.write(line3)
            else:
                print 'ID not found...'

            ff == field
            pp == pointing
            cc == ccd

        file1.close()
        file2.close()
        file3.close()

    print 'Sample reading completed'
    print 'Starting with mosaic...'

    nt = dim
    valor = U.sqrt(dim)
    nx = int(round(valor))
    ny = int(U.ceil(valor))

    imageout1 = alh.decapfile(file1name) + '.mosaic.fits'
    if not os.path.exists(imageout1):
        file1name = alh.decapfile(listaids) + 'Bcolor.list'
        ims1 = U.get_str(file1name, 0)
        x1, y1, field1, pointing1, ccd1 = U.get_data(file1name,
                                                     (1, 2, 3, 4, 5))
        if single:
            alhmos.singlemosaico(ims1, x1, y1, size, nt, nx, ny, imageout1)
        if wavel:
            alhmos.singlemosaico_pro(ims1, x1, y1, field1, pointing1, ccd1,
                                     size, nt, 24, nt, imageout1)

    imageout2 = alh.decapfile(file2name) + '.mosaic.fits'
    if not os.path.exists(imageout2):
        file2name = alh.decapfile(listaids) + 'Rcolor.list'
        ims2 = U.get_str(file2name, 0)
        x2, y2, field2, pointing2, ccd2 = U.get_data(file2name,
                                                     (1, 2, 3, 4, 5))
        if single:
            alhmos.singlemosaico(ims2, x2, y2, size, nt, nx, ny, imageout2)
        if wavel:
            alhmos.singlemosaico_pro(ims2, x2, y2, field2, pointing2, ccd2,
                                     size, nt, 24, nt, imageout2)

    imageout3 = alh.decapfile(file3name) + '.mosaic.fits'
    if not os.path.exists(imageout3):
        file3name = alh.decapfile(listaids) + 'zcolor.list'
        ims3 = U.get_str(file3name, 0)
        x3, y3, field3, pointing3, ccd3 = U.get_data(file3name,
                                                     (1, 2, 3, 4, 5))
        if single:
            alhmos.singlemosaico(ims3, x3, y3, size, nt, nx, ny, imageout3)
        if wavel:
            alhmos.singlemosaico_pro(ims3, x3, y3, field3, pointing3, ccd3,
                                     size, nt, 24, nt, imageout3)

    if os.path.exists(imageout1) and os.path.exists(
            imageout2) and os.path.exists(imageout3):
        alhmos.trilogy_alhambra_multiple_mosaic(imageout1, imageout2,
                                                imageout3)
Example #20
0
def overlaygalaxies2(image, cat, posx, posy, cond, shape, legend, save,
                     outfile):
    """
    Similar to version 1 but now the info display has nothing to do
    with the ID from the catalogue. Just an extra variable.
    This serves to create a color image with just stars.
============
import alhambra_webpage as alhw
import useful as U
image = '/Volumes/amb22/imagenes/f02/color_images/f02p01_OPTICAL_1.png'
cat = '/Volumes/amb22/catalogos/reduction_v4e/f02/f02p01_colorproext_1_ISO.cat'
posid = 0
posx = 3
posy = 4
sf = U.get_data(cat,71)
cond = U.greater_equal(sf,0.7)
shape = 'circle'
save = 'yes'
outfile = '/Volumes/amb22/catalogos/reduction_v4e/stars/f02/f02p01_stars_1.png'
alhw.overlaygalaxies2(image,cat,posx,posy,cond,shape,legend,save,outfile)

    """
    colorfile = image
    im = Image.open(colorfile)
    imsize = nx, ny = im.size
    stamp = im.crop((0, 0, nx, ny))
    draw = ImageDraw.Draw(stamp)

    x, y = U.get_data(cat, (posx, posy))
    x, y, legend = U.multicompress(cond, (x, y, legend))

    for ii in range(len(x)):
        xx = x[ii]
        yy = y[ii]
        shapesize = 40  # aa * 1.05
        colores = (255, 255, 1)

        if shape != 'None':
            if shape == 'circle':
                draw.ellipse((xx - shapesize, ny - yy - shapesize,
                              xx + shapesize, ny - yy + shapesize),
                             fill=None)
            elif shape == 'crosshair':
                draw.line((xx + shapesize, yy, xx + shapesize - 10, yy),
                          fill=None,
                          width=3)
                draw.line((xx - shapesize, yy, xx - shapesize + 10, yy),
                          fill=None,
                          width=3)
                draw.line((xx, yy + shapesize, xx, yy + shapesize - 10),
                          fill=None,
                          width=3)
                draw.line((xx, yy - shapesize, xx, yy - shapesize + 10),
                          fill=None,
                          width=3)
            elif shape == 'rectangle':
                draw.rectangle((dx - shapesize, dy - shapesize, dx + shapesize,
                                dy + shapesize),
                               fill=colores)  # fill=None)
            else:
                print 'Shape not found!. It will not be overlaid...'

        label = '%.2f' % (legend[ii])
        draw.text((xx - (shapesize / 2.), ny - yy - (shapesize / 2.) - 15),
                  label,
                  fill=(255, 255, 1))

    if save == 'yes':
        if outfile != 'None':
            stamp.save(outfile)
        else:
            stamp.save('imcutoff.png')
Example #21
0
# /Users/albertomolino/Postdoc/T80S_Pipeline/Commisioning/codes/
import sys

sys.path.append('/Users/albertomolino/doctorado/photo/programas/')
import numpy as N
import useful as U
import matplotlib.pyplot as plt
from matplotlib.pyplot import cm

root = '/Users/albertomolino/Postdoc/T80S_Pipeline/Commisioning/S82/Dec2017/'
root += 'data_quality/photometry/SDSSSPLUS/'
u_cat = root + 'master_SPLUS_STRIPE82_to_SDSS_Ivezick_stars_Uband.cat'
griz_cat = root + 'master_SPLUS_STRIPE82_to_SDSS_Ivezick_stars_griz.cat'

s2nu, u_sp, u_sd = U.get_data(u_cat, (2, 3, 4))
delta_u = (u_sp - u_sd)
good_u = N.greater_equal(s2nu, 5.) * N.less_equal(abs(delta_u), 2.)
good_u *= N.less_equal(u_sd, 22.)
u_sp, u_sd, delta_u = U.multicompress(good_u, (u_sp, u_sd, delta_u))

s2n, g_sp, r_sp, i_sp, z_sp = U.get_data(griz_cat, (2, 3, 4, 5, 6))  # SPLUS
g_sd, r_sd, i_sd, z_sd = U.get_data(griz_cat, (7, 8, 9, 10))  # SDSS
delta_g = (g_sp - g_sd)
delta_r = (r_sp - r_sd)
delta_i = (i_sp - i_sd)
delta_z = (z_sp - z_sd)

good_griz = N.greater_equal(s2n, 5.) * N.less_equal(abs(delta_g), 2.)
good_griz *= N.less_equal(abs(delta_r), 2.) * N.less_equal(abs(delta_i), 2.)
good_griz *= N.less_equal(abs(delta_z), 2.)
sys.path.append('/Users/albertomolino/doctorado/photo/programas/')
import useful as U
import numpy as N
import matplotlib.pyplot as plt
from matplotlib.pyplot import cm

mainroot = '/Users/albertomolino/Postdoc/T80S_Pipeline/Commisioning/S82/Dec2017/'
root2cats = mainroot + 'splus_cats/'
redshift = '05'
master_bpz_auto = root2cats + 'master_STRIPE82_spz.z%s_cali_GOSMOS_auto.bpz' % (
    redshift)
master_bpz_petro = root2cats + 'master_STRIPE82_spz.z%s_cali_GOSMOS_petro.bpz' % (
    redshift)
master_bpz_aper = root2cats + 'master_STRIPE82_spz.z%s_cali_GOSMOS_aper.bpz' % (
    redshift)
ng = len(U.get_data(master_bpz_auto, 0))

######## ######### #########
#  New figures
######## ######### #########

# Precision as a function of z for several AB intervals.
# Version II

#base_z  = N.arange(0.,0.51,0.1)
base_z = N.arange(0.0, 0.25, 0.05)
base_m = N.arange(14., 21., 1.)
base_z2 = base_z[:-1] + ((base_z[1] - base_z[0]) / 2.)
base_m2 = base_m[:-1] + ((base_m[1] - base_m[0]) / 2.)
n_z = len(base_z) - 1
n_m = len(base_m) - 1
def spurious_detect_threshold(image, sexfile):
    """
    Starting with an input configuration.sex file, 
    it runs SExtractor on both sizes of the image varying 
    the threshold value across a certain range. 
    By doing this, it is possible to stablish an bottom threshold
    for which the percentage of spurious detections is not larger
    than a few percents.
======
MAKE SURE THERE IS NOT A BLANK LINE AT THE END OF THE SEx FILE !!!!

----
image = '/Volumes/amb/imagenes/f02/f02p01_F814W_4.swp.fits'
sexfile = '/Volumes/amb/catalogos/reduction_v4/f02/f02p01_colorpro_4.sex'
fspd,base = spurious_detect_threshold(image,sexfile,'yes','yes','yes','yes')

    """

    verbose = 1

    if os.path.exists(image) and os.path.exists(sexfile):

        print
        print 'MAKE SURE THERE IS NOT A BLANK LINE AT THE END OF THE SEx FILE !!!!'
        print

        min_value = 0.9
        max_value = 1.5
        interv = 0.05
        base = N.arange(min_value, max_value + interv, interv)
        dim = len(base)
        spd = N.zeros((dim, 2), float)
        fspd = N.zeros(dim)
        newvals = N.zeros(2)
        imageinv = sdt.decapfile(image) + '_inv.fits'

        if not os.path.exists(imageinv):
            print 'Creating an inverse image...'
            coeff = -1.
            sdt.multiply_image_bya_number(image, coeff, imageinv)

        print 'Modifying SExtractor input file...'
        if os.path.exists(imageinv):
            for ii in range(dim):
                newsexcat = sdt.decapfile(
                    sexfile) + '_thr%.2f.cat' % (base[ii])
                newsexfile = sdt.decapfile(
                    sexfile) + '_thr%.2f.sex' % (base[ii])
                param = ['ANALYSIS_THRESH', 'DETECT_THRESH', 'CATALOG_NAME']
                newvals = [base[ii], base[ii], newsexcat]
                # newvals[0] = base[ii]
                # newvals[1] = base[ii]

                if verbose:
                    print 'base[%i]' % (ii), base[ii]
                    print 'sexfile', sexfile
                    print 'newsexfile', newsexfile
                    print 'param', param
                    print 'newvals', newvals

                # Modifiying THRESHOLD in conf.sex.
                sdt.modifyingSExfiles(sexfile, param, newvals, newsexfile)

                print 'Running SExtractor...'
                for ss in range(2):
                    if ss == 0: image2 = image
                    else: image2 = imageinv
                    if os.path.exists(newsexfile):
                        cmd2 = ''
                        cmd2 = 'sex %s -c %s' % (image2, newsexfile)
                        print cmd2
                        try:
                            os.system(cmd2)
                        except:
                            print 'Impossible to run SExtractor !!'

                        print
                        print 'Measuring detections...'
                        catout = newsexcat
                        if os.path.exists(catout):
                            # print 'YES, the catout exists...'
                            id, x, y = U.get_data(catout, (0, 1, 2))
                            good = N.greater(x, 1500.) * N.less(
                                x, 10300.) * N.greater(y, 1100.) * N.less(
                                    y, 10000.)
                            id_redu = N.compress(good, id)
                            print 'Compressing the sample..'
                            spd[ii, ss] = len(id_redu)
                        else:
                            print '%s does not exists!!' % (catout)
                            print 'Impossible to quantify percentage of spurious detections!!'

            print 'Estimating spurious detections...'
            for jj in range(dim):
                fspd[jj] = ((spd[jj, 1] * 1.) / (spd[jj, 0] * 1.)) * 100.

            print 'fspd', fspd
            print 'Plotting results....'
            plt.figure(1,
                       figsize=(12, 7),
                       dpi=80,
                       facecolor='w',
                       edgecolor='k')
            plt.clf()
            plt.plot(base, fspd, '-ko', linewidth=2)
            plt.plot(base, base * 0. + 3., 'm--', linewidth=1.5)
            plt.xlabel('Threshold ($\sigma$)'), plt.ylabel(
                '% Spurious detections')
            plt.xlim(min_value - interv, max_value + interv)
            plt.grid()
            outname = sdt.decapfile(image) + '_thranal.png'
            plt.savefig(outname, dpi=150)

            plt.figure(2,
                       figsize=(12, 7),
                       dpi=80,
                       facecolor='w',
                       edgecolor='k')
            plt.clf()
            plt.plot(base, spd[:, 0], '-ko', linewidth=5)
            plt.xlabel('Threshold ($\sigma$)',
                       size=15), plt.ylabel('Number Detected Sources', size=15)
            plt.xlim(min_value - interv, max_value + interv)
            plt.grid()
            figname = sdt.decapfile(image) + '_numdet.png'
            plt.savefig(figname, dpi=150)

            outname2 = sdt.decapfile(image) + '_thranal.txt'
            U.put_data(outname2, (fspd, base), '# fspd  base ', '%.3f  %.3f')
            plt.close()

            return fspd, base

    else:
        print 'Input image or input SExfile does not exist!'
        print image
        print sexfile
Example #24
0
#root2files = '/Users/albertomolino/Postdoc/JPAS/PF/Data_CEFCA_Oct11/'
#final_root_cats = root2files + 'catalogues/reformatted/'
#root_to_complet = final_root_cats + 'completeness/'
#root_to_counts  = final_root_cats + 'counts/'
#final_root = final_root_cats + 'photoz_depth/'

''

# Files to be used.
aperture = 'MAG_RESTRICTED_PSFCOR'
complet_file_mr  = root_to_complet + 'AEGIS.master.spz.%s.'%(aperture)
complet_file_mr += 'cali.completeness.mr.cat'
number_counts = root_to_counts + 'AEGIS.master.z.counts.mr.cat'

# Reading the number counts.
base_mr,mr = U.get_data(number_counts,(0,1))
# Reading the completeness fraction
base_mo,cm_o1,cm_o2,cm_o3,cm_o4 = U.get_data(complet_file_mr,(0,1,2,3,4))

# Intervals to be used.
mmin = 17.
mmax = 28.
dm = 0.5
new_base = np.arange(mmin,mmax+dm,dm)

new_numb_counts = U.match_resol(base_mr,mr,new_base)
new_complet_o1 = U.match_resol(base_mo,cm_o1,new_base)
new_complet_o1 = np.where(new_complet_o1<0.,0.,new_complet_o1)
new_complet_o2 = U.match_resol(base_mo,cm_o2,new_base)
new_complet_o2 = np.where(new_complet_o2<0.,0.,new_complet_o2)
new_complet_o3 = U.match_resol(base_mo,cm_o3,new_base)
Example #25
0
# Filters
filter_x1 = 'SPLUS_gSDSS'
filter_x2 = 'SPLUS_zSDSS'
filter_y1 = 'SPLUS_uJAVA'
filter_y2 = 'SPLUS_gSDSS'

#Models
sed_models = U.get_str(sed_path + sed_lib, 0)
n_models = len(sed_models)

# Reading the S-PLUS/S82 data (spec-z cat)
#bpz_cat = root_to_cats+'bpz/'+'master.STRIPE82_Photometry.m21.bpz'
if splus:
    photo_cat = root_to_cats + 'cat/' + 'master.STRIPE82_Photometry.m21.cat'
    u, du, g, dg, r, dr, i, z, dz, zs = U.get_data(
        photo_cat, (15, 16, 60, 61, 78, 79, 96, 114, 115, 125))
else:
    photo_cat = '/Users/albertomolino/Postdoc/T80S_Pipeline/targets/SDSS_S82/'
    photo_cat += 'catalogues/stripe82_spz_extcorr.cat'
    u, g, r, i, z, zs = U.get_data(photo_cat, (4, 6, 8, 10, 12, 3))

clean_data = N.less_equal(abs(u - g), 5.) * N.less_equal(abs(g - z), 5.)
#clean_data *= N.less_equal(du,0.1) * N.less_equal(dg,0.07) * N.less_equal(dz,0.07)
u, g, r, i, z, zs = U.multicompress(clean_data, (u, g, r, i, z, zs))

# Defining colours
color_x = g - z
color_y = u - g

# Estimating dimensionality
ab_file_example = ab_path + sed_models[0][:-3] + filter_x1 + '.AB'
Example #26
0
def get_PDZerrDistribution(hdf5file, bpzfile, m_max, o_min):
    """
    It returns the error distribution based on PDZs.
---

import splus_s82_hdf5_tools as to
root = '/Users/albertomolino/Postdoc/T80S_Pipeline/Commisioning/'
root += 'S82/Dec2017/splus_cats_NGSL/'
hdf5list = root+'hdf5.list'
bpzlist = root+'bpz/master.STRIPE82_Photometry.m21.bpz.list'
hdf5_files = U.get_str(hdf5list,0)
n_hdf5 = len(hdf5_files)
bpz_files  = U.get_str(bpzlist,0)
n_bpz = len(bpz_files)
for ii in range(n_bpz):
    name = os.path.basename(hdf5_files[ii])
    print name
    try: z,dp,df = to.get_PDZerrDistribution(hdf5_files[ii],bpz_files[ii],20)
    except: print 'Impossible to run on ',name

    """

    plots = 0

    try:
        ids, zb, zs, mo, tb, odd = U.get_data(bpzfile, (0, 1, 11, 12, 4, 5))
    except:
        ids, zb, zs, mo, tb, odd = U.get_data(bpzfile, (0, 1, 9, 10, 4, 5))
    good = N.less_equal(mo, m_max) * N.greater_equal(odd, o_min)
    ids, zb, zs, mo, tb, odd = U.multicompress(good,
                                               (ids, zb, zs, mo, tb, odd))
    ng = len(ids)

    #Readin the PDZs...
    p = h5py.File(hdf5file, mode='r')
    #pdzo = p.get('FullProbability')
    pdz = p.get('Likelihood')
    pdz = pdz[good, :, :]
    zz = p.get('redshift')[:]
    dz = (zz[2] - zz[1])
    basez2 = N.arange(-0.1, 0.1, dz)
    basez3 = N.arange(-0.1, 0.1, dz * 10.)
    basez2b = basez2[:-1] + ((basez2[1] - basez2[0]) / 2.)
    basez3b = basez3[:-1] + ((basez3[1] - basez3[0]) / 2.)
    nz = len(basez2)
    res = 1

    # starting plots if necessary
    #if plots:
    #   plt.figure(12, figsize = (8.5,10.),dpi=80, facecolor='w', edgecolor='k')

    # Computing the z error distr. function
    # based on peak values.
    delta_z_peaks = (zb - zs) / (1. + zs)
    a1, a2 = N.histogram(delta_z_peaks, basez3)

    delta_z_pdzs = N.zeros(nz - 1)
    print 'ng:', ng

    for ii in range(ng):
        pdz_mot = U.sum(pdz[ii, :, :], axis=1)
        pdz_mot_peak = pdz_mot / float(max(pdz_mot))
        # To get rid of long tails in PDFs with low probabilities.
        pdz_mot_peak = N.where(pdz_mot_peak < 1.0e-4, 0., pdz_mot_peak)
        pdz_mot_norm = pdz_mot_peak / float(sum(pdz_mot_peak))
        #pdz_mot_norm = N.where(pdz_mot_norm<0.,0.,pdz_mot_norm)
        #pdz_mot_norm  = pdz_mot/float(sum(pdz_mot))
        pdz_mot_norm_resample = U.match_resol(zz - zs[ii], pdz_mot_norm,
                                              basez2b)
        pdz_mot_norm_resample = N.where(pdz_mot_norm_resample < 0., 0.,
                                        pdz_mot_norm_resample)
        delta_z_pdzs += pdz_mot_norm_resample[:]

    # New variables to handle data easily.
    # It scales the normalized PDFs by the ng!


#    norm_dz_peaks = a1/float(sum(a1))
#    norm_dz_pdfs = delta_z_pdzs/float(sum(delta_z_pdzs))
    norm_dz_peaks = a1 / float(max(a1))
    norm_dz_pdfs = delta_z_pdzs / float(max(delta_z_pdzs))

    if plots:
        plt.figure(11,
                   figsize=(8.5, 10.),
                   dpi=80,
                   facecolor='w',
                   edgecolor='k')
        plt.clf()
        #plt.subplot(212)
        plt.plot(basez3b, norm_dz_peaks, 'b-', lw=8, alpha=0.6)
        plt.plot(basez2b, norm_dz_pdfs, 'r-', lw=5, alpha=0.9)
        plt.grid()
        plt.xlim(-0.2, 0.2)
        plt.ylabel('P(z)', size=20, labelpad=+1)
        plt.legend(['peaks', 'pdfs'], loc='upper left', fontsize=20)
        plt.xlabel('$\delta_{z}$', size=30)
        final_name = os.path.dirname(hdf5file) + '/PDFs/' + os.path.basename(
            hdf5file)
        plot_filename = final_name[:-4] + 'deltaz.mmax%.2fAB.png' % (m_max)
        #plt.savefig(plot_filename,dpi=80)

    # Saving data into a file.
    #output_filename = hdf5file[:-4]+'deltaz.mmax%.2fAB.mat'%(m_max)
    #U.put_data(output_filename,(basez2b,norm_dz_peaks,norm_dz_pdfs),'z dz_peak dz_PDFs')

    return basez2b, basez3b, norm_dz_peaks, norm_dz_pdfs, ng
Example #27
0
# filter names
filters = [
    'u', 'J0378', 'J0395', 'J0410', 'J0430', 'g', 'J0515', 'r', 'J0660', 'i',
    'J0861', 'z'
]

base_filtros = N.arange(12) + 1

final_zpo = N.zeros((n_cats, 12), float)
final_zpe = N.zeros((n_cats, 12), float)

for ii in range(n_cats):
    cali_columns = cats_names[ii][:-4] + '.spz.z05.%s_cali.columns' % (
        aperture)
    final_zpe[ii, :], final_zpo[ii, :] = U.get_data(cali_columns, (3, 4), 12)

pepe = U.sum(final_zpe, axis=0) / (1. * n_cats)
pepo = U.sum(final_zpo, axis=0) / (1. * n_cats)

plt.figure(1, figsize=(14, 8), dpi=80, facecolor='w', edgecolor='k')
plt.clf()
plt.errorbar(base_filtros,
             pepo - pepo[7],
             pepe,
             fmt="-rs",
             alpha=0.5,
             ms=10,
             lw=7)
for ii in range(n_cats):
    plt.plot(base_filtros,