PLUTO
pyPLUTO.pyPLUTO.pload Class Reference
Inheritance diagram for pyPLUTO.pyPLUTO.pload:
Collaboration diagram for pyPLUTO.pyPLUTO.pload:

Public Member Functions

def __init__
 
def ReadTimeInfo (self, timefile)
 
def ReadVarFile (self, varfile)
 
def ReadGridFile (self, gridfile)
 
def DataScanVTK (self, fp, n1, n2, n3, endian, dtype)
 
def DataScanHDF5 (self, fp, myvars, ilev)
 
def DataScan
 
def ReadSingleFile (self, datafilename, myvars, n1, n2, n3, endian, dtype, ddict)
 
def ReadMultipleFiles (self, nstr, dataext, myvars, n1, n2, n3, endian, dtype, ddict)
 
def ReadDataFile (self, num)
 

Public Attributes

 NStep
 
 Dt
 
 n1
 
 n2
 
 n3
 
 x1
 
 x2
 
 x3
 
 dx1
 
 dx2
 
 dx3
 
 x1range
 Allow to load only a portion of the domain. More...
 
 x2range
 
 x3range
 
 NStepStr
 
 datatype
 
 level
 
 wdir
 
 SimTime
 
 filetype
 
 endianess
 
 vars
 
 geometry
 
 n2_tot
 
 n3_tot
 
 irange
 
 jrange
 
 krange
 
 Slice
 
 x1r
 
 x2r
 
 x3r
 
 nshp
 

Static Public Attributes

tuple off_fmt = endian+str(off)
 
tuple nboff = np.dtype(off_fmt)
 
 n1_tot = self.n3_tot
 
tuple A = array.array(dtype)
 
tuple fmt = endian+str(n1_tot*n2_tot*n3_tot)
 
tuple nb = np.dtype(fmt)
 
tuple darr = np.zeros((n1*n2*n3))
 
tuple indxx = np.sort([n3_tot*n2_tot*k + j*n2_tot + i for i in self.irange for j in self.jrange for k in self.krange])
 
list darr = [darr]
 

Detailed Description

Definition at line 90 of file pyPLUTO.py.

Constructor & Destructor Documentation

def pyPLUTO.pyPLUTO.pload.__init__ (   self,
  ns,
  w_dir = None,
  datatype = None,
  level = 0,
  x1range = None,
  x2range = None,
  x3range = None 
)
Loads the data.
    
**Inputs**:
      
  ns -- Step Number of the data file\n
      w_dir -- path to the directory which has the data files\n
  datatype -- Datatype (default = 'double')
      
**Outputs**:
  
  pyPLUTO pload object whose keys are arrays of data values.

Definition at line 91 of file pyPLUTO.py.

91  def __init__(self, ns, w_dir=None, datatype=None, level = 0, x1range=None, x2range=None, x3range=None):
92  """Loads the data.
93 
94  **Inputs**:
95 
96  ns -- Step Number of the data file\n
97  w_dir -- path to the directory which has the data files\n
98  datatype -- Datatype (default = 'double')
99 
100  **Outputs**:
101 
102  pyPLUTO pload object whose keys are arrays of data values.
103 
104  """
105  self.NStep = ns
106  self.Dt = 0.0
107 
108  self.n1 = 0
109  self.n2 = 0
110  self.n3 = 0
111 
112  self.x1 = []
113  self.x2 = []
114  self.x3 = []
115  self.dx1 = []
116  self.dx2 = []
117  self.dx3 = []
118 
119  self.x1range = x1range
120  self.x2range = x2range
121  self.x3range = x3range
122 
123  self.NStepStr = str(self.NStep)
124  while len(self.NStepStr) < 4:
125  self.NStepStr = '0'+self.NStepStr
126 
127  if datatype is None:
128  datatype = "double"
129  self.datatype = datatype
130 
131  if ((not hasH5) and (datatype == 'hdf5')):
132  print 'To read AMR hdf5 files with python'
133  print 'Please install h5py (Python HDF5 Reader)'
134  return
135 
136  self.level = level
137 
138  if w_dir is None:
139  w_dir = os.getcwd() + '/'
140  self.wdir = w_dir
141 
142  Data_dictionary = self.ReadDataFile(self.NStepStr)
143  for keys in Data_dictionary:
144  object.__setattr__(self, keys, Data_dictionary.get(keys))
145 
x1range
Allow to load only a portion of the domain.
Definition: pyPLUTO.py:119
def ReadDataFile(self, num)
Definition: pyPLUTO.py:676

Member Function Documentation

def pyPLUTO.pyPLUTO.pload.DataScan (   self,
  fp,
  n1,
  n2,
  n3,
  endian,
  dtype,
  off = None 
)

Definition at line 550 of file pyPLUTO.py.

550  def DataScan(self, fp, n1, n2, n3, endian, dtype, off=None):

Here is the caller graph for this function:

