Beispiel #1
0
def reset_cube(name, namer="-1", namev="-1"):
    import pyfits as pyf
    namef = name
    if pt.exists(name + ".fits.gz") == True:
        name = name + ".fits.gz"
    if pt.exists(name + ".fits") == True:
        name = name + ".fits"
    if pt.exists(name + ".fits.fz") == True:
        name = name + ".fits.fz"
    hdulist = pyfits.open(name)
    img = hdulist[0].data
    hd_d = hdulist[0].header
    [nz, nx, ny] = img.shape
    if namer != "-1":
        [img_e, hd_e] = gdata(namer, 0, header=True)
    else:
        img_e = np.ones([nz, nx, ny])
    if namev != "-1":
        [img_v, hd_v] = gdata(namev, 0, header=True)
    else:
        img_v = np.ones([nz, nx, ny])
    if not 'CDELT3' in hd_d:
        hd_d['CDELT3'] = hd_d['CD3_3']
    ivar_list = pyf.ImageHDU(img_e)
    mask_list = pyf.ImageHDU(img_v)
    hlist = pyf.HDUList([hdulist[0], ivar_list, mask_list, mask_list])
    hlist.update_extend()
    wfits_ext(namef + '.cube.fits', hlist)
    call = "gzip " + namef + '.cube.fits'
    sycall(call)
Beispiel #2
0
import os.path as pt


def sycall(comand):
    from subprocess import call
    line = comand.split(" ")
    fcomand = []
    fcomand.extend(line)
    call(fcomand)


sys.argv = filter(None, sys.argv)
if len(sys.argv) < 3:
    print "USE: create_mask_map.pl map.fits cut mask.fits"
    sys.exit(0)
input_file = sys.argv[1]
cut = float_(sys.argv[2])
output_file = sys.argv[3]
[pdl_input, h] = gdata(input_file, 0, header=True)
[nx, ny] = pdl_input.shape
pdl_output = np.zeros([nx, ny])
for j in range(0, ny):
    for i in range(0, nx):
        val = pdl_input[i, j]
        if val > cut:
            pdl_output[i, j] = 1
if pt.exists(output_file) == False:
    wfits(output_file, pdl_output, h)
else:
    sycall("rm " + output_file)
    wfits(output_file, pdl_output, h)
Beispiel #3
0
    print "USE: radial_sum_cube.pl CUBE.fits Delta_R X_C Y_C OUTPUT.RSS.fits [PLOT]"
    print "It will use images coordinates: 0,nx 0,ny"
    sys.exit(0)

input = sys.argv[1]
Dr = float(sys.argv[2])
x_c = int(sys.argv[3])
y_c = int(sys.argv[4])
output = sys.argv[5]
e_output = "e_" + output
weight_output = "weight." + output
plot = 0
if len(sys.argv) == 7:
    plot = int(sys.argv[6])

[pdl_cube, hd] = gdata(input, 0, header=True)
[NX, NY, NZ] = pdl_cube.shape
y_c = NY - y_c

crval = hd["CRVAL3"]
cdelt = hd["CDELT3"]
crpix = hd["CRPIX3"]

pdl_mask = np.ones([NX, NY, NZ])
extend = hd["EXTEND"]
print "EXTEND = " + str(extend)
if (extend == 1) or (extend == "T"):
    mask_ext = input
    [b_mask, hd_m] = gdata(mask_ext, 3, header=True)
    pdl_mask = pdl_mask  #-b_mask checar
    e_ext = input
Beispiel #4
0
    out[5]=np.std(data)
    out[6]=np.mean(data)+np.std(data)
    return out

sys.argv=filter(None,sys.argv)
if len(sys.argv) < 5:
    print "USE: FIT3D_output_rss_seg2cube.py FIT3D_output.RSS.fits N.OUT SEGMENTATION.fits OUTPUT.CUBE.FITS"
    sys.exit(0)

infile=sys.argv[1]
nout=int(sys.argv[2])
segfile=sys.argv[3]
outfile=sys.argv[4]
pt=outfile
pt=pt.replace('fits','pt.txt')
[a_in_rss, h]=gdata(infile, 0, header=True)
[Ny,nz,Nx]=a_in_rss.shape
crval=h["CRVAL1"]
cdelt=h["CDELT1"]
crpix=h["CRPIX1"]
if crval == 0:
    crval=hdr["CRVAL3"]
    cdelt=hdr["CDELT3"]
    crpix=hdr["CRPIX3"]
if cdelt == 0:
    cdelt=1
a_in=a_in_rss[:,:,nout]
[s_in, h2]=gdata(segfile, 0, header=True)
[nx,ny]=s_in.shape
out_cube=np.zeros([nz,nx,ny])
h2["CRVAL3"]=crval
    out[3]=np.amin(data)
    out[4]=np.amax(data)
    out[5]=np.std(data)
    out[6]=np.mean(data)+np.std(data)
    return out

sys.argv=filter(None,sys.argv)
if len(sys.argv) < 4:
    print "USE: spec_extract_cube_error.pl INPUT.CUBE.fits SEGMENTATION.fits OUTPUT.RSS.FITS"
    sys.exit(0)
infile=sys.argv[1]
segfile=sys.argv[2]
outfile=sys.argv[3]
pt=outfile
pt=pt.replace('fits','pt.txt')
a_in=gdata(infile, 1)
hd=ghead(infile, 0)
[nz,nx,ny]=a_in.shape
crval=hd["CRVAL3"]
cdelt=hd["CDELT3"]
crpix=hd["CRPIX3"]
[s_in,h2]=gdata(segfile, 0, header=True)
[NX,NY]=s_in.shape
inverse_s=np.zeros([NX,NY])
if nx > NX or ny > NY:
    print "Dimensions does not match ("+str(nx)+","+str(ny)+") != ("+str(NX)+","+str(NY)+")"
    sys.exit(0)
DATA=stats(s_in)
ns=int(DATA[4])
a_out=np.zeros([ns,nz])
statsa=stats(a_in)
Beispiel #6
0

def wfits(name, data, hdr):
    if ptt.exists(name) == False:
        wfit(name, data, hdr)
    else:
        sycall("rm " + name)
        wfit(name, data, hdr)


sys.argv = filter(None, sys.argv)
file1 = sys.argv[1]
file2 = sys.argv[2]
file3 = sys.argv[3]

[data1, head1] = gdata(file1, 0, header=True)
[data2, head2] = gdata(file2, 0, header=True)

data0 = data1 - data2
crpix1 = head1["CRPIX1"]
crval1 = head1["CRVAL1"]
cd1_1 = head1["CD1_1"]
cd1_2 = head1["CD1_2"]
crpix2 = head1["CRPIX2"]
crval2 = head1["CRVAL2"]
cd2_1 = head1["CD2_1"]
cd2_2 = head1["CD2_2"]

