BHAC Python tools
Public Member Functions | Public Attributes | List of all members
read.particles Class Reference

Load binary particles data. More...

Public Member Functions

def __init__ (self, offset, file='data', components=3)
 
def makefilename (self)
 
def openfile (self)
 
def closefile (self)
 
def readheader (self)
 
def read_next_particle (self)
 
def read (self)
 
def particle (self, index)
 
def get_sorted (self, i)
 

Public Attributes

 offset
 
 filenameout
 
 isLoaded
 
 components
 
 data
 
 mynparticles
 
 filename
 
 file
 
 index
 
 sorted
 

Detailed Description

Load binary particles data.

Definition at line 590 of file read.py.

Constructor & Destructor Documentation

◆ __init__()

def read.particles.__init__ (   self,
  offset,
  file = 'data',
  components = 3 
)

Definition at line 592 of file read.py.

592  def __init__(self,offset,file='data',components=3):
593  self.offset=offset
594  self.filenameout = file
595  self.isLoaded = False
596  self.components = components
597 
598  self.data=[]
599  self.mynparticles = 0
600 
601  self.makefilename()
602  self.openfile()
603  self.read()
604  self.closefile()
605 
606 
def __init__(self, offset, file='data', headersize=256, nvars=8)
Definition: read.py:752

Member Function Documentation

◆ closefile()

def read.particles.closefile (   self)

Definition at line 616 of file read.py.

616  def closefile(self):
617  self.file.close()
618  self.isLoaded = False
619 
620 

◆ get_sorted()

def read.particles.get_sorted (   self,
  i 
)

Definition at line 675 of file read.py.

675  def get_sorted(self,i):
676  try:
677  self.sorted
678  except AttributeError:
679  self.index=np.array(self.nparticles)
680  index=[]
681  for particle in self.data:
682  index.append(particle['index'])
683  index=np.array(index)
684  self.sorted=index.argsort()
685  return self.sorted[i-1]
686 
687 #=============================================================================

◆ makefilename()

def read.particles.makefilename (   self)

Definition at line 607 of file read.py.

607  def makefilename(self):
608  self.filename = self.filenameout+'_particles'+str(self.offset).zfill(4)+'.dat'
609 
610 

◆ openfile()

def read.particles.openfile (   self)

Definition at line 611 of file read.py.

611  def openfile(self):
612  self.file = open(self.filename,'rb')
613  self.isLoaded = True
614 
615 

◆ particle()

def read.particles.particle (   self,
  index 
)

Definition at line 668 of file read.py.

668  def particle(self,index):
669  for particle in self.data:
670  if particle['index'] == index :
671  return particle
672  return False
673 
674 

◆ read()

def read.particles.read (   self)

Definition at line 662 of file read.py.

662  def read(self):
663  self.readheader()
664  while (self.mynparticles < self.nparticles):
665  self.read_next_particle()
666 
667 
Definition: read.py:1

◆ read_next_particle()

def read.particles.read_next_particle (   self)

Definition at line 628 of file read.py.

628  def read_next_particle(self):
629  x = np.empty(self.components)
630  u = np.empty(self.components)
631  payload = np.empty(self.npayload)
632 
633  (index,) = struct.unpack('i',self.file.read(4))
634 
635  (ifollow,) = struct.unpack('i',self.file.read(4))
636  if (ifollow == -1):
637  follow = True
638  else:
639  follow = False
640 
641  (q,) = struct.unpack('d',self.file.read(8))
642  (m,) = struct.unpack('d',self.file.read(8))
643  (t,) = struct.unpack('d',self.file.read(8))
644  (dt,) = struct.unpack('d',self.file.read(8))
645 
646  for icomp in range(self.components):
647  (x[icomp],) = struct.unpack('d',self.file.read(8))
648 
649  for icomp in range(self.components):
650  (u[icomp],) = struct.unpack('d',self.file.read(8))
651 
652  for ipayload in range(self.npayload):
653  (payload[ipayload],) = struct.unpack('d',self.file.read(8))
654 
655  self.data.append({'index':index, 'q':q,
656  'follow':follow, 'm':m, 't':t,
657  'dt':dt, 'x':x, 'u':u, 'payload':payload})
658 
659  self.mynparticles= self.mynparticles + 1
660 
661 
Definition: read.py:1

◆ readheader()

def read.particles.readheader (   self)

Definition at line 621 of file read.py.

621  def readheader(self):
622  self.file.seek(0)
623  (self.nparticles,) = struct.unpack('i',self.file.read(4))
624  (self.itparticles,) = struct.unpack('i',self.file.read(4))
625  (self.npayload,) = struct.unpack('i',self.file.read(4))
626 
627 
Definition: read.py:1

Member Data Documentation

◆ components

read.particles.components

Definition at line 596 of file read.py.

◆ data

read.particles.data

Definition at line 598 of file read.py.

◆ file

read.particles.file

Definition at line 612 of file read.py.

◆ filename

read.particles.filename

Definition at line 608 of file read.py.

◆ filenameout

read.particles.filenameout

Definition at line 594 of file read.py.

◆ index

read.particles.index

Definition at line 679 of file read.py.

◆ isLoaded

read.particles.isLoaded

Definition at line 595 of file read.py.

◆ mynparticles

read.particles.mynparticles

Definition at line 599 of file read.py.

◆ offset

read.particles.offset

Definition at line 593 of file read.py.

◆ sorted

read.particles.sorted

Definition at line 684 of file read.py.


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