def pyPLUTO.pyPLUTO.pload.DataScanHDF5 (   self,
  fp,
  myvars,
  ilev 
)
Scans the Chombo HDF5 data files for AMR in PLUTO. 

**Inputs**:

  fp     -- Data file pointer\n
  myvars -- Names of the variables to read\n
  ilev   -- required AMR level

**Output**:

  Dictionary consisting of variable names as keys and its values. 

**Note**:

  Due to the particularity of AMR, the grid arrays loaded in ReadGridFile are overwritten here.

Definition at line 334 of file pyPLUTO.py.

334  def DataScanHDF5(self, fp, myvars, ilev):
335  """ Scans the Chombo HDF5 data files for AMR in PLUTO.
336 
337  **Inputs**:
338 
339  fp -- Data file pointer\n
340  myvars -- Names of the variables to read\n
341  ilev -- required AMR level
342 
343  **Output**:
344 
345  Dictionary consisting of variable names as keys and its values.
346 
347  **Note**:
348 
349  Due to the particularity of AMR, the grid arrays loaded in ReadGridFile are overwritten here.
350 
351  """
352  # Read the grid information
353  dim = fp['Chombo_global'].attrs.get('SpaceDim')
354  nlev = fp.attrs.get('num_levels')
355  il = min(nlev-1,ilev)
356  lev = []
357  for i in range(nlev):
358  lev.append('level_'+str(i))
359  freb = np.zeros(nlev,dtype='int')
360  for i in range(il+1)[::-1]:
361  fl = fp[lev[i]]
362  if (i == il):
363  pdom = fl.attrs.get('prob_domain')
364  dx = fl.attrs.get('dx')
365  dt = fl.attrs.get('dt')
366  ystr = 1. ; zstr = 1. ; logr = 0
367  try:
368  geom = fl.attrs.get('geometry')
369  logr = fl.attrs.get('logr')
370  if (dim == 2):
371  ystr = fl.attrs.get('g_x2stretch')
372  elif (dim == 3):
373  zstr = fl.attrs.get('g_x3stretch')
374  except:
375  print 'Old HDF5 file, not reading stretch and logr factors'
376  freb[i] = 1
377  x1b = fl.attrs.get('domBeg1')
378  if (dim == 1):
379  x2b = 0
380  else:
381  x2b = fl.attrs.get('domBeg2')
382  if (dim == 1 or dim == 2):
383  x3b = 0
384  else:
385  x3b = fl.attrs.get('domBeg3')
386  jbeg = 0 ; jend = 0 ; ny = 1
387  kbeg = 0 ; kend = 0 ; nz = 1
388  if (dim == 1):
389  ibeg = pdom[0] ; iend = pdom[1] ; nx = iend-ibeg+1
390  elif (dim == 2):
391  ibeg = pdom[0] ; iend = pdom[2] ; nx = iend-ibeg+1
392  jbeg = pdom[1] ; jend = pdom[3] ; ny = jend-jbeg+1
393  elif (dim == 3):
394  ibeg = pdom[0] ; iend = pdom[3] ; nx = iend-ibeg+1
395  jbeg = pdom[1] ; jend = pdom[4] ; ny = jend-jbeg+1
396  kbeg = pdom[2] ; kend = pdom[5] ; nz = kend-kbeg+1
397  else:
398  rat = fl.attrs.get('ref_ratio')
399  freb[i] = rat*freb[i+1]
400 
401  dx0 = dx*freb[0]
402 
403  ## Allow to load only a portion of the domain
404  if (self.x1range != None):
405  if logr == 0:
406  self.x1range = self.x1range-x1b
407  else:
408  self.x1range = [log(self.x1range[0]/x1b),log(self.x1range[1]/x1b)]
409  ibeg0 = min(self.x1range)/dx0 ; iend0 = max(self.x1range)/dx0
410  ibeg = max([ibeg, int(ibeg0*freb[0])]) ; iend = min([iend,int(iend0*freb[0]-1)])
411  nx = iend-ibeg+1
412  if (self.x2range != None):
413  self.x2range = (self.x2range-x2b)/ystr
414  jbeg0 = min(self.x2range)/dx0 ; jend0 = max(self.x2range)/dx0
415  jbeg = max([jbeg, int(jbeg0*freb[0])]) ; jend = min([jend,int(jend0*freb[0]-1)])
416  ny = jend-jbeg+1
417  if (self.x3range != None):
418  self.x3range = (self.x3range-x3b)/zstr
419  kbeg0 = min(self.x3range)/dx0 ; kend0 = max(self.x3range)/dx0
420  kbeg = max([kbeg, int(kbeg0*freb[0])]) ; kend = min([kend,int(kend0*freb[0]-1)])
421  nz = kend-kbeg+1
422 
423  ## Create uniform grids at the required level
424  if logr == 0:
425  x1 = x1b + (ibeg+np.array(range(nx))+0.5)*dx
426  else:
427  x1 = x1b*(exp((ibeg+np.array(range(nx))+1)*dx)+exp((ibeg+np.array(range(nx)))*dx))*0.5
428 
429  x2 = x2b + (jbeg+np.array(range(ny))+0.5)*dx*ystr
430  x3 = x3b + (kbeg+np.array(range(nz))+0.5)*dx*zstr
431  if logr == 0:
432  dx1 = np.ones(nx)*dx
433  else:
434  dx1 = x1b*(exp((ibeg+np.array(range(nx))+1)*dx)-exp((ibeg+np.array(range(nx)))*dx))
435  dx2 = np.ones(ny)*dx*ystr
436  dx3 = np.ones(nz)*dx*zstr
437 
438  # Create the xr arrays containing the edges positions
439  # Useful for pcolormesh which should use those
440  x1r = np.zeros(len(x1)+1) ; x1r[1:] = x1 + dx1/2.0 ; x1r[0] = x1r[1]-dx1[0]
441  x2r = np.zeros(len(x2)+1) ; x2r[1:] = x2 + dx2/2.0 ; x2r[0] = x2r[1]-dx2[0]
442  x3r = np.zeros(len(x3)+1) ; x3r[1:] = x3 + dx3/2.0 ; x3r[0] = x3r[1]-dx3[0]
443  NewGridDict = dict([('n1',nx),('n2',ny),('n3',nz),\
444  ('x1',x1),('x2',x2),('x3',x3),\
445  ('x1r',x1r),('x2r',x2r),('x3r',x3r),\
446  ('dx1',dx1),('dx2',dx2),('dx3',dx3),\
447  ('Dt',dt)])
448 
449  # Variables table
450  nvar = len(myvars)
451  vars = np.zeros((nx,ny,nz,nvar))
452 
453  LevelDic = {'nbox':0,'ibeg':ibeg,'iend':iend,'jbeg':jbeg,'jend':jend,'kbeg':kbeg,'kend':kend}
454  AMRLevel = []
455  AMRBoxes = np.zeros((nx,ny,nz))
456  for i in range(il+1):
457  AMRLevel.append(LevelDic.copy())
458  fl = fp[lev[i]]
459  data = fl['data:datatype=0']
460  boxes = fl['boxes']
461  nbox = len(boxes['lo_i'])
462  AMRLevel[i]['nbox'] = nbox
463  ncount = 0L
464  AMRLevel[i]['box']=[]
465  for j in range(nbox): # loop on all boxes of a given level
466  AMRLevel[i]['box'].append({'x0':0.,'x1':0.,'ib':0L,'ie':0L,\
467  'y0':0.,'y1':0.,'jb':0L,'je':0L,\
468  'z0':0.,'z1':0.,'kb':0L,'ke':0L})
469  # Box indexes
470  ib = boxes[j]['lo_i'] ; ie = boxes[j]['hi_i'] ; nbx = ie-ib+1
471  jb = 0 ; je = 0 ; nby = 1
472  kb = 0 ; ke = 0 ; nbz = 1
473  if (dim > 1):
474  jb = boxes[j]['lo_j'] ; je = boxes[j]['hi_j'] ; nby = je-jb+1
475  if (dim > 2):
476  kb = boxes[j]['lo_k'] ; ke = boxes[j]['hi_k'] ; nbz = ke-kb+1
477  szb = nbx*nby*nbz*nvar
478  # Rescale to current level
479  kb = kb*freb[i] ; ke = (ke+1)*freb[i] - 1
480  jb = jb*freb[i] ; je = (je+1)*freb[i] - 1
481  ib = ib*freb[i] ; ie = (ie+1)*freb[i] - 1
482 
483  # Skip boxes lying outside ranges
484  if ((ib > iend) or (ie < ibeg) or \
485  (jb > jend) or (je < jbeg) or \
486  (kb > kend) or (ke < kbeg)):
487  ncount = ncount + szb
488  else:
489 
490  ### Read data
491  q = data[ncount:ncount+szb].reshape((nvar,nbz,nby,nbx)).T
492 
493  ### Find boxes intersections with current domain ranges
494  ib0 = max([ibeg,ib]) ; ie0 = min([iend,ie])
495  jb0 = max([jbeg,jb]) ; je0 = min([jend,je])
496  kb0 = max([kbeg,kb]) ; ke0 = min([kend,ke])
497 
498  ### Store box corners in the AMRLevel structure
499  if logr == 0:
500  AMRLevel[i]['box'][j]['x0'] = x1b + dx*(ib0)
501  AMRLevel[i]['box'][j]['x1'] = x1b + dx*(ie0+1)
502  else:
503  AMRLevel[i]['box'][j]['x0'] = x1b*exp(dx*(ib0))
504  AMRLevel[i]['box'][j]['x1'] = x1b*exp(dx*(ie0+1))
505  AMRLevel[i]['box'][j]['y0'] = x2b + dx*(jb0)*ystr
506  AMRLevel[i]['box'][j]['y1'] = x2b + dx*(je0+1)*ystr
507  AMRLevel[i]['box'][j]['z0'] = x3b + dx*(kb0)*zstr
508  AMRLevel[i]['box'][j]['z1'] = x3b + dx*(ke0+1)*zstr
509  AMRLevel[i]['box'][j]['ib'] = ib0 ; AMRLevel[i]['box'][j]['ie'] = ie0
510  AMRLevel[i]['box'][j]['jb'] = jb0 ; AMRLevel[i]['box'][j]['je'] = je0
511  AMRLevel[i]['box'][j]['kb'] = kb0 ; AMRLevel[i]['box'][j]['ke'] = ke0
512  AMRBoxes[ib0-ibeg:ie0-ibeg+1, jb0-jbeg:je0-jbeg+1, kb0-kbeg:ke0-kbeg+1] = il
513 
514  ### Extract the box intersection from data stored in q
515  cib0 = (ib0-ib)/freb[i] ; cie0 = (ie0-ib)/freb[i]
516  cjb0 = (jb0-jb)/freb[i] ; cje0 = (je0-jb)/freb[i]
517  ckb0 = (kb0-kb)/freb[i] ; cke0 = (ke0-kb)/freb[i]
518  q1 = np.zeros((cie0-cib0+1, cje0-cjb0+1, cke0-ckb0+1,nvar))
519  q1 = q[cib0:cie0+1,cjb0:cje0+1,ckb0:cke0+1,:]
520 
521  # Remap the extracted portion
522  if (dim == 1):
523  new_shape = (ie0-ib0+1,1)
524  elif (dim == 2):
525  new_shape = (ie0-ib0+1,je0-jb0+1)
526  else:
527  new_shape = (ie0-ib0+1,je0-jb0+1,ke0-kb0+1)
528 
529  stmp = list(new_shape)
530  while stmp.count(1) > 0:
531  stmp.remove(1)
532  new_shape = tuple(stmp)
533 
534  myT = Tools()
535  for iv in range(nvar):
536  vars[ib0-ibeg:ie0-ibeg+1,jb0-jbeg:je0-jbeg+1,kb0-kbeg:ke0-kbeg+1,iv] = \
537  myT.congrid(q1[:,:,:,iv].squeeze(),new_shape,method='linear',minusone=True).reshape((ie0-ib0+1,je0-jb0+1,ke0-kb0+1))
538  ncount = ncount+szb
539 
540  h5vardict={}
541  for iv in range(nvar):
542  h5vardict[myvars[iv]] = vars[:,:,:,iv].squeeze()
543  AMRdict = dict([('AMRBoxes',AMRBoxes),('AMRLevel',AMRLevel)])
544  OutDict = dict(NewGridDict)
545  OutDict.update(AMRdict)
546  OutDict.update(h5vardict)
547  return OutDict
548 
549 
x1range
Allow to load only a portion of the domain.
Definition: pyPLUTO.py:119
def DataScanHDF5(self, fp, myvars, ilev)
Definition: pyPLUTO.py:334
double max
Definition: analysis.c:5