hd = pyf.PrimaryHDU().header
hd["CRPIX1"] = crpix1
hd["CRVAL1"] = crval1
Beispiel #7
0
DIR_DATA_OUT_final=DIR_DATA_OUT+"/"+SPLIT[1]+"/"+SPLIT[2]
FILE=DIR_DATA+"/"+NAME+".cube.fits.gz"
logfile="ana_single."+NAME+".log"
flog=open(logfile,"w")
init_time=print_time()
call="re_config.py "+config+" "+config_no+" "+config_SII+" "+DIR_CONF
mycall(call)
#sys.exit()
config=config+"_n"
config_no=config_no+"_n"
config_SII=config_SII+"_n"
call="get_slice.py "+FILE+" img_"+NAME+" "+DIR_CONF+"/slice_V.conf" 
mycall(call)

V_img="img_"+NAME+"_V_4500_5500.fits"
[img,hd_mask]=gdata(V_img,0,header=True)                                             
[nx,ny]=img.shape    
img_mask=np.zeros([nx,ny])
V_mask="../masks_v1.4/"+NAME+".mask.fits"
nx1=nx 
ny1=ny
if pt.exists(V_mask) == True:
    [img_mask,hd_mask]=gdata(V_mask,0,header=True)
    [nx1,ny1]=img_mask.shape   
print "DIM = "+str(nx)+","+str(ny)+","+str(nx1)+","+str(ny1)          
img_mask_new=np.ones([nx1,ny1])
for ii in range(0, nx1):                                                     
    for jj in range(0, ny1):
        val_mask=img_mask[ii,jj]                                                 
        if val_mask == 2:
            img_mask_new[ii,jj]=0
Beispiel #8
0
    line = comand.split(" ")
    fcomand = []
    fcomand.extend(line)
    call(fcomand)


sys.argv = filter(None, sys.argv)
if len(sys.argv) < 4:
    print "USE: imarith.pl INPUT1.FITS OPERATOR(+,-,/,*) INPUT2.FITS OUTPUT.FITS"
    sys.exit(0)
infile1 = sys.argv[1]
operator = sys.argv[2]
infile2 = sys.argv[3]
outfile = sys.argv[4]
print infile1
[a_in1, h] = gdata(infile1, 0, header=True)
if not "fit" in infile2:
    a_in2 = infile2
else:
    [a_in2, h2] = gdata(infile2, 0, header=True)
if operator == "+":
    a_in1 = a_in1 + a_in2
if operator == "-":
    a_in1 = a_in1 - a_in2
if operator == "/":
    a_in1 = a_in1 / a_in2
if operator == "*":
    a_in1 = a_in1 * a_in2
if pt.exists(outfile) == False:
    wfits(outfile, a_in1, h)
else:
Beispiel #9
0
prefix = sys.argv[3]
npi = 0
LINE = []
f = open(pack, "r")
for line in f:
    if not "#" in line:
        line = line.replace('NAME', name)
        LINE.extend([line])
        npi = npi + 1
f.close()

for i in range(0, npi):
    line = LINE[i]
    data = line.split(",")
    if i == 0:
        [pdl_img, hdr] = gdata(data[1], 0, header=True)
        [nx, ny] = pdl_img.shape
        pdl_cube = np.zeros([npi, nx, ny])
        hdr["NAXIS"] = 3
        hdr["NAXIS1"] = nx
        hdr["NAXIS2"] = ny
        hdr["NAXIS3"] = npi
        hdr["COMMENT"] = "FITs header"
        head = "OBJECT"
        hdr[head] = name
    else:
        pdl_img = gdata(data[1])
    pdl_cube[i, :, :] = pdl_img
    head = "ID_" + str(i)
    hdr[head] = data[0]
    head = "FILE_" + str(i)
Beispiel #10
0
line=f.readline()
data=line.split(" ")
data=filter(None,data)
if len(data) == 3:
    wave_norm=data[0]
    w_wave_norm=data[1]
    new_back_file=data[2]
else:
    wave_norm=[]
    w_wave_norm=[]
    new_back_file=[]
f.close()
#
# SFH template
#
[pdl_flux_c_ini,hdr]=gdata(back_list, 0, header=True)
[nf,n_c]=pdl_flux_c_ini.shape
coeffs=np.zeros([nf,3])
crpix1=hdr["CRPIX1"]
cdelt1=hdr["CDELT1"]
crval1=hdr["CRVAL1"]
#
# Kinematics template
#

[pdl_flux_c_ini_kin, hdr2]=gdata(back_list_kin, 0, header=True)
[nf_kin,n_c_kin]=pdl_flux_c_ini_kin.shape
coeffs_kin=np.zeros([nf_kin,3])
crpix_kin=hdr2["CRPIX1"]
cdelt_kin=hdr2["CDELT1"]
crval_kin=hdr2["CRVAL1"]
    OL2[i] = data[2]
    OLb1[i] = data[3]
    OLb2[i] = data[4]
    OLr1[i] = data[5]
    OLr2[i] = data[6]
    OLb[i] = (OLb1[i] + OLb2[i]) / 2.
    OLr[i] = (OLr1[i] + OLr2[i]) / 2.
    if OLb1[i] < w_min:
        w_min = OLb1[i]
    if OLr2[i] > w_max:
        w_max = OLr2[i]

w_min = w_min - 200
w_max = w_max + 200

[pdl, hdr] = gdata(spec_file, 0, header=True)
[ny, nx, nz] = pdl.shape
print ny, nx, nz
crval = hdr["CRVAL1"]
cdelt = hdr["CDELT1"]
crpix = hdr["CRPIX1"]
if crval == 0:
    crval = hdr["CRVAL3"]
    cdelt = hdr["CDELT3"]
    crpix = hdr["CRPIX3"]
fwhm = 2.345 * 3 * cdelt
nsim = NSIM

w = np.zeros(nx)
for i in range(0, nx):
    w[i] = crval + cdelt * (i + 1 - crpix)
Beispiel #12
0
from pyfits import writeto as wfits
import os.path as pt
from scipy.ndimage.filters import median_filter as med2df


def sycall(comand):
    from subprocess import call
    line = comand.split(" ")
    fcomand = []
    fcomand.extend(line)
    call(fcomand)


sys.argv = filter(None, sys.argv)

if len(sys.argv) < 4:
    print "USE: med2df.py INPUT.FITS OUTPUT.fits X_WIDTH Y_WIDTH"
    sys.exit(0)

infile = sys.argv[1]
outfile = sys.argv[2]
dx = int(sys.argv[3])
dy = int(sys.argv[4])
[pdl, hdr] = gdata(infile, 0, header=True)
mpdl = med2df(pdl, size=(dx, dy), mode='reflect')
if pt.exists(outfile) == False:
    wfits(outfile, mpdl, hdr)
else:
    sycall("rm " + outfile)
    wfits(outfile, mpdl, hdr)
Beispiel #13
0
    else:
        if nseg == 0:
            INDEX = INDEX_0
            e_INDEX = INDEX_0
        else:
            INDEX = np.concatenate((INDEX, INDEX_0), axis=1)
            e_INDEX = np.concatenate((e_INDEX, INDEX_0), axis=1)
        for i in range(0, n_index):
            INDEX[i][nseg] = 0
            e_INDEX[i][nseg] = 0
    nseg = nseg + 1
f.close()

print INDEX

[s_in, h] = gdata(segfile, 0, header=True)
[nx, ny] = s_in.shape
nz = 2 * n_index
pdl_cube = np.zeros([nz, nx, ny])

