def do(): h_r = 8.3 vc_list = [216.78]*4#,203.7565,200.516,242.0] zlist = [0,0.43,0.86,1.72] w = 0.8 N = 6 view_ang = 0. pitch_list = [0.17] #np.arange(0.17,0.52,0.10) for z, vc in zip(zlist,vc_list): for pitch in pitch_list: name = 'sim_z{:n}_spirala_p{:04.0f}.fits'.format(z/0.43,pitch*1000) print name salty.simcurve(1001,z,vc,5.45,scale=100/1001.,output=name, spiralpars=dict(w=w, N=N, view_ang=view_ang, pitch=pitch)) salty.plt.close('all') salty.gc.collect() return
def galaxy_batch(): for w in [0.6,0.8,0.9,1.0]: for pitch in np.pi/np.array([3.,4.,5.,6.]): for view in np.pi/np.array([2.,3.,4.,5.]): for N in [4,6,8]: name = 'sim_{:.1f}_{:}_{:n}_{:n}.fits'.\ format(w,N,np.pi/pitch,np.pi/view) print name salty.simcurve(205,0.83,256,5.45,w=w,N=N,pitch=pitch, view_ang=view,scale=0.39,output=name) return
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 do(): h_r = 8.3 r_R = h_r*3. r_sig = 1. vc_list = [216.78] * 4 #,203.7565,200.516,242.0] zlist = [0,0.43,0.86,1.72] for z, vc in zip(zlist,vc_list): name = 'sim_z{:n}_boring.fits'.format(z/0.43) print name salty.simcurve(1001,z,vc,5.45,scale=100/1001.,output=name) salty.plt.close('all') salty.gc.collect() return
def do(): h_r = 8.3 hzrlist = [12.45]#np.arange(0.25,1.75,0.25) * h_r filelist = [ '/d/monk/eigenbrot/EdgeOn/SALT_data/tiESO_z0_MgI_binz2.slay.fits', '/d/monk/eigenbrot/EdgeOn/SALT_data/tiESO_z1_MgI_binz2.slay.fits', '/d/monk/eigenbrot/EdgeOn/SALT_data/tiESO_z2_MgI_bin60.slay.fits', '/d/monk/eigenbrot/EdgeOn/SALT_data/tiESO_z4_MgI_binz2.slay.fits'] zlist = [0,0.43,0.86,1.72] fliplist = [True,False,False,False] print "hzrlist:" print hzrlist vclist = [216]*4#[salty.find_Vc(*salty.openslay(i),back=back) #for (i,back) in zip(filelist,fliplist)] salty.plt.close('all') '''generate some sim files''' for filename, z, flip, vc in zip(filelist,zlist,fliplist,vclist): zx = filename.split('_')[2] noname = 'sim_{}_noflare.fits'.format(zx) salty.simcurve(1001,z,vc,5.45,scale=100/1001.,output = noname) noprefix = 'noflare_comp_{}'.format(zx) # mt.line_comp(noname,filename,noprefix,flip=flip) for hzr in hzrlist: flarename = 'sim_{:}_nflarea_{:3.0f}.fits'.format(zx,hzr*100.) salty.simcurve(1001,z,vc,5.45,scale=100/1001., output=flarename,flarepars=dict(h_zR = hzr, ftype='exp')) prefix = 'nflare_comp_{:}_f{:04.0f}'.format(zx,hzr*100.) # mt.line_comp(flarename,filename,prefix,flip=flip) salty.plt.close('all') mt.plt.close('all') salty.gc.collect() mt.gc.collect() gc.collect() return
def do_radius(): h_r = 8.3 r_w = 0.7 r_sig = 1. vc_list = [216.78,203.7565,200.516,242.0] zlist = [0,0.43,0.86,1.72] radius_list = np.arange(1,30,10.) for z, vc in zip(zlist,vc_list): for r_R in radius_list: name = 'sim_z{:n}_ring_R{:04.0f}.fits'.format(z/0.43,r_R*100) print name salty.simcurve(1001,z,vc,5.45,scale=100/1001.,output=name, ringpars=dict(r_R=r_R,r_sig=r_sig,r_w=r_w)) salty.plt.close('all') salty.gc.collect() return
def do(): h_r = 8.3 r_R = h_r*3. r_sig = 1. vc_list = [216.78] * 4 #,203.7565,200.516,242.0] zlist = [0,0.43,0.86,1.72] weight_list = [0.28] #np.linspace(0.05,0.5,3) for z, vc in zip(zlist,vc_list): for r_w in weight_list: name = 'sim_z{:n}_ringa_w{:03.0f}.fits'.format(z/0.43,r_w*100) print name salty.simcurve(1001,z,vc,5.45,scale=100/1001.,output=name, ringpars=dict(r_R=r_R,r_sig=r_sig,r_w=r_w)) salty.plt.close('all') salty.gc.collect() return
def make_image(output): v_r = 238.3067 hrot = 5.45 h_z = 0.43 size = 501 scale = 100.0/size warppars = dict(warp_factor=7e-7, warp_ang=0) maxz = 30. numz = 500 heights = np.linspace(-1*maxz,maxz,numz) SBlist = [] for Z in heights: name = 'eonview_warp_{:04.0f}.fits'.format(Z*1000) print Z, name # salty.simcurve(size,Z,v_r,hrot,scale=scale,flarepars=flarepars, # output=name) salty.simcurve(size,Z,v_r,hrot,scale=scale,warppars=warppars, output=name) SB = pyfits.open(name)['SB'].data[size/2,:] SBlist = SBlist + [SB] galaxy = np.vstack(SBlist) HDU = pyfits.PrimaryHDU(galaxy) HDU.header.update('CRPIX1',size/2,comment='WCS: X reference pixel') HDU.header.update('CRPIX2',numz/2,comment='WCS: Y reference pixel') HDU.header.update('CRVAL1',0.0,'WCS: X reference coordinate value') HDU.header.update('CRVAL2',0.0,'WCS: Y reference coordinate value') HDU.header.update('CDELT1',scale,comment='WCS: X pixel size') HDU.header.update('CDELT2',maxz/(numz-1)*2,comment='WCS: Y pixel size') HDU.header.update('CTYPE1','LINEAR',comment='X type') HDU.header.update('CTYPE2','LINEAR',comment='Y type') HDU.writeto(output,clobber=True) return
def make_image(output,h_zR): v_r = 238.3067 hrot = 5.45 h_z = 0.43 size = 501 scale = 100.0/size flarepars = dict(ftype='linear', h_zR = h_zR) maxz = 30. numz = 250 heights = np.linspace(0,maxz,numz) SBlist = [] for Z in heights: name = 'eonview_lf{:04.0f}_{:04.0f}.fits'.format(h_zR*100,Z*1000) print Z, name salty.simcurve(size,Z,v_r,hrot,scale=scale,flarepars=flarepars, output=name) SB = pyfits.open(name)['SB'].data[size/2,:] SBlist = [SB] + SBlist if Z != 0.0: SBlist = SBlist + [SB] galaxy = np.vstack(SBlist) HDU = pyfits.PrimaryHDU(galaxy) HDU.header.update('CRPIX1',size/2,comment='WCS: X reference pixel') HDU.header.update('CRPIX2',numz,comment='WCS: Y reference pixel') HDU.header.update('CRVAL1',0.0,'WCS: X reference coordinate value') HDU.header.update('CRVAL2',0.0,'WCS: Y reference coordinate value') HDU.header.update('CDELT1',scale,comment='WCS: X pixel size') HDU.header.update('CDELT2',maxz/(numz-1),comment='WCS: Y pixel size') HDU.header.update('CTYPE1','LINEAR',comment='X type') HDU.header.update('CTYPE2','LINEAR',comment='Y type') HDU.writeto(output,clobber=True) return
def make_boring(vr_list, h_rot_list, h_dust=8.43, kappa_0=1.62,nofits=False, z=0, size=1001, z_d=0.23, name='boring',flarepars=None): '''Given a list of values for v_r and h_rot, make a grid of galaxy models with all possible combinations of those two parameters. ''' basename = 'sim_z{:n}_{}'.format(z,name) outlist = [] for v_r in vr_list: for h_rot in h_rot_list: name = '{}_{}.fits'.format(basename,int(round(time.time(), 3)*100)) sim = salty.simcurve(size,z,v_r,h_rot,output=name,scale=0.0999, h_dust=h_dust,kappa_0=kappa_0,z_d=z_d, flarepars=flarepars,full=True, verbose=False,nofits=nofits) if nofits: outlist.append(sim) else: outlist.append(name) return outlist
def do_linear(): '''run in /d/monk/eigenbrot/EdgeOn/flare_test/linear ''' h_r = 8.3 hzrlist = np.arange(0.1,1.0,0.25) * h_r filelist = [ '/d/monk/eigenbrot/EdgeOn/SALT_data/tiESO_z0_MgI_binz2.slay.fits', '/d/monk/eigenbrot/EdgeOn/SALT_data/tiESO_z1_MgI_binz2.slay.fits', '/d/monk/eigenbrot/EdgeOn/SALT_data/tiESO_z2_MgI_bin60.slay.fits', '/d/monk/eigenbrot/EdgeOn/SALT_data/tiESO_z4_MgI_binz2.slay.fits'] zlist = [0,0.43,0.86,1.72] fliplist = [True,False,False,False] print "hzrlist:" print hzrlist vclist = [salty.find_Vc(*salty.openslay(i),back=back) for (i,back) in zip(filelist,fliplist)] print "vclist:" print vclist salty.plt.close('all') '''generate some sim files''' for filename, z, flip, vc in zip(filelist,zlist,fliplist,vclist): print filename+':' zx = filename.split('_')[2] noname = 'sim_{}_noflare.fits'.format(zx) salty.simcurve(1001,z,vc,5.45,scale=100/1001.,output = noname) noprefix = 'noflare_comp_{}'.format(zx) # mt.line_comp(noname,filename,noprefix,flip=flip) for hzr in hzrlist: print filename+'\t'+str(hzr) flarename = 'sim_{:}_lflare_{:03.0f}.fits'.format(zx,hzr*100.) salty.simcurve(1001,z,vc,5.45,scale=100/1001., output=flarename, flarepars=dict(ftype='linear',h_zR = hzr)) prefix = 'lflare_comp_{:}_f{:04.0f}'.format(zx,hzr*100.) # mt.line_comp(flarename,filename,prefix,flip=flip) salty.plt.close('all') mt.plt.close('all') salty.gc.collect() mt.gc.collect() gc.collect() return
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]