Here is the caller graph for this function:

def pyPLUTO.pyPLUTO.pload.DataScanVTK (   self,
  fp,
  n1,
  n2,
  n3,
  endian,
  dtype 
)
Scans the VTK data files. 
    
**Inputs**:
    
     fp -- Data file pointer\n
     n1 -- No. of points in X1 direction\n
     n2 -- No. of points in X2 direction\n
     n3 -- No. of points in X3 direction\n
     endian -- Endianess of the data\n
     dtype -- datatype 
     
**Output**:
  
  Dictionary consisting of variable names as keys and its values. 

Definition at line 282 of file pyPLUTO.py.

282  def DataScanVTK(self, fp, n1, n2, n3, endian, dtype):
283  """ Scans the VTK data files.
284 
285  **Inputs**:
286 
287  fp -- Data file pointer\n
288  n1 -- No. of points in X1 direction\n
289  n2 -- No. of points in X2 direction\n
290  n3 -- No. of points in X3 direction\n
291  endian -- Endianess of the data\n
292  dtype -- datatype
293 
294  **Output**:
295 
296  Dictionary consisting of variable names as keys and its values.
297 
298  """
299  ks = []
300  vtkvar = []
301  while True:
302  l = fp.readline()
303  try:
304  l.split()[0]
305  except IndexError:
306  pass
307  else:
308  if l.split()[0] == 'SCALARS':
309  ks.append(l.split()[1])
310  elif l.split()[0] == 'LOOKUP_TABLE':
311  A = array.array(dtype)
312  fmt = endian+str(n1*n2*n3)+dtype
313  nb = np.dtype(fmt).itemsize
314  A.fromstring(fp.read(nb))
315  if (self.Slice):
316  darr = np.zeros((n1*n2*n3))
317  indxx = np.sort([n3_tot*n2_tot*k + j*n2_tot + i for i in self.irange for j in self.jrange for k in self.krange])
318  if (sys.byteorder != self.endianess):
319  A.byteswap()
320  for ii,iii in enumerate(indxx):
321  darr[ii] = A[iii]
322  vtkvar_buf = [darr]
323  else:
324  vtkvar_buf = np.frombuffer(A,dtype=np.dtype(fmt))
325  vtkvar.append(np.reshape(vtkvar_buf,self.nshp).transpose())
326  else:
327  pass
328  if l == '':
329  break
330 
331  vtkvardict = dict(zip(ks,vtkvar))
332  return vtkvardict
333 
def DataScanVTK(self, fp, n1, n2, n3, endian, dtype)
Definition: pyPLUTO.py:282

