[yt-svn] commit/yt: 4 new changesets

Bitbucket commits-noreply at bitbucket.org
Thu Jun 14 08:56:29 PDT 2012


4 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/0ca36e01d8ac/
changeset:   0ca36e01d8ac
branch:      yt
user:        brittonsmith
date:        2012-06-14 01:02:40
summary:     Created SimulationTimeSeries super class for the EnzoSimulation
class and any future analogs for other simulation codes.  Moved
a number of the EnzoSimulation methods into SimulationTimeSeries.
Created a "simulation" convenience function analagous to "load"
but for SimulationTimeSeries.
affected #:  6 files

diff -r 08f29a9cec42435bb0581a2059b4f1c7abd6c8c5 -r 0ca36e01d8ac896284ce3f52afd8fda2efc070c2 yt/convenience.py
--- a/yt/convenience.py
+++ b/yt/convenience.py
@@ -33,6 +33,7 @@
 from yt.config import ytcfg
 from yt.utilities.parameter_file_storage import \
     output_type_registry, \
+    simulation_time_series_registry, \
     EnzoRunDatabase
 
 def load(*args ,**kwargs):
@@ -111,3 +112,14 @@
     f.close()
     return proj
 
+def simulation(parameter_filename, simulation_type):
+    """
+    Loads a simulation time series object of the specified
+    simulation type.
+    """
+
+    if simulation_type not in simulation_time_series_registry:
+        raise YTSimulationNotIdentified(simulation_type)
+
+    return simulation_time_series_registry[simulation_type](parameter_filename)
+


diff -r 08f29a9cec42435bb0581a2059b4f1c7abd6c8c5 -r 0ca36e01d8ac896284ce3f52afd8fda2efc070c2 yt/data_objects/time_series.py
--- a/yt/data_objects/time_series.py
+++ b/yt/data_objects/time_series.py
@@ -33,7 +33,9 @@
 from .derived_quantities import quantity_info
 from yt.utilities.exceptions import YTException
 from yt.utilities.parallel_tools.parallel_analysis_interface \
-    import parallel_objects
+    import parallel_objects, parallel_root_only
+from yt.utilities.parameter_file_storage import \
+    simulation_time_series_registry
 
 class AnalysisTaskProxy(object):
     def __init__(self, time_series):
@@ -189,3 +191,65 @@
         # hierarchy
         cls = getattr(pf.h, self.data_object_name)
         return cls(*self._args, **self._kwargs)
+
+
+class SimulationTimeSeries(object):
+    class __metaclass__(type):
+        def __init__(cls, name, b, d):
+            type.__init__(cls, name, b, d)
+            code_name = name[:name.find('Simulation')]
+            if code_name:
+                simulation_time_series_registry[code_name] = cls
+                mylog.debug("Registering simulation: %s as %s", code_name, cls)
+
+    def __init__(self, parameter_filename):
+        """
+        Base class for generating simulation time series types.
+        Principally consists of a *parameter_filename*.
+        """
+
+        if not os.path.exists(parameter_filename):
+            raise IOError(parameter_filename)
+        self.parameter_filename = parameter_filename
+        self.parameters = {}
+
+        # Set some parameter defaults.
+        self._set_parameter_defaults()
+        # Read the simulation parameter file.
+        self._parse_parameter_file()
+        # Set up time units dictionary.
+        self._set_time_units()
+
+        # Figure out the starting and stopping times and redshift.
+        self._calculate_simulation_bounds()
+        self.print_key_parameters()
+        
+        # Get all possible datasets.
+        self._get_all_outputs()
+
+    def __repr__(self):
+        return self.parameter_filename
+
+    @parallel_root_only
+    def print_key_parameters(self):
+        """
+        Print out some key parameters for the simulation.
+        """
+        for a in ["domain_dimensions", "domain_left_edge",
+                  "domain_right_edge", "initial_time", "final_time",
+                  "stop_cycle", "cosmological_simulation"]:
+            if not hasattr(self, a):
+                mylog.error("Missing %s in parameter file definition!", a)
+                continue
+            v = getattr(self, a)
+            mylog.info("Parameters: %-25s = %s", a, v)
+        if hasattr(self, "cosmological_simulation") and \
+           getattr(self, "cosmological_simulation"):
+            for a in ["omega_lambda", "omega_matter",
+                      "hubble_constant", "initial_redshift",
+                      "final_redshift"]:
+                if not hasattr(self, a):
+                    mylog.error("Missing %s in parameter file definition!", a)
+                    continue
+                v = getattr(self, a)
+                mylog.info("Parameters: %-25s = %s", a, v)


