[Yt-svn] yt-commit r1224 - in trunk/yt: . lagos
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Sat Mar 21 00:36:14 PDT 2009
Author: mturk
Date: Sat Mar 21 00:36:13 2009
New Revision: 1224
URL: http://yt.spacepope.org/changeset/1224
Log:
* New convenience function 'load' that guesses the parameter type. This
function only returns if it can be for sure which type of data type to load it
as. (This requires the _is_valid class method for StaticOutput types.)
* Import some of the convenience functions into mods.
* Bunch of Orion fixes, some from Jeff & some from me (changelog is on
BitBucket) that bring it up to speed in trunk
* Attendant to that, fixing the domain decomposition to work with non 0..1
boundaries.
* Refactored some of the Orion stuff
* Fixed a bug for multiple grid parents, at the cost of another iteration
inside the overlap check.
Modified:
trunk/yt/convenience.py
trunk/yt/lagos/BaseDataTypes.py
trunk/yt/lagos/HierarchyType.py
trunk/yt/lagos/OutputTypes.py
trunk/yt/lagos/ParallelTools.py
trunk/yt/mods.py
Modified: trunk/yt/convenience.py
==============================================================================
--- trunk/yt/convenience.py (original)
+++ trunk/yt/convenience.py Sat Mar 21 00:36:13 2009
@@ -33,6 +33,7 @@
import os.path, inspect, types
from functools import wraps
from yt.logger import ytLogger as mylog
+from yt.fido import output_type_registry
def all_pfs(max_depth=1, name_spec="*.hierarchy"):
list_of_names = []
@@ -47,3 +48,18 @@
for pf in all_pfs(**kwargs):
v, c = pf.h.find_max("Density")
yield pf.h.sphere(c, width/pf[unit])
+
+def load(*args ,**kwargs):
+ candidates = []
+ for n, c in output_type_registry.items():
+ if n is None: continue
+ if c._is_valid(*args, **kwargs): candidates.append(n)
+ if len(candidates) == 1:
+ return output_type_registry[candidates[0]](*args, **kwargs)
+ if len(candidates) == 0:
+ mylog.error("Couldn't figure out output type for %s", fn)
+ return None
+ mylog.error("Multiple output type candidates for %s:", fn)
+ for c in candidates:
+ mylog.error(" Possible: %s", c)
+ return None
Modified: trunk/yt/lagos/BaseDataTypes.py
==============================================================================
--- trunk/yt/lagos/BaseDataTypes.py (original)
+++ trunk/yt/lagos/BaseDataTypes.py Sat Mar 21 00:36:13 2009
@@ -1076,6 +1076,7 @@
for pi, grid1 in enumerate(grids):
pbar.update(pi)
for parent in ensure_list(grid1.Parent):
+ if parent.id not in self.__overlap_masks: continue
for grid2 in self.source._grids[grids_up][self.__overlap_masks[parent.id]]:
if self.__retval_coords[grid2.id][0].shape[0] == 0: continue
args = []
Modified: trunk/yt/lagos/HierarchyType.py
==============================================================================
--- trunk/yt/lagos/HierarchyType.py (original)
+++ trunk/yt/lagos/HierarchyType.py Sat Mar 21 00:36:13 2009
@@ -37,7 +37,7 @@
6: (readDataPacked, readAllDataPacked, getFieldsPacked, readDataSlicePacked,
getExceptionHDF5, DataQueuePackedHDF5),
7: (readDataNative, readAllDataNative, None, readDataSliceNative,
- getExceptionHDF5, None), \
+ getExceptionHDF5, DataQueueNative), \
8: (readDataInMemory, readAllDataInMemory, getFieldsInMemory, readDataSliceInMemory,
getExceptionInMemory, DataQueueInMemory),
'enzo_packed_2d': (readDataPacked, readAllDataPacked, getFieldsPacked, readDataSlicePacked2D,
@@ -135,6 +135,9 @@
self._data_file = None
pass
+ def _setup_data_queue(self):
+ self.queue = _data_style_funcs[self.data_style][5]()
+
def _setup_grid_corners(self):
self.gridCorners = na.array([ # Unroll!
[self.gridLeftEdge[:,0], self.gridLeftEdge[:,1], self.gridLeftEdge[:,2]],
@@ -688,9 +691,6 @@
else:
raise TypeError
- def _setup_data_queue(self):
- self.queue = _data_style_funcs[self.data_style][5]()
-
def __setup_filemap(self, grid):
if not self.data_style == 6:
return
@@ -1130,6 +1130,7 @@
self.readGlobalHeader(header_filename,self.parameter_file.paranoid_read) # also sets up the grid objects
self.__cache_endianness(self.levels[-1].grids[-1])
AMRHierarchy.__init__(self,pf)
+ self._setup_data_queue()
self._setup_field_list()
def readGlobalHeader(self,filename,paranoid_read):
Modified: trunk/yt/lagos/OutputTypes.py
==============================================================================
--- trunk/yt/lagos/OutputTypes.py (original)
+++ trunk/yt/lagos/OutputTypes.py Sat Mar 21 00:36:13 2009
@@ -89,6 +89,9 @@
self["InitialTime"], self["CurrentTimeIdentifier"])
return hashlib.md5(s).hexdigest()
+ @classmethod
+ def _is_valid(cls, *args, **kwargs):
+ return False
def __getitem__(self, key):
"""
@@ -372,6 +375,10 @@
(1.0 + self.parameters["CosmologyCurrentRedshift"])
return k
+ @classmethod
+ def _is_valid(cls, *args, **kwargs):
+ return os.path.exists("%s.hierarchy" % args[0])
+
# We set our default output type to EnzoStaticOutput
output_type_registry[None] = EnzoStaticOutput
@@ -402,6 +409,10 @@
for p, v in self.__conversion_override.items():
self.conversion_factors[p] = v
+ @classmethod
+ def _is_valid(cls, *args, **kwargs):
+ return False
+
class OrionStaticOutput(StaticOutput):
"""
This class is a stripped down class that simply reads and parses, without
@@ -415,7 +426,7 @@
_hierarchy_class = OrionHierarchy
_fieldinfo_class = OrionFieldContainer
- def __init__(self, plotname, paramFilename='inputs',fparamFilename='probin',data_style=7,paranoia=False):
+ def __init__(self, plotname, paramFilename=None,fparamFilename=None,data_style=7,paranoia=False):
"""need to override for Orion file structure.
the paramfile is usually called "inputs"
@@ -427,27 +438,18 @@
ASCII (not implemented in yt)
"""
- self.field_info = self._fieldinfo_class()
- self.data_style = data_style
+
self.paranoid_read = paranoia
- plotname = plotname.rstrip('/')
- self.basename = os.path.basename(plotname)
- # this will be the directory ENCLOSING the pltNNNN directory
- self.directory = os.path.dirname(plotname)
- self.parameter_filename = os.path.join(self.directory,paramFilename)
- # fortran parameters
+ self.parameter_filename = paramFilename
+ self.fparameter_filename = fparamFilename
+ self.__ipfn = paramFilename
+
self.fparameters = {}
- self.fparameter_filename = os.path.join(self.directory,fparamFilename)
- self.fullpath = os.path.abspath(self.directory)
- self.fullplotdir = os.path.abspath(plotname)
- if len(self.directory) == 0:
- self.directory = "."
- self.conversion_factors = {}
- self.parameters = {}
- self._parse_parameter_file()
- if os.path.isfile(self.fparameter_filename):
- self._parse_fparameter_file()
- self._set_units()
+
+ StaticOutput.__init__(self, plotname.rstrip("/"), data_style=7)
+ self.field_info = self._fieldinfo_class()
+
+ # self.directory is the directory ENCLOSING the pltNNNN directory
# These should maybe not be hardcoded?
self.parameters["HydroMethod"] = 'orion' # always PPM DE
@@ -455,12 +457,33 @@
self.parameters["DualEnergyFormalism"] = 0 # always off.
if self.fparameters.has_key("mu"):
self.parameters["mu"] = self.fparameters["mu"]
+
+ def _localize(self, f, default):
+ if f is None:
+ return os.path.join(self.directory, default)
+ return f
+
+ @classmethod
+ def _is_valid(self, *args, **kwargs):
+ # fill our args
+ pname = args[0].rstrip("/")
+ dn = os.path.dirname(pname)
+ if len(args) > 1: kwargs['paramFilename'] = args[1]
+ pfname = kwargs.get("paramFilename", os.path.join(dn, "inputs"))
+ return os.path.exists(os.path.join(pfname))
def _parse_parameter_file(self):
"""
Parses the parameter file and establishes the various
dictionaries.
"""
+ self.fullplotdir = os.path.abspath(self.parameter_filename)
+ self.parameter_filename = self._localize(
+ self.__ipfn, 'inputs')
+ self.fparameter_filename = self._localize(
+ self.fparameter_filename, 'probin')
+ if os.path.isfile(self.fparameter_filename):
+ self._parse_fparameter_file()
# Let's read the file
self.parameters["CurrentTimeIdentifier"] = \
int(os.stat(self.parameter_filename)[ST_CTIME])
Modified: trunk/yt/lagos/ParallelTools.py
==============================================================================
--- trunk/yt/lagos/ParallelTools.py (original)
+++ trunk/yt/lagos/ParallelTools.py Sat Mar 21 00:36:13 2009
@@ -181,18 +181,21 @@
if not parallel_capable:
return False, self.hierarchy.grid_collection(self.center, self.hierarchy.grids)
+ xax, yax = x_dict[axis], y_dict[axis]
cc = MPI.Compute_dims(MPI.COMM_WORLD.size, 2)
mi = MPI.COMM_WORLD.rank
cx, cy = na.unravel_index(mi, cc)
x = na.mgrid[0:1:(cc[0]+1)*1j][cx:cx+2]
y = na.mgrid[0:1:(cc[1]+1)*1j][cy:cy+2]
- LE = na.zeros(3, dtype='float64')
- RE = na.ones(3, dtype='float64')
- LE[x_dict[axis]] = x[0] # It actually doesn't matter if this is x or y
- RE[x_dict[axis]] = x[1]
- LE[y_dict[axis]] = y[0]
- RE[y_dict[axis]] = y[1]
+ DLE, DRE = self.pf["DomainLeftEdge"], self.pf["DomainRightEdge"]
+ LE = na.ones(3, dtype='float64') * DLE
+ RE = na.ones(3, dtype='float64') * DRE
+ LE[xax] = x[0] * (DRE[xax]-DLE[xax]) + DLE[xax]
+ RE[xax] = x[1] * (DRE[xax]-DLE[xax]) + DLE[xax]
+ LE[yax] = y[0] * (DRE[yax]-DLE[yax]) + DLE[yax]
+ RE[yax] = y[1] * (DRE[yax]-DLE[yax]) + DLE[yax]
+ mylog.debug("Dimensions: %s %s", LE, RE)
reg = self.hierarchy.region_strict(self.center, LE, RE)
return True, reg
Modified: trunk/yt/mods.py
==============================================================================
--- trunk/yt/mods.py (original)
+++ trunk/yt/mods.py Sat Mar 21 00:36:13 2009
@@ -67,6 +67,8 @@
import yt.funcs
+from yt.convenience import all_pfs, max_spheres, load
+
# Some convenience functions to ease our time running scripts
# from the command line
More information about the yt-svn
mailing list