示例#1
0
def get_active_sim():
    cmd = "SELECT name FROM sim WHERE active=1;"
    # print("len = ",len(my.sql(cmd))
    if(len(my.sql(cmd))<1):
        return " "
    sim = my.sql(cmd)[0][0]
    return sim
示例#2
0
def set_ss_stars(snap,hid,xs_star,ys_star,zs_star,rs_star):
    cmd  = "UPDATE halo SET "
    cmd += "xs_star="+str(xs_star)+", "
    cmd += "ys_star="+str(ys_star)+", "
    cmd += "zs_star="+str(zs_star)+", "
    cmd += "rs_star="+str(rs_star)+", "
    cmd += "atime=now() WHERE snap="+str(snap)+" and hid ="+str(hid)+";"
    my.sql(cmd)
示例#3
0
def set_ss(snap,hid,xs,ys,zs,rs):
    cmd  = "UPDATE halo SET "
    cmd += "xs="+str(xs)+", "
    cmd += "ys="+str(ys)+", "
    cmd += "zs="+str(zs)+", "
    cmd += "rs="+str(rs)+", "
    cmd += "atime=now() WHERE snap="+str(snap)+" and hid ="+str(hid)+";"
    my.sql(cmd)
示例#4
0
def physical_xcm(snap, h):
    actsim = my.sql("SELECT name FROM sim WHERE active=1;")
    actsim = actsim[0][0]
    sh  = str(h);
    cmd  = "UPDATE halo SET xc=xc/"+sh+", yc=yc/"+sh+", zc=zc/"+sh
    cmd += ", rvir=rvir/"+sh+", atime=now() WHERE snap="+str(snap)+" and sim like '"+actsim+"';"
    my.sql(cmd)
    return
示例#5
0
def setup_snapshot():
    my.sql('CREATE TABLE if not exists snapshot (\
                  snap INT NOT NULL PRIMARY KEY,\
                  a float, z float,\
                  nhalo int,\
                  xm float, ym float, zm float, rm float,\
                  xms float, yms float, zms float, rms float,\
                  atime TIMESTAMP DEFAULT NOW()\
                  );')
示例#6
0
def setup_sim():
    my.sql('CREATE TABLE if not exists sim (\
                  id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,\
                  dir VARCHAR(255) NOT NULL,\
                  nsnap INT NOT NULL,\
                  nstart INT NOT NULL,\
                  nstop INT NOT NULL,\
                  atime TIMESTAMP DEFAULT NOW()\
                  );')
示例#7
0
def set_ss_stars(snap, hid, xs_star, ys_star, zs_star, rs_star):
    cmd = "UPDATE halo SET "
    cmd += "xs_star=" + str(xs_star) + ", "
    cmd += "ys_star=" + str(ys_star) + ", "
    cmd += "zs_star=" + str(zs_star) + ", "
    cmd += "rs_star=" + str(rs_star) + ", "
    cmd += "atime=now() WHERE snap=" + str(snap) + " and hid =" + str(
        hid) + ";"
    my.sql(cmd)
示例#8
0
def getxyzrstars_hid(snap, hid):

    wc = " from halo where snap=" + str(snap) + " and hid=" + str(hid) + ";"
    xm = my.sql("select xs_star " + wc)
    ym = my.sql("select ys_star " + wc)
    zm = my.sql("select zs_star " + wc)
    rm = my.sql("select rs_star " + wc)

    return xm[0][0], ym[0][0], zm[0][0], rm[0][0]
示例#9
0
def getxyzrstars_hid(snap,hid):

    wc=" from halo where snap="+str(snap)+" and hid="+str(hid)+";"
    xm=my.sql("select xs_star "+wc)
    ym=my.sql("select ys_star "+wc)
    zm=my.sql("select zs_star "+wc)
    rm=my.sql("select rs_star "+wc)

    return xm[0][0],ym[0][0],zm[0][0],rm[0][0]
示例#10
0
def setup_snapshot():
    my.sql('CREATE TABLE if not exists snapshot (\
                  snap INT NOT NULL PRIMARY KEY,\
                  a float, z float,\
                  nhalo int,\
                  xm float, ym float, zm float, rm float,\
                  xms float, yms float, zms float, rms float,\
                  atime TIMESTAMP DEFAULT NOW()\
                  );')
示例#11
0
def set_ss(snap, hid, xs, ys, zs, rs):
    cmd = "UPDATE halo SET "
    cmd += "xs=" + str(xs) + ", "
    cmd += "ys=" + str(ys) + ", "
    cmd += "zs=" + str(zs) + ", "
    cmd += "rs=" + str(rs) + ", "
    cmd += "atime=now() WHERE snap=" + str(snap) + " and hid =" + str(
        hid) + ";"
    my.sql(cmd)
示例#12
0
def setup_sim():
    my.sql('CREATE TABLE if not exists sim (\
                  id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,\
                  dir VARCHAR(255) NOT NULL,\
                  nsnap INT NOT NULL,\
                  nstart INT NOT NULL,\
                  nstop INT NOT NULL,\
                  atime TIMESTAMP DEFAULT NOW()\
                  );')