diff -r 08f29a9cec42435bb0581a2059b4f1c7abd6c8c5 -r 0ca36e01d8ac896284ce3f52afd8fda2efc070c2 yt/frontends/enzo/simulation_handling.py
--- a/yt/frontends/enzo/simulation_handling.py
+++ b/yt/frontends/enzo/simulation_handling.py
@@ -30,21 +30,21 @@
 import os
 
 from yt.data_objects.time_series import \
-    TimeSeriesData
+    SimulationTimeSeries, TimeSeriesData
 from yt.utilities.cosmology import \
     Cosmology, \
     EnzoCosmology
 from yt.utilities.exceptions import \
-    YTException
-from yt.utilities.parallel_tools.parallel_analysis_interface import \
-    parallel_root_only
+    AmbiguousOutputs, \
+    MissingParameter, \
+    NoStoppingCondition
 
 from yt.convenience import \
     load
 
-class EnzoSimulation(TimeSeriesData):
-    r"""Super class for performing the same operation over all data outputs in 
-    a simulation from one redshift to another.
+class EnzoSimulation(SimulationTimeSeries, TimeSeriesData):
+    r"""Class for creating TimeSeriesData object from an Enzo
+    simulation parameter file.
     """
     def __init__(self, parameter_filename):
         r"""Initialize an Enzo Simulation object.
@@ -65,23 +65,8 @@
         >>> print es.all_outputs
 
         """
-        self.parameter_filename = parameter_filename
-        self.parameters = {}
-
-        # Set some parameter defaults.
-        self._set_parameter_defaults()
-        # Read the simulation parameter file.
-        self._parse_parameter_file()
-        # Set up time units dictionary.
-        self._set_time_units()
-
-        # Figure out the starting and stopping times and redshift.
-        self._calculate_simulation_bounds()
-        self.print_key_parameters()
+        SimulationTimeSeries.__init__(self, parameter_filename)
         
-        # Get all possible datasets.
-        self._get_all_outputs()
-
     def get_time_series(self, time_data=True, redshift_data=True,
                         initial_time=None, final_time=None, time_units='1',
                         initial_redshift=None, final_redshift=None,
@@ -260,30 +245,6 @@
                                 parallel=parallel)
         mylog.info("%d outputs loaded into time series." % len(my_outputs))
 
-    @parallel_root_only
-    def print_key_parameters(self):
-        """
-        Print out some key parameters for the simulation.
-        """
-        for a in ["domain_dimensions", "domain_left_edge",
-                  "domain_right_edge", "initial_time", "final_time",
-                  "stop_cycle", "cosmological_simulation"]:
-            if not hasattr(self, a):
-                mylog.error("Missing %s in parameter file definition!", a)
-                continue
-            v = getattr(self, a)
-            mylog.info("Parameters: %-25s = %s", a, v)
-        if hasattr(self, "cosmological_simulation") and \
-           getattr(self, "cosmological_simulation"):
-            for a in ["omega_lambda", "omega_matter",
-                      "hubble_constant", "initial_redshift",
-                      "final_redshift"]:
-                if not hasattr(self, a):
-                    mylog.error("Missing %s in parameter file definition!", a)
-                    continue
-                v = getattr(self, a)
-                mylog.info("Parameters: %-25s = %s", a, v)
-
     def _parse_parameter_file(self):
         """
         Parses the parameter file and establishes the various
