Example #1
0
 def onMass(self, event):
     print(" ")
     print("find DM mass and star mass (if present)")
     nstop = mys.get_nstop()
     d = mys.d(nstop)
     print("m_dm = ")
     my.run_command("get_sphere_dm -inp "+d+" -xc 0.5 -yc 0.5 -zc 0.5 -rc 0.001|head -n1|cut -d'.' -f1,2|rev|cut -d' ' -f2-|rev")
     print("m_star = ")
     my.run_command("get_sphere_stars -inp "+d+" -xc 0.5 -yc 0.5 -zc 0.5 -rc 0.01|head -n1|cut -d'.' -f1,2|rev|cut -d' ' -f2-|rev")
     my.done()
Example #2
0
 def onShowHalos(self, event):
     nstart,nstop = mys.get_range()
     nstart = nstop #! show only latest snapshot
     for nc in range(nstop-nstart+1):
         nsnap = nc + nstart
         if(not mys.snap_exists(nsnap)):
             continue
         cmd = "vis_AHF_centers.py "+str(nsnap)+" && xview "+mys.d(nsnap)+"ov.dat.png"
         print(cmd)
         my.thread(cmd)
         exit
Example #3
0
 def onGenAOI(self, event):
     nstart,nstop=mys.get_range()
     for nc in range(nstop-nstart+1):
         nsnap = nc + nstart
         if(not mys.snap_exists(nsnap)):
             continue
         d  = mys.d(nsnap)
         my.mkdir(d+"stars")
         my.mkdir(d+"dm")
         cmd = "gen_spheres.py "+str(nsnap)+" 2" # 1 at end: centers from AHF. 2: after shrinking sphere
         my.run(cmd)
     my.done()
Example #4
0
 def onShowHalos(self, event):
     nstart, nstop = mys.get_range()
     nstart = nstop  #! show only latest snapshot
     for nc in range(nstop - nstart + 1):
         nsnap = nc + nstart
         if (not mys.snap_exists(nsnap)):
             continue
         cmd = "vis_AHF_centers.py " + str(nsnap) + " && xview " + mys.d(
             nsnap) + "ov.dat.png"
         print(cmd)
         my.thread(cmd)
         exit
Example #5
0
 def onGenSpheres(self, event):
     nstart, nstop = mys.get_range()
     for nc in range(nstop - nstart + 1):
         nsnap = nc + nstart
         if (not mys.snap_exists(nsnap)):
             continue
         d = mys.d(nsnap)
         my.mkdir(d + "dm")
         if (not mys.is_dmonly()):
             my.mkdir(d + "stars")
         cmd = "cd " + d + " && gen_spheres.py " + str(nsnap) + " 1"
         my.run(cmd)
     my.done()
Example #6
0
 def onGenSpheres(self, event):
     nstart,nstop=mys.get_range()
     for nc in range(nstop-nstart+1):
         nsnap = nc + nstart
         if(not mys.snap_exists(nsnap)):
             continue
         d  = mys.d(nsnap)
         my.mkdir(d+"dm")
         if(not mys.is_dmonly()):
             my.mkdir(d+"stars");
         cmd = "cd "+d+" && gen_spheres.py "+str(nsnap)+" 1"
         my.run(cmd)
     my.done()
Example #7
0
 def onGenAOI(self, event):
     nstart, nstop = mys.get_range()
     for nc in range(nstop - nstart + 1):
         nsnap = nc + nstart
         if (not mys.snap_exists(nsnap)):
             continue
         d = mys.d(nsnap)
         my.mkdir(d + "stars")
         my.mkdir(d + "dm")
         cmd = "gen_spheres.py " + str(
             nsnap
         ) + " 2"  # 1 at end: centers from AHF. 2: after shrinking sphere
         my.run(cmd)
     my.done()
Example #8
0
 def onRunR2G(self, event):
     nstart,nstop=mys.get_range()
     print('nstart, nstop = ', nstart, nstop)
     for nc in range(nstop-nstart+1):
         nsnap = nc + nstart
         print('nsnap = ', nsnap)
         if(not mys.snap_exists(nsnap)):
             continue
         d = mys.d(nsnap)
         my.mkdir(d+"/r2g")
         if(mys.is_dmonly()):
             cmd = "mpirun -np 8 r2g -d "+d
         else:
             cmd = "mpirun -np 8 r2g -i "+d
         print(cmd)
         my.thread(cmd)
     self.SetBackgroundColour("darkgreen")
     my.done()
Example #9
0
 def onRunR2G(self, event):
     nstart, nstop = mys.get_range()
     print('nstart, nstop = ', nstart, nstop)
     for nc in range(nstop - nstart + 1):
         nsnap = nc + nstart
         print('nsnap = ', nsnap)
         if (not mys.snap_exists(nsnap)):
             continue
         d = mys.d(nsnap)
         my.mkdir(d + "/r2g")
         if (mys.is_dmonly()):
             cmd = "mpirun -np 8 r2g -d " + d
         else:
             cmd = "mpirun -np 8 r2g -i " + d
         print(cmd)
         my.thread(cmd)
     self.SetBackgroundColour("darkgreen")
     my.done()