示例#13
0
def getxyzmr(snap, typ):
    actsim=my.sql("SELECT name FROM sim WHERE active=1;")
    actsim=actsim[0][0]
    if(typ==1):
        xc=my.sql("SELECT xc FROM halo WHERE snap="+str(snap)+" AND sim LIKE '"+actsim+"';")
        yc=my.sql("SELECT yc FROM halo WHERE snap="+str(snap)+" AND sim LIKE '"+actsim+"';")
        zc=my.sql("SELECT zc FROM halo WHERE snap="+str(snap)+" AND sim LIKE '"+actsim+"';")
    if(typ==2):
        xc=my.sql("SELECT xs FROM halo WHERE snap="+str(snap)+" AND sim LIKE '"+actsim+"';")
        yc=my.sql("SELECT ys FROM halo WHERE snap="+str(snap)+" AND sim LIKE '"+actsim+"';")
        zc=my.sql("SELECT zs FROM halo WHERE snap="+str(snap)+" AND sim LIKE '"+actsim+"';")
    mvir=my.sql("SELECT mvir FROM halo WHERE snap="+str(snap)+" AND sim LIKE '"+actsim+"';")
    rvir=my.sql("SELECT rvir FROM halo WHERE snap="+str(snap)+" AND sim LIKE '"+actsim+"';")
    x=[];y=[];z=[];r=[];m=[]
    for i in range(len(xc)):
        x.append(xc[i][0])
        y.append(yc[i][0])
        z.append(zc[i][0])
        r.append(rvir[i][0])
        m.append(mvir[i][0])
    x=np.array(x)
    y=np.array(y)
    z=np.array(z)
    r=np.array(r)
    m=np.array(m)
    order = m.argsort()
    x = x[order]
    y = y[order]
    z = z[order]
    r = r[order]
    m = m[order]
    return x[::-1],y[::-1],z[::-1],m[::-1],r[::-1]
示例#14
0
def get_rhalf_star(snap):
    r2s=my.sql("SELECT rhalf_star FROM halo WHERE snap="+str(snap)+";")
    mvir=my.sql("SELECT mvir FROM halo WHERE snap="+str(snap)+";")
    r=[];m=[]
    for i in range(len(r2s)):
        r.append(r2s[i][0])
        m.append(mvir[i][0])
    r = np.array(r)
    m = np.array(m)
    order = m.argsort()
    r = r[order]
    return r[::-1]
示例#15
0
def get_is_sub(snap):
    issub=my.sql("SELECT hosthid FROM halo WHERE snap="+str(snap)+";")
    mvir=my.sql("SELECT mvir from halo WHERE snap="+str(snap)+";")
    iss=[]; mv =[]
    for i in range(len(issub)):
        iss.append(issub[i][0]>0)
        mv.append(mvir[i][0])
    mv = np.array(mv)
    iss = np.array(iss)
    order = mv.argsort()
    iss = iss[order]
    return iss[::-1]
示例#16
0
def get_M_star(snap):
    mstar=my.sql("SELECT M_star FROM halo WHERE snap="+str(snap)+";")
    mvir=my.sql("SELECT mvir FROM halo WHERE snap="+str(snap)+";")
    ms=[]; mv=[]
    for i in range(len(mstar)):
        ms.append(mstar[i][0])
        mv.append(mvir[i][0])
    mv = np.array(mv)
    ms = np.array(ms)
    order = mv.argsort()
    mv = mv[order]
    ms = ms[order]
    return ms[::-1]
示例#17
0
def get_M_dm(snap):
    mvir=my.sql("SELECT mvir FROM halo WHERE snap="+str(snap)+";")
    mdm = my.sql("SELECT mvir-M_star-M_gas FROM halo WHERE snap="+str(snap)+";")
    md=[]; mv = []
    for i in range(len(mdm)):
        md.append(mdm[i][0])
        mv.append(mvir[i][0])
    md = np.array(md)
    mv = np.array(mv)
    order = mv.argsort()
    mv = mv[order]
    md = md[order]
    return md[::-1]
示例#18
0
def fill_snapshot(snap):
    a=str(my.read_a(snap))
    print('a read: ', a)
    z=str(my.read_z(snap))
    print('z read: ', z)
    nhalo=str(get_nhalo(snap))
    print('nhalo:', nhalo)
    cmd  = "INSERT INTO snapshot(snap,a,z,nhalo,sim,atime) "
    cmd += " VALUES ('"
    cmd += str(snap)+"','"+a+"','"+z+"','"+nhalo+"','"+get_active_sim()
    cmd += "', now())"
    cmd += " ON DUPLICATE KEY UPDATE atime=now();"
    my.sql(cmd)
    my.sql("ALTER TABLE snapshot ORDER BY snap DESC;")