@@ -665,28 +626,3 @@
         return self._get_outputs_by_key('time', times, tolerance=tolerance,
                                         outputs=outputs)
 
-class MissingParameter(YTException):
-    def __init__(self, pf, parameter):
-        YTException.__init__(self, pf)
-        self.parameter = parameter
-
-    def __str__(self):
-        return "Parameter file %s is missing %s parameter." % \
-            (self.pf, self.parameter)
-
-class NoStoppingCondition(YTException):
-    def __init__(self, pf):
-        YTException.__init__(self, pf)
-
-    def __str__(self):
-        return "Simulation %s has no stopping condition.  StopTime or StopCycle should be set." % \
-            self.pf
-
-class AmbiguousOutputs(YTException):
-    def __init__(self, pf):
-        YTException.__init__(self, pf)
-
-    def __str__(self):
-        return "Simulation %s has both dtDataDump and CycleSkipDataDump set.  Unable to calculate datasets." % \
-            self.pf
-


diff -r 08f29a9cec42435bb0581a2059b4f1c7abd6c8c5 -r 0ca36e01d8ac896284ce3f52afd8fda2efc070c2 yt/mods.py
--- a/yt/mods.py
+++ b/yt/mods.py
@@ -129,7 +129,8 @@
 for name, cls in callback_registry.items():
     exec("%s = cls" % name)
 
-from yt.convenience import load, projload
+from yt.convenience import \
+    load, projload, simulation
 
 # Import some helpful math utilities
 from yt.utilities.math_utils import \


diff -r 08f29a9cec42435bb0581a2059b4f1c7abd6c8c5 -r 0ca36e01d8ac896284ce3f52afd8fda2efc070c2 yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -67,3 +67,37 @@
         if self.obj_type == "slice":
             s += "  It may lie on a grid face.  Try offsetting slightly."
         return s
+
+class YTSimulationNotIdentified(YTException):
+    def __init__(self, sim_type):
+        YTException.__init__(self)
+        self.sim_type = sim_type
+
+    def __str__(self):
+        return "Simulation time-series type %s not defined." % self.sim_type
+
+class AmbiguousOutputs(YTException):
+    def __init__(self, pf):
+        YTException.__init__(self, pf)
+
+    def __str__(self):
+        return "Simulation %s has both dtDataDump and CycleSkipDataDump set.  Unable to calculate datasets." % \
+            self.pf
+
+class MissingParameter(YTException):
+    def __init__(self, pf, parameter):
+        YTException.__init__(self, pf)
+        self.parameter = parameter
+
+    def __str__(self):
+        return "Parameter file %s is missing %s parameter." % \
+            (self.pf, self.parameter)
+
+class NoStoppingCondition(YTException):
+    def __init__(self, pf):
+        YTException.__init__(self, pf)
+
+    def __str__(self):
+        return "Simulation %s has no stopping condition.  StopTime or StopCycle should be set." % \
+            self.pf
+


diff -r 08f29a9cec42435bb0581a2059b4f1c7abd6c8c5 -r 0ca36e01d8ac896284ce3f52afd8fda2efc070c2 yt/utilities/parameter_file_storage.py
--- a/yt/utilities/parameter_file_storage.py
+++ b/yt/utilities/parameter_file_storage.py
@@ -33,6 +33,7 @@
     parallel_simple_proxy
 
 output_type_registry = {}
+simulation_time_series_registry = {}
 _field_names = ('hash', 'bn', 'fp', 'tt', 'ctid', 'class_name', 'last_seen')
 
 class NoParameterShelf(Exception):



https://bitbucket.org/yt_analysis/yt/changeset/120a07d9f418/
changeset:   120a07d9f418
branch:      yt
user:        brittonsmith
date:        2012-06-14 01:03:03
summary:     Merged.
affected #:  1 file