Here is the caller graph for this function:

def pyPLUTO.pyPLUTO.pload.ReadDataFile (   self,
  num 
)
Reads the data file generated from PLUTO code.

    **Inputs**:
    
      num -- Data file number in form of an Integer.

**Outputs**:
    
      Dictionary that contains all information about Grid, Time and 
      variables.

Definition at line 676 of file pyPLUTO.py.

676  def ReadDataFile(self, num):
677  """Reads the data file generated from PLUTO code.
678 
679  **Inputs**:
680 
681  num -- Data file number in form of an Integer.
682 
683  **Outputs**:
684 
685  Dictionary that contains all information about Grid, Time and
686  variables.
687 
688  """
689  gridfile = self.wdir+"grid.out"
690  if self.datatype == "float":
691  dtype = "f"
692  varfile = self.wdir+"flt.out"
693  dataext = ".flt"
694  elif self.datatype == "vtk":
695  dtype = "f"
696  varfile = self.wdir+"vtk.out"
697  dataext=".vtk"
698  elif self.datatype == 'hdf5':
699  dtype = 'd'
700  dataext = '.hdf5'
701  nstr = num
702  varfile = self.wdir+"data."+nstr+dataext
703  else:
704  dtype = "d"
705  varfile = self.wdir+"dbl.out"
706  dataext = ".dbl"
707 
708  self.ReadVarFile(varfile)
709  self.ReadGridFile(gridfile)
710  self.ReadTimeInfo(varfile)
711  nstr = num
712  if self.endianess == 'big':
713  endian = ">"
714  elif self.datatype == 'vtk':
715  endian = ">"
716  else:
717  endian = "<"
718 
719  D = [('NStep', self.NStep), ('SimTime', self.SimTime), ('Dt', self.Dt),
720  ('n1', self.n1), ('n2', self.n2), ('n3', self.n3),
721  ('x1', self.x1), ('x2', self.x2), ('x3', self.x3),
722  ('dx1', self.dx1), ('dx2', self.dx2), ('dx3', self.dx3),
723  ('endianess', self.endianess), ('datatype', self.datatype),
724  ('filetype', self.filetype)]
725  ddict = dict(D)
726 
727  if self.filetype == "single_file":
728  datafilename = self.wdir+"data."+nstr+dataext
729  self.ReadSingleFile(datafilename, self.vars, self.n1, self.n2,
730  self.n3, endian, dtype, ddict)
731  elif self.filetype == "multiple_files":
732  self.ReadMultipleFiles(nstr, dataext, self.vars, self.n1, self.n2,
733  self.n3, endian, dtype, ddict)
734  else:
735  print "Wrong file type : CHECK pluto.ini for file type."
736  print "Only supported are .dbl, .flt, .vtk, .hdf5"
737  sys.exit()
738 
739  return ddict
740 
741 
def ReadSingleFile(self, datafilename, myvars, n1, n2, n3, endian, dtype, ddict)
Definition: pyPLUTO.py:594
def ReadGridFile(self, gridfile)
Definition: pyPLUTO.py:193
def ReadVarFile(self, varfile)
Definition: pyPLUTO.py:169
def ReadMultipleFiles(self, nstr, dataext, myvars, n1, n2, n3, endian, dtype, ddict)
Definition: pyPLUTO.py:645
def ReadTimeInfo(self, timefile)
Definition: pyPLUTO.py:146
def ReadDataFile(self, num)
Definition: pyPLUTO.py:676