示例#19
0
def fill_sim(name,nsnap,dmonly):
    simdir = "/library/home/psteger/sci/sim/"+name
    print(dmonly)
    cmd  = "INSERT INTO sim(name,active,dir,nsnap,nstart,nstop,dmonly) "
    cmd += "VALUES ("
    # default values 1, nsnap for nstart, nstop
    cmd += "'"+name+"','1','"+simdir+"','"+str(nsnap)+"','"+str(1)+"','"+str(nsnap)+"',"+str(dmonly)+") "
    cmd += "ON DUPLICATE KEY UPDATE atime=now(),active='1',dmonly="+str(dmonly)+";"
    print(cmd)
    my.sql(cmd)
    cmd = "UPDATE sim SET active='0' WHERE name not like '"+name+"';"
    print(cmd)
    my.sql(cmd)
    return
示例#20
0
def setup_halo():
    my.sql('CREATE TABLE if not exists halo (\
                  id varchar(33) NOT NULL PRIMARY KEY,\
                  snap INT NOT NULL,\
                  sim VARCHAR(255),\
                  buhid INT NOT NULL,\
                  atime TIMESTAMP DEFAULT NOW(),\
                  hid INT NOT NULL DEFAULT 0,\
                  proghid INT NOT NULL DEFAULT 0,\
                  hosthid INT NOT NULL DEFAULT 0,\
                  npart INT,\
                  fmhires float,\
                  xc float, yc float, zc float,\
                  xs float, ys float, zs float, rs float,\
                  vxc float, vyc float, vzc float,\
                  mvir FLOAT, rvir FLOAT, rcore FLOAT,\
                  vmax float, rmax float, sigv float, lambda float,\
                  lx float, ly float, lz float,\
                  a float, eax float, eay float, eaz float,\
                  b float, ebx float, eby float, ebz float,\
                  c float, ecx float, ecy float, ecz float,\
                  ovdens float, Redge float,\
                  nbins int,\
                  Ekin float, Epot float,\
                  mbp_offset float, com_offset float, r2 float,\
                  lambdaE float, v_esc float, Phi0 float,\
                  n_gas int default 0,\
                  xs_gas float, ys_gas float, zs_gas float,\
                  rs_gas float default 0.0,\
                  M_gas float default 0.0, lambda_gas float,\
                  Lx_gas float, Ly_gas float, Lz_gas float,\
                  a_gas float, Eax_gas float, Eay_gas float, Eaz_gas float,\
                  b_gas float, Ebx_gas float, Eby_gas float, Ebz_gas float,\
                  c_gas float, Ecx_gas float, Ecy_gas float, Ecz_gas float,\
                  Ekin_gas float, Epot_gas float, lambdaE_gas float,\
                  n_star int default 0,\
                  xs_star float, ys_star float, zs_star float,\
                  rs_star float default 0.0,\
                  rhalf_star float default 0.0,\
                  M_star float, lambda_star float,\
                  Lx_star float, Ly_star float, Lz_star float,\
                  a_star float,\
                  Eax_star float, Eay_star float, Eaz_star float,\
                  b_star float,\
                  Ebx_star float, Eby_star float, Ebz_star float,\
                  c_star float,\
                  Ecx_star float, Ecy_star float, Ecz_star float,\
                  Ekin_star float, Epot_star float, lambdaE_star float,\
                  m_dm float\
                  );')
示例#21
0
def getxyzmr(snap, typ):

    if (typ == 1):
        xc = my.sql("select xc from halo where snap=" + str(snap) + ";")
        yc = my.sql("select yc from halo where snap=" + str(snap) + ";")
        zc = my.sql("select zc from halo where snap=" + str(snap) + ";")
    if (typ == 2):
        xc = my.sql("select xs from halo where snap=" + str(snap) + ";")
        yc = my.sql("select ys from halo where snap=" + str(snap) + ";")
        zc = my.sql("select zs from halo where snap=" + str(snap) + ";")
    mvir = my.sql("select mvir from halo where snap=" + str(snap) + ";")
    rvir = my.sql("select rvir from halo where snap=" + str(snap) + ";")

    x = []
    y = []
    z = []
    r = []
    m = []
    for i in range(len(xc)):
        x.append(xc[i][0])
        y.append(yc[i][0])
        z.append(zc[i][0])
        r.append(rvir[i][0])
        m.append(mvir[i][0])

    return x, y, z, m, r
示例#22
0
def setup_sim():
    my.sql('CREATE TABLE if not exists sim (\
                  name VARCHAR(255) NOT NULL PRIMARY KEY,\
                  active BOOL NOT NULL DEFAULT 0,\
                  dir VARCHAR(255) NOT NULL,\
                  lma INT NOT NULL DEFAULT 14,\
                  nsnap INT NOT NULL,\
                  nstart INT NOT NULL,\
                  nstop INT NOT NULL,\
                  dmonly BOOL DEFAULT FALSE,\
                  atime TIMESTAMP DEFAULT NOW()\
                  );')
    #                  id INT NOT NULL AUTO_INCREMENT,\
    return