diff -r 0ca36e01d8ac896284ce3f52afd8fda2efc070c2 -r 120a07d9f418472d6d1a6a03197dccc00f92d1f4 yt/frontends/enzo/io.py
--- a/yt/frontends/enzo/io.py
+++ b/yt/frontends/enzo/io.py
@@ -201,6 +201,8 @@
     _data_style = "enzo_packed_3d_gz"
 
     def modify(self, field):
+        if len(field.shape) < 3:
+            return field
         tr = field[3:-3,3:-3,3:-3].swapaxes(0,2)
         return tr.copy() # To ensure contiguous
 



https://bitbucket.org/yt_analysis/yt/changeset/2fa8dc3114e8/
changeset:   2fa8dc3114e8
branch:      yt
user:        brittonsmith
date:        2012-06-14 17:22:20
summary:     EnzoSimulation now prepends the directory of the parameter
file to the name for each pf.
affected #:  2 files

diff -r 120a07d9f418472d6d1a6a03197dccc00f92d1f4 -r 2fa8dc3114e8f9daac80a746d754821149998111 yt/data_objects/time_series.py
--- a/yt/data_objects/time_series.py
+++ b/yt/data_objects/time_series.py
@@ -211,6 +211,8 @@
         if not os.path.exists(parameter_filename):
             raise IOError(parameter_filename)
         self.parameter_filename = parameter_filename
+        self.basename = os.path.basename(parameter_filename)
+        self.directory = os.path.dirname(parameter_filename)
         self.parameters = {}
 
         # Set some parameter defaults.


diff -r 120a07d9f418472d6d1a6a03197dccc00f92d1f4 -r 2fa8dc3114e8f9daac80a746d754821149998111 yt/frontends/enzo/simulation_handling.py
--- a/yt/frontends/enzo/simulation_handling.py
+++ b/yt/frontends/enzo/simulation_handling.py
@@ -460,7 +460,7 @@
     def _set_parameter_defaults(self):
         "Set some default parameters to avoid problems if they are not in the parameter file."
 
-        self.parameters['GlobalDir'] = "."
+        self.parameters['GlobalDir'] = self.directory
         self.parameters['DataDumpName'] = "data"
         self.parameters['DataDumpDir'] = "DD"
         self.parameters['RedshiftDumpName'] = "RedshiftOutput"



https://bitbucket.org/yt_analysis/yt/changeset/38a09b2207e9/
changeset:   38a09b2207e9
branch:      yt
user:        brittonsmith
date:        2012-06-14 17:54:13
summary:     Changing classing structure slightly so that SimulationTimeSeries
is a subclass of TimeSeriesData and EnzoSimulation is only a subclass
of SimulationTimeSeries.
affected #:  2 files

diff -r 2fa8dc3114e8f9daac80a746d754821149998111 -r 38a09b2207e912525f7b12dbe68adc7c9a74e193 yt/data_objects/time_series.py
--- a/yt/data_objects/time_series.py
+++ b/yt/data_objects/time_series.py
@@ -193,7 +193,7 @@
         return cls(*self._args, **self._kwargs)
 
 
-class SimulationTimeSeries(object):
+class SimulationTimeSeries(TimeSeriesData):
     class __metaclass__(type):
         def __init__(cls, name, b, d):
             type.__init__(cls, name, b, d)


diff -r 2fa8dc3114e8f9daac80a746d754821149998111 -r 38a09b2207e912525f7b12dbe68adc7c9a74e193 yt/frontends/enzo/simulation_handling.py
--- a/yt/frontends/enzo/simulation_handling.py
+++ b/yt/frontends/enzo/simulation_handling.py
@@ -42,7 +42,7 @@
 from yt.convenience import \
     load
 
-class EnzoSimulation(SimulationTimeSeries, TimeSeriesData):
+class EnzoSimulation(SimulationTimeSeries):
     r"""Class for creating TimeSeriesData object from an Enzo
     simulation parameter file.
     """

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