Here is the call graph for this function:

def pyPLUTO.pyPLUTO.pload.ReadGridFile (   self,
  gridfile 
)
Read grid values from the grid.out file.

    **Inputs**:
      
      gridfile -- name of the grid.out file which has information about the grid. 

Definition at line 193 of file pyPLUTO.py.

193  def ReadGridFile(self, gridfile):
194  """ Read grid values from the grid.out file.
195 
196  **Inputs**:
197 
198  gridfile -- name of the grid.out file which has information about the grid.
199 
200  """
201  xL = []
202  xR = []
203  nmax = []
204  gfp = open(gridfile, "r")
205  for i in gfp.readlines():
206  if len(i.split()) == 1:
207  try:
208  int(i.split()[0])
209  nmax.append(int(i.split()[0]))
210  except:
211  pass
212 
213  if len(i.split()) == 3:
214  try:
215  int(i.split()[0])
216  xL.append(float(i.split()[1]))
217  xR.append(float(i.split()[2]))
218  except:
219  if (i.split()[1] == 'GEOMETRY:'):
220  self.geometry=i.split()[2]
221  pass
222 
223  self.n1, self.n2, self.n3 = nmax
224  n1 = self.n1
225  n1p2 = self.n1 + self.n2
226  n1p2p3 = self.n1 + self.n2 + self.n3
227  self.x1 = np.asarray([0.5*(xL[i]+xR[i]) for i in range(n1)])
228  self.dx1 = np.asarray([(xR[i]-xL[i]) for i in range(n1)])
229  self.x2 = np.asarray([0.5*(xL[i]+xR[i]) for i in range(n1, n1p2)])
230  self.dx2 = np.asarray([(xR[i]-xL[i]) for i in range(n1, n1p2)])
231  self.x3 = np.asarray([0.5*(xL[i]+xR[i]) for i in range(n1p2, n1p2p3)])
232  self.dx3 = np.asarray([(xR[i]-xL[i]) for i in range(n1p2, n1p2p3)])
233 
234 
235  # Stores the total number of points in '_tot' variable in case only
236  # a portion of the domain is loaded. Redefine the x and dx arrays
237  # to match the requested ranges
238  self.n1_tot = self.n1 ; self.n2_tot = self.n2 ; self.n3_tot = self.n3
239  if (self.x1range != None):
240  self.n1_tot = self.n1
241  self.irange = range(abs(self.x1-self.x1range[0]).argmin(),abs(self.x1-self.x1range[1]).argmin()+1)
242  self.n1 = len(self.irange)
243  self.x1 = self.x1[self.irange]
244  self.dx1 = self.dx1[self.irange]
245  else:
246  self.irange = range(self.n1)
247  if (self.x2range != None):
248  self.n2_tot = self.n2
249  self.jrange = range(abs(self.x2-self.x2range[0]).argmin(),abs(self.x2-self.x2range[1]).argmin()+1)
250  self.n2 = len(self.jrange)
251  self.x2 = self.x2[self.jrange]
252  self.dx2 = self.dx2[self.jrange]
253  else:
254  self.jrange = range(self.n2)
255  if (self.x3range != None):
256  self.n3_tot = self.n3
257  self.krange = range(abs(self.x3-self.x3range[0]).argmin(),abs(self.x3-self.x3range[1]).argmin()+1)
258  self.n3 = len(self.krange)
259  self.x3 = self.x3[self.krange]
260  self.dx3 = self.dx3[self.krange]
261  else:
262  self.krange = range(self.n3)
263  self.Slice=(self.x1range != None) or (self.x2range != None) or (self.x3range != None)
264 
265 
266  # Create the xr arrays containing the edges positions
267  # Useful for pcolormesh which should use those
268  self.x1r = np.zeros(len(self.x1)+1) ; self.x1r[1:] = self.x1 + self.dx1/2.0 ; self.x1r[0] = self.x1r[1]-self.dx1[0]
269  self.x2r = np.zeros(len(self.x2)+1) ; self.x2r[1:] = self.x2 + self.dx2/2.0 ; self.x2r[0] = self.x2r[1]-self.dx2[0]
270  self.x3r = np.zeros(len(self.x3)+1) ; self.x3r[1:] = self.x3 + self.dx3/2.0 ; self.x3r[0] = self.x3r[1]-self.dx3[0]
271 
272 
273  prodn = self.n1*self.n2*self.n3
274  if prodn == self.n1:
275  self.nshp = (self.n1)
276  elif prodn == self.n1*self.n2:
277  self.nshp = (self.n2, self.n1)
278  else:
279  self.nshp = (self.n3, self.n2, self.n1)
280 
281 
def ReadGridFile(self, gridfile)
Definition: pyPLUTO.py:193
x1range
Allow to load only a portion of the domain.
Definition: pyPLUTO.py:119