for i in range(0, nx):
    for j in range(0, ny):
        ist = int(s_in[i, j])
        is_out = ist - 1
        if is_out >= 0:
            for k in range(n_index):
                kk = k + n_index
                val = INDEX[k][is_out]
                e_val = e_INDEX[k][is_out]
                pdl_cube[k, i, j] = val
                pdl_cube[kk, i, j] = e_val
Beispiel #14
0
    prefix = sys.argv[11]
    memo = float_(sys.argv[12])

guided = 0
guided_type = 2
if len(sys.argv) == 14:
    n_mc = int(sys.argv[7])
    n_loops = int(sys.argv[8])
    plot = int(sys.argv[9])
    scale_ini = float_(sys.argv[10])
    prefix = sys.argv[11]
    memo = float_(sys.argv[12])
    JUNK = sys.argv[13]
    guided = 1
    [guided_map, guided_mask, guided_type] = JUNK.split(",")
    gmap = gdata(guided_map)
    gmask = gdata(guided_mask)
    guided_type = float_(guided_type)

guided_disp = 0
guided_disp_type = 2
if len(sys.argv) == 15:
    n_mc = int(sys.argv[7])
    n_loops = int(sys.argv[8])
    plot = int(sys.argv[9])
    scale_ini = float_(sys.argv[10])
    prefix = sys.argv[11]
    memo = float_(sys.argv[12])
    JUNK = sys.argv[13]
    guided = 1
    [guided_map, guided_mask, guided_type] = JUNK.split(",")
Beispiel #15
0
if "," in junk_input_cube:
    data=junk_input_cube.split(",")
    input_cube=data[0]
    input_e_cube=data[1]
    n_mc=int(data[2])
    input_cont_cube=data[3]
else:
    input_cube=junk_input_cube
    input_e_cube="none"
elines_list=sys.argv[2]
output=sys.argv[3]
guided_map=sys.argv[4]
guided_sigma=sys.argv[5]

# Reading cube
[pdl_input_cube, h]=gdata(input_cube, 0, header=True)
[nz,nx,ny]=pdl_input_cube.shape
crpix=h["CRPIX3"]
crval=h["CRVAL3"]
cdelt=h["CDELT3"]
pdl_input_cube[np.isnan(pdl_input_cube)]=0
if input_e_cube != "none":
    if "[1]" in input_e_cube:
        input_e_cube=input_e_cube.replace('[1]','')
        pdl_input_e_cube=gdata(input_e_cube, 1)
    else:
        pdl_input_e_cube=gdata(input_e_cube)
    statst=my.stats(pdl_input_e_cube)
    pdl_input_e_cube[np.where(pdl_input_e_cube <= -5*statst[2])]=np.nan
    pdl_input_e_cube[np.where(pdl_input_e_cube >= +5*statst[2])]=np.nan
    pdl_input_e_cube[np.isnan(pdl_input_e_cube)]=5*statst[2]
    else:
        sycall("rm " + name)
        wfit(name, data, hdr)


vel_light = 299792.458
sys.argv = filter(None, sys.argv)
if len(sys.argv) < 6:
    print "USE: map_auto_ssp.py AUTO.OUT seg_file.fits  PREFIX_OUT WAVE_CEN INST_DIST"
    sys.exit(0)
infile = sys.argv[1]
seg_file = sys.argv[2]
prefix = sys.argv[3]
wave_cen = float_(sys.argv[4])
inst_disp = float_(sys.argv[5])
[pdl_seg, hdr] = gdata(seg_file, 0, header=True)
[nx, ny] = pdl_seg.shape
pdl_chi = np.zeros([nx, ny])
pdl_age = np.zeros([nx, ny])
pdl_age_mass = np.zeros([nx, ny])
pdl_e_age = np.zeros([nx, ny])
pdl_age_lum = np.zeros([nx, ny])
pdl_e_age_lum = np.zeros([nx, ny])
pdl_age_lum_M = np.zeros([nx, ny])
pdl_e_age_lum_M = np.zeros([nx, ny])
pdl_met_lum = np.zeros([nx, ny])
pdl_met_mass = np.zeros([nx, ny])
pdl_met_lumI = np.zeros([nx, ny])
pdl_met_lumII = np.zeros([nx, ny])
pdl_met_lumII_mass = np.zeros([nx, ny])
pdl_e_met_lumII = np.zeros([nx, ny])
Beispiel #17
0
wave_ref=float_(sys.argv[5])
dev=sys.argv[6]

map_outfile=outfile+".vel_map.fits"
mask_outfile=outfile+".mask_map.fits"


if len(sys.argv) == 9:
    wmin=float_(sys.argv[7])
    wmax=float_(sys.argv[8])
else:
    wmin=0
    wmax=1e12
dmin=0

[pdl_in, hdr]=gdata(input, 0, header= True)
crval3=hdr["CRVAL3"]
cdelt3=hdr["CDELT3"]
crpix3=hdr["CRPIX3"]
[nz,nx,ny]=pdl_in.shape
map_out=np.zeros([nx,ny])
mask_out=np.zeros([nx,ny])

for ii in range(0, nx):
    for jj in range(0, ny):
# Define data
        n=0
        wave=[]
        flux=[]
        y_min=1e12
        y_max=-1e12
Beispiel #18
0
start_w=[]
end_w=[]
f=open(conf_file, "r");
for line in f:
    if line != "\n":
        data=line.split(" ")
        if data[0] != "#":
            data=filter(None,data)
            name.extend([data[0]])
            start_w.extend([float(data[1])])
            end_w.extend([float(data[2])])
f.close()
ns=len(name)
print str(ns)+" slices to cut"
print "Reading cube"
[b, hdr] = gdata(input_cube, 0 ,header=True)
crval3 = hdr["CRVAL3"]
cdelt3= hdr["CDELT3"]
crpix3= hdr["CRPIX3"]
[nx,ny,nz]=b.shape

for i in range(0, ns):
    out_file=prefix+"_"+name[i]+"_"+str(int(start_w[i]))+"_"+str(int(end_w[i]))+".fits"
    start_i=int((start_w[i]-crval3)/cdelt3+crpix3-1)
    end_i=int((end_w[i]-crval3)/cdelt3+crpix3-1)
    if (start_i > -1 ) and (end_i < nx): 
        npix=end_i-start_i+1
        a=b[start_i:end_i,:,:]
        c=np.average(a,0)
        hdr["PIX_WIDT"]=npix
        hdr["START_W"]=start_w[i]
