3 Particles object, with methods: 5 part=particles(it=2,read=True) 6 part.read_shell(r=100,dr=5) 8 Created on Wed Nov 29 09:25:50 2017 12 from __future__
import print_function
13 from scipy.io
import FortranFile
15 if sys.version_info[0]!=2:
16 from importlib
import reload
17 from numpy
import size,sqrt,product,mean,mod
18 import dispatch_utils; reload(dispatch_utils)
19 import dispatch_data; reload(dispatch_data)
20 from dispatch_utils
import patch_files
21 from dispatch_data
import Patch
22 from scaling
import cgs, scaling
26 def __init__(self,it=0,run='',data='../data',read=0,r=0,dr=1,gas_mass=0,verbose=0):
27 ''' Initialize, by reading in the list of patch files ''' 29 self.
files=patch_files(it,run,data)
33 print(
'{} files ({:.3f} sec)'.format(size(self.
files),time()-start))
38 ''' Sum up the gas mass ''' 41 print(
"computing gas mass ...")
44 for file
in self.
files:
48 mass+=product(p.size)*mean(p.data[l[0]:u[0],l[1]:u[1],l[2]:u[2],0])
51 if mod(n,200)==0: print(n,mass)
54 print(
'mass: {:.4f} ({:.2f} sec)'.format(mass,time()-start))
57 ''' Trigger reading of all patches (may take a long time) ''' 61 ''' Read particles in a patch ''' 63 f=FortranFile(name,
'rb')
66 print(
'ioformat:',fmt[0])
70 a=a.reshape(dim[1],dim[0]).transpose()
75 for i
in range(size(idx)):
77 dict[id]={
'p':a[i,0:3],
'v':a[i,0:3],
't':a[i,6],
's':a[i,7],
'w':a[i,8]}
80 def read_shell(self,r=100,dr=1,dust2gas=0.01,save=True,verbose=0):
81 ''' Read particles in a shell, by default saving them ''' 96 for file
in self.
files:
101 if rc.min() < (r+dr)
and rc.max() > (r-dr)
or r==0:
103 idx,dd=self.read_file(file)
107 for i
in range(size(idx)):
112 if p2>r2min
and p2<r2max:
115 rate -= sum(p*v)/sqrt(p2)*w
120 for i
in range(size(idx)):
125 print(
'{:.3f} sec'.format(now-start))
129 print(
'{:.3f} sec'.format(time()-start))
131 if not hasattr(self,
'gas_mass'):
138 print(
'{} self.particles saved'.format(size(dict.keys())))
141 rate1=dust2gas*rate*cgs.yr/units.t*units.m/cgs.m_earth
142 s=
'rate:{:9.2e} ={:9.2e} M_E/yr'.format(rate,rate1)
143 s=s+
', based on {} particles from {} patches'.format(n,npatch)
144 print(s+
' ({:.1f} sec)'.format(time()-t0))
146 def read_plane(self,x=None,y=None,z=None,ds=1,wmin=1e-9,dust2gas=0.01,save=True,verbose=0):
147 ''' Read particles in a plane, by default saving them ''' 151 def read_patch_plane(j,s,ds,c):
152 ''' read particles in patch belonging to a plane ''' 153 if c[1] > (s-ds)
and c[0] < (s+ds):
157 for i
in range(size(idx)):
161 if d[
'w']>wmin
and p[j]>(s-ds)
and p[j]<(s+ds):
168 for file
in self.
files:
171 if type(x) != type(
None):
172 npatch+=read_patch_plane(0,x,ds,c[:,0])
173 elif type(y) != type(
None):
174 npatch+=read_patch_plane(1,y,ds,c[:,1])
175 elif type(z) != type(
None):
176 npatch+=read_patch_plane(2,z,ds,c[:,2])
179 print(
'{}: {:.3f} sec'.format(file,now-start))
183 print(
'{} particles from {} patches ({:.2f} sec)'.format(size(dict.keys()),npatch,time()-start))
185 def shell(self,r=100,dr=1,dust2gas=0.01,verbose=0):
186 ''' evaluate rate of particles in a shell ''' 200 if p2>r2min
and p2<r2max:
203 rate -= sum(p*v)/sqrt(p2)*w
205 if not hasattr(self,
'gas_mass'):
211 rate1=dust2gas*rate*cgs.yr/units.t*units.m/cgs.m_earth
212 s=
'rate:{:9.2e} ={:9.2e} M_E/yr, based on {} particles.'.format(rate,rate1,n)
213 s=s+
' Time used: {:.1f} sec.'.format(time()-t0)
def read_shell(self, r=100, dr=1, dust2gas=0.01, save=True, verbose=0)
def get_gas_mass(self, verbose=0)
def read_plane(self, x=None, y=None, z=None, ds=1, wmin=1e-9, dust2gas=0.01, save=True, verbose=0)
def shell(self, r=100, dr=1, dust2gas=0.01, verbose=0)
def read_all(self, verbose=0)
def read_patch(self, file, verbose=0)
def __init__(self, it=0, run='', data='../data', read=0, r=0, dr=1, gas_mass=0, verbose=0)