Here is the caller graph for this function:

def pyPLUTO.pyPLUTO.pload.ReadMultipleFiles (   self,
  nstr,
  dataext,
  myvars,
  n1,
  n2,
  n3,
  endian,
  dtype,
  ddict 
)
Reads a  multiple data files, varname.****.dataext.
    
**Inputs**:
      
  nstr -- File number in form of a string\n
      dataext -- Data type of the file, e.g., 'dbl', 'flt' or 'vtk' \n
  myvars -- List of variable names to be read\n
  n1 -- No. of points in X1 direction\n
  n2 -- No. of points in X2 direction\n
  n3 -- No. of points in X3 direction\n
  endian -- Endianess of the data\n
  dtype -- datatype\n
  ddict -- Dictionary containing Grid and Time Information
  which is updated.
     
**Output**:
  
  Updated Dictionary consisting of variable names as keys and its values.

Definition at line 645 of file pyPLUTO.py.

645  dtype, ddict):
646  """Reads a multiple data files, varname.****.dataext.
647 
648  **Inputs**:
649 
650  nstr -- File number in form of a string\n
651  dataext -- Data type of the file, e.g., 'dbl', 'flt' or 'vtk' \n
652  myvars -- List of variable names to be read\n
653  n1 -- No. of points in X1 direction\n
654  n2 -- No. of points in X2 direction\n
655  n3 -- No. of points in X3 direction\n
656  endian -- Endianess of the data\n
657  dtype -- datatype\n
658  ddict -- Dictionary containing Grid and Time Information
659  which is updated.
660 
661  **Output**:
662 
663  Updated Dictionary consisting of variable names as keys and its values.
664 
665  """
666  for i in range(len(myvars)):
667  datafilename = self.wdir+myvars[i]+"."+nstr+dataext
668  fp = open(datafilename, "rb")
669  if self.datatype == 'vtk':
670  ddict.update(self.DataScanVTK(fp, n1, n2, n3, endian, dtype))
671  else:
672  ddict.update({myvars[i]: self.DataScan(fp, n1, n2, n3, endian,
673  dtype)})
674  fp.close()
675 
def DataScanVTK(self, fp, n1, n2, n3, endian, dtype)
Definition: pyPLUTO.py:282