Example #10
0
 def onFolderSetup(self, event):
     print(" ")
     print("folder setup")
     nstop = mys.getNmax()
     print('nstop = ',nstop)
     for nc in range(nstop):
         if(not mys.snap_exists(nc+1)):
             continue
         print("generating folders in output ",nc+1)
         d=mys.d(nc+1)
         print(d)
         my.mkdir(d+'amr');    my.mv(d+"amr_*",d+"amr")
         my.mkdir(d+'grav');   my.mv(d+"grav_*",d+'/grav')
         my.mkdir(d+'part');   my.mv(d+'part_*',d+'/part')
         if(not self.dmonly):
             print("create folder hydro as well")
             my.mkdir(d+'hydro');  my.mv(d+"hydro_*",d+'/hydro')
     self.SetBackgroundColour("darkgreen")
     my.done()
Example #11
0
import sys, os
import lib.mysql as mys

i = len(sys.argv)
if i! = 6:
    print("usage: gen_prof_stars.py sim xc yc zc r")
    print("example: gen_prof_stars.py 270 0.5 0.5 0.5 0.05")
    sys.exit()

rout = 1 # * rvir from AHF for maximal radial distance to include particles from
show = True
run  = True

ddm = mys.simdir()+"/ana/stars/"
snap = sys.argv[1].zfill(5)
outp = mys.d(snap)

xc = sys.argv[2]; yc = sys.argv[3]; zc = sys.argv[4]
r = str(float(sys.argv[5])*rout)

os.nice(0)

# stars
cmd = "get_sphere_stars -inp "+outp
cmd +=" -xc "+xc+" -yc "+yc+" -zc "+zc+" -rc "+r+"> "+ddm+"stars_"+snap+".dat"
cmd += " && octreef "+ddm+"stars_"+snap+".dat > "+ddm+"rho_"+snap+".dat"
if(show): print(cmd)
if(run): os.system(cmd)

cmd = "get_prof_sph.py "+ddm+"rho_"+snap+".dat "+xc+" "+yc+" "+zc+" "+r+" > "+ddm+"prof_"+snap+".dat"
if(show): print(cmd)
Example #12
0
run = True
loop = True

gsd = "get_sphere_dm"
gss = "get_sphere_stars"

i = len(sys.argv)
if(i!=3):
    print("usage: gen_spheres.py snap typ")
    exit(1)

facr = 1 # * rvir from AHF for maximal radial distance to include particles

snap = sys.argv[1]
typ = int(sys.argv[2])
sim = mys.d(snap)

# get xc,yc,zc,mvir,rvir
xcl, ycl, zcl, mvirl,rvirl = mys.getxyzmr(snap, typ)
xsl, ysl, zsl, rsl = mys.getxyzrstars(snap, typ)
pdb.set_trace()
#print('select ',xcl[0])
#print(len(xcl))

for i in range(3):
    xc=str(xcl[i]);       xs=str(xsl[i]);
    yc=str(ycl[i]);       ys=str(ysl[i]);
    zc=str(zcl[i]);       zs=str(zsl[i]);
    r=str(rvirl[i]*facr); rs=str(rsl[i]*facr*0.9);
    sj=str(i+1)
Example #13
0
#!/usr/bin/env python2

## \file
# after AHF has finished, fill found halo values into MySQL database

# (c) 2015 ETHZ, Pascal Steger, [email protected]

import os, sys
import lib.mysql as mys
import lib.initialize as my

nsnap = int(sys.argv[1])
d = mys.d(nsnap)

# reading center, rvir, make comoving again
if (not os.path.exists(d + "halos")):
    exit

co, cu = my.sqlstart()

halos = open(d + "halos", "r")
hid = 0
for line in halos:
    if (line[0] == "#"):
        continue
    hid = hid + 1
    val = line.split()
    mys.fill_halo(nsnap, hid, val, co, cu)

    # if less than 100 particles in halo
    # if nvpart (mass in internal units)/npart = fmhires < 5 (arbitrary! but excludes halos with many lowres particles)
Example #14
0
# (c) 2014 ETHZ, Pascal Steger, [email protected]

import sys
import lib.initialize as my
import lib.mysql as mys
from numpy import zeros

if(len(sys.argv)!=3):
    print("usage: merger_tree.py snap1 snap2")
    print("assumption: output_00snap1,2 contain particles_dm in AHF format")
    exit(1)

snap1 = int(sys.argv[1]); snap2 = int(sys.argv[2])

# read in halos repeatedly
fname=mys.d(snap1)+"particles_dm"
print('file = ', fname)
in1 = my.open_file(fname,"r")
alm1 = int(in1.readline())
size1 = []; split1 = []
for i in range(alm1):
    size = int(in1.readline())
    size1.append(size)
    part = []
    for c in range(size):
        part.append(int(in1.readline()))
    split1.append(part)
in1.close()

in2 = my.open_file(mys.d(snap2)+"particles_dm","r")
alm2 = int(in2.readline())
    print("shrink_sphere.py snap hid")
    exit(0)

snap=int(sys.argv[1])
hid=int(sys.argv[2])