Beispiel #19
0
def ensamble(name,
             dir1,
             dir3,
             dir4,
             fo,
             fi=0,
             fii=0,
             pdf=1,
             rx=[0, 0.5, 1.0, 1.5],
             fits_f=0):
    rad = 1.0
    names = name.split("-")
    dir3 = dir3  #+"/"+names[1]+"/"+names[2]
    dir_map = dir3 + "/" + names[1] + "/" + names[2]
    DIRS = dir3.split("/")
    DRT = ""
    for DR in DIRS:
        DRT = DRT + DR + "/"
        call = "mkdir -p " + DRT
        sycall(call)
    DIRS = dir_map.split("/")
    DRT = ""
    for DR in DIRS:
        DRT = DRT + DR + "/"
        call = "mkdir -p " + DRT
        sycall(call)
    speed_of_light = 299792.458
    dir1 = dir1 + "/" + names[1] + "/" + names[2]
    #    dir2=dir2+"/"+names[1]+"-"+names[2]
    file = dir1 + "/" + name + ".SFH.cube.fits.gz"
    file2 = dir1 + "/" + name + ".p_e.pdl_r.fits"
    #file2=dir2+"/"+name+".photo.r_Lc_rad.fits"
    #file3=dir1+"/"+'mask.'+name+'.V.fits.gz'
    file3 = dir1 + "/" + 'DMASK.' + name + '.fits.gz'
    [pdl_cube, hdr] = gdata(file, 0, header=True)
    [pdl_rad, hdr2] = gdata(file2, 0, header=True)
    [pdl_mask, hdr3] = gdata(file3, 0, header=True)
    pdl_mask = 1.0 - pdl_mask
    if np.sum(pdl_mask) == 0:
        pdl_mask[:, :] = 1.0
    ind = []
    inda = []
    nr = len(rx)
    for ii in range(0, nr - 1):
        nt = np.where(pdl_rad < rx[ii + 1] * rad)
        nta = np.where(pdl_rad[nt] >= rx[ii] * rad)
        ind.extend([nt])
        inda.extend([nta])
#    n2=np.where(pdl_rad< r2*rad)
#    n2a=np.where(pdl_rad[n2]>= r1*rad)
#    n3=np.where(pdl_rad< r3*rad)
#    n3a=np.where(pdl_rad[n3]>= r2*rad)
#    n4=np.where(pdl_rad< r4*rad)
#    n4a=np.where(pdl_rad[n4]>= r3*rad)
    SN_file = "norm_SN_" + name + ".CS.fits.gz"
    if ptt.exists(dir1 + "/" + SN_file) == True:
        [pdl_SN, hdr000] = gdata(dir1 + "/" + SN_file, 0, header=True)
    Ha_file = "map.CS." + name + "_flux_6562.fits.gz"
    if ptt.exists(dir1 + "/" + Ha_file) == True:
        [pdl_ha, hdr001] = gdata(dir1 + "/" + Ha_file, 0, header=True)
        pdl_ha = pdl_ha * pdl_mask  #[0,:,:]#-z_r*speed_of_light
        pdl_ha[np.isnan(pdl_ha)] = 0
    Av_file = "map.CS." + name + "_Av_ssp.fits.gz"
    [pdl_Av, hdr002] = gdata(dir1 + "/" + Av_file, 0, header=True)
    Av_file_e = "map.CS." + name + "_e_Av_ssp.fits.gz"
    if ptt.exists(dir1 + "/" + Av_file_e) == True:
        [pdl_Av_e, hdr002e] = gdata(dir1 + "/" + Av_file_e, 0, header=True)
        pdl_Av_e[np.isnan(pdl_Av_e)] = 0
    else:
        pdl_Av_e = np.zeros(Av_file.shape)
    nt = hdr['NAXIS3'] - 5  #5#4#n_met
    flux_file = "map.CS." + name + "_flux_ssp.fits.gz"
    [pdl_flux, hdr0] = gdata(dir1 + "/" + flux_file, 0, header=True)
    flux_file_e = "map.CS." + name + "_e_flux_ssp.fits.gz"
    if ptt.exists(dir1 + "/" + flux_file_e) == True:
        [pdl_flux_e, hdr0e] = gdata(dir1 + "/" + flux_file_e, 0, header=True)
        pdl_flux_e[np.isnan(pdl_flux_e)] = 0
    else:
        pdl_flux_e = np.zeros(pdl_flux.shape)
    mass_file = "map.CS." + name + "_Mass_dust_cor_ssp.fits.gz"  #dust_cor_
    [pdl_mass, hdr00] = gdata(dir1 + "/" + mass_file, 0, header=True)
    pdl_mass[np.isnan(pdl_mass)] = 1
    MassT2 = np.log10(np.sum(10.0**pdl_mass))
    #print MassT2, name

    f = open(dir4 + "/BASE.gsd01", "r")
    #f=open(dir4+"/BASE.bc17_salp_Agelin_Metlin_330","r")
    yunk = f.readline()
    age_t = []
    met_t = []
    cor_t = []
    for line in f:
        if not "#" in line:
            data = line.split(" ")
            data = filter(None, data)
            age_t.extend([float_(data[1])])
            met_t.extend([float_(data[2])])
            cor_t.extend([float_(data[4])])
    n_t = len(age_t)
    age_t = np.array(age_t)
    met_t = np.array(met_t)
    cor_t = np.array(cor_t)
    age_t = np.around(age_t / 1e9, decimals=4)
    met_t = np.around(met_t, decimals=4)
    f.close()
    a_redshift = []
    filet = "auto_ssp.CS." + name + ".rss.out"
    f = open(dir1 + "/" + filet, "r")
    for line in f:
        if not "#" in line:
            data = line.split(",")
            data = filter(None, data)
            #print data
            a_redshift.extend([float_(data[7])])
    f.close()
    a_redshift = np.array(a_redshift)
    redshift = np.median(a_redshift)
    cosmo = {'omega_M_0': 0.27, 'omega_lambda_0': 0.73, 'h': 0.71}
    cosmo = cd.set_omega_k_0(cosmo)
    DL1 = cd.luminosity_distance(redshift, **cosmo)
    #print DL, redshift
    ratio = 3.08567758e24
    modz = 5.0 * np.log10(DL1) + 25.0
    DL = DL1 * ratio
    DA = DL1 / (1 + redshift)**2.0 * 1e6 * np.pi / 180. / 3600.
    L = 4.0 * np.pi * (DL**2.0)  #/(1+$redshift);
    Factor = (L * 1e-16) / 3.826e33
    filed = "coeffs_auto_ssp.CS." + name + ".rss.out"
    f2 = open(dir1 + "/" + filed, "r")
    n = 0
    n_ini = 0
    n_ssp = 156  #330
    ML = np.zeros(n_ssp)
    a_age = []
    a_met = []
    n_age = 0
    n_met = 0
    AGE = np.zeros(n_ssp)
    MET = np.zeros(n_ssp)
    COR = np.zeros(n_ssp)
    for line in f2:
        if n_ini < n_ssp:
            if not "#" in line:
                data = line.split(" ")
                data = filter(None, data)
                n = int(data[0])
                AGE[n] = float_(data[1])
                MET[n] = float_(data[2])
                ML[n] = float_(data[5])
                diff_age = 1
                for i in range(0, n):
                    if AGE[n] == AGE[i]:
                        diff_age = 0
                if diff_age == 1:
                    a_age.extend([AGE[n]])
                    n_age = n_age + 1
                diff_met = 1
                for i in range(0, n):
                    if MET[n] == MET[i]:
                        diff_met = 0
                if diff_met == 1:
                    a_met.extend([MET[n]])
                    n_met = n_met + 1
                n_ini = n_ini + 1
                for jt in range(0, n_t):
                    if age_t[jt] == 0.02:
                        age_t[jt] = 0.0199
                    if AGE[n] == age_t[jt]:
                        if MET[n] == met_t[jt]:
                            COR[n] = cor_t[jt]
    f2.close()
    n = n + 1
    MassT = 0
    LighT = 0
    massN = np.zeros(nr)
    massN_e = np.zeros(nr)
    lightN = np.zeros(nr)
    lightN_e = np.zeros(nr)
    #mas1=0
    #mas2=0
    #mas3=0
    #mas4=0
    mass = np.zeros([n_age, nr])
    mass_e = np.zeros([n_age, nr])
    light = np.zeros([n_age, nr])
    light_e = np.zeros([n_age, nr])
    ages = np.zeros([n_age])
    sfrt = np.zeros([n_age, nr])
    sfdt = np.zeros([n_age])
    [nz, nx, ny] = pdl_cube.shape
    temp_a = np.zeros([nx, ny])
    mass_age = np.zeros([nx, ny])
    pdl_cube[np.isnan(pdl_cube)] = 1

    pdl_cube_e = np.zeros([n, nx, ny])
    #print name
    for i in range(0, n):
        norm_file = dir1 + "/" + "map.CS." + name + "_eNORM_" + str(
            i) + "_ssp.fits.gz"
        if ptt.exists(norm_file) == True:
            pdl_cube_e[i, :, :] = gdata(norm_file)
        else:
            pdl_cube_e[i, :, :] = np.zeros([nx, ny])
    pdl_cube_e[np.isnan(pdl_cube_e)] = 0
    #print AGE
    #sys.exit()
    for i in range(nt - 1, n_ssp - 1, -1):
        label = hdr['FILE_' + str(i)]
        #        print label,n_age,n_met,n_age-i+n_ssp-1,-i+n_ssp,i
        time = label.replace('_NORM_age.fits.gz', '')
        time = float_(time.replace('map.CS.' + name + '_', ''))
        ages[n_age - i + n_ssp - 1] = np.log10(time) + 9
    #print np.log10(time)+9, 38-i+156
    #temp=pdl_cube[i,:,:]
    #temp=temp*10.0**(ML[i-156])*pdl_flux*Factor
    #temp_a=temp+temp_a
