示例#1
0
def disc_analysis (path, threshold=0.1, sigma=4, verbose=False):
    """read in and peform a fitting on the fits file at path containing an imcube and write out
the results to a new fits file called Xfitted.fits of shape [7,x,y] where the 7 planes of the 
output are fitting parameters amplitude sigma and mean of the 2 gaussians and the baseline level"""
    im=cube_convolve(P.getdata(path), sigma)
    print('starting: '+path)
#    data=[i for i in xrange(im.shape[1]) if im[:,i,:].sum()/im.shape[0]/im.shape[-1] > np.power(10, -1.5)]
    mn,mx=70,130#min(data),max(data)
#    res=scipy_double_gaussian_fit(im, verbose=verbose)
    res=double_gaussian_fit_wCentral(im[:,mn:mx,:], verbose=verbose)
    ans=np.ones(res.shape, dtype=np.float)
    ans+=np.nan
    shape=res.shape
    for i in xrange(shape[1]):
        for j in xrange(shape[2]):
             ele=res[:,i,j]
             if abs(ele[0])>=abs(ele[3]) and not(1.6<abs(ele[1])<2.1 and 122<abs(ele[2])<128 and ele[0]<-4):
                  ans[:,i,j]=ele
             else:
                  ans[:,i,j]=(ele[3],ele[4],ele[5],ele[0],ele[1],ele[2],ele[6])
    try :
        print('writting: '+path)
        P.writeto(path[:-5]+'_fitted.fits', ans)
    except IOError as msg: print msg 
    return ans
示例#2
0
def produce_figs (path, name=''):
    if name=='': name=''.join(path.split('.')[:-1])
    hdr=P.getheader(path)
    im=P.getdata(path)
    if len(im.shape)==4 and im.shape[1]==1: im=stripStokes(im)
    cube_convolve(im,1.0)
    nchan=hdr.get('NAXIS3')
    vcentre=nchan/2
    pixels=hdr.get('NAXIS2')
    pcentre=pixels/2
    imres=round(hdr.get('CDELT2')*3600*10000)/10000
    if 'STOKES' in hdr.get('CTYPE3'):
        velres=hdr.get('CDELT4')
        if 'FREQ' in hdr.get('CTYPE4'): velres=velres/hdr.get('CRVAL4')*2.99792458e8
    else:
        velres=hdr.get('CDELT3')
        if 'FREQ' in hdr.get('CTYPE3'): velres=velres/hdr.get('CRVAL3')*2.99792458e8
    im_cs=im-im[-1,...]
    
    mom0=im_cs[:round(vcentre-500/velres),...].sum(0)*velres/1000.+im_cs[round(vcentre+500/velres):,...].sum(0)*velres/1000. 
    extent=sorted(abs(mom0).flat)[mom0.size*999/1000]
    F=pylab.figure();pylab.clf();pylab.imshow(mom0, interpolation='nearest', cmap=cm , vmin=-extent, vmax=extent, origin='image');c=pylab.colorbar();c.set_label('K km/s')
    decorate_image(F, pixels-1,imres)
    pylab.draw()
    pylab.savefig(name+'_contSub.eps')
    
    cbar=pv(im_cs[:,pcentre,:],contSub=False, spatRes=imres, velRes=velres/1000., cutFrac=0.003)
    cbar.set_label('K')
    decorate_pv(F, pixels-1,imres, nchan-1,velres)
    draw()
    savefig(name+'_PV_centre.eps')
    
    im_cs[round(vcentre-500/velres):round(vcentre+500/velres),...]=(im_cs[round(vcentre-500/velres),...]+im_cs[round(vcentre+500/velres),...])/2
    mask=abs(mom0)>abs(mom0).max()/100
    cbar=mom1map(im_cs*mask, contSub=False, velwidth=velres/1000.)
    cbar.set_label('km/s')
    decorate_image(F, pixels-1,imres)
    draw()
    savefig(name+'_mom1.eps')
示例#3
0
def produce_normal_figs (path, name='', pv_plane=100, mom0_centred_on_0=0):
    if name=='': name=''.join(path.split('.')[:-1])
    hdr=P.getheader(path)
    im=P.getdata(path)
    cube_convolve(im,1.0)
    nchan=hdr.get('NAXIS3')
    vcentre=nchan/2
    pixels=hdr.get('NAXIS2')
    imres=round(hdr.get('CDELT2')*3600*10000)/10000
    velres=hdr.get('CDELT3')
    mom0=im.sum(0)*velres/1000.
    
    F=figure()
    clf()
    if mom0_centred_on_0: 
        extent=sorted(abs(mom0).flat)[mom0.size*999/1000]
        imshow(mom0, interpolation='nearest', vmax=extent, vmin=-extent, cmap=cm , origin='image')
    else:
        imshow(mom0, interpolation='nearest', cmap=cm , origin='image')
    c=colorbar();c.set_label('K km/s')
    decorate_image(F, pixels,imres)
    draw()
    savefig(name+'.png')
    
    cbar=pv(im[:,pv_plane,:],contSub=False, spatRes=imres, velRes=velres/1000., cutFrac=0.003)
    cbar.set_label('K')
    decorate_pv(F, pixels,imres, nchan,velres)
    draw()
    savefig(name+'_PV_centre.png')
    
    mask=abs(mom0)>abs(mom0).max()/1000
    cbar=mom1map(im*mask, contSub=False, velwidth=velres/1000.)
    cbar.set_label('km/s')
    decorate_image(F, pixels,imres)
    draw()
    savefig(name+'_mom1.png')