def read_zeta(self, gp): for pop in np.arange(gp.pops + 1): D1, D2, D3, zetaa, zetaaerr = gh.readcol5(gp.files.zetaafiles[pop]) self.zetaa.append(zetaa) self.zetaaerr.append(zetaaerr) D1, D2, D3, zetab, zetaberr = gh.readcol5(gp.files.zetabfiles[pop]) self.zetab.append(zetab) self.zetaberr.append(zetaberr) return
def read_zeta(self, gp): for pop in np.arange(gp.pops+1): D1,D2,D3,zetaa,zetaaerr=gh.readcol5(gp.files.zetaafiles[pop]) self.zetaa.append(zetaa) self.zetaaerr.append(zetaaerr) D1,D2,D3,zetab,zetaberr=gh.readcol5(gp.files.zetabfiles[pop]) self.zetab.append(zetab) self.zetaberr.append(zetaberr) return
def read_kappa(self, gp): for pop in np.arange(gp.pops+1): Dummy1, Dummy2, Dummy3, kapdat, kaperr = gh.readcol5(gp.files.kappafiles[pop]) # 3*[Xscale], [1], [1] self.kap.append(kapdat) # [1] self.kaperr.append(kaperr) # [1] return
def read_kappa(self, gp): for pop in np.arange(gp.pops + 1): Dummy1, Dummy2, Dummy3, kapdat, kaperr = gh.readcol5( gp.files.kappafiles[pop]) # 3*[Xscale], [1], [1] self.kap.append(kapdat) # [1] self.kaperr.append(kaperr) # [1] return
def read_sig(self, gp): # only ever use the tracer particles for velocity information self.sig.append(np.zeros(gp.nipol)) self.sigerr.append(np.zeros(gp.nipol)) for pop in np.arange(gp.pops): print('read_sig on file ', gp.files.sigfiles[pop+1]) Dummy1, Dummy2, Dummy3, sigdat, sigerr = gh.readcol5(gp.files.sigfiles[pop+1]) # 3*[Xscale], [maxsiglos], [maxsiglos] # change to km/s here self.sig.append(sigdat[:] * gp.maxsiglos[pop+1]) # [km/s] self.sigerr.append(sigerr[:] * gp.maxsiglos[pop+1]) # [km/s] self.barsig.append(np.mean(sigerr[:]*gp.maxsiglos[pop+1])) return
def read_sig(self, gp): # only ever use the tracer particles for velocity information self.sig.append(np.zeros(gp.nipol)) self.sigerr.append(np.zeros(gp.nipol)) for pop in np.arange(gp.pops): print('read_sig on file ', gp.files.sigfiles[pop + 1]) Dummy1, Dummy2, Dummy3, sigdat, sigerr = gh.readcol5( gp.files.sigfiles[pop + 1]) # 3*[Xscale], [maxsiglos], [maxsiglos] # change to km/s here self.sig.append(sigdat[:] * gp.maxsiglos[pop + 1]) # [km/s] self.sigerr.append(sigerr[:] * gp.maxsiglos[pop + 1]) # [km/s] self.barsig.append(np.mean(sigerr[:] * gp.maxsiglos[pop + 1])) return
ip.insert_sys_path(basedir + 'programs/sphere') import gi_params as ngip ngp = ngip.Params(tt) print(ngp) print('ngp.rinfty = ', ngp.rinfty) import select_run as sr ngp.pops = sr.get_pops(basedir) print('working with ', ngp.pops, ' populations') prepare_output_folder(basedir) # check whether we need to read in ngp.dat, or whether we are plotting from inside gravimage main program if len(ngp.dat.Sig) == 0: import gi_file as glf ngp.dat = glf.get_binned_data(ngp) read_scale(ngp) # store half-light radii in gp.Xscale import gi_helper as gh Radii, Binmin, Binmax, Sigdat1, Sigerr1 = gh.readcol5(ngp.files.Sigfiles[0]) # [Xscale0], [Munit/Xscale0^2] # verified that indeed the stored files in the run directory are used ngp.xipol = Radii * ngp.Xscale[0] # [pc] maxR = max(Radii) # [pc] minR = min(Radii) # [pc] Radii = np.hstack( [minR / 8, minR / 4, minR / 2, Radii, 2 * maxR, 4 * maxR, 8 * maxR]) ngp.xepol = Radii * ngp.Xscale[0] # [pc] pc = pcload_single_entries(basedir, ngp) with open(basedir + 'pc', 'wb') as fn: pickle.dump(pc, fn)
ip.insert_sys_path(basename+tt+'/programs/sphere') import gi_params as gip gp = gip.Params(tt) gp.pops = sr.get_pops(basename+tt+'/') print('working with ', gp.pops, ' populations') if len(pcall.chis) == 0: gh.LOG(1, 'no profiles found for plotting') sys.exit(1) # first plot all chi^2 values in histogram pcall.plot_profile(basename+tt+'/', 'chi2', 0, gp) # then select only the best models for plotting the profiles pcall.cut_subset() import gi_helper as gh read_scale(gp) # store half-light radii in gp.Xscale Radii, Binmin, Binmax, Sigdat1, Sigerr1 = gh.readcol5(gp.files.Sigfiles[0]) # [Xscale0], [Munit/Xscale0^2] # verified that indeed the stored files in the run directory are used gp.xipol = Radii * gp.Xscale[0] # [pc] maxR = max(Radii) # [pc] minR = min(Radii) # [pc] Radii = np.hstack([minR/8, minR/4, minR/2, Radii, 2*maxR, 4*maxR, 8*maxR]) gp.xepol = Radii * gp.Xscale[0] # [pc] pcall.set_x0(gp.xepol, Binmin*gp.Xscale[0], Binmax*gp.Xscale[0]) # [pc] #if gp.investigate == 'obs': #pc.calculate_J(gp) if gp.investigate =='walk' or gp.investigate=='gaia' or gp.investigate =='triax': r0analytic = np.logspace(np.log10(1.), np.log10(max(gp.xepol)), 100) pcall.set_analytic(r0analytic, gp)
def read_Sig(self, gp): for pop in np.arange(gp.pops+1): print('read_Sig on file ', gp.files.Sigfiles[pop]) Sigx, binmin, binmax, Sigdat, Sigerr = gh.readcol5(gp.files.Sigfiles[pop]) # 3*[rscale], [Sig0], [Sig0] # switch to Munit (msun) and pc here Sigx = Sigx[:] * gp.Xscale[pop] # [pc] Sigdat = Sigdat[:] * gp.Sig0pc[pop] # [Munit/pc^2] Sigerr = Sigerr[:] * gp.Sig0pc[pop] # [Munit/pc^2] # take the overall bins for rbin, binmin, binmax vals if pop == 0: self.rbin = Sigx # [pc] self.binmin = binmin * gp.Xscale[pop] # [pc] self.binmax = binmax * gp.Xscale[pop] # [pc] gp.xipol = self.rbin # [pc] minr = min(self.rbin) # [pc] maxr = max(self.rbin) # [pc] gp.xepol = np.hstack([minr/8., minr/4., minr/2., self.rbin, 2*maxr, 4*maxr, 8*maxr]) # [pc] gp.xfine = introduce_points_in_between(gp.xepol, gp) # deproject, # takes [pc], 2* [Munit/pc^2], gives [pc], 2* [Munit/pc^3], # already normalized to same total mass if gp.geom == 'sphere': Sigdatnu, Sigerrnu = gh.complete_nu(self.rbin, Sigdat, Sigerr, gp.xfine) dummyx, nudatnu, nuerrnu, Mrnu = gip.Sig_NORM_rho(gp.xfine, Sigdatnu, Sigerrnu, gp) self.nu_epol.append(gh.linipollog(gp.xfine, nudatnu, gp.xepol)) self.nuerr_epol.append(gh.linipollog(gp.xfine, nuerrnu, gp.xepol)) nudat = gh.linipollog(gp.xfine, nudatnu, gp.xipol) nuerr = gh.linipollog(gp.xfine, nuerrnu, gp.xipol) Mr = gh.linipollog(gp.xfine, Mrnu, gp.xipol) self.Mr.append(Mr) # [Munit] Mhalf = Mr[-1]/2. # [Munit] self.Mhalf.append(Mhalf) # [Munit] # spline interpolation with M as x axis, to get half-mass of system: splpar_M = splrep(np.log(Mr), np.log(self.binmax), s=0.01) r_half = np.exp(splev(np.log(Mhalf), splpar_M)) # [pc] self.rhalf.append(r_half) # [pc] # spline interpolation of nu at r_half: splpar_nu = splrep(np.log(gp.xipol), np.log(nudat), s=0.01) nuhalf = np.exp(splev(np.log(r_half), splpar_nu)) # [pc] self.nuhalf.append(nuhalf) # [Munit/pc^3] # calculate n(r) parameters as used in gi_physics from the nu(r) profile rleft = gp.xfine[gp.xfine <= r_half] rleft = rleft[::-1] rright= gp.xfine[gp.xfine > r_half] nuleft = nudatnu[gp.xfine <= r_half] nuleft = nuleft[::-1] nuright = nudatnu[gp.xfine > r_half] rlast = 1.*r_half nulast = 1.*nuhalf sloperight = [] for r0 in rright: i = np.argmin(np.abs(rright - r0)) Deltanu = -(np.log(nuright[i]) - np.log(nulast)) Deltar = np.log(rright[i]) - np.log(rlast) sloperight.append(Deltanu/Deltar) nulast = nuright[i] rlast = rright[i] rlast = 1.*r_half nulast = 1.*nuhalf slopeleft = [] # work through the array from the left, from r_half for r0 in rleft: i = np.argmin(np.abs(rleft - r0)) Deltanu = np.log(nuleft[i]) - np.log(nulast) Deltar = np.log(rlast) - np.log(rleft[i]) slopeleft.append(Deltanu/Deltar) nulast = nuleft[i] rlast = rleft[i] # inverse order of slopeleft to have it sorted according increasing r slopeleft = slopeleft[::-1] slopes = np.hstack([slopeleft, sloperight]) nrpar = 1.*slopes[:-1] # Deltalogr = np.log(gp.xfine[1:]) - np.log(gp.xfine[:-1]) # nrpar = (slopes[1:]-slopes[:-1])/Deltalogr spl_nrpar = splrep(gp.xfine[:-1], nrpar, k=1) nre = splev( gp.xipol, spl_nrpar) extleft = splev(gp.xepol[0:3], spl_nrpar) # np.array([nrpar[0], nrpar[0], nrpar[0]]) extright = splev(gp.xepol[-3:], spl_nrpar) #[nrpar[-1], nrpar[-1], nrpar[-1]]) maxnre = max(nre) self.nrnu.append(np.hstack([nuhalf, nre[0], extleft, nre, extright, nre[-1]])) # checking for correct n(r) profile, have to wait for pop==1 # if pop==1: # from pylab import plot, xscale # import gi_analytic as ga # testnu = ga.rho_gaia(gp.xfine,gp)[pop] # testnrnu = -gh.derivipol(np.log(testnu), np.log(gp.xfine)) # plot(gp.xfine, testnrnu, 'b-') # plot(gp.xfine[:-1], nrpar, 'r.-') # xscale('log') errnre = np.ones(1+len(extleft)+len(nre)+len(extright)+1)*maxnre/10. for k in np.arange(1,4): errnre[k-1] *= 5 errnre[-k] *= 5 self.nrnuerr.append(np.hstack([nuhalf/3., errnre])) # import gi_physics as phys # from pylab import loglog, axvline, axhline, plot, xscale, clf # loglog(gp.xepol, self.nu_epol[0], 'b.-', lw=1) # axvline(r_half) # axhline(nuhalf) # rh = phys.rho(gp.xepol, self.nrnu, 0, gp) # rhmin = phys.rho(gp.xepol, self.nrnu - self.nrnuerr, 0, gp) # rhmax = phys.rho(gp.xepol, self.nrnu + self.nrnuerr, 0, gp) # loglog(gp.xepol, rh, 'r.-', linewidth=2) # loglog(gp.xepol, rhmin, 'g.-') # loglog(gp.xepol, rhmax, 'g--') # clf() # plot(gp.xfine[:-1], nrpar, '.-') # plot(gp.xipol, nre, '.-') # xscale('log') # axvline(r_half) # print(nrpar) else: gh.LOG(1, 'working in disc symmetry: reading nu directly') dummy1, dummy2, dummy3, nudat, nuerr = \ gh.readcol5(gp.files.nufiles[pop]) self.nuhalf.append(nudat[round(len(nudat)/2)]) #HS ToDo: check validity of this self.Sig.append(Sigdat) # [Munit/pc^2] self.Sigerr.append(Sigerr) # [Munit/pc^2] self.barSig.append(np.mean(Sigerr)) self.nu.append(nudat) # [Munit/pc^3] self.nuerr.append(nuerr) # [Munit/pc^3] return
def read_Sig(self, gp): for pop in np.arange(gp.pops + 1): print('read_Sig on file ', gp.files.Sigfiles[pop]) Sigx, binmin, binmax, Sigdat, Sigerr = gh.readcol5( gp.files.Sigfiles[pop]) # 3*[rscale], [Sig0], [Sig0] # switch to Munit (msun) and pc here Sigx = Sigx[:] * gp.Xscale[pop] # [pc] Sigdat = Sigdat[:] * gp.Sig0pc[pop] # [Munit/pc^2] Sigerr = Sigerr[:] * gp.Sig0pc[pop] # [Munit/pc^2] # take the overall bins for rbin, binmin, binmax vals if pop == 0: self.rbin = Sigx # [pc] self.binmin = binmin * gp.Xscale[pop] # [pc] self.binmax = binmax * gp.Xscale[pop] # [pc] gp.xipol = self.rbin # [pc] minr = min(self.rbin) # [pc] maxr = max(self.rbin) # [pc] gp.xepol = np.hstack([ minr / 8., minr / 4., minr / 2., self.rbin, 2 * maxr, 4 * maxr, 8 * maxr ]) # [pc] gp.xfine = introduce_points_in_between(gp.xepol, gp) # deproject, # takes [pc], 2* [Munit/pc^2], gives [pc], 2* [Munit/pc^3], # already normalized to same total mass if gp.geom == 'sphere': Sigdatnu, Sigerrnu = gh.complete_nu(self.rbin, Sigdat, Sigerr, gp.xfine) dummyx, nudatnu, nuerrnu, Mrnu = gip.Sig_NORM_rho( gp.xfine, Sigdatnu, Sigerrnu, gp) self.nu_epol.append(gh.linipollog(gp.xfine, nudatnu, gp.xepol)) self.nuerr_epol.append( gh.linipollog(gp.xfine, nuerrnu, gp.xepol)) nudat = gh.linipollog(gp.xfine, nudatnu, gp.xipol) nuerr = gh.linipollog(gp.xfine, nuerrnu, gp.xipol) Mr = gh.linipollog(gp.xfine, Mrnu, gp.xipol) self.Mr.append(Mr) # [Munit] Mhalf = Mr[-1] / 2. # [Munit] self.Mhalf.append(Mhalf) # [Munit] # spline interpolation with M as x axis, to get half-mass of system: splpar_M = splrep(np.log(Mr), np.log(self.binmax), s=0.01) r_half = np.exp(splev(np.log(Mhalf), splpar_M)) # [pc] self.rhalf.append(r_half) # [pc] # spline interpolation of nu at r_half: splpar_nu = splrep(np.log(gp.xipol), np.log(nudat), s=0.01) nuhalf = np.exp(splev(np.log(r_half), splpar_nu)) # [pc] self.nuhalf.append(nuhalf) # [Munit/pc^3] # calculate n(r) parameters as used in gi_physics from the nu(r) profile rleft = gp.xfine[gp.xfine <= r_half] rleft = rleft[::-1] rright = gp.xfine[gp.xfine > r_half] nuleft = nudatnu[gp.xfine <= r_half] nuleft = nuleft[::-1] nuright = nudatnu[gp.xfine > r_half] rlast = 1. * r_half nulast = 1. * nuhalf sloperight = [] for r0 in rright: i = np.argmin(np.abs(rright - r0)) Deltanu = -(np.log(nuright[i]) - np.log(nulast)) Deltar = np.log(rright[i]) - np.log(rlast) sloperight.append(Deltanu / Deltar) nulast = nuright[i] rlast = rright[i] rlast = 1. * r_half nulast = 1. * nuhalf slopeleft = [] # work through the array from the left, from r_half for r0 in rleft: i = np.argmin(np.abs(rleft - r0)) Deltanu = np.log(nuleft[i]) - np.log(nulast) Deltar = np.log(rlast) - np.log(rleft[i]) slopeleft.append(Deltanu / Deltar) nulast = nuleft[i] rlast = rleft[i] # inverse order of slopeleft to have it sorted according increasing r slopeleft = slopeleft[::-1] slopes = np.hstack([slopeleft, sloperight]) nrpar = 1. * slopes[:-1] # Deltalogr = np.log(gp.xfine[1:]) - np.log(gp.xfine[:-1]) # nrpar = (slopes[1:]-slopes[:-1])/Deltalogr spl_nrpar = splrep(gp.xfine[:-1], nrpar, k=1) nre = splev(gp.xipol, spl_nrpar) extleft = splev( gp.xepol[0:3], spl_nrpar) # np.array([nrpar[0], nrpar[0], nrpar[0]]) extright = splev( gp.xepol[-3:], spl_nrpar) #[nrpar[-1], nrpar[-1], nrpar[-1]]) maxnre = max(nre) self.nrnu.append( np.hstack( [nuhalf, nre[0], extleft, nre, extright, nre[-1]])) # checking for correct n(r) profile, have to wait for pop==1 # if pop==1: # from pylab import plot, xscale # import gi_analytic as ga # testnu = ga.rho_gaia(gp.xfine,gp)[pop] # testnrnu = -gh.derivipol(np.log(testnu), np.log(gp.xfine)) # plot(gp.xfine, testnrnu, 'b-') # plot(gp.xfine[:-1], nrpar, 'r.-') # xscale('log') errnre = np.ones(1 + len(extleft) + len(nre) + len(extright) + 1) * maxnre / 10. for k in np.arange(1, 4): errnre[k - 1] *= 5 errnre[-k] *= 5 self.nrnuerr.append(np.hstack([nuhalf / 3., errnre])) # import gi_physics as phys # from pylab import loglog, axvline, axhline, plot, xscale, clf # loglog(gp.xepol, self.nu_epol[0], 'b.-', lw=1) # axvline(r_half) # axhline(nuhalf) # rh = phys.rho(gp.xepol, self.nrnu, 0, gp) # rhmin = phys.rho(gp.xepol, self.nrnu - self.nrnuerr, 0, gp) # rhmax = phys.rho(gp.xepol, self.nrnu + self.nrnuerr, 0, gp) # loglog(gp.xepol, rh, 'r.-', linewidth=2) # loglog(gp.xepol, rhmin, 'g.-') # loglog(gp.xepol, rhmax, 'g--') # clf() # plot(gp.xfine[:-1], nrpar, '.-') # plot(gp.xipol, nre, '.-') # xscale('log') # axvline(r_half) # print(nrpar) else: gh.LOG(1, 'working in disc symmetry: reading nu directly') dummy1, dummy2, dummy3, nudat, nuerr = \ gh.readcol5(gp.files.nufiles[pop]) self.nuhalf.append(nudat[round( len(nudat) / 2)]) #HS ToDo: check validity of this self.Sig.append(Sigdat) # [Munit/pc^2] self.Sigerr.append(Sigerr) # [Munit/pc^2] self.barSig.append(np.mean(Sigerr)) self.nu.append(nudat) # [Munit/pc^3] self.nuerr.append(nuerr) # [Munit/pc^3] return