[Yt-svn] yt: First import of a few astrophysical objects; still experimen...

hg at spacepope.org hg at spacepope.org
Tue Feb 15 11:51:17 PST 2011


hg Repository: yt
details:   yt/rev/d4b7fc2328c3
changeset: 3742:d4b7fc2328c3
user:      Matthew Turk <matthewturk at gmail.com>
date:
Tue Feb 15 14:51:13 2011 -0500
description:
First import of a few astrophysical objects; still experimenting with API.

diffstat:

 yt/astro_objects/api.py                  |   9 ++-
 yt/astro_objects/astrophysical_object.py |  90 ++++++++++++++++++++++++++++++++
 yt/astro_objects/clumped_region.py       |  39 +++++++++++++
 yt/astro_objects/simulation_volume.py    |  32 +++++++++++
 4 files changed, 169 insertions(+), 1 deletions(-)

diffs (189 lines):

diff -r d8f67aaa2e0d -r d4b7fc2328c3 yt/astro_objects/api.py
--- a/yt/astro_objects/api.py	Mon Feb 14 14:52:00 2011 -0700
+++ b/yt/astro_objects/api.py	Tue Feb 15 14:51:13 2011 -0500
@@ -24,4 +24,11 @@
 
 """
 
-# Nothing here yet!
+from .astrophysical_object import \
+    AstrophysicalObject, identification_method, correlation_method
+    
+from .simulation_volume import \
+    SimulationVolume
+    
+from .clumped_region import \
+    ClumpedRegion
diff -r d8f67aaa2e0d -r d4b7fc2328c3 yt/astro_objects/astrophysical_object.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/astro_objects/astrophysical_object.py	Tue Feb 15 14:51:13 2011 -0500
@@ -0,0 +1,90 @@
+"""
+A base-class representing an astrophysical object
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: NSF / Columbia
+Homepage: http://yt.enzotools.org/
+License:
+  Copyright (C) 2011 Matthew Turk.  All Rights Reserved.
+
+  This file is part of yt.
+
+  yt is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
+astro_object_registry = {}
+
+class AstrophysicalObject(object):
+    # No _type_name
+    _skip_add = False
+
+    class __metaclass__(type):
+        def __init__(cls, name, b, d):
+            type.__init__(cls, name, b, d)
+            if hasattr(cls, "_type_name") and not cls._skip_add:
+                astro_object_registry[cls._type_name] = cls
+            cls.identification_methods = {}
+            cls.correlation_methods = {}
+
+    def _lookup_object(self, obj_name):
+        if obj_name not in astro_object_registry:
+            raise KeyError(obj_name)
+        return astro_object_registry[obj_name]
+
+    def correlate(self, other_collection, correlation_name):
+        pass
+
+    def __init__(self, data_source):
+        self.objects = {}
+        # We mandate that every object have a corresponding AMR3DData source
+        # affiliated with it.
+        self.data_source = data_source
+
+    def find(self, obj_name, identification_name, *args, **kwargs):
+        obj = self._lookup_object(obj_name)
+        if callable(identification_name):
+            identification_method = identification_name
+        else:
+            if identification_name not in obj.identification_methods:
+                raise KeyError(identification_name)
+            identification_method = \
+                obj.identification_methods[identification_name]
+        new_objs = identification_method(self, *args, **kwargs)
+        setattr(self, obj_name, new_objs)
+        self.objects[obj_name] = new_objs
+        return new_objs
+
+    def correlate(self, other_set, correlation_name, *args, **kwargs):
+        if callable(correlation_name):
+            correlation_method = correlation_name
+        else:
+            if correlation_name not in self.correlation_methods:
+                raise KeyError(correlation_name)
+            correlation_method = self.correlation_methods[correlation_name]
+        linked_objs = correlation_method(self, *args, **kwargs)
+        return linked_objs
+
+def correlation_method(obj_name, link_name):
+    def passthrough(func):
+        obj = astro_object_registry[obj_name]
+        obj.correlation_methods[link_name] = func
+        return func
+    return passthrough
+
+def identification_method(obj_name, id_name):
+    def passthrough(func):
+        obj = astro_object_registry[obj_name]
+        obj.identification_methods[id_name] = func
+        return func
+    return passthrough
diff -r d8f67aaa2e0d -r d4b7fc2328c3 yt/astro_objects/clumped_region.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/astro_objects/clumped_region.py	Tue Feb 15 14:51:13 2011 -0500
@@ -0,0 +1,39 @@
+"""
+A base-class representing an astrophysical object
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: NSF / Columbia
+Homepage: http://yt.enzotools.org/
+License:
+  Copyright (C) 2011 Matthew Turk.  All Rights Reserved.
+
+  This file is part of yt.
+
+  yt is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
+from .astrophysical_object import \
+    AstrophysicalObject, identification_method, correlation_method
+    
+class ClumpedRegion(AstrophysicalObject):
+    _type_name = "clumped_region"
+    def __init__(self, data_source):
+        AstrophysicalObject.__init__(self, data_source)
+
+ at identification_method("clumped_region", "level_set")
+def clumps(obj, field, min_val):
+    ds = obj.data_source
+    mi, ma = ds.quantities["Extrema"](field)[0]
+    cls = obj.data_source.extract_connected_sets(field, 1, min_val, ma)
+    return [ClumpedRegion(o) for o in cls[1][0]]
diff -r d8f67aaa2e0d -r d4b7fc2328c3 yt/astro_objects/simulation_volume.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/astro_objects/simulation_volume.py	Tue Feb 15 14:51:13 2011 -0500
@@ -0,0 +1,32 @@
+"""
+An AstrophysicalObject that represents a simulation volume
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: NSF / Columbia
+Homepage: http://yt.enzotools.org/
+License:
+  Copyright (C) 2011 Matthew Turk.  All Rights Reserved.
+
+  This file is part of yt.
+
+  yt is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
+from .astrophysical_object import \
+    AstrophysicalObject, identification_method, correlation_method
+    
+class SimulationVolume(AstrophysicalObject):
+    _type_name = "simulation_volume"
+    def __init__(self, data_source):
+        AstrophysicalObject.__init__(self, data_source)



More information about the yt-svn mailing list