#    MassT=MassT+np.sum(temp)
#    mas1=np.sum(temp[n1])+mas1
#    mas2=np.sum(temp[n2][n2a])+mas2
#    mas3=np.sum(temp[n3][n3a])+mas3
#    mas4=np.sum(temp[n4][n4a])+mas4
#    mass[38-i+156,0]=np.log10(mas1)
#    mass[38-i+156,1]=np.log10(mas2)
#    mass[38-i+156,2]=np.log10(mas3)
#    mass[38-i+156,3]=np.log10(mas4)
    f2 = open(dir3 + "/" + name + "_Ensemble.csv", "w")
    f2.write(
        "#  LOG_AGE  N_MASSR_1  N_MASSR_2  N_MASSR_3  N_MASSR_4  LOG_MASSR_1  LOG_MASSR_2  LOG_MASSR_3  LOG_MASSR_4 \n"
    )
    fL2 = open(dir3 + "/" + name + "_Ensemble_L.csv", "w")
    fL2.write(
        "#  LOG_AGE  N_LIGHTR_1  N_LIGHTR_2  N_LIGHTR_3  N_LIGHTR_4  LOG_LIGHTR_1  LOG_LIGHTR_2  LOG_LIGHTR_3  LOG_LIGHTR_4 \n"
    )
    mass_age_t = np.zeros([n_age, nx, ny])
    mass_age_t_2 = np.zeros([n_age, nx, ny])
    mass_age_t_e = np.zeros([n_age, nx, ny])
    light_age_t = np.zeros([n_age, nx, ny])
    light_age_t_2 = np.zeros([n_age, nx, ny])
    light_age_t_e = np.zeros([n_age, nx, ny])
    for i in range(0, n_age):
        age_now = a_age[i]
        pdl_age = np.zeros([nx, ny])
        pdl_age_2 = np.zeros([nx, ny])
        pdl_age_e = np.zeros([nx, ny])
        pdl_ageL = np.zeros([nx, ny])
        pdl_age_2L = np.zeros([nx, ny])
        pdl_age_eL = np.zeros([nx, ny])
        for j in range(0, n):
            if age_now == AGE[j]:
                #if AGE[j] <= 2:
                pdl_age = pdl_age + pdl_cube[j, :, :] * 10.0**(
                    ML[j]) * pdl_flux * Factor * 10.0**(
                        0.4 * pdl_Av) * pdl_mask  #*0.25/np.pi#/1.47
                pdl_age_e = pdl_age_e + (
                    (pdl_cube_e[j, :, :] / pdl_cube[j, :, :])**2.0 +
                    (pdl_flux_e / pdl_flux)**2.0 +
                    (np.log(10.0) * 0.4 * pdl_Av_e)**2.0) * (
                        pdl_cube[j, :, :] * 10.0**(ML[j]) * pdl_flux * Factor *
                        pdl_mask * 10.0**(0.4 * pdl_Av))**2.0
                pdl_age_2 = pdl_age_2 + pdl_cube[j, :, :] * 10.0**(
                    ML[j]) * pdl_flux * Factor * pdl_mask * 10.0**(
                        0.4 * pdl_Av) / COR[j]
                pdl_age_2L = pdl_age_2L + pdl_cube[
                    j, :, :] * pdl_flux * Factor * pdl_mask * 10.0**(
                        0.4 * pdl_Av) / COR[j]
                pdl_ageL = pdl_ageL + pdl_cube[
                    j, :, :] * pdl_flux * Factor * 10.0**(0.4 *
                                                          pdl_Av) * pdl_mask
                pdl_age_eL = pdl_age_eL + (
                    (pdl_cube_e[j, :, :] / pdl_cube[j, :, :])**2.0 +
                    (pdl_flux_e / pdl_flux)**2.0 +
                    (np.log(10.0) * 0.4 * pdl_Av_e)**2.0
                ) * (pdl_cube[j, :, :] * pdl_flux * Factor * pdl_mask * 10.0**
                     (0.4 * pdl_Av))**2.0
                #else:
                #    pdl_age=pdl_age+pdl_cube[j,:,:]*10.0**(ML[j])*pdl_flux*Factor*pdl_mask*COR[j]
        pdl_age[np.where(np.isfinite(pdl_age) == False)] = 0
        pdl_age_2[np.where(np.isfinite(pdl_age_2) == False)] = 0
        pdl_age_e[np.where(np.isfinite(pdl_age_e) == False)] = 0
        pdl_ageL[np.where(np.isfinite(pdl_ageL) == False)] = 0
        pdl_age_2L[np.where(np.isfinite(pdl_age_2L) == False)] = 0
        pdl_age_eL[np.where(np.isfinite(pdl_age_eL) == False)] = 0
        #pdl_age_e[np.isnan(pdl_age_e)]=0
        for k in range(0, n_age):
            if np.log10(age_now) + 9 == ages[k]:
                mass_age_t[k, :, :] = pdl_age
                mass_age_t_2[k, :, :] = pdl_age_2
                mass_age_t_e[k, :, :] = pdl_age_e
                light_age_t[k, :, :] = pdl_ageL
                light_age_t_2[k, :, :] = pdl_age_2L
                light_age_t_e[k, :, :] = pdl_age_eL
    temp5 = np.sum(mass_age_t, axis=0) + 0.01
    #    temp6=np.log10(np.sum(mass_age_t,axis=0)+1.0)#QUITAR
    #    wfits(dir3+"/"+name+"mass_tot.fits",temp6,hdr001)#QUITAR
    upvalue = math.ceil(np.log10(np.amax(temp5)) / .05) * .05
    if np.isinf(upvalue):
        upvalue = 8
    if upvalue - 1 <= 6.5:
        lovalue = math.ceil(np.log10(np.amin(temp5)) / .05) * .05
        if upvalue - 2 > lovalue:
            lovalue = upvalue - 2
    else:
        lovalue = 6.5
    mass_temp_total = 0
    light_temp_total = 0
    for i in range(0, n_age):
        if i == 0:
            age_s = 10.0**((ages[i] + ages[i + 1]) / 2.0)
            age_i = 0.0
        elif i == n_age - 1:
            age_i = 10.0**((ages[i] + ages[i - 1]) / 2.0)
            age_s = 2.0 * 10.0**(ages[i]) - age_i
        else:
            age_i = 10.0**((ages[i] + ages[i - 1]) / 2.0)
            age_s = 10.0**((ages[i] + ages[i + 1]) / 2.0)
        Dt_age = np.abs(age_s - age_i)
        sfdt[i] = Dt_age / 1e6
        temp = mass_age_t[i, :, :]
        temp_2 = mass_age_t_2[i, :, :]
        temp_e = mass_age_t_e[i, :, :]
        tempL = light_age_t[i, :, :]
        temp_2L = light_age_t_2[i, :, :]
        temp_eL = light_age_t_e[i, :, :]
        #temp[np.where(np.isfinite(temp) == False)]=0
        #temp_e[np.where(np.isfinite(temp_e) == False)]=1
        #temp_2[np.where(np.isfinite(temp_2) == False)]=0
        if i == 0:
            if fits_f == 1:
                [nx, ny] = temp.shape
                MASS_map_cube = np.zeros([n_age, nx, ny])
                MGH_map_cube = np.zeros([n_age, nx, ny])
                SFH_map_cube = np.zeros([n_age, nx, ny])
                LIGHT_map_cube = np.zeros([n_age, nx, ny])
                LGH_map_cube = np.zeros([n_age, nx, ny])
            temp1 = temp
            temp1L = tempL
        else:
            temp1 = temp1 + temp
            temp1L = temp1L + tempL
        if fits_f == 1:
            MASS_map_cube[i, :, :] = temp
            MGH_map_cube[i, :, :] = temp1
            SFH_map_cube[i, :, :] = temp_2 / Dt_age
            LIGHT_map_cube[i, :, :] = tempL
            LGH_map_cube[i, :, :] = temp1L
        #if pdf==1:
        #map_plot(temp1,ages[i],pdl_rad,dir=dir_map+"/",pdf=1,title=name,form='pdf',fname=name+'_smap_'+str(i),minval=lovalue,maxval=upvalue)
        MassT = MassT + np.sum(temp)
        LighT = LighT + np.sum(tempL)
        for ii in range(0, nr - 1):
            # print ind[ii],inda[ii],ii
            #            print temp[ind[ii]]
            #            print len(temp[ind[ii]]),np.amax(inda[ii])
            Dt_mass = np.sum(temp[ind[ii]][inda[ii]])
            Dt_mass_e = np.sum(temp_e[ind[ii]][inda[ii]])
            Dt_mass_2 = np.sum(temp_2[ind[ii]][inda[ii]])
            Dt_light = np.sum(tempL[ind[ii]][inda[ii]])
            Dt_light_e = np.sum(temp_eL[ind[ii]][inda[ii]])
            Dt_light_2 = np.sum(temp_2L[ind[ii]][inda[ii]])
            massN[ii] = Dt_mass + massN[ii]
            massN_e[ii] = Dt_mass_e + massN_e[ii]
            lightN[ii] = Dt_light + lightN[ii]
            lightN_e[ii] = Dt_light_e + lightN_e[ii]
            #mas2=np.sum(temp[n2][n2a])+mas2
            #mas3=np.sum(temp[n3][n3a])+mas3
            #mas4=np.sum(temp[n4][n4a])+mas4
            #            print temp[ind[ii]][inda[ii]]
            mass[i, ii] = np.log10(massN[ii])
            mass_e[i, ii] = massN_e[ii]
            light[i, ii] = np.log10(lightN[ii])
            light_e[i, ii] = lightN_e[ii]
            sfrt[
                i,
                ii] = Dt_mass_2 / Dt_age  #/massN[ii]#/(np.pi*(rx[ii+1]**2.0-rx[ii]**2.0)*rad**2.0)#/(float_(len(temp[ind[ii]][inda[ii]]))*(0.5*DA)**2.0)
        #mass[i,1]=np.log10(mas2)
        #mass[i,2]=np.log10(mas3)
        #mass[i,3]=np.log10(mas4)
    mass_temp_total = np.log10(np.sum(10**mass[nt - n_ssp - 1, :]))
    light_temp_total = np.log10(np.sum(10**light[nt - n_ssp - 1, :]))
    MassT = np.log10(MassT)
    MassT = mass_temp_total
    LighT = np.log10(LighT)
    LighT = light_temp_total
    if fits_f == 1:
        #if ptt.exists() == True:
        h1 = pyf.PrimaryHDU(MASS_map_cube)  #.header
        h2 = pyf.PrimaryHDU(SFH_map_cube)  #.header
        h3 = pyf.PrimaryHDU(MGH_map_cube)
        h4 = pyf.PrimaryHDU(LIGHT_map_cube)
        h5 = pyf.PrimaryHDU(LGH_map_cube)
        h = h1.header
        h["NAXIS"] = 3
        h["NAXIS3"] = n_age
        h["NAXIS1"] = nx
        h["NAXIS2"] = ny
        hlist = pyf.HDUList([h1])
        hlist.update_extend()
        wfits_ext(dir_map + "/" + "MASS_maps_" + name + ".fits", hlist)
        #if ptt.exists() == True:
        h = h2.header
        h["NAXIS"] = 3
        h["NAXIS3"] = n_age
        h["NAXIS1"] = nx
        h["NAXIS2"] = ny
        hlist = pyf.HDUList([h2])
        hlist.update_extend()
        wfits_ext(dir_map + "/" + "SFH_maps_" + name + ".fits", hlist)
        #if ptt.exists() == True:
        h = h3.header
        h["NAXIS"] = 3
        h["NAXIS3"] = n_age
        h["NAXIS1"] = nx
        h["NAXIS2"] = ny
        hlist = pyf.HDUList([h3])
        hlist.update_extend()
        wfits_ext(dir_map + "/" + "MGH_maps_" + name + ".fits", hlist)
        h = h4.header
        h["NAXIS"] = 3
        h["NAXIS3"] = n_age
        h["NAXIS1"] = nx
        h["NAXIS2"] = ny
        hlist = pyf.HDUList([h4])
        hlist.update_extend()
        wfits_ext(dir_map + "/" + "LIGHT_maps_" + name + ".fits", hlist)
        h = h5.header
        h["NAXIS"] = 3
        h["NAXIS3"] = n_age
        h["NAXIS1"] = nx
        h["NAXIS2"] = ny
        hlist = pyf.HDUList([h5])
        hlist.update_extend()
        wfits_ext(dir_map + "/" + "LGH_maps_" + name + ".fits", hlist)
    #print MassT,name
    if ptt.exists(dir1 + "/" + SN_file) == True:
        SN = np.zeros(nr - 1)
        sn_l = ''
        for ii in range(0, nr - 1):
            SN[ii] = np.average(pdl_SN[ind[ii]][inda[ii]])
            sn_l = sn_l + ' , ' + str(SN[ii])
        if fi != 0:
            fi.write(name + sn_l + ' \n')
    if ptt.exists(dir1 + "/" + Ha_file) == True:
        Ha = np.zeros(nr - 1)
        ha_l = ''
        for ii in range(0, nr - 1):
            Ha[ii] = np.sum(pdl_ha[ind[ii]][inda[ii]] * 10.0**
                            (0.4 * pdl_Av[ind[ii]][inda[ii]])) * (L * 1e-16)
            ha_l = ha_l + ' , ' + str(Ha[ii])
        if fii != 0:
            fii.write(name + ha_l + ' \n')
    else:
        ha_l = ''
        for ii in range(0, nr - 1):
            ha_l = ha_l + ' , ' + str(-100)
        if fii != 0:
            fii.write(name + ha_l + ' \n')
    #print Ha,(L*1e-16)
    #sys.exit(0)
    mass_n = 10**(10**(mass - mass[nt - n_ssp - 1, :]))
    mass_n_e = np.sqrt(
        (10**(mass - mass[nt - n_ssp - 1, :]))**2.0 *
        ((mass_e / 10**(2.0 * mass)) +
         (mass_e[nt - n_ssp - 1, :] / 10**(2.0 * mass[nt - n_ssp - 1, :]))))
    light_n = 10**(10**(light - light[nt - n_ssp - 1, :]))
    light_n_e = np.sqrt(
        (10**(light - light[nt - n_ssp - 1, :]))**2.0 *
        ((light_e / 10**(2.0 * light)) +
         (light_e[nt - n_ssp - 1, :] / 10**(2.0 * light[nt - n_ssp - 1, :]))))
    #mass_n=10**(mass-mass[nt-156-1,:])
    #mass_n=(mass-mass[nt-156-1,:])
    for i in range(0, n_age):
        #print ages[i],a_age[i],"test_ages"
        line = ''
        line = line + str(ages[i])
        for ii in range(0, nr - 1):
            line = line + ';' + str(mass_n[i, ii])
        for ii in range(0, nr - 1):
            line = line + ';' + str(mass[i, ii])
        for ii in range(0, nr - 1):
            line = line + ';' + str(sfrt[i, ii])
        for ii in range(0, nr - 1):
            line = line + ';' + str(mass_n_e[i, ii])
        line = line + ';' + str(sfdt[i])
        line = line + ' \n'
        f2.write(line)
        lineL = ''
        lineL = lineL + str(ages[i])
        for ii in range(0, nr - 1):
            lineL = lineL + ';' + str(light_n[i, ii])
        for ii in range(0, nr - 1):
            lineL = lineL + ';' + str(light[i, ii])
        for ii in range(0, nr - 1):
            lineL = lineL + ';' + str(sfrt[i, ii])
        for ii in range(0, nr - 1):
            lineL = lineL + ';' + str(light_n_e[i, ii])
        lineL = lineL + ';' + str(sfdt[i])
        lineL = lineL + ' \n'
        fL2.write(lineL)
    #if not pdf == 0:
    #dev=dir3+"/"+name+"_Relative_Mass.pdf"
    ##if pdf == 1:
    #    #matplotlib.use('Agg')
    #import matplotlib.pyplot as plt
    ##plt.axis([8, 10.5, 0, 10])
    #plt.xlabel("$log_{10}(time/yr)$",fontsize=14)
    #plt.ylabel("$10^{M(t)/M_{0}}$",fontsize=14)
    #plt.title(name+' $\log M_{tot}='+('%7.2f' % MassT)+'$',fontsize=15)
    ##plt.semilogx('log')
    #for ii in range(0, nr-1):
    #    plt.plot(ages,mass_n[:,ii],label='$'+('%6.1f' % rx[ii])+'R_e<R<'+('%6.1f' % rx[ii+1])+'R_e$')
    ##plt.plot(ages,mass_n[:,1],label='$'+('%6.1f' % r1)+'<R<'+('%6.1f' % r2)+'R_e$')
    ##plt.plot(ages,mass_n[:,2],label='$'+('%6.1f' % r2)+'<R<'+('%6.1f' % r3)+'R_e$')
    ##plt.plot(ages,mass_n[:,3],label='$'+('%6.1f' % r3)+'<R<'+('%6.1f' % r4)+'R_e$')
    #plt.legend(loc=3)
    #if pdf == 1:
    #    plt.savefig(dev,dpi = 1000)
    #else:
    #    plt.show()
    #plt.close()
    if not pdf == 0:
        dev = dir3 + '/' + name + "_Relative_Mass2.pdf"
        #if pdf == 1:
        #    matplotlib.use('Agg')
        import matplotlib.pyplot as plt
        fig, ax = plt.subplots(figsize=(6, 5.5))
        ax.set_xlabel("$log_{10}(time/yr)$", fontsize=14)
        ax.set_ylabel("$M(t)/M_{0}$", fontsize=14)
        #MassT=10.32
        ax.set_title(name + ' $\log M_{tot}=' + ('%7.2f' % MassT) + '$',
                     fontsize=15)
        ax.set_xlim(8.6, 10.1)
        #ax.set_ylim(0,12)
        ax.set_ylim(func_plot(np.log10(1.78), ftype=1),
                    func_plot(np.log10(12), ftype=1))
        for ii in range(0, nr - 1):
            plt.plot(ages,
                     func_plot(np.log10(mass_n[:, ii]), ftype=1),
                     label='$' + ('%6.1f' % rx[ii]) + 'R_e<R<' +
                     ('%6.1f' % rx[ii + 1]) + 'R_e$')
        plt.legend(loc=3)
        plt.plot(np.arange(0, 20, .1),
                 np.ones(200) * func_plot(0.95, ftype=1),
                 '--',
                 color='black')
        plt.plot(np.arange(0, 20, .1),
                 np.ones(200) * func_plot(0.50, ftype=1),
                 '--',
                 color='green')
        fig.canvas.draw()
        labels = [item.get_text() for item in ax.get_yticklabels()]
        for i in range(0, len(labels)):
            labels[i] = labels[i].replace(u'\u2212', '-')
        for i in range(0, len(labels)):
            if labels[i] != u'':
                if float_(labels[i]) == 0:
                    labels[i] = u'%3.2f' % 10**(0)
                else:
                    labels[i] = u'%3.2f' % 10**(float_(labels[i]))
        ax.set_yticklabels(labels)
        if pdf == 1:
            fig.tight_layout()
            plt.savefig(dev)  #,dpi = 1000)
        else:
            plt.show()
        plt.close()
    f2.close()
    fL2.close()
    fo.write(name + " " + str(MassT) + " " + str(redshift) + " ")
