[Yt-svn] yt: Two things, both related.
hg at spacepope.org
hg at spacepope.org
Fri Jan 28 19:10:07 PST 2011
hg Repository: yt
details: yt/rev/3bb373d4f5cd
changeset: 3696:3bb373d4f5cd
user: Matthew Turk <matthewturk at gmail.com>
date:
Fri Jan 28 22:10:02 2011 -0500
description:
Two things, both related.
* Change to the mechanism by which spheres are instantiated. You can now
specify the radius as a tuple of the form:
(value, unit name)
The sphere will then pull the unit from the parameter file and do the
conversion itself.
* Re-enabling of the imports of time_series stuff, a minor refactoring of
the classes, and a mechanism for catching YTExceptions so that things like
quantities can operate on all objects independent of resolution.
This script now works for me:
from yt.mods import *
from yt.data_objects.api import *
ts = EnzoTimeSeries("PopulationIII", output_log = "OutputLog")
sp = ts.sphere("max", (100.0,'au'))
rr = sp.quantities["Extrema"]("Density")
rr will be a list of the results of computing the Density extrema on a sphere
generated on a rolling basis on every output in ts, which is found from Enzo's
"OutputLog" file.
diffstat:
yt/data_objects/api.py | 14 ++++----
yt/data_objects/data_containers.py | 4 ++
yt/data_objects/time_series.py | 60 ++++++++++++++++++++++---------------
3 files changed, 46 insertions(+), 32 deletions(-)
diffs (122 lines):
diff -r 2e98ba6d864b -r 3bb373d4f5cd yt/data_objects/api.py
--- a/yt/data_objects/api.py Fri Jan 28 14:27:50 2011 -0500
+++ b/yt/data_objects/api.py Fri Jan 28 22:10:02 2011 -0500
@@ -52,13 +52,13 @@
BinnedProfile3D
# Disabled for now
-#from time_series import \
-# TimeSeriesData, \
-# EnzoTimeSeries, \
-# TimeSeriesDataObject
-#
-#from analyzer_objects import \
-# AnalysisTask
+from time_series import \
+ TimeSeriesData, \
+ EnzoTimeSeries, \
+ TimeSeriesDataObject
+
+from analyzer_objects import \
+ AnalysisTask
from data_containers import \
data_object_registry
diff -r 2e98ba6d864b -r 3bb373d4f5cd yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py Fri Jan 28 14:27:50 2011 -0500
+++ b/yt/data_objects/data_containers.py Fri Jan 28 22:10:02 2011 -0500
@@ -2544,6 +2544,10 @@
*center* and a *radius*.
"""
AMR3DData.__init__(self, center, fields, pf, **kwargs)
+ # Unpack the radius, if necessary
+ if isinstance(radius, tuple) and len(radius) == 2 and \
+ isinstance(radius[1], types.StringTypes):
+ radius = radius[0]/self.pf[radius[1]]
if radius < self.hierarchy.get_smallest_dx():
raise YTSphereTooSmall(pf, radius, self.hierarchy.get_smallest_dx())
self.set_field_parameter('radius',radius)
diff -r 2e98ba6d864b -r 3bb373d4f5cd yt/data_objects/time_series.py
--- a/yt/data_objects/time_series.py Fri Jan 28 14:27:50 2011 -0500
+++ b/yt/data_objects/time_series.py Fri Jan 28 22:10:02 2011 -0500
@@ -30,6 +30,7 @@
from .data_containers import data_object_registry
from .analyzer_objects import create_quantity_proxy
from .derived_quantities import quantity_info
+from yt.utilities.exceptions import YTException
class TimeSeriesData(object):
def __init__(self, name):
@@ -39,6 +40,40 @@
# We can make this fancier, but this works
return self.outputs.__iter__()
+ def __getitem__(self, key):
+ if isinstance(key, types.SliceType):
+ if isinstance(key.start, types.FloatType):
+ return self.get_range(key.start, key.stop)
+ return self.outputs[key]
+
+ def _insert(self, pf):
+ # We get handed an instantiated parameter file
+ # Here we'll figure out a couple things about it, and then stick it
+ # inside our list.
+ self.outputs.append(pf)
+
+ def eval(self, tasks, obj=None):
+ if obj == None: obj = TimeSeriesDataObject(self, "all_data")
+ tasks = ensure_list(tasks)
+ return_values = []
+ for pf in self:
+ return_values.append([])
+ for task in tasks:
+ try:
+ style = inspect.getargspec(task.eval)[0][1]
+ if style == 'pf':
+ arg = pf
+ elif style == 'data_object':
+ arg = obj.get(pf)
+ rv = task.eval(arg)
+ # We catch and store YT-originating exceptions
+ # This fixes the standard problem of having a sphere that's too
+ # small.
+ except YTException as rv:
+ pass
+ return_values[-1].append(rv)
+ return return_values
+
class EnzoTimeSeries(TimeSeriesData):
_enzo_header = "DATASET WRITTEN "
def __init__(self, name, **kwargs):
@@ -61,31 +96,6 @@
fn = line[len(self._enzo_header):].strip()
self._insert(load(fn))
- def __getitem__(self, key):
- if isinstance(key, types.SliceType):
- if isinstance(key.start, types.FloatType):
- return self.get_range(key.start, key.stop)
- return self.outputs[key]
-
- def _insert(self, pf):
- # We get handed an instantiated parameter file
- # Here we'll figure out a couple things about it, and then stick it
- # inside our list.
- self.outputs.append(pf)
-
- def eval(self, tasks, obj=None):
- if obj == None: obj = TimeSeriesDataObject(self, "all_data")
- tasks = ensure_list(tasks)
- return_values = []
- for pf in self:
- return_values.append([])
- for task in tasks:
- style = inspect.getargspec(task.eval)[0][1]
- if style == 'pf': arg = pf
- elif style == 'data_object': arg = obj.get(pf)
- return_values[-1].append(task.eval(arg))
- return return_values
-
class TimeSeriesQuantitiesContainer(object):
def __init__(self, data_object, quantities):
self.data_object = data_object
More information about the yt-svn
mailing list