[Yt-svn] commit/yt: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Thu Mar 10 13:25:35 PST 2011


2 new changesets in yt:

http://bitbucket.org/yt_analysis/yt/changeset/8e66b2684b99/
changeset:   r3809:8e66b2684b99
branch:      yt
user:        atmyers
date:        2011-03-10 22:01:41
summary:     patch for Chombo reader. Attemps to read pluto/orion2 input files if present
affected #:  3 files (4.6 KB)

--- a/yt/frontends/chombo/data_structures.py	Thu Mar 10 12:33:13 2011 -0800
+++ b/yt/frontends/chombo/data_structures.py	Thu Mar 10 13:01:41 2011 -0800
@@ -24,13 +24,34 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
+import h5py
+import re
+import os
+import weakref
+import numpy as na
+
+from collections import \
+     defaultdict
+from string import \
+     strip, \
+     rstrip
+from stat import \
+     ST_CTIME
+
+from .definitions import \
+     pluto2enzoDict, \
+     yt2plutoFieldsDict, \
+     parameterDict \
+     
 from yt.funcs import *
 from yt.data_objects.grid_patch import \
-           AMRGridPatch
+     AMRGridPatch
 from yt.data_objects.hierarchy import \
-           AMRHierarchy
+     AMRHierarchy
 from yt.data_objects.static_output import \
-           StaticOutput
+     StaticOutput
+from yt.utilities.definitions import \
+     mpc_conversion
 
 from .fields import ChomboFieldContainer
 
@@ -66,12 +87,15 @@
     grid = ChomboGrid
     
     def __init__(self,pf,data_style='chombo_hdf5'):
+        self.domain_left_edge = pf.domain_left_edge # need these to determine absolute grid locations
+        self.domain_right_edge = pf.domain_right_edge # need these to determine absolute grid locations
         self.data_style = data_style
         self.field_info = ChomboFieldContainer()
         self.field_indexes = {}
         self.parameter_file = weakref.proxy(pf)
         # for now, the hierarchy file is the parameter file!
         self.hierarchy_filename = self.parameter_file.parameter_filename
+        self.hierarchy = os.path.abspath(self.hierarchy_filename)
         self.directory = os.path.dirname(self.hierarchy_filename)
         self._fhandle = h5py.File(self.hierarchy_filename)
 
@@ -117,8 +141,8 @@
                                start = si, stop = ei)
                 self.grids.append(pg)
                 self.grids[-1]._level_id = level_id
-                self.grid_left_edge[i] = dx*si.astype(self.float_type)
-                self.grid_right_edge[i] = dx*(ei.astype(self.float_type) + 1)
+                self.grid_left_edge[i] = dx*si.astype(self.float_type) + self.domain_left_edge
+                self.grid_right_edge[i] = dx*(ei.astype(self.float_type)+1) + self.domain_left_edge
                 self.grid_particle_count[i] = 0
                 self.grid_dimensions[i] = ei - si + 1
                 i += 1
@@ -152,18 +176,13 @@
     _fieldinfo_class = ChomboFieldContainer
     
     def __init__(self, filename, data_style='chombo_hdf5',
-                 storage_filename = None):
+                 storage_filename = None, ini_filename = None):
+        # hardcoded for now 
+        self.current_time = 0.0
+        self.ini_filename = ini_filename
         StaticOutput.__init__(self,filename,data_style)
         self.storage_filename = storage_filename
-
         self.field_info = self._fieldinfo_class()