eps=1e-5
frad = 0.9 # shrinked sphere has radius frad*maxr, i.e. frad = 0.90 means 10% smaller

#print("missing file")
if(not mys.exists_snap(snap)):
    print("snapshot "+str(snap)+" missing")
    exit(0)

xc,yc,zc,mvir,rvir=mys.getxyzmr(snap,1)
halo = my.open_file(mys.d(snap)+"stars/stars_"+str(hid)+".dat","r")
x=[];y=[];z=[];m=[]
for line in halo:
    val=line.split()
    m.append(float(val[0]))
    x.append(float(val[1]))
    y.append(float(val[2]))
    z.append(float(val[3]))

x = array(x); y = array(y); z = array(z); m = array(m)
#print(x)

def converged(xc,yc,zc,xc2,yc2,zc2):
    return  abs(xc-xc2)/abs(xc)   < eps \
        and abs(yc-yc2)/abs(yc)   < eps \
        and abs(zc-zc2)/abs(zc)   < eps #\
Example #16
0
os.nice(10)

show= True; run = True; loop=True

# choose: get_particles    for all particles
#         get_particles_dm for dm  particles only
gps = "get_particles"

i = len(sys.argv)
if(i!=2):
    print("usage: gen_particles_list.py snap")
    exit(1)
    
facr = 1 # * rvir from AHF for maximal radial distance to include particles
snap = int(sys.argv[1])
d    = mys.d(snap)
pdm = d+"particles_dm"
xl,yl,zl,ml,rl = mys.getxyzmr(snap,2)

nhalo= mys.get_nhalo(snap)
os.system("rm "+d+"particles_dm")
os.system("echo '"+str(nhalo)+"' >> "+pdm)

for i in range(len(xl)):
    xc=str(xl[i]); yc=str(yl[i]); zc=str(zl[i]); r=str(facr*rl[i])
    tmpdat = d+"tmp_"+str(i+1)+".dat"

    # all particles (DM/stars mixed)
    cmd1 = gps+" -inp "+d
    cmd1 += " -xc " + xc + " -yc " + yc + " -zc " + zc + " -r " + r
    cmd1 += ">" + tmpdat
Example #17
0
    def onRunAHF(self,event):
        nstart,nstop=mys.get_range()
        print('nstart, nstop: ',nstart, nstop)
        for nc in range(nstop-nstart+1):
            nsnap = nc + nstart
            print('nsnap = ', nsnap)
            if(not mys.snap_exists(nsnap)):
                continue
            d  = mys.d(nsnap)
            f = open(d+"AHFinput","w")

            f.write("[AHF]\n\
\n\
# (stem of the) filename from which to read the data to be analysed\n\
ic_filename       = r2g/r2g.\n\
\n\
# what type of input file (cf. src/libio/io_file.h)\n\
ic_filetype       = 61\n\
\n\
# prefix for the output files\n\
outfile_prefix    = testahf\n\
\n\
# number of grid cells for the domain grid (1D)\n\
LgridDomain       = 4\n\
\n\
# number of grid cells for the domain grid (1D) (limits spatial resolution to BoxSize/LgridMax)\n\
LgridMax          = 16777216\n\
\n\
# refinement criterion on domain grid (#particles/cell)\n\
NperDomCell       = 5.0\n\
\n\
# refinement criterion on all higher resolution grids (#particles/cells)\n\
NperRefCell       = 5.0\n\
\n\
# particles with velocity v > VescTune x Vesc are considered unbound\n\
VescTune          = 1.5\n\
\n\
# minimum number of particles for a halo\n\
NminPerHalo       = 100\n\
\n\
# normalisation for densities (1: RhoBack(z), 0:RhoCrit(z))\n\
RhoVir            = 1\n\
\n\
# virial overdensity criterion (<0: let AHF calculate it); Rvir is defined via M(<Rvir)/Vol = Dvir * RhoVir\n\
Dvir              = 200\n\
#-1\n\
\n\
# maximum radius (in Mpc/h) used when gathering initial set of particles for each halo (should be larger than the largest halo expected)\n\
MaxGatherRad      = 0.2\n\
\n\
# the level on which to perform the domain decomposition (MPI only, 4=16^3, 5=32^3, 6=64^3, 7=128^3, 8=256^3, etc.)\n\
LevelDomainDecomp = 4\n\
\n\
# how many CPU's for reading (MPI only)\n\
NcpuReading       = 16\n\
\n\
############################### FILE SPECIFIC DEFINITIONS ###############################\n\
\n\
# NOTE: all these factors are supposed to transform your internal units to\n\
#           [x] = Mpc/h\n\
#           [v] = km/sec\n\
#           [m] = Msun/h\n\
#           [e] = (km/sec)^2\n\
\n\
[GADGET]\n\
GADGET_LUNIT      = 0.001\n\
GADGET_MUNIT      = 1.0E10\n")
            f.close()

            print("TODO: AHFinput written?")
            cmd = "cd "+d+" && AHF AHFinput"
            cmd += " && mv "+d+"*_halos "+d+"halos"
            cmd += " && mv "+d+"*_centres "+"centres"
            cmd += " && mv "+d+"*_particles "+d+"particles"
            cmd += " && mv "+d+"*_profiles "+d+"profiles"
            cmd += " && rm -f "+d+"halo"
            cmd += " && echo 'done'"
            print(cmd)
            my.thread(cmd)
        my.done()