示例#23
0
def mt_xyzrsnap_stars(start,stop):
    wc=" FROM snapshot WHERE snap>="+str(start)+" AND snap<="+str(stop)+";"
    xm=my.sql("SELECT xms "+wc)
    ym=my.sql("SELECT yms "+wc)
    zm=my.sql("SELECT zms "+wc)
    rm=my.sql("SELECT rms "+wc)
    sm=my.sql("SELECT snap "+wc)
    x=[];y=[];z=[];r=[];s=[];
    for i in range(len(xm)):
        x.append(xm[i][0])
        y.append(ym[i][0])
        z.append(zm[i][0])
        r.append(rm[i][0])
        s.append(sm[i][0])
    return x,y,z,r,s
示例#24
0
def getxyzrsnap(snap):
    wc="FROM snapshot WHERE snap="+str(snap)+";"
    xm=my.sql("SELECT xs  "+wc)
    ym=my.sql("SELECT ys  "+wc)
    zm=my.sql("SELECT zs  "+wc)
    rm=my.sql("SELECT rs "+wc)
    sm=my.sql("SELECT snap "+wc)
    x=[];y=[];z=[];r=[];s=[]
    for i in range(len(xm)):
        x.append(xm[i][0])
        y.append(ym[i][0])
        z.append(zm[i][0])
        r.append(rm[i][0])
        s.append(sm[i][0])
    return x,y,z,r,s
示例#25
0
def setup_halo():
    my.sql('CREATE TABLE if not exists halo (\
                  id varchar(33) NOT NULL PRIMARY KEY,\
                  snap INT NOT NULL,\
                  buhid INT NOT NULL,\
                  atime TIMESTAMP DEFAULT NOW(),\
                  hid INT NOT NULL DEFAULT 0,\
                  proghid INT NOT NULL DEFAULT 0,\
                  hosthid INT NOT NULL DEFAULT 0,\
                  npart INT,\
                  fmhires float,\
                  xc float, yc float, zc float,\
                  xs float, ys float, zs float, rs float,\
                  vxc float, vyc float, vzc float,\
                  mvir FLOAT, rvir FLOAT,\
                  vmax float, rmax float, sigv float, lambda float,\
                  lx float, ly float, lz float,\
                  a float, eax float, eay float, eaz float,\
                  b float, ebx float, eby float, ebz float,\
                  c float, ecx float, ecy float, ecz float,\
                  ovdens float, Redge float,\
                  nbins int,\
                  Ekin float, Epot float,\
                  mbp_offset float, com_offset float, r2 float,\
                  lambdaE float, v_esc float, Phi0 float,\
                  n_gas int default 0,\
                  xs_gas float, ys_gas float, zs_gas float,\
                  rs_gas float default 0.0,\
                  M_gas float default 0.0, lambda_gas float,\
                  Lx_gas float, Ly_gas float, Lz_gas float,\
                  a_gas float, Eax_gas float, Eay_gas float, Eaz_gas float,\
                  b_gas float, Ebx_gas float, Eby_gas float, Ebz_gas float,\
                  c_gas float, Ecx_gas float, Ecy_gas float, Ecz_gas float,\
                  Ekin_gas float, Epot_gas float, lambdaE_gas float,\
                  n_star int default 0,\
                  xs_star float, ys_star float, zs_star float,\
                  rs_star float default 0.0,\
                  rhalf_star float default 0.0,\
                  M_star float, lambda_star float,\
                  Lx_star float, Ly_star float, Lz_star float,\
                  a_star float,\
                  Eax_star float, Eay_star float, Eaz_star float,\
                  b_star float,\
                  Ebx_star float, Eby_star float, Ebz_star float,\
                  c_star float,\
                  Ecx_star float, Ecy_star float, Ecz_star float,\
                  Ekin_star float, Epot_star float, lambdaE_star float\
                  );')
示例#26
0
def get_M_star(snap):

    mstar=my.sql("select M_star from halo where snap="+str(snap)+";")
    m=[]
    for i in range(len(mstar)):
        m.append(mstar[i][0])
    return m
示例#27
0
def get_is_sub(snap):

    issub=my.sql("select hosthid from halo where snap="+str(snap)+";")
    iss=[]
    for i in range(len(issub)):
        iss.append(issub[i][0]>0)
    return iss
示例#28
0
def d(nsnap):
    d = my.sql("select dir from sim where id=1")
#    print d[0][0]
#    d = d[0][0]+
    d = "/scratch/psteger/sim/sim_aboley/output_"+str(nsnap).zfill(5)+"/"
    d = "/scratch/psteger/sim/nec_20111220/output_"+str(nsnap).zfill(5)+"/"
    return d
示例#29
0
def exists_snap(snap):
    c = my.sql("SELECT snap from snapshot where snap="+str(snap)+";")

    if(len(c)==0):
        return False;
    else:
        return True;