-        # hardcoded for now
-        self.current_time = 0.0
-        # These should be explicitly obtained from the file, but for now that
-        # will wait until a reorganization of the source tree and better
-        # generalization.
-        self.dimensionality = 3
-        self.refine_by = 2
         
     def _set_units(self):
         """
@@ -177,11 +196,11 @@
         self.conversion_factors = defaultdict(lambda: 1.0)
         self.time_units['1'] = 1
         self.units['1'] = 1.0
-        self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max()
+        self.units['unitary'] = 1.0 / (self.domain_right_edge - self.domain_left_edge).max()
         seconds = 1 #self["Time"]
         self.time_units['years'] = seconds / (365*3600*24.0)
         self.time_units['days']  = seconds / (3600*24.0)
-        for key in yt2orionFieldsDict:
+        for key in yt2plutoFieldsDict:
             self.conversion_factors[key] = 1.0
 
     def _setup_nounits_units(self):
@@ -194,13 +213,79 @@
             self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"]
 
 
+    def _localize(self, f, default):
+        if f is None:
+            return os.path.join(self.directory, default)
+        return f
+
     def _parse_parameter_file(self):
+        """
+        Check to see whether a 'pluto.ini' or 'orion2.ini' file
+        exists in the plot file directory. If one does, attempt to parse it.
+        Otherwise, assume the left edge starts at 0 and get the right edge
+        from the hdf5 file.
+        """
+        if os.path.isfile('pluto.ini'):
+            self._parse_pluto_file('pluto.ini')
+        elif os.path.isfile('orion2.ini'):
+            self._parse_pluto_file('orion2.ini')
+        else:
+            self.unique_identifier = \
+                                   int(os.stat(self.parameter_filename)[ST_CTIME])
+            self.domain_left_edge = na.array([0.,0.,0.])
+            self.domain_right_edge = self.__calc_right_edge()
+
+    def _parse_pluto_file(self, ini_filename):
+        """
+        Reads in an inputs file in the 'pluto.ini' format. Probably not
+        especially robust at the moment.
+        """
+        self.fullplotdir = os.path.abspath(self.parameter_filename)
+        self.ini_filename = self._localize( \
+            self.ini_filename, ini_filename)
         self.unique_identifier = \
-            int(os.stat(self.parameter_filename)[ST_CTIME])
-        self.domain_left_edge = na.array([0.,0.,0.])
-        self.domain_right_edge = self.__calc_right_edge()
-        
+                               int(os.stat(self.parameter_filename)[ST_CTIME])
+        lines = open(self.ini_filename).readlines()
+        # read the file line by line, storing important parameters
+        for lineI, line in enumerate(lines):
+            try: 
+                param, sep, vals = map(rstrip,line.partition(' '))
+            except ValueError:
+                mylog.error("ValueError: '%s'", line)
+            if pluto2enzoDict.has_key(param):
+                paramName = pluto2enzoDict[param]
+                t = map(parameterDict[paramName], vals.split())
+                if len(t) == 1:
+                    self.parameters[paramName] = t[0]
+                else:
+                    if paramName == "RefineBy":
+                        self.parameters[paramName] = t[0]
+                    else:
+                        self.parameters[paramName] = t
 
+            # assumes 3D for now
+            elif param.startswith("X1-grid"):
+                t = vals.split()
+                low1 = float(t[1])
+                high1 = float(t[4])
+                N1 = int(t[2])
+            elif param.startswith("X2-grid"):
+                t = vals.split()
+                low2 = float(t[1])
+                high2 = float(t[4])
+                N2 = int(t[2])
+            elif param.startswith("X3-grid"):
+                t = vals.split()
+                low3 = float(t[1])
+                high3 = float(t[4])
+                N3 = int(t[2])
+
+        self.dimensionality = 3
+        self.domain_left_edge = na.array([low1,low2,low3])
+        self.domain_right_edge = na.array([high1,high2,high3])
+        self.domain_dimensions = na.array([N1,N2,N3])
+        self.refine_by = self.parameters["RefineBy"]
+            
     def __calc_right_edge(self):
         fileh = h5py.File(self.parameter_filename,'r')
         dx0 = fileh['/level_0'].attrs['dx']


--- a/yt/frontends/chombo/definitions.py	Thu Mar 10 12:33:13 2011 -0800
+++ b/yt/frontends/chombo/definitions.py	Thu Mar 10 13:01:41 2011 -0800
@@ -23,3 +23,43 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 """
+
+parameterDict = {"CosmologyCurrentRedshift": float,
+                 "CosmologyComovingBoxSize": float,
+                 "CosmologyOmegaMatterNow": float,
+                 "CosmologyOmegaLambdaNow": float,
+                 "CosmologyHubbleConstantNow": float,
+                 "CosmologyInitialRedshift": float,
+                 "DualEnergyFormalismEta1": float,
+                 "DualEnergyFormalismEta2": float,
+                 "MetaDataString": str,
+                 "HydroMethod": int,
+                 "DualEnergyFormalism": int,
+                 "InitialTime": float,
+                 "ComovingCoordinates": int,
+                 "DensityUnits": float,
+                 "LengthUnits": float,
+                 "LengthUnit": float,
+                 "TemperatureUnits": float,
+                 "TimeUnits": float,
+                 "GravitationalConstant": float,
+                 "Gamma": float,
+                 "MultiSpecies": int,
+                 "CompilerPrecision": str,
+                 "CurrentTimeIdentifier": int,
+                 "RefineBy": int,
+                 "BoundaryConditionName": str,
+                 "TopGridRank": int,
+                 "TopGridDimensions": int,
+                 "EOSSoundSpeed": float,
+                 "EOSType": int,
+                 "NumberOfParticleAttributes": int,
+                                 }
+
+pluto2enzoDict = {"GAMMA": "Gamma",
+                  "Ref_ratio": "RefineBy"
+                                    }
+
+yt2plutoFieldsDict = {}
+pluto2ytFieldsDict = {}
+


--- a/yt/frontends/chombo/io.py	Thu Mar 10 12:33:13 2011 -0800
+++ b/yt/frontends/chombo/io.py	Thu Mar 10 13:01:41 2011 -0800
@@ -23,6 +23,9 @@
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
+import h5py
+import re
+
 from yt.utilities.io_handler import \
            BaseIOHandler
 


http://bitbucket.org/yt_analysis/yt/changeset/44ef2576918c/
changeset:   r3810:44ef2576918c
branch:      yt
user:        atmyers
date:        2011-03-10 22:18:32
summary:     need to assume a dimensionality and refinement ratio if no inputs file found
affected #:  1 file (67 bytes)

--- a/yt/frontends/chombo/data_structures.py	Thu Mar 10 13:01:41 2011 -0800
+++ b/yt/frontends/chombo/data_structures.py	Thu Mar 10 13:18:32 2011 -0800
@@ -234,6 +234,8 @@
                                    int(os.stat(self.parameter_filename)[ST_CTIME])
             self.domain_left_edge = na.array([0.,0.,0.])
             self.domain_right_edge = self.__calc_right_edge()
+            self.dimensionality = 3
+            self.refine_by = 2
 
     def _parse_pluto_file(self, ini_filename):
         """

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list