def profile_batch(radius,output): pp = PDF(output) for sim in glob('sim*.fits'): print sim header = pyfits.open(sim)[0].header w = header['W'] N = header['N'] pitch = header['PITCH'] ang = header['VIEWANG'] pitch = int(np.pi*2/pitch) ang = int(np.pi*2/ang) v, line, _ = salty.line_profile(sim,radius,pxbin=4.,plot=False) ax = plt.figure().add_subplot(111) ax.set_xlabel('Velocity [km/s]') ax.set_ylabel('Normalized power') ax.set_title(sim) ax.text(300,0.005, '$w={}$\n$N={}$\n$p=\\tau/{}$\n$\\theta_{{view}}=\\tau/{}$'.\ format(w,N,pitch,ang)) ax.plot(v,line) pp.savefig(ax.figure) pp.close()
def do_line(simfile,radius,peak_scale,plot=True,Iwidth=17,rwidth=1., ax=None,label=None,observe=True,**plotargs): v, I, _ = salty.line_profile(simfile,radius,plot=False,Iwidth=Iwidth, width=rwidth,observe=observe,fit=False) # v, I = ADE.ADE_gauss(1000,500,50) # I *= peak_scale/I.max() if not ax: fig = plt.figure() ax = fig.add_subplot(111) l = ax.plot(v,I,label=label,**plotargs)[0] cdf = np.cumsum(I) cdf /= cdf.max() lowidx = int(np.interp(0.1,cdf,np.arange(cdf.size))) highidx = int(np.interp(0.90,cdf,np.arange(cdf.size))) # ax.axvline(x=v[lowidx],alpha=0.4,color=l.get_color()) # ax.axvline(x=v[highidx],alpha=0.4,color=l.get_color()) moments = ADE.ADE_moments(v[lowidx:highidx+1], I[lowidx:highidx+1], threshold=np.inf) # ADE.eplot(v[lowidx:highidx+1], I[lowidx:highidx+1]) if plot: fig.show() return moments, v, I, ax
def get_line(simfile, radius, observe=True): rwidth = 10. mV, mI, _ = salty.line_profile(simfile,radius,plot=False,Iwidth=17, width=rwidth,observe=observe,fit=False, verbose=False,nofits=False) return mV, mI
def moments_notice(slayfile, simfile, plotprefix=False,nofits=False, flip=False, cent_lambda = 5048.126, skip_radii = []): '''Take an extracted spectrum (slayfile) and model galaxy (simfile) and compute the first 3 statistical moments for both at all radii sampled by the spectrum. The model is binned and degraded to match the data quality of the actual data. The return values are the radii used, and then a tuple for each of the first three moments containing the moment and error on the data and the moment of the model. The moments are computed in the same window for both model and data so that we can compare the two as closely as possible. The exception is the first moment. ''' # radii, rwidths, vwidths, m1, m2, m3 = drunkdata radii, _, _ = sa.openslay(slayfile,flip=flip,moments=False) big_dm1 = np.array([]) big_dm1e = np.array([]) big_dm2 = np.array([]) big_dm2e = np.array([]) big_dm3 = np.array([]) big_dm3e = np.array([]) big_mm1 = np.array([]) big_mm2 = np.array([]) big_mm3 = np.array([]) plot_radii = np.array([]) if plotprefix: pp = PDF(plotprefix+'_lines.pdf') for radius in radii: if int(np.floor(radius)) in skip_radii: print "user skipping radius {} kpc".format(radius) continue dV, dI, derr, rwidth = sa.plot_line(slayfile,radius,verbose=False, wavelength=cent_lambda,velo=True, plot=False,baseline=1,flip=flip) mV, mI, _ = salty.line_profile(simfile,radius,plot=False,Iwidth=17, width=rwidth,observe=True,fit=False, verbose=False,nofits=nofits) '''We need to compute the peak of the model line separately because we shifted it to find the window used for the higher order moments''' mpeak, mwidth, _, _ = ADE.ADE_moments(mV,mI) vwidth = mwidth**0.5 mlowV = mpeak - vwidth/2. mhighV = mpeak + vwidth/2. mmoment_idx = np.where((mV >= mlowV) & (mV <= mhighV)) mmoments = ADE.ADE_moments(mV[mmoment_idx],mI[mmoment_idx]) '''Now find the peak in the data''' dpeak, _, _, _ = ADE.ADE_moments(dV,dI) dlowV = dpeak - vwidth/2. dhighV = dpeak + vwidth/2. dmoment_idx = np.where((dV >= dlowV) & (dV <= dhighV)) dmoments, derr = ADE.ADE_moments(dV[dmoment_idx],dI[dmoment_idx],err=derr[dmoment_idx]) if dmoment_idx[0].size == 0 or mmoment_idx[0].size ==0: continue # print mmoments big_mm1 = np.append(big_mm1,mmoments[0]) big_mm2 = np.append(big_mm2,np.sqrt(mmoments[1])) big_mm3 = np.append(big_mm3,mmoments[2]) big_dm1 = np.append(big_dm1,dmoments[0]) big_dm1e = np.append(big_dm1e,derr[0]) big_dm2 = np.append(big_dm2,dmoments[1]) big_dm2e = np.append(big_dm2e,derr[1]) big_dm3 = np.append(big_dm3,dmoments[2]) big_dm3e = np.append(big_dm3e,derr[2]) plot_radii = np.append(plot_radii,radius) return plot_radii, [big_dm1, big_dm1e, big_mm1],\ [big_dm2, big_dm2e, big_mm2],\ [big_dm3, big_dm3e, big_mm3]