示例#30
0
def fill_snapshot(snap):
    a=str(my.read_a(snap))
    print 'a read: ',a
    z=str(my.read_z(snap))
    print 'z read: ',z
    nhalo=str(get_nhalo(snap))
    print 'nhalo:',nhalo

    cmd  = "INSERT INTO snapshot(snap,a,z,nhalo,atime) "
    cmd += " VALUES ('"
    cmd += str(snap)+"','"+a+"','"+z+"','"+nhalo
    cmd += "', now())"
    cmd += " ON DUPLICATE KEY UPDATE atime=now();"
    my.sql(cmd)

    my.sql("alter table snapshot order by snap desc;")
示例#31
0
def fill_snapshot(snap):
    a = str(my.read_a(snap))
    print 'a read: ', a
    z = str(my.read_z(snap))
    print 'z read: ', z
    nhalo = str(get_nhalo(snap))
    print 'nhalo:', nhalo

    cmd = "INSERT INTO snapshot(snap,a,z,nhalo,atime) "
    cmd += " VALUES ('"
    cmd += str(snap) + "','" + a + "','" + z + "','" + nhalo
    cmd += "', now())"
    cmd += " ON DUPLICATE KEY UPDATE atime=now();"
    my.sql(cmd)

    my.sql("alter table snapshot order by snap desc;")
示例#32
0
def d(nsnap):
    d = my.sql("select dir from sim where id=1")
    #    print d[0][0]
    #    d = d[0][0]+
    d = "/scratch/psteger/sim/sim_aboley/output_" + str(nsnap).zfill(5) + "/"
    d = "/scratch/psteger/sim/nec_20111220/output_" + str(nsnap).zfill(5) + "/"
    return d
示例#33
0
def get_M_star(snap):

    mstar = my.sql("select M_star from halo where snap=" + str(snap) + ";")
    m = []
    for i in range(len(mstar)):
        m.append(mstar[i][0])
    return m
示例#34
0
def get_is_sub(snap):

    issub = my.sql("select hosthid from halo where snap=" + str(snap) + ";")
    iss = []
    for i in range(len(issub)):
        iss.append(issub[i][0] > 0)
    return iss
示例#35
0
def exists_snap(snap):
    c = my.sql("SELECT snap from snapshot where snap=" + str(snap) + ";")

    if (len(c) == 0):
        return False
    else:
        return True
示例#36
0
def get_sims():
    cmd="select name from sim;"
    o=my.sql(cmd)
    if(len(o)<1):
        o=[['find...']]
    p=np.array(o)
    q=np.transpose(p)[0]
    return q
示例#37
0
def get_rhalf_star(snap):

    r2s = my.sql("select rhalf_star from halo where snap=" + str(snap) + ";")
    r = []
    for i in range(len(r2s)):
        r.append(r2s[i][0])

    return r
示例#38
0
def get_rhalf_star(snap):

    r2s=my.sql("select rhalf_star from halo where snap="+str(snap)+";")
    r=[]
    for i in range(len(r2s)):
        r.append(r2s[i][0])
        
    return r
示例#39
0
def getxyzrsnap_stars(start,stop):

    wc=" from halo where snap>="+str(start)+" and snap<="+str(stop)+";"
    xm=my.sql("select xs_star "+wc)
    ym=my.sql("select ys_star "+wc)
    zm=my.sql("select zs_star "+wc)
    rm=my.sql("select rs_star "+wc)
    sm=my.sql("select snap "+wc)

    x=[];y=[];z=[];r=[];s=[];sn=[]
    for i in range(len(xm)):
        x.append(xm[i][0])
        y.append(ym[i][0])
        z.append(zm[i][0])
        r.append(rm[i][0])
        s.append(sm[i][0])
        
    return x,y,z,r,s
示例#40
0
def getxyzrstars_hid(snap,hid):
    wc=" FROM halo WHERE snap="+str(snap)+" AND hid="+str(hid)+";"
    xm=my.sql("SELECT xs_star "+wc)
    ym=my.sql("SELECT ys_star "+wc)
    zm=my.sql("SELECT zs_star "+wc)
    mvir=my.sql("SELECT mvir "+wc)
    rm=my.sql("SELECT rs_star "+wc)
    xms=[];yms=[];zms=[];mvirs=[];rms=[]
    for i in range(len(mvir)):
        xms.append(xm[i][0])
        yms.append(ym[i][0])
        zms.append(zm[i][0])
        mvirs.append(mvir[i][0])
        rms.append(rm[i][0])
    xms=np.array(xms); yms=np.array(yms); zms=np.array(zms); mvirs=np.array(mvirs);rms=np.array(rms)
    order = mvirs.argsort()
    xms=xms[order]; yms=yms[order]; zms=zms[order]; rms=rms[order]; mvirs=mvirs[order]
    return xms[-1],yms[-1],zms[-1],rms[-1]
