def calc_one_fisher(this_info): ''' routine called by worker bee function to do all the heavy lifting. calculates many fisher matrices for a given array configuration (one fishMx for each angular scale to be assessed) ''' lam=this_info[0] cfg_file=this_info[1] cfg_resolution=this_info[2] min_resolution=this_info[3] cfg_las=this_info[4] beamfwhm=this_info[5] master_norm=this_info[6] typical_err=this_info[7] n_samps=this_info[8] do_constSurfBright=this_info[9] mytag=this_info[10] if do_constSurfBright: print "SURFACE BRIGHTNESS of components held fixed" else: print "TOTAL FLUX density of components held fixed" parvec=sp.array([master_norm,cfg_resolution,cfg_resolution,cfg_resolution,cfg_resolution,25.0*sp.pi/180.0]) # param order is - norm,l0,m0,fwhm_1,fwhm_2,axis_angle - last is deg others rad. # initialize variables norm_snr=sp.zeros(n_samps) fwhm_snr=sp.zeros(n_samps) fwhm2_snr=sp.zeros(n_samps) pos_err0=sp.zeros(n_samps) pos_err1=sp.zeros(n_samps) angle_err=sp.zeros(n_samps) nzeros=sp.zeros(n_samps,dtype=sp.int_) # go from resolution/5 to LAS*2 #min_scale=cfg_resolution*0.1 min_scale=min_resolution*0.05 max_scale=cfg_las*2.5 # compute range of models to consider- step_size=(max_scale-min_scale)/n_samps signal_fwhm= (sp.arange(n_samps)*step_size+step_size) # this will return the uv baselines in inverse radians- bl=tv.getbaselines(cfg_file,lam=lam) # loop over gaussian component sizes- print '***',step_size,max_scale,min_scale,cfg_file if do_constSurfBright: mystring='-constSB_2' else: mystring='-constFlux_2' test_delta = tv.create_delta_vec(parvec,parvec) print " *** Representative deltas: {}".format(test_delta) # save (signal_fwhm,norm_snr, fwhm_snr) here fh=open(cfg_file+mytag+mystring+'.parErrs.txt','w',1) for i in range(n_samps): parvec[3] = signal_fwhm[i] * 1.05 parvec[4] = signal_fwhm[i] / 1.05 if do_constSurfBright: # normalize total flux so that master_norm is the flux in mJy # of a component with 1" FWHM - note signal_fwhm here # is in radians parvec[0] = master_norm * (signal_fwhm[i] * 206264.8)**2 default_scales = sp.array([parvec[0],cfg_resolution,cfg_resolution,cfg_resolution,cfg_resolution,0.35]) default_par_delta = tv.create_delta_vec(parvec,default_scales) # put telescope gain scaling in to the errors (which are in mJy)- this_err = typical_err * (beamfwhm/2.91e-4)**2 f=tv.make_fisher_mx(bl,this_err,default_par_delta,beamfwhm,parvec,brute_force=False,flux_norm=True) # use SVD pseudo inverse instead of direct # inverse for stability #finv=spla.inv(f) finv=spla.pinv(f) norm_snr[i]= parvec[0] / (finv[0,0])**0.5 # save position error = average 1D error- pos_err0[i]= (finv[1,1])**0.5 pos_err1[i] = (finv[2,2])**0.5 fwhm_snr[i]= parvec[3] / (finv[3,3])**0.5 fwhm2_snr[i] = parvec[4]/ (finv[4,4])**0.5 angle_err[i]= (finv[5,5])**0.5 diags = sp.diag(finv) nzeros[i]=diags[diags==0.0].size dumpfile='raw_fish/f-'+cfg_file+'-'+mytag+mystring+'{}'.format(i)+'.pkl' pickle.dump(f,open(dumpfile,"wb")) dumpfile='raw_fish/finv-'+cfg_file+'-'+mytag+mystring+'{}'.format(i)+'.pkl' pickle.dump(finv,open(dumpfile,"wb")) outstr='{0:d} {1:.5e} {2:.5e} {3:.5e} {4:.5e} {5:.5e} {6:.5e} {7:.5e} {8:.5e} {9:d}'.format(i,signal_fwhm[i],beamfwhm,norm_snr[i],fwhm_snr[i],fwhm2_snr[i],angle_err[i],pos_err0[i],pos_err1[i],nzeros[i]) fh.write(outstr+'\n') print cfg_file,outstr fh.close()
# param order is - norm,l0,m0,fwhm_1,fwhm_2,axis_angle - last is deg others rad. # initialize variables norm_snr = sp.zeros(n_samps) fwhm_snr = sp.zeros(n_samps) fwhm2_snr = sp.zeros(n_samps) pos_err0 = sp.zeros(n_samps) pos_err1 = sp.zeros(n_samps) # go from resolution/5 to LAS*2 #min_scale=cfg_resolution[j]*0.1 min_scale = min_resolution * 0.05 max_scale = cfg_las[j] * 2.5 # compute range of models to consider- step_size = (max_scale - min_scale) / n_samps signal_fwhm = (sp.arange(n_samps) * step_size + step_size) # this will return the uv baselines in inverse radians- bl = tv.getbaselines(cfg_files[j], lam=lam) # loop over gaussian component sizes- print '***', j, step_size, max_scale, min_scale, cfg_files[j] for i in range(n_samps): parvec[3] = signal_fwhm[i] * 1.05 parvec[4] = signal_fwhm[i] / 1.05 if do_constSurfBright: # normalize total flux so that master_norm is the flux in mJy # of a component with 1" FWHM - note signal_fwhm here # is in radians parvec[0] = master_norm * (signal_fwhm[i] * 206264.8)**2 # set default deltas for calculating the numerical derivative # default to 1% for nonzero params; 0.1xsynth beam for positions; # and 0.5 deg for the axis angle- default_par_delta = sp.copy(parvec * 0.01) default_par_delta[1] = cfg_resolution[j] * 0.1
def calc_one_fisher(this_info): ''' routine called by worker bee function to do all the heavy lifting. ''' lam = this_info[0] cfg_file = this_info[1] cfg_resolution = this_info[2] min_resolution = this_info[3] cfg_las = this_info[4] beamfwhm = this_info[5] master_norm = this_info[6] typical_err = this_info[7] n_samps = this_info[8] do_constSurfBright = this_info[9] if do_constSurfBright: print "SURFACE BRIGHTNESS of components held fixed" else: print "TOTAL FLUX density of components held fixed" deltax = beamfwhm * 0.01 parvec = sp.array( [master_norm, deltax, deltax, cfg_resolution, cfg_resolution, 10.0]) # param order is - norm,l0,m0,fwhm_1,fwhm_2,axis_angle - last is deg others rad. # initialize variables norm_snr = sp.zeros(n_samps) fwhm_snr = sp.zeros(n_samps) fwhm2_snr = sp.zeros(n_samps) pos_err0 = sp.zeros(n_samps) pos_err1 = sp.zeros(n_samps) angle_err = sp.zeros(n_samps) # go from resolution/5 to LAS*2 #min_scale=cfg_resolution*0.1 min_scale = min_resolution * 0.05 max_scale = cfg_las * 2.5 # compute range of models to consider- step_size = (max_scale - min_scale) / n_samps signal_fwhm = (sp.arange(n_samps) * step_size + step_size) # this will return the uv baselines in inverse radians- bl = tv.getbaselines(cfg_file, lam=lam) # loop over gaussian component sizes- print '***', step_size, max_scale, min_scale, cfg_file for i in range(n_samps): parvec[3] = signal_fwhm[i] * 1.05 parvec[4] = signal_fwhm[i] / 1.05 if do_constSurfBright: # normalize total flux so that master_norm is the flux in mJy # of a component with 1" FWHM - note signal_fwhm here # is in radians parvec[0] = master_norm * (signal_fwhm[i] * 206264.8)**2 # set default deltas for calculating the numerical derivative # default to 1% for nonzero params; 0.1xsynth beam for positions; # and 0.5 deg for the axis angle- default_par_delta = sp.copy(parvec * 0.01) default_par_delta[1] = cfg_resolution * 0.1 default_par_delta[2] = cfg_resolution * 0.1 default_par_delta[5] = 0.5 # put telescope gain scaling in to the errors (which are in mJy)- this_err = typical_err * (beamfwhm / 2.91e-4)**2 f = tv.make_fisher_mx(bl, this_err, default_par_delta, beamfwhm, parvec, brute_force=False, flux_norm=True) # use SVD pseudo inverse instead of direct # inverse for stability #finv=spla.inv(f) finv = spla.pinv(f) norm_snr[i] = parvec[0] / (finv[0, 0])**0.5 # save position error = average 1D error- pos_err0[i] = (finv[1, 1])**0.5 pos_err1[i] = (finv[2, 2])**0.5 fwhm_snr[i] = parvec[3] / (finv[3, 3])**0.5 fwhm2_snr[i] = parvec[4] / (finv[4, 4])**0.5 angle_err[i] = (finv[5, 5])**0.5 print cfg_file, i, norm_snr[i], fwhm_snr[i], pos_err0[i] # save fisher mx i here # save (signal_fwhm,norm_snr, fwhm_snr) here if do_constSurfBright: mystring = '-constSB' else: mystring = '-constFlux' fh = open(cfg_file + mystring + '.parErrs.txt', 'w') for i in range(n_samps): outstr = '{0:.3e} {1:.3e} {2:.3e} {3:.4e} {3:.4e} {4:.3e} {4:.3e} {4:.3e}'.format( signal_fwhm[i], beamfwhm, norm_snr[i], fwhm_snr[i], fwhm2_snr[i], angle_err[i], pos_err0[i], pos_err1[i]) fh.write(outstr + '\n') fh.close()
#b3=tv.getbaselines('c40-3n.cfg',lam=lam) #b4=tv.getbaselines('c40-4n.cfg',lam=lam) #b5=tv.getbaselines('c40-5n.cfg',lam=lam) #b6=tv.getbaselines('c40-6n.cfg',lam=lam) #b7=tv.getbaselines('c40-7n2.cfg',lam=lam) #b8=tv.getbaselines('c40-8n2.cfg',lam=lam) #b9=tv.getbaselines('c40-9n2.cfg',lam=lam) #baca=tv.getbaselines('aca.std10.cfg',lam=lam) filelist = [ 'aca.std10.cfg', 'c40-1n.cfg', 'c40-2n.cfg', 'c40-3n.cfg', 'c40-4n.cfg', 'c40-5n.cfg', 'c40-6n.cfg', 'c40-7n2.cfg', 'c40-8n2.cfg', 'c40-9n2.cfg' ] for ff in filelist: b = tv.getbaselines(ff, lam=lam) lasmin = 0.5 / (b['qspecial'])[0] * 206265. las5 = 0.5 / (b['qspecial'])[1] * 206265. las10 = 0.5 / (b['qspecial'])[2] * 206265. print ff, ' ', lasmin, ' ', las5, ' ', las10 ### RESULTS - 100GHz; 0.5 lambda/B_min , 0.5 lam/B_5 , 0.5 lam/B_10 # #aca.std10.cfg 34.8 34.1 32.2 #c40-1n.cfg 20.6 14.6 11.2 #c40-2n.cfg 20.5 11.2 8.0 #c40-3n.cfg 20.5 6.9 5.1 #c40-4n.cfg 20.5 4.5 3.2 #c40-5n.cfg 18.5 3.0 1.9 #c40-6n.cfg 20.2 1.56 1.11 #c40-7n2.cfg 3.80 0.82 0.65
i_poserr=7 i_pos2err=8 i_zeros=9 c1=pl.genfromtxt('c40-1n.cfgnew-constFlux_2.parErrs.txt') c2=pl.genfromtxt('c40-2n.cfgnew-constFlux_2.parErrs.txt') c3=pl.genfromtxt('c40-3n.cfgnew-constFlux_2.parErrs.txt') c4=pl.genfromtxt('c40-4n.cfgnew-constFlux_2.parErrs.txt') c5=pl.genfromtxt('c40-5n.cfgnew-constFlux_2.parErrs.txt') c6=pl.genfromtxt('c40-6n.cfgnew-constFlux_2.parErrs.txt') c7=pl.genfromtxt('c40-7n2.cfgnew-constFlux_2.parErrs.txt') c8=pl.genfromtxt('c40-8n2.cfgnew-constFlux_2.parErrs.txt') c9=pl.genfromtxt('c40-9n2.cfgnew-constFlux_2.parErrs.txt') lam=3e8/(100e9) b1=tv.getbaselines('c40-1n.cfg',lam=lam) b2=tv.getbaselines('c40-2n.cfg',lam=lam) b3=tv.getbaselines('c40-3n.cfg',lam=lam) b4=tv.getbaselines('c40-4n.cfg',lam=lam) b5=tv.getbaselines('c40-5n.cfg',lam=lam) b6=tv.getbaselines('c40-6n.cfg',lam=lam) b7=tv.getbaselines('c40-7n2.cfg',lam=lam) b8=tv.getbaselines('c40-8n2.cfg',lam=lam) b9=tv.getbaselines('c40-9n2.cfg',lam=lam) sbfac = sp.ones(c1[:,0].size) # or sbfac = sp.ones(c1[:,0].size) * (c1[:,i_theta]/c1[5,i_pb])**2 * 10 ########################## #
filelist = [ "aca.std10.cfg", "c40-1n.cfg", "c40-2n.cfg", "c40-3n.cfg", "c40-4n.cfg", "c40-5n.cfg", "c40-6n.cfg", "c40-7n2.cfg", "c40-8n2.cfg", "c40-9n2.cfg", ] for ff in filelist: b = tv.getbaselines(ff, lam=lam) lasmin = 0.5 / (b["qspecial"])[0] * 206265.0 las5 = 0.5 / (b["qspecial"])[1] * 206265.0 las10 = 0.5 / (b["qspecial"])[2] * 206265.0 print ff, " ", lasmin, " ", las5, " ", las10 ### RESULTS - 100GHz; 0.5 lambda/B_min , 0.5 lam/B_5 , 0.5 lam/B_10 # # aca.std10.cfg 34.8 34.1 32.2 # c40-1n.cfg 20.6 14.6 11.2 # c40-2n.cfg 20.5 11.2 8.0 # c40-3n.cfg 20.5 6.9 5.1 # c40-4n.cfg 20.5 4.5 3.2 # c40-5n.cfg 18.5 3.0 1.9 # c40-6n.cfg 20.2 1.56 1.11 # c40-7n2.cfg 3.80 0.82 0.65
# loop over configurations for j in range(n_configs): parvec=sp.array([master_norm,0.0,0.0,cfg_resolution[j],cfg_resolution[j],0.0]) # param order is - norm,l0,m0,fwhm_1,fwhm_2,axis_angle # initialize variables norm_snr=sp.zeros(n_samps) fwhm_snr=sp.zeros(n_samps) pos_err=sp.zeros(n_samps) # go from resolution/5 to LAS*2 min_scale=cfg_resolution[j]*0.1 max_scale=cfg_las[j]*2.5 # compute range of models to consider- step_size=(max_scale-min_scale)/n_samps signal_fwhm= (sp.arange(n_samps)*step_size+step_size) # this will return the uv baselines in inverse radians- bl=tv.getbaselines(cfg_files[j],lam=lam) # loop over gaussian component sizes- print '***',j,step_size,max_scale,min_scale,cfg_files[j] for i in range(n_samps): parvec[3] = signal_fwhm[i] parvec[4] = signal_fwhm[i] # set default deltas for calculating the numerical derivative # default to 1% for nonzero params; 0.1xsynth beam for positions; # and 0.5 deg for the axis angle- default_par_delta=sp.copy(parvec*0.01) default_par_delta[1]=cfg_resolution[j]*0.1 default_par_delta[2]=cfg_resolution[j]*0.1 default_par_delta[5]=0.5 f=tv.make_fisher_mx(bl,typical_err,default_par_delta,beamfwhm[j],parvec,brute_force=False,flux_norm=True) finv=spla.inv(f) norm_snr[i]= parvec[0] / (finv[0,0])**0.5
import scipy.linalg as spla import scipy as sp import testvis as tv nu=100.0 lam=3e8/(nu*1e9) # this will return the uv baselines in inverse radians- bl=tv.getbaselines('Alma_cycle1_2.cfg.txt',lam=lam) # beam fwhm in rad- (B3 alma) - 1' fwhm = 2.91e-4 radians fwhm beamfwhm=2.91e-4 parvec=sp.array([0.01,0.0,0.0,2e-5,2e-5,0.0]) # param order is - norm,l0,m0,fwhm_1,fwhm_2,axis_angle parvec += 1e-9 print tv.visval(beamfwhm,0,0,parvec[0],parvec[1],parvec[2],parvec[3],parvec[4],parvec[5],brute_force=False) # this is a typical visibility value. set the error in make_fisher_mx to something of this order signal_fwhm= (sp.arange(100)*0.02+0.02) * beamfwhm norm_snr=sp.zeros(100) fwhm_snr=sp.zeros(100) for i in range(100): parvec[3] = signal_fwhm[i] parvec[4] = signal_fwhm[i] f=tv.make_fisher_mx(bl,1e-12,0.01,beamfwhm,parvec,brute_force=False) finv=spla.inv(f) norm_snr[i]= parvec[0] / (finv[0,0])**0.5 fwhm_snr[i]= parvec[3] / (finv[3,3])**0.5
import scipy.linalg as spla import scipy as sp import testvis as tv nu = 100.0 lam = 3e8 / (nu * 1e9) # this will return the uv baselines in inverse radians- bl = tv.getbaselines('Alma_cycle1_2.cfg.txt', lam=lam) # beam fwhm in rad- (B3 alma) - 1' fwhm = 2.91e-4 radians fwhm beamfwhm = 2.91e-4 parvec = sp.array([0.01, 0.0, 0.0, 2e-5, 2e-5, 0.0]) # param order is - norm,l0,m0,fwhm_1,fwhm_2,axis_angle parvec += 1e-9 print tv.visval(beamfwhm, 0, 0, parvec[0], parvec[1], parvec[2], parvec[3], parvec[4], parvec[5], brute_force=False) # this is a typical visibility value. set the error in make_fisher_mx to something of this order signal_fwhm = (sp.arange(100) * 0.02 + 0.02) * beamfwhm norm_snr = sp.zeros(100) fwhm_snr = sp.zeros(100)
cfg_las = sp.array([25.0,25.0,25.0,10.0,8.0,5.0,1.5,1.1])*3.1415/180.0/3600.0 # beam fwhm in rad- (B3 alma) - 1' fwhm = 2.91e-4 radians fwhm beamfwhm= sp.array([2.91e-4,2.91e-4,2.91e-4,2.91e-4,2.91e-4,2.91e-4,2.91e-4,])*(100.0/nu) # TBD - the ACA one crashed for some reason :/ # keep integrated flux density of Gaussian constant as the size of the Gaussina changes? do_const_flux=True # get some typical #s... # master normalization master_norm=1.0 ref_cfg=4 parvec=sp.array([master_norm,0.0,0.0,cfg_resolution[ref_cfg],cfg_resolution[ref_cfg],0.0]) if do_const_flux: parvec[0] = master_norm / (parvec[3]*parvec[4]) bl=tv.getbaselines(cfg_files[ref_cfg],lam=lam) typical_q = sp.median(bl['q'])*0.7 # compute a typical visibility value and use it as typical error (SNR per vis = 1) #typical_err=sp.median(abs(tv.visval(beamfwhm[ref_cfg],typical_q,typical_q,parvec[0],parvec[1],parvec[2],parvec[3],parvec[4],parvec[5],brute_force=False))) # assuming 1 mJy typical error per visibility typical_err = 1.0 # number of x-axis samples at which to evaluate the parameter uncertainties of interest- n_samps=100 # n_configs=1 # loop over configurations for j in range(n_configs): parvec=sp.array([master_norm,0.0,0.0,cfg_resolution[j],cfg_resolution[j],0.0]) # param order is - norm,l0,m0,fwhm_1,fwhm_2,axis_angle if do_const_flux: parvec[0] = master_norm / (parvec[3]*parvec[4])
def calc_one_fisher(this_info): ''' routine called by worker bee function to do all the heavy lifting. ''' lam=this_info[0] cfg_file=this_info[1] cfg_resolution=this_info[2] min_resolution=this_info[3] cfg_las=this_info[4] beamfwhm=this_info[5] master_norm=this_info[6] typical_err=this_info[7] n_samps=this_info[8] do_constSurfBright=this_info[9] if do_constSurfBright: print "SURFACE BRIGHTNESS of components held fixed" else: print "TOTAL FLUX density of components held fixed" deltax=beamfwhm * 0.01 parvec=sp.array([master_norm,deltax,deltax,cfg_resolution,cfg_resolution,10.0]) # param order is - norm,l0,m0,fwhm_1,fwhm_2,axis_angle - last is deg others rad. # initialize variables norm_snr=sp.zeros(n_samps) fwhm_snr=sp.zeros(n_samps) fwhm2_snr=sp.zeros(n_samps) pos_err0=sp.zeros(n_samps) pos_err1=sp.zeros(n_samps) angle_err=sp.zeros(n_samps) # go from resolution/5 to LAS*2 #min_scale=cfg_resolution*0.1 min_scale=min_resolution*0.05 max_scale=cfg_las*2.5 # compute range of models to consider- step_size=(max_scale-min_scale)/n_samps signal_fwhm= (sp.arange(n_samps)*step_size+step_size) # this will return the uv baselines in inverse radians- bl=tv.getbaselines(cfg_file,lam=lam) # loop over gaussian component sizes- print '***',step_size,max_scale,min_scale,cfg_file for i in range(n_samps): parvec[3] = signal_fwhm[i] * 1.05 parvec[4] = signal_fwhm[i] / 1.05 if do_constSurfBright: # normalize total flux so that master_norm is the flux in mJy # of a component with 1" FWHM - note signal_fwhm here # is in radians parvec[0] = master_norm * (signal_fwhm[i] * 206264.8)**2 # set default deltas for calculating the numerical derivative # default to 1% for nonzero params; 0.1xsynth beam for positions; # and 0.5 deg for the axis angle- default_par_delta=sp.copy(parvec*0.01) default_par_delta[1]=cfg_resolution*0.1 default_par_delta[2]=cfg_resolution*0.1 default_par_delta[5]=0.5 # put telescope gain scaling in to the errors (which are in mJy)- this_err = typical_err * (beamfwhm/2.91e-4)**2 f=tv.make_fisher_mx(bl,this_err,default_par_delta,beamfwhm,parvec,brute_force=False,flux_norm=True) # use SVD pseudo inverse instead of direct # inverse for stability #finv=spla.inv(f) finv=spla.pinv(f) norm_snr[i]= parvec[0] / (finv[0,0])**0.5 # save position error = average 1D error- pos_err0[i]= (finv[1,1])**0.5 pos_err1[i] = (finv[2,2])**0.5 fwhm_snr[i]= parvec[3] / (finv[3,3])**0.5 fwhm2_snr[i] = parvec[4]/ (finv[4,4])**0.5 angle_err[i]= (finv[5,5])**0.5 print cfg_file,i, norm_snr[i],fwhm_snr[i],pos_err0[i] # save fisher mx i here # save (signal_fwhm,norm_snr, fwhm_snr) here if do_constSurfBright: mystring='-constSB' else: mystring='-constFlux' fh=open(cfg_file+mystring+'.parErrs.txt','w') for i in range(n_samps): outstr='{0:.3e} {1:.3e} {2:.3e} {3:.4e} {3:.4e} {4:.3e} {4:.3e} {4:.3e}'.format(signal_fwhm[i],beamfwhm,norm_snr[i],fwhm_snr[i],fwhm2_snr[i],angle_err[i],pos_err0[i],pos_err1[i]) fh.write(outstr+'\n') fh.close()