Beispiel #20
0
import sys
import numpy as np
import pyfits
from pyfits import getdata as gdata
from pyfits import writeto as wfits
import os.path as pt


def sycall(comand):
    from subprocess import call
    line = comand.split(" ")
    fcomand = []
    fcomand.extend(line)
    call(fcomand)


sys.argv = filter(None, sys.argv)

if len(sys.argv) < 2:
    print "USE: clean_nan.pl INPUT.FITS BADVAL"
    sys.exit(0)

infile1 = sys.argv[1]
val = int(sys.argv[2])
[a_in1, head] = gdata(infile1, 0, header=True)
a_in1[np.isnan(a_in1)] = val
if pt.exists(infile1) == False:
    wfits(infile1, c, hdr)
else:
    sycall("rm " + infile1)
    wfits(infile1, a_in1, head)
Beispiel #21
0
sys.argv = filter(None, sys.argv)

if len(sys.argv) < 2:
    print "USE: img2spec.py INPUT_FILE.FITS NY OUTPUTFILE.txt"
    sys.exit(0)

inputf = sys.argv[1]
e_input = "e_" + sys.argv[1]
NY = int(sys.argv[2])
output = sys.argv[3]
y_min = 1e12
y_max = -1e12
n = 0
print inputf
[pdl, hdr] = gdata(inputf, 0, header=True)
crval = hdr["CRVAL1"]
cdelt = hdr["CDELT1"]
crpix = hdr["CRPIX1"]
[nx, ny] = pdl.shape
pdl_e = gdata(e_input, 0)
if cdelt == 0:
    cdelt = 1