Example #18
0
    def onRunAHF(self, event):
        nstart, nstop = mys.get_range()
        print('nstart, nstop: ', nstart, nstop)
        for nc in range(nstop - nstart + 1):
            nsnap = nc + nstart
            print('nsnap = ', nsnap)
            if (not mys.snap_exists(nsnap)):
                continue
            d = mys.d(nsnap)
            f = open(d + "AHFinput", "w")

            f.write("[AHF]\n\
\n\
# (stem of the) filename from which to read the data to be analysed\n\
ic_filename       = r2g/r2g.\n\
\n\
# what type of input file (cf. src/libio/io_file.h)\n\
ic_filetype       = 61\n\
\n\
# prefix for the output files\n\
outfile_prefix    = testahf\n\
\n\
# number of grid cells for the domain grid (1D)\n\
LgridDomain       = 4\n\
\n\
# number of grid cells for the domain grid (1D) (limits spatial resolution to BoxSize/LgridMax)\n\
LgridMax          = 16777216\n\
\n\
# refinement criterion on domain grid (#particles/cell)\n\
NperDomCell       = 5.0\n\
\n\
# refinement criterion on all higher resolution grids (#particles/cells)\n\
NperRefCell       = 5.0\n\
\n\
# particles with velocity v > VescTune x Vesc are considered unbound\n\
VescTune          = 1.5\n\
\n\
# minimum number of particles for a halo\n\
NminPerHalo       = 100\n\
\n\
# normalisation for densities (1: RhoBack(z), 0:RhoCrit(z))\n\
RhoVir            = 1\n\
\n\
# virial overdensity criterion (<0: let AHF calculate it); Rvir is defined via M(<Rvir)/Vol = Dvir * RhoVir\n\
Dvir              = 200\n\
#-1\n\
\n\
# maximum radius (in Mpc/h) used when gathering initial set of particles for each halo (should be larger than the largest halo expected)\n\
MaxGatherRad      = 0.2\n\
\n\
# the level on which to perform the domain decomposition (MPI only, 4=16^3, 5=32^3, 6=64^3, 7=128^3, 8=256^3, etc.)\n\
LevelDomainDecomp = 4\n\
\n\
# how many CPU's for reading (MPI only)\n\
NcpuReading       = 16\n\
\n\
############################### FILE SPECIFIC DEFINITIONS ###############################\n\
\n\
# NOTE: all these factors are supposed to transform your internal units to\n\
#           [x] = Mpc/h\n\
#           [v] = km/sec\n\
#           [m] = Msun/h\n\
#           [e] = (km/sec)^2\n\
\n\
[GADGET]\n\
GADGET_LUNIT      = 0.001\n\
GADGET_MUNIT      = 1.0E10\n")
            f.close()

            print("TODO: AHFinput written?")
            cmd = "cd " + d + " && AHF AHFinput"
            cmd += " && mv " + d + "*_halos " + d + "halos"
            cmd += " && mv " + d + "*_centres " + "centres"
            cmd += " && mv " + d + "*_particles " + d + "particles"
            cmd += " && mv " + d + "*_profiles " + d + "profiles"
            cmd += " && rm -f " + d + "halo"
            cmd += " && echo 'done'"
            print(cmd)
            my.thread(cmd)
        my.done()
Example #19
0
#!/usr/bin/env python2

## \file
# after AHF has finished, fill found halo values into MySQL database

# (c) 2015 ETHZ, Pascal Steger, [email protected]

import os, sys
import lib.mysql as mys
import lib.initialize as my

nsnap = int(sys.argv[1])
d = mys.d(nsnap)

# reading center, rvir, make comoving again
if(not os.path.exists(d+"halos")):
    exit

co, cu = my.sqlstart()

halos = open(d+"halos","r")
hid=0
for line in halos:
    if(line[0]=="#"):
        continue
    hid = hid+1
    val = line.split()
    mys.fill_halo(nsnap, hid, val, co, cu)

    # if less than 100 particles in halo
    # if nvpart (mass in internal units)/npart = fmhires < 5 (arbitrary! but excludes halos with many lowres particles)
Example #20
0
# (c) 2014 ETHZ, Pascal Steger, [email protected]

import sys
from numpy import zeros
import lib.initialize as my
import lib.mysql as mys

if(len(sys.argv)!=2):
    print("usage: substructure.py snap")
    print("assumption: output_snap contains particles_dm in AHF format")
    print("wrong number of arguments")
    exit(1)

snap = int(sys.argv[1])
# read in halos repeatedly
inf = my.open_file(mys.d(snap)+"particles_dm","r")
alm = int(inf.readline())
size = []; split = []
for i in range(alm):
    siz = int(inf.readline())
    size.append(siz)
    part = []
    for c in range(siz):
        part.append(int(inf.readline()))
    split.append(part)
inf.close()
print("read in successful")


def count_shared(m1,m2):
    cc = 0
Example #21
0
if (i != 3):
    print("shrink_sphere.py snap hid")
    exit(0)

snap = int(sys.argv[1])
hid = int(sys.argv[2])

eps = 1e-5
frad = 0.90  # shrinked sphere has radius frad*maxr, i.e. frad = 0.90 means 10% smaller

if (not mys.exists_snap(snap)):
    print("snapshot " + str(snap) + " missing")
    exit(0)

xc, yc, zc, mvir, rvir = mys.getxyzmr(snap, 1)
halo = my.open_file(mys.d(snap) + "dm/dm_" + str(hid) + ".dat", "r")
x = []
y = []
z = []
m = []
for line in halo:
    val = line.split()
    m.append(float(val[0]))
    x.append(float(val[1]))
    y.append(float(val[2]))
    z.append(float(val[3]))

x = array(x)
y = array(y)
z = array(z)
m = array(m)
Example #22
0
if RM == 4:
	SRM = "i"
elif RM == 8:
	SRM = "l"
else:
	print("Your choice of RM is unreasonable.")

i = len(sys.argv)

if i != 2:
	print("Incorrect Usage. Received ", i-1, " arguments.")
	print("$: vis_centers.py nsnap")
	sys.exit()

nsnap=int(sys.argv[1])
fname=mys.d(nsnap)+"/ov.dat"
cmd = part2map+" -inp "+mys.d(nsnap)+" -out "+fname+" -dir z -nx 1024 -ny 1024"
print(cmd)
os.system(cmd)

f = open(fname,'rb')
s = f.read(2*RM+struct.calcsize("2i"))
par,nx,ny,par = struct.unpack(SRM+"i"+"i"+SRM,s)

print("Found image size. ", nx,ny)
s = f.read(RM)
binvalues = ar.array(IMGSIZE)
binvalues.read(f,nx*ny)
data = np.array(binvalues,'float')
data = np.reshape(data,(ny,nx))
Example #23
0
if(i!=3):
    print("shrink_sphere.py snap hid")
    exit(0)

snap = int(sys.argv[1])
hid  = int(sys.argv[2])

eps = 1e-5
frad = 0.90 # shrinked sphere has radius frad*maxr, i.e. frad = 0.90 means 10% smaller

if(not mys.exists_snap(snap)):
    print("snapshot "+str(snap)+" missing")
    exit(0)

xc, yc, zc, mvir, rvir = mys.getxyzmr(snap,1)
halo = my.open_file(mys.d(snap)+"dm/dm_"+str(hid)+".dat","r")
x=[];y=[];z=[];m=[]
for line in halo:
    val=line.split()
    m.append(float(val[0]))
    x.append(float(val[1]))
    y.append(float(val[2]))
    z.append(float(val[3]))

x = array(x); y = array(y); z = array(z); m = array(m)
if(len(m)==0):
    print("no particles, skipping shrinking sphere")
    exit(0)

def converged(xc,yc,zc,xc2,yc2,zc2):
    print(max(abs(xc-xc2), abs(yc-yc2),abs(zc-zc2)))
Example #24
0
if RM == 4:
    SRM = "i"
elif RM == 8:
    SRM = "l"
else:
    print("Your choice of RM is unreasonable.")

i = len(sys.argv)

if i != 2:
    print("Incorrect Usage. Received ", i - 1, " arguments.")
    print("$: vis_centers.py nsnap")
    sys.exit()

nsnap = int(sys.argv[1])
fname = mys.d(nsnap) + "/ov.dat"
cmd = part2map + " -inp " + mys.d(
    nsnap) + " -out " + fname + " -dir z -nx 1024 -ny 1024"
print(cmd)
os.system(cmd)

f = open(fname, 'rb')
s = f.read(2 * RM + struct.calcsize("2i"))
par, nx, ny, par = struct.unpack(SRM + "i" + "i" + SRM, s)

print("Found image size. ", nx, ny)
s = f.read(RM)
binvalues = ar.array(IMGSIZE)
binvalues.read(f, nx * ny)
data = np.array(binvalues, 'float')
data = np.reshape(data, (ny, nx))
Example #25
0
    def OnPlot(self, event):
        print("plot")
        f=1 # scaling of sphere wrt rvir
        vis  = True; show = True; run  = True;
        my.mkdir(mys.simdir()+"/ana")
        ddm  = mys.simdir() + "/ana/dm/";    my.mkdir(ddm)
        dgas = mys.simdir() + "/ana/gas/";   my.mkdir(dgas)
        dstar= mys.simdir() + "/ana/stars/"; my.mkdir(dstar)
        dpd  = mys.simdir() + "/phasediag/"; my.mkdir(dpd)
        nstart,nstop=mys.get_range()
        x,y,z,r,snap=mys.getxyzrsnap(nstop)#TODO: nstart,nstop
        xs,ys,zs,rs,snap=mys.getxyzrsnap_stars(nstart,nstop)
        #x,y,z,r,snap=mys.mt_xyzrsnap(nstart,nstop)
        #xs,ys,zs,rs,snap=mys.mt_xyzrsnap_stars(nstart,nstop)
        for i in range(nstop-nstart+1):
            nc = nstop-i
            if(not mys.snap_exists(nc)):
                continue
            stri=str(nc).zfill(5)
            print("nc = ",nc)
            print(x[i], xs[i])
            print(y[i], ys[i])
            print(z[i], zs[i])
            print(r[i], rs[i])
            d = mys.d(nc)
            # scale
            if self.fix:
                r[i]=0.002; rs[i]=0.002;

            sx = str(x[i])
            sy = str(y[i])
            sz = str(z[i])
            sr = str(r[i])
            ssx= str(sx[i])
            ssy= str(ys[i])
            ssz= str(sz[i])
            ssr= str(rs[i])
            lma = str(mys.get_lma())
            bndry  = " "+sx+" "+sy+" "+sz+" "+sr+" "
            bndryc =" -xc "+sx+" -yc "+sy+" -zc "+sz+" -rc "+sr+" "

            #calc all pix, dep. on which option was clicked
            if self.radio==0:
                print("gas density")
                ofname = dgas+"gas_boxall_"+stri+".png"
                cmd1 = amr2map+" -typ 1 -lma "+lma+" -inp "+d+" -out "+dgas+"gas_boxall_"+stri
                cmd1 = cmd1 +".dat -dir z "+bndryc
                cmd2 = "map2img.py -l --colormap=hot "+dgas+"gas_boxall_"+stri+".dat "
                cmd2 = cmd2+"-o "+ofname+" && xview "+ofname
                print(dgas+"gas_boxall_"+stri+".png")
                my.threadif(cmd1,cmd2,self.calc,vis,show,run)

            if self.radio==1:
                print("gas pressure")
                if(mys.is_dmonly()):
                    print("not available, dm only simulation!")
                    exit
                cmd1 = amr2map + " -typ 5 -lma "+lma+" -inp "+d
                cmd1 = cmd1+" -out "+dgas+"p_"+stri+".dat "+"-dir z "+bndryc
                cmd2 = "map2img.py -l --colormap=hot "+dgas+"p_"+stri+".dat "
                ofname = dgas+"p_"+stri+".png"
                cmd2 = cmd2+" -o "+ofname+" && xview "+ofname
                my.threadif(cmd1,cmd2,self.calc,vis,show,run)

            if self.radio==2:
                print("gas temperature")
                cmd1 = amr2map+" -typ 18 -lma "+lma+" -inp "+d
                cmd1 = cmd1+" -out "+dgas+"temp_"+stri+".dat "+"-dir z "+bndryc
                cmd2 = "map2img.py -l --colormap=hot "+dgas+"temp_"+stri+".dat "
                ofname = dgas+"temp_"+stri+".png"
                cmd2 = cmd2+" -o "+ofname+" && xview "+ofname
                my.threadif(cmd1,cmd2,self.calc,vis,show,run)

            if self.radio==3:
                print("DM contours")
                # get DM particle positions for each halo
                cmd1 = "get_sphere_dm -inp "+d+bndryc+" > "+ddm+"dm_"+stri+".dat"
                cmd1+= "&& octreef "+ddm+"dm_"+stri+".dat > "+ddm+"rho_"+stri+".dat"
                cmd2 ="vis_part_proj_dm.py "+bndry+" "\
                       +ddm+"dm_"+stri+".dat "+ddm+"dm_part_"+stri+".png"
                ofname=ddm+"rho_"+stri+".dat "+ddm+"contour_"+stri+".png"
                cmd2+="; vis_dm_contour.py "+bndry+" "\
                       +ofname+" && xview "+ofname
                my.threadif(cmd1,cmd2,self.calc,vis,show,run)

            if self.radio==4:
                print("metallicity")
                #cmd = "vis_parts.py stars.part"
                #cmd = "get_sphere_stars -inp "+d\
                #+" -xc "+sx+" -yc "+sy+" -zc "+sz+" -r "+sr+">ana/stars/stars_"+stri
                cmd1 = "metal2map -inp "+d+" -out "+dstar+"stars_"+stri+".dat "
                cmd1 = cmd1+"-nx 512 -ny 512 -dir z "+bndryc
                cmd2 = "map2img.py -l --colormap=jet "+dstar+"stars_"+stri+".dat "
                ofname = dstar+"stars_"+stri+".png"
                cmd2 = cmd2+"-o "+ofname+" && xview "+ofname
                my.threadif(cmd1,cmd2,self.calc,vis,show,run)

            if self.radio==5:
                print("phase diagram")
                fn = dpd+"temp_"+str(nc).zfill(5)
                cmd1 = "get_temp -inp "+d+" -out "+fn
                cmd1+=  " -lma "+lma+" -typ 18"
                ofname=fn+".png"
                cmd2 = "plot_temp_rho.py "+fn+" "+ofname+" && xview "+ofname
                my.threadif(cmd1,cmd2,self.calc,vis,show,run)

            if self.radio==6:
                print("rho_dm(r)")
                cmd1 = "gen_prof_dm.py "+str(nc)+" "+sx+" "+sy+" "+sz+" "+sr;
                ofname = ddm+"prof_"+stri+".png "
                cmd2 = "plot_prof_sph.py "+ddm+"prof_"+stri+".dat "\
                       +ddm+"rho_"+stri+".dat "\
                       +ofname+sx+" "+sy+" "+sz+" "+str(mys.get_z(nc))+"&& xview "+ofname
                my.threadif(cmd1,cmd2,self.calc,vis,show,run)


            if self.radio==7:
                print("rho_gas(r)")
                cmd1 = "gen_prof_gas.py "+str(nc)+" "+sx+" "+sy+" "+sz+" "+sr+" "+lma;
                ofname = dgas+"prof_"+stri+".png "
                cmd2 = "plot_prof_sph.py "+dgas+"prof_"+stri+".dat "\
                       +dgas+"rho_"+stri+".dat "\
                       +ofname+sx+" "+sy+" "+sz+" && xview "+ofname
                my.threadif(cmd1,cmd2,self.calc,vis,show,run)


            if self.radio==8:
                print("rho_star(r)")
                cmd1 = "gen_prof_stars.py "+str(nc)+" "+sx+" "+sy+" "+sz+" "+sr;
                ofname = dstar+"prof_"+stri+".png "
                cmd2 = "plot_prof_sph.py "+dstar+"prof_"+stri+".dat "\
                       +dstar+"rho_"+stri+".dat "\
                       +ofname+sx+" "+sy+" "+sz+" && xview "+ofname
                my.threadif(cmd1,cmd2,self.calc,vis,show,run)

            if self.radio==9:
                print("SFR")
                cmd1 = "count_stars -inp "+d+bndryc+" >> "+dstar+"star_counts.dat"
                #cmd2 = "plot_columns.py star_counts.dat 1 4"
                cmd2 = "calc_sfr.py "+dstar+"star_counts.dat 0 4"
                my.threadif(cmd1,cmd2,self.calc,vis,show,run)

            if(not self.loop):
                break
        my.done()