Here is the call graph for this function:

Here is the caller graph for this function:

def pyPLUTO.pyPLUTO.pload.ReadSingleFile (   self,
  datafilename,
  myvars,
  n1,
  n2,
  n3,
  endian,
  dtype,
  ddict 
)
Reads a single data file, data.****.dtype.
    
**Inputs**: 

  datafilename -- Data file name\n
      myvars -- List of variable names to be read\n
  n1 -- No. of points in X1 direction\n
  n2 -- No. of points in X2 direction\n
  n3 -- No. of points in X3 direction\n
  endian -- Endianess of the data\n
  dtype -- datatype\n
  ddict -- Dictionary containing Grid and Time Information
  which is updated
     
**Output**:

  Updated Dictionary consisting of variable names as keys and its values.

Definition at line 594 of file pyPLUTO.py.

594  dtype, ddict):
595  """Reads a single data file, data.****.dtype.
596 
597  **Inputs**:
598 
599  datafilename -- Data file name\n
600  myvars -- List of variable names to be read\n
601  n1 -- No. of points in X1 direction\n
602  n2 -- No. of points in X2 direction\n
603  n3 -- No. of points in X3 direction\n
604  endian -- Endianess of the data\n
605  dtype -- datatype\n
606  ddict -- Dictionary containing Grid and Time Information
607  which is updated
608 
609  **Output**:
610 
611  Updated Dictionary consisting of variable names as keys and its values.
612  """
613  if self.datatype == 'hdf5':
614  fp = h5.File(datafilename,'r')
615  else:
616  fp = open(datafilename, "rb")
617 
618  print "Reading Data file : %s"%datafilename
619 
620  if self.datatype == 'vtk':
621  vtkd = self.DataScanVTK(fp, n1, n2, n3, endian, dtype)
622  ddict.update(vtkd)
623  elif self.datatype == 'hdf5':
624  h5d = self.DataScanHDF5(fp,myvars,self.level)
625  ddict.update(h5d)
626  else:
627  for i in range(len(myvars)):
628  if myvars[i] == 'bx1s':
629  ddict.update({myvars[i]: self.DataScan(fp, n1, n2, n3, endian,
630  dtype, off=n2*n3)})
631  elif myvars[i] == 'bx2s':
632  ddict.update({myvars[i]: self.DataScan(fp, n1, n2, n3, endian,
633  dtype, off=n3*n1)})
634  elif myvars[i] == 'bx3s':
635  ddict.update({myvars[i]: self.DataScan(fp, n1, n2, n3, endian,
636  dtype, off=n1*n2)})
637  else:
638  ddict.update({myvars[i]: self.DataScan(fp, n1, n2, n3, endian,
639  dtype)})
640 
641 
642  fp.close()
643 
def DataScanVTK(self, fp, n1, n2, n3, endian, dtype)
Definition: pyPLUTO.py:282
def DataScanHDF5(self, fp, myvars, ilev)
Definition: pyPLUTO.py:334

Here is the call graph for this function:

Here is the caller graph for this function:

def pyPLUTO.pyPLUTO.pload.ReadTimeInfo (   self,
  timefile 
)
Read time info from the outfiles.

    **Inputs**:
      
      timefile -- name of the out file which has timing information. 

Definition at line 146 of file pyPLUTO.py.