wave = []
flux = []
e_flux = []
f = open(output, 'w')
for i in range(0, nx):
    k = i + 1
    wave.extend([crval + cdelt * (i + 1 - crpix)])
    flux.extend([pdl[i, NY]])
Beispiel #22
0
from pyfits import getheader as ghead
from pyfits import getdata as gdata
from pyfits import writeto as wfits
import os.path as ptt
import my

sys.argv = filter(None, sys.argv)
if len(sys.argv) < 2:
    print "USE: get_CS_slice.pl name"
    sys.exit(0)
name = sys.argv[1]
segfile = "cont_seg." + name + ".fits.gz"
mapHa = name + ".V.fits.gz"
output = "CS." + name + ".slice"

[seg, h1] = gdata(segfile, 0, header=True)
[Ha, h2] = gdata(mapHa, 0, header=True)
[nx, ny] = seg.shape
n = 0
ns = int(np.amax(seg))
flux = np.zeros(ns)
X = np.zeros(ns)
Y = np.zeros(ns)
A = np.zeros(ns)
for i in range(0, nx):
    for j in range(0, ny):
        ID = int(seg[i, j])
        if ID > 0:
            if n < ID:
                n = ID
            val = Ha[i, j]
Beispiel #23
0
line = f.readline()
data = line.split(" ")
data = filter(None, data)
if len(data) == 3:
    wave_norm = data[0]
    w_wave_norm = data[1]
    new_back_file = data[2]
