Example #1
0
 def local_composition(self, outfile):
     """ Variable radius sliding average Goes pixel by pixel and calculates the
     composition around that pixel (within some radius) and assigns the center
     pixel that composition. Use a 256 x 256 x 256 matrix. """
     # TODO Rewrite if I ever need this again
     radius = 3.6 * 2
     npix = 64
     #mat = np.zeros((npix,npix,npix),dtype=np.float)
     #mat = np.zeros((npix,npix,npix),dtype={'names':['col1', 'col2', 'col3'], 'formats':['f4','f4','f4']})
     #mat = np.zeros((npix,npix,npix),dtype={'names':['40', '13', '29'], 'formats':['f4','f4','f4']})
     #mat = np.zeros((npix,npix,npix),dtype={'names':['id','data'], 'formats':['f4','f4']})
     #names = ['id','data']
     #formats = ['i4',('f4','f4','f4')]
     #mat = np.zeros((npix,npix,npix),dtype=dict(names = names, formats=formats))
     #mat = np.zeros((npix,npix,npix),dtype={'40':('i4',0), '29':('f4',0), '13':('f4',0)})
     print("Creating matrix...")
     mat = [[[{} for i in range(npix)] for j in range(npix)] for k in range(npix)]
     print("Finished creating matrix.")
     #print(repr(mat))
     dx = self.xsize/npix
     dy = self.ysize/npix
     dz = self.zsize/npix
     for ii,i in enumerate(drange(-npix/2*dx,npix/2*dx-dx,dx)):
         print("On ii = {0}".format(ii))
         for jj,j in enumerate(drange(-npix/2*dy,npix/2*dy-dy,dy)):
             for kk,k in enumerate(drange(-npix/2*dz,npix/2*dz-dz,dz)):
                 atoms = self.get_atoms_in_cutoff( (i,j,k), radius )
                 comp = {}
                 for atom in atoms:
                     comp[str(atom.z)] = comp.get(str(atom.z),0) + 1.0
                 for key in comp:
                     comp[key] /= len(atoms)
                 #print(comp)
                 #mat[ii][jj][kk] = copy.copy(comp)
                 mat[ii][jj][kk] = comp
     of = open(outfile,'w')
     of.write('IGOR\n')
     for atomtype in self.atomtypes:
         of.write('\nWAVES/N=({0},{1},{2})\t {3}\nBEGIN\n'.format(npix,npix,npix,'partial_comp_'+znum2sym.z2sym(atomtype)))
         for layer in mat:
             for column in layer:
                 for value in column:
                     try:
                         of.write("{0} ".format(value[str(atomtype)]))
                     except KeyError:
                         of.write("{0} ".format(0.0))
             of.write("\n")
         of.write('END\n')
         of.write('X SetScale/P x 0,1,"", {0}; SetScale/P y 0,1,"", {0}; SetScale/P z 0,1,"", {0}; SetScale d 0,0,"", {0}\n'.format('partial_comp_'+znum2sym.z2sym(atomtype)))
     of.close()
     return mat
Example #2
0
def main():
    axis = list(tools.drange(-0.05, 1.05, 0.1))
    hists = []
    for m in ["mass", "mass10"]:
        h = pyroot.h1_axis(axis=axis)
        h.blue() if m == "mass" else h.red()
        for i, l in enumerate(range(0, 11), start=1):

            db = shelve.open("data/ups3s/%s/lambda%d.db" % (m, l), "r")
            mass = dbtools.get_db_param(
                db=db,
                param="mean_b1_3p",
                year="all",
                bin=(24, 40))
            h[i] = mass
        
        if m == "mass10":
            g = h.asGraph3(0.01)
            for j in g:
                g.SetPointEXhigh(j, 0)
                g.SetPointEXlow(j, 0)
            g.Draw("P")
            hists.append(g)
        else:
            h.Draw("e1x0")
            hists.append(h)
    tools.save_figure("ups3s/m3p_lambda")
Example #3
0
def main():
    axis = list(tools.drange(-0.05, 1.05, 0.1))
    hists = []
    for year in ["2011", "2012"]:
        h = pyroot.h1_axis(axis=axis)
        h.blue() if year == "2011" else h.red()
        for i, l in enumerate(range(0, 11), start=1):

            db = shelve.open("data/ups1s/mass/lambda%d.db" % l, "r")
            mass = dbtools.get_db_param(
                db=db,
                param="mean_b1_1p",
                year=year,
                bin=(18, 22))
            h[i] = mass
        if year == "2012":
            g = h.asGraph3(0.01)
            for j in g:
                g.SetPointEXhigh(j, 0)
                g.SetPointEXlow(j, 0)
            g.Draw("P")
            hists.append(g)
        else:
            h.Draw("e1x0")
            hists.append(h)

    tools.save_figure("ups1s/m1p_lambda")
Example #4
0
 def radial_composition(self, outfile):
     """ Creates 1D waves stored in outfile for each element in the model. Each 
     wave is a histogram of the number of atoms between two radial positions
     starting at the center of model and radiating outward. """
     # TODO Rewrite if I ever need this again
     npix = 16
     keys = self.atomtypes.keys()
     #histo = [[0.0 for x in range(npix)] for key in keys]
     histo = [{} for x in range(npix)]
     dx = (self.xsize/2.0)/npix # Cube assumed
     for i,r in enumerate(drange(dx, npix*dx-dx, dx)):
         atoms = self.get_atoms_in_cutoff( (0.0,0.0,0.0), r)
         print(r, len(atoms))
         comp = {}
         for atom in atoms:
             comp[str(atom.z)] = comp.get(str(atom.z),0) + 1.0
         for type in self.atomtypes:
             if( str(type) not in comp.keys()):
                 comp[str(type)] = 0.0
         comp['Total'] = len(atoms)
         histo[i] = comp
     of = open(outfile,'w')
     of.write('IGOR\n')
     for atomtype in keys:
         of.write('\nWAVES/N=({0})\t {1}\nBEGIN\n'.format(npix,'partial_radial_comp_'+znum2sym.z2sym(atomtype)))
         for i in range(npix-2):
             if(i != 0):
                 of.write("{0} ".format((histo[i][str(atomtype)] - histo[i-1][str(atomtype)])/( 4.0/3.0*np.pi*( (i*dx)**3 - ((i-1)*dx)**3 ))))
                 #print("{1}  {0} ".format(histo[i][str(atomtype)],i*dx))
                 #print("  {1}  {0} ".format(histo[i][str(atomtype)] - histo[i-1][str(atomtype)],i*dx))
             else:
                 of.write("{0} ".format(histo[i][str(atomtype)]))
                 #print("{1}  {0} ".format(histo[i][str(atomtype)],i*dx))
         of.write("\n")
         of.write('END\n')
         of.write('X SetScale x 0,{1}, {0};\n'.format('partial_comp_'+znum2sym.z2sym(atomtype),npix*dx-dx))
     of.close()