[Yt-svn] yt: 7 new changesets
hg at spacepope.org
hg at spacepope.org
Thu Jul 29 23:24:23 PDT 2010
hg Repository: yt
details: yt/rev/bb2c72cc74e0
changeset: 1898:bb2c72cc74e0
user: Matthew Turk <matthewturk at gmail.com>
date:
Wed Jul 28 23:32:47 2010 -0700
description:
Initial import of the wrapping code for Oliver's RAMSES data reader.
hg Repository: yt
details: yt/rev/3f91c765bb5b
changeset: 1899:3f91c765bb5b
user: Matthew Turk <matthewturk at gmail.com>
date:
Thu Jul 29 07:43:11 2010 -0700
description:
Simplify the counting of zones on a level.
hg Repository: yt
details: yt/rev/e0ef663026b6
changeset: 1900:e0ef663026b6
user: Matthew Turk <matthewturk at gmail.com>
date:
Thu Jul 29 09:47:24 2010 -0700
description:
Moved the RAMSES reader into a persistent class
hg Repository: yt
details: yt/rev/b4f3594ca17e
changeset: 1901:b4f3594ca17e
user: Matthew Turk <matthewturk at gmail.com>
date:
Thu Jul 29 12:24:43 2010 -0700
description:
Can now read grids from the RAMSES file.
hg Repository: yt
details: yt/rev/166ef72b51d9
changeset: 1902:166ef72b51d9
user: Matthew Turk <matthewturk at gmail.com>
date:
Thu Jul 29 12:36:54 2010 -0700
description:
Skeleton of RAMSESStaticOutput, using the FLASH code
hg Repository: yt
details: yt/rev/c4936f528dba
changeset: 1903:c4936f528dba
user: Matthew Turk <matthewturk at gmail.com>
date:
Thu Jul 29 16:10:15 2010 -0700
description:
Continuing to work on RAMSES. Cell identification and reading sort of works. Hierarchy almost works.
hg Repository: yt
details: yt/rev/fffba6d37716
changeset: 1904:fffba6d37716
user: Matthew Turk <matthewturk at gmail.com>
date:
Thu Jul 29 23:23:16 2010 -0700
description:
RAMSES now works, if you are willing to wait quite some time for it to pull the
data from in-memory data structures. This is completely un-optimized code, and
I strongly advise against expecting to be able to use it in any production
environment.
hG: Enter commit message. Lines beginning with 'HG:' are removed.
diffstat:
yt/lagos/BaseGridType.py | 30 ++
yt/lagos/DataReadingFuncs.py | 17 +
yt/lagos/HierarchyType.py | 78 ++++++
yt/lagos/OutputTypes.py | 68 +++++
yt/lagos/RAMSESFields.py | 33 ++
yt/lagos/__init__.py | 1 +
yt/ramses_reader.pyx | 585 ++++++++++++++++++++++++++++++++++++++++++++++++
yt/setup.py | 8 +
8 files changed, 820 insertions(+), 0 deletions(-)
diffs (truncated from 883 to 300 lines):
diff -r c9dea0de23c6 -r fffba6d37716 yt/lagos/BaseGridType.py
--- a/yt/lagos/BaseGridType.py Wed Jul 28 20:38:40 2010 -0700
+++ b/yt/lagos/BaseGridType.py Thu Jul 29 23:23:16 2010 -0700
@@ -715,3 +715,33 @@
self.Parent = None
self.Children = []
self.Level = level
+
+ def __repr__(self):
+ return "FLASHGrid_%04i (%s)" % (self.id, self.ActiveDimensions)
+
+class RAMSESGrid(AMRGridPatch):
+ _id_offset = 0
+ #__slots__ = ["_level_id", "stop_index"]
+ def __init__(self, id, hierarchy, level, domain, grid_offset, parent_id,
+ cm):
+ AMRGridPatch.__init__(self, id, filename = hierarchy.hierarchy_filename,
+ hierarchy = hierarchy)
+ self.Level = level
+ self.domain = domain
+ self.grid_offset = grid_offset
+ self._parent_id = parent_id
+ self._children_ids = []
+ self._child_mask = cm.reshape((2,2,2))
+
+ @property
+ def Parent(self):
+ if self._parent_id == -1: return None
+ return self.hierarchy.grids[self._parent_id - self._id_offset]
+
+ @property
+ def Children(self):
+ return [self.hierarchy.grids[cid - self._id_offset]
+ for cid in self._children_ids]
+
+ def __repr__(self):
+ return "RAMSESGrid_%04i (%s)" % (self.id, self.ActiveDimensions)
diff -r c9dea0de23c6 -r fffba6d37716 yt/lagos/DataReadingFuncs.py
--- a/yt/lagos/DataReadingFuncs.py Wed Jul 28 20:38:40 2010 -0700
+++ b/yt/lagos/DataReadingFuncs.py Thu Jul 29 23:23:16 2010 -0700
@@ -517,3 +517,20 @@
f = h5py.File(grid.pf.parameter_filename, "r")
tr = f["/%s" % field][grid.id - grid._id_offset].transpose()[sl]
return tr.astype("float64")
+
+class IOHandlerRAMSES(BaseIOHandler):
+ _data_style = "ramses"
+
+ def __init__(self, ramses_tree, *args, **kwargs):
+ self.ramses_tree = ramses_tree
+ BaseIOHandler.__init__(self, *args, **kwargs)
+
+ def _read_data_set(self, grid, field):
+ d = self.ramses_tree.read_grid(field, grid.Level, grid.domain,
+ grid.grid_offset)
+ return d
+
+ def _read_data_slice(self, grid, field, axis, coord):
+ sl = [slice(None), slice(None), slice(None)]
+ sl[axis] = slice(coord, coord + 1)
+ return self._read_data_set(grid, field)[sl]
diff -r c9dea0de23c6 -r fffba6d37716 yt/lagos/HierarchyType.py
--- a/yt/lagos/HierarchyType.py Wed Jul 28 20:38:40 2010 -0700
+++ b/yt/lagos/HierarchyType.py Thu Jul 29 23:23:16 2010 -0700
@@ -1512,3 +1512,81 @@
def _setup_derived_fields(self):
self.derived_field_list = []
+
+class RAMSESHierarchy(AMRHierarchy):
+
+ grid = RAMSESGrid
+ _handle = None
+
+ def __init__(self,pf,data_style='ramses'):
+ self.data_style = data_style
+ self.field_info = RAMSESFieldContainer()
+ self.parameter_file = weakref.proxy(pf)
+ # for now, the hierarchy file is the parameter file!
+ self.hierarchy_filename = self.parameter_file.parameter_filename
+ self.directory = os.path.dirname(self.hierarchy_filename)
+ self.tree_proxy = pf.ramses_tree
+
+ self.float_type = na.float64
+ AMRHierarchy.__init__(self,pf,data_style)
+
+ def _initialize_data_storage(self):
+ pass
+
+ def _detect_fields(self):
+ self.field_list = self.tree_proxy.field_names[:]
+
+ def _setup_classes(self):
+ dd = self._get_data_reader_dict()
+ AMRHierarchy._setup_classes(self, dd)
+ self.object_types.sort()
+
+ def _count_grids(self):
+ self._level_info = self.tree_proxy.count_zones()
+ self.num_grids = sum(self._level_info)
+
+ def _parse_hierarchy(self):
+ self.grid_dimensions.flat[:] = 2
+ grid_file_locations = na.zeros((self.num_grids, 3), dtype='int64')
+ child_masks = na.zeros((self.num_grids, 8), dtype='int32')
+ self.tree_proxy.fill_hierarchy_arrays(
+ self.grid_left_edge, self.grid_right_edge,
+ self.grid_levels, grid_file_locations, child_masks)
+ ggi = 0
+ gs = []
+ gs = [self.grid(i, self, self.grid_levels[i,0],
+ grid_file_locations[i,0],
+ grid_file_locations[i,1],
+ grid_file_locations[i,2],
+ child_masks[i,:])
+ for i in xrange(self.num_grids)]
+ self.grids = na.array(gs, dtype='object')
+
+ def _populate_grid_objects(self):
+ for gi,g in enumerate(self.grids):
+ if g.Parent is not None:
+ g.Parent._children_ids.append(gi)
+ g._prepare_grid()
+ g._setup_dx()
+ self.max_level = self.grid_levels.max()
+
+ def _setup_unknown_fields(self):
+ for field in self.field_list:
+ if field in self.parameter_file.field_info: continue
+ mylog.info("Adding %s to list of fields", field)
+ cf = None
+ if self.parameter_file.has_key(field):
+ def external_wrapper(f):
+ def _convert_function(data):
+ return data.convert(f)
+ return _convert_function
+ cf = external_wrapper(field)
+ add_field(field, lambda a, b: None,
+ convert_function=cf, take_log=False)
+
+ def _setup_derived_fields(self):
+ self.derived_field_list = []
+
+ def _setup_data_io(self):
+ self.io = io_registry[self.data_style](self.tree_proxy)
+
diff -r c9dea0de23c6 -r fffba6d37716 yt/lagos/OutputTypes.py
--- a/yt/lagos/OutputTypes.py Wed Jul 28 20:38:40 2010 -0700
+++ b/yt/lagos/OutputTypes.py Thu Jul 29 23:23:16 2010 -0700
@@ -872,3 +872,71 @@
pass
return False
+class RAMSESStaticOutput(StaticOutput):
+ _hierarchy_class = RAMSESHierarchy
+ _fieldinfo_class = RAMSESFieldContainer
+ _handle = None
+
+ def __init__(self, filename, data_style='ramses',
+ storage_filename = None):
+ StaticOutput.__init__(self, filename, data_style)
+ self.storage_filename = storage_filename
+
+ self.field_info = self._fieldinfo_class()
+ # hardcoded for now
+ self.parameters["InitialTime"] = 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.parameters["TopGridRank"] = 3
+ self.parameters["RefineBy"] = 2
+ self.parameters["HydroMethod"] = 'ramses'
+ self.parameters["Time"] = 1. # default unit is 1...
+
+ def _set_units(self):
+ """
+ Generates the conversion to various physical _units based on the parameter file
+ """
+ self.units = {}
+ self.time_units = {}
+ if len(self.parameters) == 0:
+ self._parse_parameter_file()
+ self._setup_nounits_units()
+ 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()
+ 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:
+ self.conversion_factors[key] = 1.0
+
+ def _setup_nounits_units(self):
+ z = 0
+ mylog.warning("Setting 1.0 in code units to be 1.0 cm")
+ if not self.has_key("TimeUnits"):
+ mylog.warning("No time units. Setting 1.0 = 1 second.")
+ self.conversion_factors["Time"] = 1.0
+ for unit in mpc_conversion.keys():
+ self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"]
+
+ def _parse_parameter_file(self):
+ self.parameters["CurrentTimeIdentifier"] = \
+ int(os.stat(self.parameter_filename)[ST_CTIME])
+ import yt.ramses_reader as rr
+ self.ramses_tree = rr.RAMSES_tree_proxy(self.parameter_filename)
+ rheader = self.ramses_tree.get_file_info()
+ self.parameters.update(rheader)
+ self.parameters["DomainRightEdge"] = na.ones(3, dtype='float64') \
+ * rheader['boxlen']
+ self.parameters["DomainLeftEdge"] = na.zeros(3, dtype='float64')
+ self.parameters["TopGridDimensions"] = na.zeros(3, dtype='int64') + 2
+
+ @classmethod
+ def _is_valid(self, *args, **kwargs):
+ if not os.path.basename(args[0]).startswith("info_"): return False
+ fn = args[0].replace("info_", "amr_").replace(".txt", ".out00001")
+ print fn
+ return os.path.exists(fn)
+
diff -r c9dea0de23c6 -r fffba6d37716 yt/lagos/RAMSESFields.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/lagos/RAMSESFields.py Thu Jul 29 23:23:16 2010 -0700
@@ -0,0 +1,33 @@
+"""
+RAMSES-specific fields
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: UCSD
+Homepage: http://yt.enzotools.org/
+License:
+ Copyright (C) 2010 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 UniversalFields import *
+class RAMSESFieldContainer(CodeFieldInfoContainer):
+ _shared_state = {}
+ _field_list = {}
+RAMSESFieldInfo = RAMSESFieldContainer()
+add_ramses_field = RAMSESFieldInfo.add_field
+
+add_field = add_ramses_field
diff -r c9dea0de23c6 -r fffba6d37716 yt/lagos/__init__.py
--- a/yt/lagos/__init__.py Wed Jul 28 20:38:40 2010 -0700
+++ b/yt/lagos/__init__.py Thu Jul 29 23:23:16 2010 -0700
@@ -77,6 +77,7 @@
from OrionFields import *
from ChomboFields import *
from FLASHFields import *
+from RAMSESFields import *
fieldInfo = EnzoFieldInfo
# NOT the same as fieldInfo.add_field
diff -r c9dea0de23c6 -r fffba6d37716 yt/ramses_reader.pyx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/ramses_reader.pyx Thu Jul 29 23:23:16 2010 -0700
@@ -0,0 +1,585 @@
+"""
+Wrapping code for Oliver Hahn's RamsesRead++
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: UCSD
+Author: Oliver Hahn <ohahn at stanford.edu>
+Affiliation: KIPAC / Stanford
+Homepage: http://yt.enzotools.org/
+License:
+ Copyright (C) 2010 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/>.
+"""
+
More information about the yt-svn
mailing list