else:
    wave_norm = []
    w_wave_norm = []
    new_back_file = []
f.close()
#
# SFH template
#
[pdl_flux_c_ini, hdr] = gdata(back_list, 0, header=True)
[nf, n_c] = pdl_flux_c_ini.shape
coeffs = np.zeros([nf, 3])
crpix = hdr["CRPIX1"]
cdelt = hdr["CDELT1"]
crval = hdr["CRVAL1"]
n_mc = 30
#
# Kinematics template
#
[pdl_flux_c_ini2, hdr2] = gdata(back_list2, 0, header=True)
[nf2, n_c2] = pdl_flux_c_ini2.shape
coeffs2 = np.zeros([nf2, 3])
crpix2 = hdr2["CRPIX1"]
cdelt2 = hdr2["CDELT1"]
crval2 = hdr2["CRVAL1"]
Beispiel #24
0
    #    import matplotlib.colorbar as colorbar
    #    import matplotlib.cm as cmx
    import matplotlib.image as mpimg
else:
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    #    from matplotlib import gridspec
    #    import matplotlib.colors as colors
    #    import matplotlib.colorbar as colorbar
    #    import matplotlib.cm as cmx
    import matplotlib.image as mpimg
root_dir = sycallo("echo $FIT3DP_PATH")
table = "califaCT"
reverse = 0
color_cont = 0
[pdl_map, h] = gdata(mapfile, 0, header=True)
[nx, ny] = pdl_map.shape
crval2 = h["CRVAL2"]
cdelt2 = h["CD2_2"]
cdelt1 = h["CD1_1"]
crval1 = h["CRVAL1"]
#crval1=-138.839996337891
#cdelt1=4
#crval2=-210.726806640625
#cdelt2=4
if id_mask == 1:
    pdl_mask = gdata(mask_file)
    pdl_map = pdl_map * pdl_mask * factor
else:
    pdl_map = pdl_map * factor
Beispiel #25
0
    return seg_map


sys.argv = filter(None, sys.argv)
if (sys.argv) < 8:
    print "USE: cont_seg_all.py Ha_map.fits FLUX_LIMIT_PEAK MAX_DIST_PEAK FRAC_PEAK MIN_FLUX SEGFILE.fits DIFFUSE_MASK.fits"
    sys.exit(0)

Ha_file = sys.argv[1]
F_max = float_(sys.argv[2])
max_dist = float_(sys.argv[3])
frac = float_(sys.argv[4])
MIN_FLUX = float_(sys.argv[5])
segfile = sys.argv[6]
maskfile = sys.argv[7]
[Ha_map, hdr] = gdata(Ha_file, 0, header=True)
Ha_map[np.isnan(Ha_map)] = -1e12
[nx, ny] = Ha_map.shape
seg_map = np.zeros([nx, ny])
mask_map = np.ones([nx, ny])
flux = []
fluxl = []
nup = 0
for i in range(0, nx):
    for j in range(0, ny):
        val = Ha_map[i, j]
        if val > 0 and val < 1e30:
            flux.extend([val])
            nup = nup + 1
statsa = stats(np.array(flux))
print str(nup) + " " + str(statsa)
Beispiel #26
0
import os.path as ptt
import my
from my import mycall


def sycall(comand):
    from subprocess import call
    line = comand.split(" ")
    fcomand = []
    fcomand.extend(line)
    call(fcomand)


def wfits(name, data, hdr):
    if ptt.exists(name) == False:
        wfit(name, data, hdr)
    else:
        sycall("rm " + name)
        wfit(name, data, hdr)


sys.argv = filter(None, sys.argv)
if len(sys.argv) < 2:
    print "USE: write_img_header.py FILE.FITS HEADER VALUE"
    sys.exit(0)
file = sys.argv[1]
header = sys.argv[2]
value = float_(sys.argv[3])
[pdl, h] = gdata(file, 0, header=True)
h[header] = value
wfits(file, pdl, h)