146  def ReadTimeInfo(self, timefile):
147  """ Read time info from the outfiles.
148 
149  **Inputs**:
150 
151  timefile -- name of the out file which has timing information.
152 
153  """
154 
155  if (self.datatype == 'hdf5'):
156  fh5 = h5.File(timefile,'r')
157  self.SimTime = fh5.attrs.get('time')
158  #self.Dt = 1.e-2 # Should be erased later given the level in AMR
159  fh5.close()
160  else:
161  ns = self.NStep
162  f_var = open(timefile, "r")
163  tlist = []
164  for line in f_var.readlines():
165  tlist.append(line.split())
166  self.SimTime = float(tlist[ns][1])
167  self.Dt = float(tlist[ns][2])
168 
def ReadTimeInfo(self, timefile)
Definition: pyPLUTO.py:146

Here is the caller graph for this function:

def pyPLUTO.pyPLUTO.pload.ReadVarFile (   self,
  varfile 
)
Read variable names from the outfiles.

    **Inputs**:
      
      varfile -- name of the out file which has variable information. 

Definition at line 169 of file pyPLUTO.py.

169  def ReadVarFile(self, varfile):
170  """ Read variable names from the outfiles.
171 
172  **Inputs**:
173 
174  varfile -- name of the out file which has variable information.
175 
176  """
177  if (self.datatype == 'hdf5'):
178  fh5 = h5.File(varfile,'r')
179  self.filetype = 'single_file'
180  self.endianess = '>' # not used with AMR, kept for consistency
181  self.vars = []
182  for iv in range(fh5.attrs.get('num_components')):
183  self.vars.append(fh5.attrs.get('component_'+str(iv)))
184  fh5.close()
185  else:
186  vfp = open(varfile, "r")
187  varinfo = vfp.readline().split()
188  self.filetype = varinfo[4]
189  self.endianess = varinfo[5]
190  self.vars = varinfo[6:]
191  vfp.close()
192 
def ReadVarFile(self, varfile)
Definition: pyPLUTO.py:169

Here is the caller graph for this function:

Member Data Documentation

tuple pyPLUTO.pyPLUTO.pload.A = array.array(dtype)
static

Definition at line 575 of file pyPLUTO.py.

tuple pyPLUTO.pyPLUTO.pload.darr = np.zeros((n1*n2*n3))
static

Definition at line 581 of file pyPLUTO.py.

list pyPLUTO.pyPLUTO.pload.darr = [darr]
static

Definition at line 587 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.datatype

Definition at line 129 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.Dt

Definition at line 106 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.dx1

Definition at line 115 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.dx2

Definition at line 116 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.dx3

Definition at line 117 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.endianess

Definition at line 180 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.filetype

Definition at line 179 of file pyPLUTO.py.

tuple pyPLUTO.pyPLUTO.pload.fmt = endian+str(n1_tot*n2_tot*n3_tot)
static

Definition at line 576 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.geometry

Definition at line 220 of file pyPLUTO.py.

tuple pyPLUTO.pyPLUTO.pload.indxx = np.sort([n3_tot*n2_tot*k + j*n2_tot + i for i in self.irange for j in self.jrange for k in self.krange])
static

Definition at line 582 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.irange

Definition at line 241 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.jrange

Definition at line 249 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.krange

Definition at line 257 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.level

Definition at line 136 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.n1

Definition at line 108 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.n1_tot = self.n3_tot
static

Definition at line 573 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.n2

Definition at line 109 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.n2_tot

Definition at line 238 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.n3

Definition at line 110 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.n3_tot

Definition at line 238 of file pyPLUTO.py.

tuple pyPLUTO.pyPLUTO.pload.nb = np.dtype(fmt)
static

Definition at line 577 of file pyPLUTO.py.

tuple pyPLUTO.pyPLUTO.pload.nboff = np.dtype(off_fmt)
static

Definition at line 570 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.nshp

Definition at line 275 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.NStep

Definition at line 105 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.NStepStr

Definition at line 123 of file pyPLUTO.py.

tuple pyPLUTO.pyPLUTO.pload.off_fmt = endian+str(off)
static
Scans the data files in all formats. 

**Inputs**:
  
  fp -- Data file pointer\n
  n1 -- No. of points in X1 direction\n
  n2 -- No. of points in X2 direction\n
  n3 -- No. of points in X3 direction\n
  endian -- Endianess of the data\n
  dtype -- datatype, eg : double, float, vtk, hdf5\n
  off -- offset (for avoiding staggered B fields) 
 
**Output**:
 
  Dictionary consisting of variable names as keys and its values. 

Definition at line 569 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.SimTime

Definition at line 157 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.Slice

Definition at line 263 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.vars

Definition at line 181 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.wdir

Definition at line 140 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.x1

Definition at line 112 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.x1r

Definition at line 268 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.x1range

Allow to load only a portion of the domain.

Definition at line 119 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.x2

Definition at line 113 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.x2r

Definition at line 269 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.x2range

Definition at line 120 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.x3

Definition at line 114 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.x3r

Definition at line 270 of file pyPLUTO.py.

pyPLUTO.pyPLUTO.pload.x3range

Definition at line 121 of file pyPLUTO.py.


The documentation for this class was generated from the following file: