Exemple #1
0
                    ip = i
                    jp = j
    JP.extend([jp])
    IP.extend([ip])
    F_PEAK.extend([Ha_map[ip, jp]])
    print "ip,jp " + str(ip) + "," + str(jp) + " " + str(NR)
    if ip == -1 and jp == -1:
        stop = 1
    else:
        [seg_map, mask_map] = LOOP(ip, jp, seg_map, mask_map)
        map_now = map_now * mask_map
        NR = NR + 1
for i in range(0, nx):
    for j in range(0, ny):
        val = Ha_map[i, j]
        if val >= MIN_FLUX:
            mask_map[i, j] = 0
        nr = seg_map[i, j]
        if nr == 0 and val != -1e12:
            seg_map = nearest(i, j, NR, IP, JP, seg_map)
if pt.exists(segfile) == False:
    wfits(segfile, seg_map, hdr)
else:
    sycall("rm " + segfile)
    wfits(segfile, seg_map, hdr)
if pt.exists(maskfile) == False:
    wfits(maskfile, mask_map, hdr)
else:
    sycall("rm " + maskfile)
    wfits(maskfile, mask_map, hdr)
Exemple #2
0
                met_min_mass) + ") Av=" + str(Av_min) + " z=" + str(
                    redshift) + " sigma=" + str(sigma)
        ssp.plot_results(plot, pdl_wave_elines, pdl_output, out_ps, title)
    print "I.Iter = " + str(NITER) + " DONE"
    NITER = NITER + 1
# Write output file
h = pyf.PrimaryHDU().header
h["NAXIS"] = 2
h["NAXIS1"] = n_unc
h["NAXIS2"] = 6
h["COMMENT"] = "OUTPUT auto_ssp_elines_rnd.pl FITs"
h["CRVAL1"] = wave_unc[0]
h["CDELT1"] = wave_unc[1] - wave_unc[0]
h["CRPIX1"] = 1
if pt.exists(out_fit) == False:
    wfits(out_fit, pdl_output, h)
else:
    sycall("rm " + out_fit)
    wfits(out_fit, pdl_output, h)
################################
print "--------------------------------------------------------------"
pdl_masked = np.array(masked)
pdl_chi_now = ((pdl_masked * pdl_res_JOINT)**2) / ((np.array(e_flux_unc))**2)
pdl_chi_now[np.isnan(pdl_chi_now)] = 0
chi_joint = np.sum(pdl_chi_now)
chi_joint = (chi_joint / (n_unc - n_mod_fixed - nf - 1))**0.5
rms = np.std(pdl_masked * pdl_res_JOINT)
j1 = int(0.4 * n_unc)
j2 = int(0.6 * n_unc)
rms = np.std(pdl_res_JOINT[j1:j2])
pdl_flux_unc_now = np.array(flux_unc)
        else:
            nd=nd+1

for j in range(0, ns):
    print str(j)+" "+str(int(npt[j]))
    a_out[j,:] = a_out[j,:]/npt[j]
h=pyf.PrimaryHDU().header
h["CRPIX1"]=crpix
h["CRVAL1"]=crval
h["CDELT1"]=cdelt
h["CRPIX2"]=1
h["CRVAL2"]=1
h["CDELT2"]=1
a_out=np.sqrt(abs(a_out))
if ptt.exists(outfile) == False:
    wfits(outfile,a_out,h)
else:
    sycall("rm "+outfile)
    wfits(outfile,a_out,h)
if ptt.exists("e_diffuse.fits") == False:
    wfits("e_diffuse.fits",inverse_s,h2)
else:
    sycall("rm "+"e_diffuse.fits")
    wfits("e_diffuse.fits",inverse_s,h2)
size=np.sqrt(nx**2+ny**2)/(2*ns)
f=open(pt,'w')
f.write( "C "+str(size)+" "+str(size)+" 0\n")
for i in range(0, ns):
    x[i]=x[i]/npt[i]
    y[i]=y[i]/npt[i]
    f.write(str(i)+" "+str(x[i])+" "+str(y[i])+" 1\n")
Exemple #4
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)
Exemple #5
0
    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:
    sycall("rm " + outfile)
    wfits(outfile, a_in1, h)
Exemple #6
0
outfile = sys.argv[3]
pt = outfile
pt = pt.replace('fits', 'pt.txt')
[a_in, h] = gdata(infile, 0, header=True)
[N, nz] = a_in.shape
crval = h["CRVAL1"]
cdelt = h["CDELT1"]
crpix = h["CRPIX1"]
[s_in, h2] = gdata(segfile, 0, header=True)
[nx, ny] = s_in.shape
out_cube = np.zeros([nz, nx, ny])
h2["CRVAL3"] = crval
h2["CDELT3"] = cdelt
h2["CRPIX3"] = crpix
h2["NAXIS"] = 3
h2["NAXIS"] = nz

for i in range(0, nx):
    for j in range(0, ny):
        ist = int(s_in[i, j])
        if ist > 0:
            is_out = ist - 1
            out_cube[:, i, j] = a_in[is_out, :]

if ptt.exists(outfile) == False:
    wfits(outfile, out_cube, h2)
else:
    sycall("rm " + outfile)
    wfits(outfile, out_cube, h2)

print outfile + " created"
Exemple #7
0
        for ii in range(0, i + 1):
            t_now = pdl_out[:, ii]
            spec = t_now
            ax1.plot(wave, spec)
        plt.tight_layout()
        if dev == "null":
            plt.show()
            plt.close()
        else:
            plt.savefig(dev)
            plt.close()
hd["CRPIX1"] = crpix
hd["CRVAL1"] = crval
hd["CDELT1"] = cdelt
if pt.exists(output) == False:
    wfits(output, pdl_out, hd)
else:
    sycall("rm " + output)
    wfits(output, pdl_out, hd)

hd_e["CRPIX1"] = crpix
hd_e["CRVAL1"] = crval
hd_e["CDELT1"] = cdelt
if pt.exists(e_output) == False:
    wfits(e_output, pdl_out_e, hd_e)
else:
    sycall("rm " + e_output)
    wfits(e_output, pdl_out_e, hd_e)

hd_m["CRPIX1"] = crpix
hd_m["CRVAL1"] = crval
Exemple #8
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)
Exemple #9
0
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]
        hdr["END_W"]=end_w[i]
        hdr["NAXIS"]=2
        del hdr["NAXIS3"]
        if pt.exists(out_file) == False:
            wfits(out_file,c,hdr)
        else:
            sycall("rm "+out_file)
            wfits(out_file,c,hdr)
        print out_file+" saved"
    else:
        print "section ("+str(int(start_w[i]))+","+str(int(end_w[i]))+") out of margings"
Exemple #10
0
sys.argv = filter(None, sys.argv)
if len(sys.argv) < 7:
    print "USE: smooth_spec_clip_cube.py intput_spec.cube.fits output_spec.cube.fits WIDTH NSIGMA NXMIN NXMAX"
    sys.exit(0)
input = sys.argv[1]
outfile = sys.argv[2]
box = int(sys.argv[3])
nsigma = float_(sys.argv[4])
nxmin = int(sys.argv[5])
nxmax = int(sys.argv[6])

[pdl_in, hdr] = gdata(input, 0, header=True)
[nz, nx, ny] = pdl_in.shape

for i in range(0, nx):
    pdl_now = pdl_in[:, i, :]
    pdl_cut = pdl_now[nxmin:nxmax, :]
    statst = my.stats(pdl_cut)
    med = statst[2]
    sig = statst[1]
    min = statst[3]
    max = med + nsigma * sig
    pdl_now = np.clip(pdl_now, min, max)
    pdl_smooth = med2df(pdl_now, size=(box, 1), mode='reflect')
    pdl_in[:, i, :] = pdl_smooth
if pt.exists(outfile) == False:
    wfits(outfile, pdl_in, hdr)
else:
    sycall("rm " + outfile)
    wfits(outfile, pdl_in, hdr)
Exemple #11
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)
Exemple #12
0
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
h["NAXIS"] = 3
h["NAXIS1"] = nx
h["NAXIS2"] = ny
h["NAXIS3"] = nz
h["COMMENT"] = "FIT-header"
h["FILENAME"] = outfile
for k in range(0, n_index):
    index = "INDEX" + str(k)
    h[index] = name[k]
    kk = k + n_index
    index = "INDEX" + str(kk)
    h[index] = name[kk]

if ptt.exists(outfile) == False:
    wfits(outfile, pdl_cube, h)
else:
    sycall("rm " + outfile)
    wfits(outfile, pdl_cube, h)