[Yt-svn] yt-commit r601 - branches/yt-generalization/yt/lagos

joishi at wrangler.dreamhost.com joishi at wrangler.dreamhost.com
Sat Jun 21 15:49:41 PDT 2008


Author: joishi
Date: Sat Jun 21 15:49:41 2008
New Revision: 601
URL: http://yt.spacepope.org/changeset/601

Log:
* added translation dict for enzo->orion data field names
* DataReadingFuncs.py -- added a data reader for Orion Native files. This is
  something of an outline: it works but is hardcoded to read one particular
  field from one grid. 


Modified:
   branches/yt-generalization/yt/lagos/DataReadingFuncs.py
   branches/yt-generalization/yt/lagos/OrionDefs.py

Modified: branches/yt-generalization/yt/lagos/DataReadingFuncs.py
==============================================================================
--- branches/yt-generalization/yt/lagos/DataReadingFuncs.py	(original)
+++ branches/yt-generalization/yt/lagos/DataReadingFuncs.py	Sat Jun 21 15:49:41 2008
@@ -143,8 +143,56 @@
 def getExceptionHDF5():
     return (exceptions.KeyError, HDF5LightReader.ReadingError)
 
-def readDataNative():
-    pass
+def readDataNative(self,field):
+    """
+    reads packed multiFABs output by BoxLib in "NATIVE" format.
+
+    """
+    inFile = open(os.path.expanduser(filename),'rb')
+    header = inFile.readline()
+    header.strip()
+
+    pattern = r"^FAB \(\((\d+), \([0-9 ]+\)\),\(\d+, \(([0-9 ]+)\)\)\)\(\((\d+,\d+,\d+)\) \((\d+,\d+,\d+)\) \((\d+,\d+,\d+)\)\) (\d+)\n"
+
+    headerRe = re.compile(pattern)
+    bytesPerReal,endian,start,stop,centerType,nComponents = headerRe.search(header).groups()
+
+    # we will build up a dtype string, starting with endian
+    # check endianness (this code is ugly. fix?)
+
+    swapEndian = False
+
+    if int(bytesPerReal) == int(endian[0]):
+        dtype = '<'
+    elif int(bytesPerReal) == int(endian[-1]):
+        dtype = '>'
+    else:
+        raise ValueError("FAB header is neither big nor little endian. Perhaps the file is corrupt?")
+
+    dtype += 'f' + bytesPerReal #always a floating point
+
+    # determine size of FAB
+    # TODO: we should check consistency of this against the MF header...
+    start = na.array(map(int,start.split(',')))
+    stop = na.array(map(int,stop.split(',')))
+
+    gridSize = stop - start + 1
+    nElements = 1
+    for i in gridSize:
+        nElements = nElements*i 
+
+
+    # one field has nElements*bytesPerReal bytes
+    # and is located at offset
+    offset = 0 # change this
+
+    field = na.fromfile(inFile,count=nElements,dtype=dtype)
+    field.reshape(gridSize[::-1]) #the FAB is fortran ordered; we want C
+
+    # we can/should also check against the max and min in the header file
+
+    inFile.close()
+    return field
 
 def readAllDataNative():
     pass

Modified: branches/yt-generalization/yt/lagos/OrionDefs.py
==============================================================================
--- branches/yt-generalization/yt/lagos/OrionDefs.py	(original)
+++ branches/yt-generalization/yt/lagos/OrionDefs.py	Sat Jun 21 15:49:41 2008
@@ -32,3 +32,10 @@
 # throughout the code. key is Orion name, value is Enzo/yt equivalent
 orion2enzoDict = {"amr.n_cell": "TopGridRank",
                   }
+
+orion2ytFieldsDict = {"x-velocity": "xvel",
+                      "y-velocity": "yvel",
+                      "z-velocity": "zvel",
+                      "Density": "density",
+                      "Total_Energy": "eden",
+                     }



More information about the yt-svn mailing list