示例#41
0
def getxyzrstars(snap,typ):
    if(typ==1):
        xs=my.sql("SELECT xc FROM halo WHERE snap="+str(snap)+";")
        ys=my.sql("SELECT yc FROM halo WHERE snap="+str(snap)+";")
        zs=my.sql("SELECT zc FROM halo WHERE snap="+str(snap)+";")
        rs=my.sql("SELECT rvir FROM halo WHERE snap="+str(snap)+";")
        mv=my.sql("SELECT mvir FROM halo WHERE snap="+str(snap)+";")
    if(typ==2):
        xs=my.sql("SELECT xs_star FROM halo WHERE snap="+str(snap)+";")
        ys=my.sql("SELECT ys_star FROM halo WHERE snap="+str(snap)+";")
        zs=my.sql("SELECT zs_star FROM halo WHERE snap="+str(snap)+";")
        rs=my.sql("SELECT rs_star FROM halo WHERE snap="+str(snap)+";")
        mv=my.sql("SELECT mvir FROM halo WHERE snap="+str(snap)+";")
    x=[]; y=[]; z=[]; r=[]; m=[]
    for i in range(len(xs)):
        x.append(xs[i][0])
        y.append(ys[i][0])
        z.append(zs[i][0])
        r.append(rs[i][0])
        m.append(mv[i][0])
    x=np.array(x);y=np.array(y);z=np.array(z);r=np.array(r);m=np.array(m)
    order = m.argsort()
    x=x[order]; y=y[order]; z=z[order]; r=r[order]; m=m[order]
    return x[::-1],y[::-1],z[::-1],r[::-1]
示例#42
0
def getxyzrsnap_stars(start, stop):

    wc = " from halo where snap>=" + str(start) + " and snap<=" + str(
        stop) + ";"
    xm = my.sql("select xs_star " + wc)
    ym = my.sql("select ys_star " + wc)
    zm = my.sql("select zs_star " + wc)
    rm = my.sql("select rs_star " + wc)
    sm = my.sql("select snap " + wc)

    x = []
    y = []
    z = []
    r = []
    s = []
    sn = []
    for i in range(len(xm)):
        x.append(xm[i][0])
        y.append(ym[i][0])
        z.append(zm[i][0])
        r.append(rm[i][0])
        s.append(sm[i][0])

    return x, y, z, r, s
示例#43
0
def getxyzrstars(snap,typ):

    if(typ==1):
        xs=my.sql("select xc from halo where snap="+str(snap)+";")
        ys=my.sql("select yc from halo where snap="+str(snap)+";")
        zs=my.sql("select zc from halo where snap="+str(snap)+";")
        rs=my.sql("select rvir from halo where snap="+str(snap)+";")
    if(typ==2):
        xs=my.sql("select xs_star from halo where snap="+str(snap)+";")
        ys=my.sql("select ys_star from halo where snap="+str(snap)+";")
        zs=my.sql("select zs_star from halo where snap="+str(snap)+";")
        rs=my.sql("select rs_star from halo where snap="+str(snap)+";")

    x=[];y=[];z=[];r=[];
    for i in range(len(xs)):
        x.append(xs[i][0])
        y.append(ys[i][0])
        z.append(zs[i][0])
        r.append(rs[i][0])
        
    return x,y,z,r
示例#44
0
def getxyzmr(snap,typ):

    if(typ==1):
        xc=my.sql("select xc from halo where snap="+str(snap)+";")
        yc=my.sql("select yc from halo where snap="+str(snap)+";")
        zc=my.sql("select zc from halo where snap="+str(snap)+";")
    if(typ==2):
        xc=my.sql("select xs from halo where snap="+str(snap)+";")
        yc=my.sql("select ys from halo where snap="+str(snap)+";")
        zc=my.sql("select zs from halo where snap="+str(snap)+";")
    mvir=my.sql("select mvir from halo where snap="+str(snap)+";")
    rvir=my.sql("select rvir from halo where snap="+str(snap)+";")

    x=[];y=[];z=[];r=[];m=[]
    for i in range(len(xc)):
        x.append(xc[i][0])
        y.append(yc[i][0])
        z.append(zc[i][0])
        r.append(rvir[i][0])
        m.append(mvir[i][0])
        
    return x,y,z,m,r
示例#45
0
def getxyzrstars(snap, typ):

    if (typ == 1):
        xs = my.sql("select xc from halo where snap=" + str(snap) + ";")
        ys = my.sql("select yc from halo where snap=" + str(snap) + ";")
        zs = my.sql("select zc from halo where snap=" + str(snap) + ";")
        rs = my.sql("select rvir from halo where snap=" + str(snap) + ";")
    if (typ == 2):
        xs = my.sql("select xs_star from halo where snap=" + str(snap) + ";")
        ys = my.sql("select ys_star from halo where snap=" + str(snap) + ";")
        zs = my.sql("select zs_star from halo where snap=" + str(snap) + ";")
        rs = my.sql("select rs_star from halo where snap=" + str(snap) + ";")

    x = []
    y = []
    z = []
    r = []
    for i in range(len(xs)):
        x.append(xs[i][0])
        y.append(ys[i][0])
        z.append(zs[i][0])
        r.append(rs[i][0])

    return x, y, z, r