Example #26
0
    def OnPlot(self, event):
        print("plot")
        f = 1  # scaling of sphere wrt rvir
        vis = True
        show = True
        run = True
        my.mkdir(mys.simdir() + "/ana")
        ddm = mys.simdir() + "/ana/dm/"
        my.mkdir(ddm)
        dgas = mys.simdir() + "/ana/gas/"
        my.mkdir(dgas)
        dstar = mys.simdir() + "/ana/stars/"
        my.mkdir(dstar)
        dpd = mys.simdir() + "/phasediag/"
        my.mkdir(dpd)
        nstart, nstop = mys.get_range()
        x, y, z, r, snap = mys.getxyzrsnap(nstop)  #TODO: nstart,nstop
        xs, ys, zs, rs, snap = mys.getxyzrsnap_stars(nstart, nstop)
        #x,y,z,r,snap=mys.mt_xyzrsnap(nstart,nstop)
        #xs,ys,zs,rs,snap=mys.mt_xyzrsnap_stars(nstart,nstop)
        for i in range(nstop - nstart + 1):
            nc = nstop - i
            if (not mys.snap_exists(nc)):
                continue
            stri = str(nc).zfill(5)
            print("nc = ", nc)
            print(x[i], xs[i])
            print(y[i], ys[i])
            print(z[i], zs[i])
            print(r[i], rs[i])
            d = mys.d(nc)
            # scale
            if self.fix:
                r[i] = 0.002
                rs[i] = 0.002

            sx = str(x[i])
            sy = str(y[i])
            sz = str(z[i])
            sr = str(r[i])
            ssx = str(sx[i])
            ssy = str(ys[i])
            ssz = str(sz[i])
            ssr = str(rs[i])
            lma = str(mys.get_lma())
            bndry = " " + sx + " " + sy + " " + sz + " " + sr + " "
            bndryc = " -xc " + sx + " -yc " + sy + " -zc " + sz + " -rc " + sr + " "

            #calc all pix, dep. on which option was clicked
            if self.radio == 0:
                print("gas density")
                ofname = dgas + "gas_boxall_" + stri + ".png"
                cmd1 = amr2map + " -typ 1 -lma " + lma + " -inp " + d + " -out " + dgas + "gas_boxall_" + stri
                cmd1 = cmd1 + ".dat -dir z " + bndryc
                cmd2 = "map2img.py -l --colormap=hot " + dgas + "gas_boxall_" + stri + ".dat "
                cmd2 = cmd2 + "-o " + ofname + " && xview " + ofname
                print(dgas + "gas_boxall_" + stri + ".png")
                my.threadif(cmd1, cmd2, self.calc, vis, show, run)

            if self.radio == 1:
                print("gas pressure")
                if (mys.is_dmonly()):
                    print("not available, dm only simulation!")
                    exit
                cmd1 = amr2map + " -typ 5 -lma " + lma + " -inp " + d
                cmd1 = cmd1 + " -out " + dgas + "p_" + stri + ".dat " + "-dir z " + bndryc
                cmd2 = "map2img.py -l --colormap=hot " + dgas + "p_" + stri + ".dat "
                ofname = dgas + "p_" + stri + ".png"
                cmd2 = cmd2 + " -o " + ofname + " && xview " + ofname
                my.threadif(cmd1, cmd2, self.calc, vis, show, run)

            if self.radio == 2:
                print("gas temperature")
                cmd1 = amr2map + " -typ 18 -lma " + lma + " -inp " + d
                cmd1 = cmd1 + " -out " + dgas + "temp_" + stri + ".dat " + "-dir z " + bndryc
                cmd2 = "map2img.py -l --colormap=hot " + dgas + "temp_" + stri + ".dat "
                ofname = dgas + "temp_" + stri + ".png"
                cmd2 = cmd2 + " -o " + ofname + " && xview " + ofname
                my.threadif(cmd1, cmd2, self.calc, vis, show, run)

            if self.radio == 3:
                print("DM contours")
                # get DM particle positions for each halo
                cmd1 = "get_sphere_dm -inp " + d + bndryc + " > " + ddm + "dm_" + stri + ".dat"
                cmd1 += "&& octreef " + ddm + "dm_" + stri + ".dat > " + ddm + "rho_" + stri + ".dat"
                cmd2 ="vis_part_proj_dm.py "+bndry+" "\
                       +ddm+"dm_"+stri+".dat "+ddm+"dm_part_"+stri+".png"
                ofname = ddm + "rho_" + stri + ".dat " + ddm + "contour_" + stri + ".png"
                cmd2+="; vis_dm_contour.py "+bndry+" "\
                       +ofname+" && xview "+ofname
                my.threadif(cmd1, cmd2, self.calc, vis, show, run)

            if self.radio == 4:
                print("metallicity")
                #cmd = "vis_parts.py stars.part"
                #cmd = "get_sphere_stars -inp "+d\
                #+" -xc "+sx+" -yc "+sy+" -zc "+sz+" -r "+sr+">ana/stars/stars_"+stri
                cmd1 = "metal2map -inp " + d + " -out " + dstar + "stars_" + stri + ".dat "
                cmd1 = cmd1 + "-nx 512 -ny 512 -dir z " + bndryc
                cmd2 = "map2img.py -l --colormap=jet " + dstar + "stars_" + stri + ".dat "
                ofname = dstar + "stars_" + stri + ".png"
                cmd2 = cmd2 + "-o " + ofname + " && xview " + ofname
                my.threadif(cmd1, cmd2, self.calc, vis, show, run)

            if self.radio == 5:
                print("phase diagram")
                fn = dpd + "temp_" + str(nc).zfill(5)
                cmd1 = "get_temp -inp " + d + " -out " + fn
                cmd1 += " -lma " + lma + " -typ 18"
                ofname = fn + ".png"
                cmd2 = "plot_temp_rho.py " + fn + " " + ofname + " && xview " + ofname
                my.threadif(cmd1, cmd2, self.calc, vis, show, run)

            if self.radio == 6:
                print("rho_dm(r)")
                cmd1 = "gen_prof_dm.py " + str(
                    nc) + " " + sx + " " + sy + " " + sz + " " + sr
                ofname = ddm + "prof_" + stri + ".png "
                cmd2 = "plot_prof_sph.py "+ddm+"prof_"+stri+".dat "\
                       +ddm+"rho_"+stri+".dat "\
                       +ofname+sx+" "+sy+" "+sz+" "+str(mys.get_z(nc))+"&& xview "+ofname
                my.threadif(cmd1, cmd2, self.calc, vis, show, run)

            if self.radio == 7:
                print("rho_gas(r)")
                cmd1 = "gen_prof_gas.py " + str(
                    nc) + " " + sx + " " + sy + " " + sz + " " + sr + " " + lma
                ofname = dgas + "prof_" + stri + ".png "
                cmd2 = "plot_prof_sph.py "+dgas+"prof_"+stri+".dat "\
                       +dgas+"rho_"+stri+".dat "\
                       +ofname+sx+" "+sy+" "+sz+" && xview "+ofname
                my.threadif(cmd1, cmd2, self.calc, vis, show, run)

            if self.radio == 8:
                print("rho_star(r)")
                cmd1 = "gen_prof_stars.py " + str(
                    nc) + " " + sx + " " + sy + " " + sz + " " + sr
                ofname = dstar + "prof_" + stri + ".png "
                cmd2 = "plot_prof_sph.py "+dstar+"prof_"+stri+".dat "\
                       +dstar+"rho_"+stri+".dat "\
                       +ofname+sx+" "+sy+" "+sz+" && xview "+ofname
                my.threadif(cmd1, cmd2, self.calc, vis, show, run)

            if self.radio == 9:
                print("SFR")
                cmd1 = "count_stars -inp " + d + bndryc + " >> " + dstar + "star_counts.dat"
                #cmd2 = "plot_columns.py star_counts.dat 1 4"
                cmd2 = "calc_sfr.py " + dstar + "star_counts.dat 0 4"
                my.threadif(cmd1, cmd2, self.calc, vis, show, run)

            if (not self.loop):
                break
        my.done()