示例#46
0
def fill_sim(simdir, nsnap, nstart, nstop):
    cmd = "INSERT INTO sim(dir,nsnap,nstart,nstop) "
    cmd += "VALUES ("
    cmd += "'" + simdir + "'," + str(nsnap) + "," + str(nstart) + "," + str(
        nstop) + ");"
    my.sql(cmd)
示例#47
0
def clear_sim():
    my.sql('DROP table if exists sim;')
示例#48
0
def fill_halo(snap, buhid, val):
    cmd = "INSERT INTO halo(id,snap,buhid) "
    cmd += " VALUES ('" + my.md5(snap, buhid)
    cmd += "','" + str(snap) + "','" + str(buhid) + "')"
    cmd += " ON DUPLICATE KEY UPDATE atime=now();"
    my.sql(cmd)

    cmd = "UPDATE halo SET "
    cmd += "npart='" + val[0] + "', "
    cmd += "fmhires='" + val[1] + "', "
    cmd += "xc='" + val[2] + "', yc='" + val[3] + "', zc='" + val[4] + "', "
    cmd += "vxc='" + val[5] + "',vyc='" + val[6] + "',vzc='" + val[7] + "', "
    cmd += "mvir='" + val[8] + "',  rvir='" + val[9] + "', "
    cmd += "vmax='" + val[10] + "', rmax='" + val[11] + "', "
    cmd += "sigv='" + val[12] + "', "
    cmd += "lambda='" + val[13] + "', "
    cmd += "lx='" + val[14] + "',ly='" + val[15] + "',lz='" + val[16] + "', "
    cmd += "a='" + val[17] + "', "
    cmd += "eax='" + val[18] + "',eay='" + val[19] + "',eaz='" + val[20] + "', "
    cmd += "b='" + val[21] + "', "
    cmd += "ebx='" + val[22] + "',eby='" + val[23] + "',ebz='" + val[24] + "', "
    cmd += "c='" + val[25] + "', "
    cmd += "ecx='" + val[26] + "',ecy='" + val[27] + "',ecz='" + val[28] + "', "
    cmd += "ovdens='" + val[29] + "', "
    cmd += "redge='" + val[30] + "', "
    cmd += "nbins='" + val[31] + "', "
    cmd += "ekin='" + val[32] + "',epot='" + val[33] + "', "
    cmd += "mbp_offset='" + val[34] + "', "
    cmd += "com_offset='" + val[35] + "', "
    cmd += "r2='" + val[36] + "', "
    cmd += "lambdae='" + val[37] + "', "
    cmd += "v_esc='" + val[38] + "', "
    cmd += "phi0='" + val[39] + "', "
    cmd += "n_gas='" + val[40] + "', m_gas='" + val[41] + "', "
    cmd += "lambda_gas='" + val[42] + "', "
    cmd += "lx_gas='" + val[43] + "',ly_gas='" + val[44] + "',lz_gas='" + val[
        45] + "', "
    cmd += "a_gas='" + val[46] + "', "
    cmd += "eax_gas='" + val[47] + "',eay_gas='" + val[
        48] + "',eaz_gas='" + val[49] + "', "
    cmd += "b_gas='" + val[50] + "', "
    cmd += "ebx_gas='" + val[51] + "', "
    cmd += "eby_gas='" + val[52] + "', "
    cmd += "ebz_gas='" + val[53] + "', "
    cmd += "c_gas='" + val[54] + "', "
    cmd += "ecx_gas='" + val[55] + "', "
    cmd += "ecy_gas='" + val[56] + "', "
    cmd += "ecz_gas='" + val[57] + "', "
    cmd += "ekin_gas='" + val[58] + "', "
    cmd += "epot_gas='" + val[59] + "', "
    cmd += "lambdae_gas='" + val[60] + "', "
    cmd += "n_star='" + val[61] + "', "
    cmd += "m_star='" + val[62] + "', "
    cmd += "lambda_star='" + val[63] + "', "
    cmd += "lx_star='" + val[64] + "', "
    cmd += "ly_star='" + val[65] + "', "
    cmd += "lz_star='" + val[66] + "', "
    cmd += "a_star='" + val[67] + "', "
    cmd += "eax_star='" + val[68] + "', "
    cmd += "eay_star='" + val[69] + "', "
    cmd += "eaz_star='" + val[70] + "', "
    cmd += "b_star='" + val[71] + "', "
    cmd += "ebx_star='" + val[72] + "', "
    cmd += "eby_star='" + val[73] + "', "
    cmd += "ebz_star='" + val[74] + "', "
    cmd += "c_star='" + val[75] + "', "
    cmd += "ecx_star='" + val[76] + "', "
    cmd += "ecy_star='" + val[77] + "', "
    cmd += "ecz_star='" + val[78] + "', "
    cmd += "ekin_star='" + val[79] + "', "
    cmd += "epot_star='" + val[80] + "', "
    cmd += "lambdae_star='" + val[81] + "', "
    cmd += "atime=now() "
    cmd += "WHERE id='" + my.md5(snap, buhid) + "';"
    my.sql(cmd)
示例#49
0
#!/usr/bin/python

import initialize as my
import mys
import sys

startsnap = int(sys.argv[1])
stopsnap = int(sys.argv[2])

curhid = 1
for nc in range(stopsnap - startsnap + 1):
    nsnap = stopsnap - nc
    print nsnap

    if (len(my.sql("select snap from halo where snap=" + str(nsnap))) == 0):
        print "missing snapshot"
        my.sql("update snapshot set " + "xm=-1,ym=-1,zm=-1,rm=-1," +
               "xms=-1,yms=-1,zms=-1,rms=-1," + "atime=now() " +
               "where snap=" + str(nsnap))
        curhid = 1
        continue

    o = my.sql("select xs,ys,zs,rvir,xs_star,ys_star,zs_star,rs_star,proghid" +
               " from halo " + "where snap=" + str(nsnap) + " and hid=" +
               str(curhid))
    x = o[0][0]
    y = o[0][1]
    z = o[0][2]
    r = o[0][3]
    xs = o[0][4]
    ys = o[0][5]
示例#50
0
def clear_snapshot():
    my.sql('DROP table if exists snapshot;')
示例#51
0
def clear_halo():
    my.sql('DROP table if exists halo;')
示例#52
0
def get_z(snap):
    c = my.sql("select z from snapshot where snap=" + str(snap) + ";")
    return c[0][0]
示例#53
0
def get_nhalo(snap):
    nhalo = my.sql("select atime from halo where snap=" + str(snap))
    #    print len(nhalo)
    return len(nhalo)
示例#54
0
def physical_xcm(snap, h):
    sh = str(h)
    sh3 = str(1000 * h)
    cmd = "UPDATE halo SET xc=xc/" + sh + ", yc=yc/" + sh + ", zc=zc/" + sh
    cmd += ", rvir=rvir/" + sh3 + ", atime=now() WHERE snap=" + str(snap) + ";"
    my.sql(cmd)
示例#55
0
def exclude(snap, npart, fmhires, bndry):
    cmd = "DELETE from halo "
    cmd += "WHERE snap=" + str(snap) + " and (npart < " + str(npart)
    cmd += " or fmhires < " + str(fmhires)
    cmd += " or xc < " + str(bndry) + " or xc > " + str(1 - bndry)
    cmd += " or yc < " + str(bndry) + " or yc > " + str(1 - bndry)
    cmd += " or zc < " + str(bndry) + " or zc > " + str(1 - bndry) + ");"
    my.sql(cmd)

    my.sql("alter table halo order by mvir desc;")
    my.sql("update halo set hid=0 where id!='' and snap=" + str(snap) + ";")
    old_buhid = 0
    for i in range(get_nhalo(snap)):
        my.sql("update halo set hid=" + str(i + 1) +
               " where id!='' and hid>=" + str(i) + " and buhid!=" +
               str(old_buhid) + " and snap=" + str(snap) + ";")
        old_buhid = my.sql("select buhid from halo where snap=" + str(snap) +
                           " and hid>" + str(i) + " limit 1;")[0][0]


#        print old_buhid
    my.sql("analyze table halo;")
示例#56
0
def set_rhalf_star(snap, hid, r):
    my.sql("update halo set rhalf_star=" + str(r) + " where snap=" +
           str(snap) + " and hid=" + str(hid) + ";")
示例#57
0
def count_shared(m1, m2):
    cc = 0
    #    print "count"
    for i in range(len(m1)):
        if m1[i] in m2:
            cc += 1
    return cc


print "find particles shared by halo_in_1, halo_in_2"
# create sparse matrix of particles shared by each halo with each other
M = zeros([alm1, alm2], int)
for i in range(alm1):
    for j in range(alm2):
        M[i, j] = count_shared(split1[i], split2[j])
        if (M[i, j] > 0):
            print i, j, M[i, j]

print "search progenitor (most particles shared)"
# find progenitor (most particles shared)
for i in range(alm1):
    maxi = 0
    maxj = i
    for j in range(alm2):
        if (M[i, j] > maxi):
            maxi = M[i, j]
            maxj = j
    my.sql("update halo set proghid=" + str(maxj) + " where snap=" +
           str(snap1) + " and hid=" + str(i))
    print i, maxj, maxi
示例#58
0

def count_shared(m1, m2):
    cc = 0
    for i in range(len(m1)):
        if m1[i] in m2:
            cc = cc + 1
    return cc


print "find particles shared by halo_in_1, halo_in_2"
# create sparse matrix of particles shared by each halo with each other
M = zeros([alm, alm], int)
for i in range(alm):
    for j in range(alm):
        M[i, j] = count_shared(split[i], split[j])
        if (M[i, j] != 0):
            print i, j, M[i, j]

print "search host (most particles shared)"
for i in range(alm):
    maxi = 0
    maxj = i
    for j in range(alm):
        if (M[i, j] > maxi):
            maxi = M[i, j]
            maxj = j
    my.sql("update halo set hosthid=" + str(maxj) + " where snap=" +
           str(snap) + " and hid=" + str(i))
    print i, maxj, maxi