[yt-svn] commit/yt: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Wed Sep 26 12:28:56 PDT 2012
2 new commits in yt:
https://bitbucket.org/yt_analysis/yt/changeset/8fcee78bcc84/
changeset: 8fcee78bcc84
branch: yt
user: ngoldbaum
date: 2012-09-26 21:25:45
summary: Adding a comment in orientation.py to clarify the possibly confusing way we've
handled north_vector.
affected #: 1 file
diff -r ae3f6a9e07a18644470391eaa684434ffc14bb8a -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 yt/utilities/orientation.py
--- a/yt/utilities/orientation.py
+++ b/yt/utilities/orientation.py
@@ -67,6 +67,8 @@
t = np.cross(normal_vector, vecs).sum(axis=1)
ax = t.argmax()
east_vector = np.cross(vecs[ax,:], normal_vector).ravel()
+ # self.north_vector must remain None otherwise rotations about a fixed axis will break.
+ # The north_vector calculated here will still be included in self.unit_vectors.
north_vector = np.cross(normal_vector, east_vector).ravel()
else:
if self.steady_north:
@@ -82,7 +84,7 @@
r"""Change the view direction based on any of the orientation parameters.
This will recalculate all the necessary vectors and vector planes related
- to a an orientable object.
+ to an orientable object.
Parameters
----------
https://bitbucket.org/yt_analysis/yt/changeset/e6915de3e4eb/
changeset: e6915de3e4eb
branch: yt
user: ngoldbaum
date: 2012-09-26 21:28:21
summary: Merging.
affected #: 20 files
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/analysis_modules/level_sets/clump_handling.py
--- a/yt/analysis_modules/level_sets/clump_handling.py
+++ b/yt/analysis_modules/level_sets/clump_handling.py
@@ -133,6 +133,7 @@
else:
exec(operation)
+ if self.children is None: return
for child in self.children:
child.pass_down(operation)
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/frontends/_skeleton/__init__.py
--- /dev/null
+++ b/yt/frontends/_skeleton/__init__.py
@@ -0,0 +1,25 @@
+"""
+API for yt.frontends.skeleton
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: Columbia University
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2012 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/>.
+
+"""
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/frontends/_skeleton/api.py
--- /dev/null
+++ b/yt/frontends/_skeleton/api.py
@@ -0,0 +1,37 @@
+"""
+API for yt.frontends._skeleton
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: Columbia University
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2012 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 .data_structures import \
+ SkeletonGrid, \
+ SkeletonHierarchy, \
+ SkeletonStaticOutput
+
+from .fields import \
+ SkeletonFieldInfo, \
+ add_flash_field
+
+from .io import \
+ IOHandlerSkeleton
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/frontends/_skeleton/data_structures.py
--- /dev/null
+++ b/yt/frontends/_skeleton/data_structures.py
@@ -0,0 +1,157 @@
+"""
+Skeleton data structures
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: Columbia University
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2012 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/>.
+"""
+
+import h5py
+import stat
+import numpy as np
+import weakref
+
+from yt.funcs import *
+from yt.data_objects.grid_patch import \
+ AMRGridPatch
+from yt.data_objects.hierarchy import \
+ AMRHierarchy
+from yt.data_objects.static_output import \
+ StaticOutput
+from yt.utilities.definitions import \
+ mpc_conversion, sec_conversion
+from yt.utilities.io_handler import \
+ io_registry
+from yt.utilities.physical_constants import cm_per_mpc
+from .fields import SkeletonFieldInfo, add_flash_field, KnownSkeletonFields
+from yt.data_objects.field_info_container import \
+ FieldInfoContainer, NullFunc, ValidateDataField, TranslationFunc
+
+class SkeletonGrid(AMRGridPatch):
+ _id_offset = 0
+ #__slots__ = ["_level_id", "stop_index"]
+ def __init__(self, id, hierarchy, level):
+ AMRGridPatch.__init__(self, id, filename = hierarchy.hierarchy_filename,
+ hierarchy = hierarchy)
+ self.Parent = None
+ self.Children = []
+ self.Level = level
+
+ def __repr__(self):
+ return "SkeletonGrid_%04i (%s)" % (self.id, self.ActiveDimensions)
+
+class SkeletonHierarchy(AMRHierarchy):
+
+ grid = SkeletonGrid
+ float_type = np.float64
+
+ def __init__(self, pf, data_style='skeleton'):
+ self.data_style = data_style
+ 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)
+ AMRHierarchy.__init__(self, pf, data_style)
+
+ def _initialize_data_storage(self):
+ pass
+
+ def _detect_fields(self):
+ # This needs to set a self.field_list that contains all the available,
+ # on-disk fields.
+ pass
+
+ def _count_grids(self):
+ # This needs to set self.num_grids
+ pass
+
+ def _parse_hierarchy(self):
+ # This needs to fill the following arrays, where N is self.num_grids:
+ # self.grid_left_edge (N, 3) <= float64
+ # self.grid_right_edge (N, 3) <= float64
+ # self.grid_dimensions (N, 3) <= int
+ # self.grid_particle_count (N, 1) <= int
+ # self.grid_levels (N, 1) <= int
+ # self.grids (N, 1) <= grid objects
+ #
+ pass
+
+ def _populate_grid_objects(self):
+ # For each grid, this must call:
+ # grid._prepare_grid()
+ # grid._setup_dx()
+ # This must also set:
+ # grid.Children <= list of child grids
+ # grid.Parent <= parent grid
+ # This is handled by the frontend because often the children must be
+ # identified.
+ pass
+
+class SkeletonStaticOutput(StaticOutput):
+ _hierarchy_class = SkeletonHierarchy
+ _fieldinfo_fallback = SkeletonFieldInfo
+ _fieldinfo_known = KnownSkeletonFields
+ _handle = None
+
+ def __init__(self, filename, data_style='skeleton',
+ storage_filename = None,
+ conversion_override = None):
+
+ if conversion_override is None: conversion_override = {}
+ self._conversion_override = conversion_override
+
+ StaticOutput.__init__(self, filename, data_style)
+ self.storage_filename = storage_filename
+
+ def _set_units(self):
+ # This needs to set up the dictionaries that convert from code units to
+ # CGS. The needed items are listed in the second entry:
+ # self.time_units <= sec_conversion
+ # self.conversion_factors <= mpc_conversion
+ # self.units <= On-disk fields
+ pass
+
+ def _parse_parameter_file(self):
+ # This needs to set up the following items:
+ #
+ # self.unique_identifier
+ # self.parameters <= full of code-specific items of use
+ # self.domain_left_edge <= array of float64
+ # self.domain_right_edge <= array of float64
+ # self.dimensionality <= int
+ # self.domain_dimensions <= array of int64
+ # self.current_time <= simulation time in code units
+ #
+ # We also set up cosmological information. Set these to zero if
+ # non-cosmological.
+ #
+ # self.cosmological_simulation <= int, 0 or 1
+ # self.current_redshift <= float
+ # self.omega_lambda <= float
+ # self.omega_matter <= float
+ # self.hubble_constant <= float
+
+ @classmethod
+ def _is_valid(self, *args, **kwargs):
+ # This accepts a filename or a set of arguments and returns True or
+ # False depending on if the file is of the type requested.
+ return False
+
+
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/frontends/_skeleton/fields.py
--- /dev/null
+++ b/yt/frontends/_skeleton/fields.py
@@ -0,0 +1,102 @@
+"""
+Skeleton-specific fields
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: Columbia University
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2012 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 yt.data_objects.field_info_container import \
+ FieldInfoContainer, \
+ NullFunc, \
+ TranslationFunc, \
+ FieldInfo, \
+ ValidateParameter, \
+ ValidateDataField, \
+ ValidateProperty, \
+ ValidateSpatial, \
+ ValidateGridType
+import yt.data_objects.universal_fields
+from yt.utilities.physical_constants import \
+ kboltz
+
+# The first field container is where any fields that exist on disk go, along
+# with their conversion factors, display names, etc.
+
+KnownSkeletonFields = FieldInfoContainer()
+add_skeleton_field = KnownSkeletonFields.add_field
+
+SkeletonFieldInfo = FieldInfoContainer.create_with_fallback(FieldInfo)
+add_field = SkeletonFieldInfo.add_field
+
+# Often, we want to translate between fields on disk and fields in yt. This
+# construct shows how to do that. Note that we use TranslationFunc.
+
+translation_dict = {"x-velocity": "velx",
+ "y-velocity": "vely",
+ "z-velocity": "velz",
+ "Density": "dens",
+ "Temperature": "temp",
+ "Pressure" : "pres",
+ "Grav_Potential" : "gpot",
+ "particle_position_x" : "particle_posx",
+ "particle_position_y" : "particle_posy",
+ "particle_position_z" : "particle_posz",
+ "particle_velocity_x" : "particle_velx",
+ "particle_velocity_y" : "particle_vely",
+ "particle_velocity_z" : "particle_velz",
+ "particle_index" : "particle_tag",
+ "Electron_Fraction" : "elec",
+ "HI_Fraction" : "h ",
+ "HD_Fraction" : "hd ",
+ "HeI_Fraction": "hel ",
+ "HeII_Fraction": "hep ",
+ "HeIII_Fraction": "hepp",
+ "HM_Fraction": "hmin",
+ "HII_Fraction": "hp ",
+ "H2I_Fraction": "htwo",
+ "H2II_Fraction": "htwp",
+ "DI_Fraction": "deut",
+ "DII_Fraction": "dplu",
+ "ParticleMass": "particle_mass",
+ "Flame_Fraction": "flam"}
+
+for f,v in translation_dict.items():
+ if v not in KnownSkeletonFields:
+ pfield = v.startswith("particle")
+ add_skeleton_field(v, function=NullFunc, take_log=False,
+ validators = [ValidateDataField(v)],
+ particle_type = pfield)
+ if f.endswith("_Fraction") :
+ dname = "%s\/Fraction" % f.split("_")[0]
+ else :
+ dname = f
+ ff = KnownSkeletonFields[v]
+ pfield = f.startswith("particle")
+ add_field(f, TranslationFunc(v),
+ take_log=KnownSkeletonFields[v].take_log,
+ units = ff._units, display_name=dname,
+ particle_type = pfield)
+
+# Here's an example of adding a new field:
+
+add_skeleton_field("dens", function=NullFunc, take_log=True,
+ convert_function=_get_convert("dens"),
+ units=r"\rm{g}/\rm{cm}^3")
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/frontends/_skeleton/io.py
--- /dev/null
+++ b/yt/frontends/_skeleton/io.py
@@ -0,0 +1,44 @@
+"""
+Skeleton-specific IO functions
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: Columbia University
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2012 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/>.
+"""
+
+import numpy as np
+import h5py
+
+from yt.utilities.io_handler import \
+ BaseIOHandler
+
+class IOHandlerSkeleton(BaseIOHandler):
+ _particle_reader = False
+ _data_style = "skeleton"
+
+ def _read_data_set(self, grid, field):
+ # This must return the array, of size/shape grid.ActiveDimensions, that
+ # corresponds to 'field'.
+ pass
+
+ def _read_data_slice(self, grid, field, axis, coord):
+ # If this is not implemented, the IO handler will just slice a
+ # _read_data_set item.
+ pass
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/frontends/_skeleton/setup.py
--- /dev/null
+++ b/yt/frontends/_skeleton/setup.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+import setuptools
+import os
+import sys
+import os.path
+
+
+def configuration(parent_package='', top_path=None):
+ from numpy.distutils.misc_util import Configuration
+ config = Configuration('skeleton', parent_package, top_path)
+ config.make_config_py() # installs __config__.py
+ #config.make_svn_version_py()
+ return config
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/frontends/castro/data_structures.py
--- a/yt/frontends/castro/data_structures.py
+++ b/yt/frontends/castro/data_structures.py
@@ -101,18 +101,11 @@
self.Parent = None
def _setup_dx(self):
- # So first we figure out what the index is. We don't assume
- # that dx=dy=dz , at least here. We probably do elsewhere.
- id = self.id - self._id_offset
- if self.Parent is not None:
- self.dds = self.Parent[0].dds / self.pf.refine_by
- else:
- LE, RE = self.hierarchy.grid_left_edge[id,:], \
- self.hierarchy.grid_right_edge[id,:]
- self.dds = np.array((RE-LE)/self.ActiveDimensions)
-
- if self.pf.dimensionality < 2: self.dds[1] = 1.0
- if self.pf.dimensionality < 3: self.dds[2] = 1.0
+ # has already been read in and stored in hierarchy
+ dx = self.hierarchy.grid_dxs[self.index][0]
+ dy = self.hierarchy.grid_dys[self.index][0]
+ dz = self.hierarchy.grid_dzs[self.index][0]
+ self.dds = np.array([dx, dy, dz])
self.field_data['dx'], self.field_data['dy'], self.field_data['dz'] = self.dds
def __repr__(self):
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/frontends/chombo/data_structures.py
--- a/yt/frontends/chombo/data_structures.py
+++ b/yt/frontends/chombo/data_structures.py
@@ -89,17 +89,8 @@
return self.start_index
def _setup_dx(self):
- # So first we figure out what the index is. We don't assume
- # that dx=dy=dz , at least here. We probably do elsewhere.
- id = self.id - self._id_offset
- if len(self.Parent) > 0:
- self.dds = self.Parent[0].dds / self.pf.refine_by
- else:
- LE, RE = self.hierarchy.grid_left_edge[id,:], \
- self.hierarchy.grid_right_edge[id,:]
- self.dds = np.array((RE-LE)/self.ActiveDimensions)
- if self.pf.dimensionality < 2: self.dds[1] = 1.0
- if self.pf.dimensionality < 3: self.dds[2] = 1.0
+ # has already been read in and stored in hierarchy
+ self.dds = self.hierarchy.dds_list[self.Level]
self.field_data['dx'], self.field_data['dy'], self.field_data['dz'] = self.dds
class ChomboHierarchy(AMRHierarchy):
@@ -176,11 +167,13 @@
# 'Chombo_global'
levels = f.keys()[1:]
grids = []
+ self.dds_list = []
i = 0
for lev in levels:
level_number = int(re.match('level_(\d+)',lev).groups()[0])
boxes = f[lev]['boxes'].value
dx = f[lev].attrs['dx']
+ self.dds_list.append(dx * np.ones(3))
for level_id, box in enumerate(boxes):
si = np.array([box['lo_%s' % ax] for ax in 'ijk'])
ei = np.array([box['hi_%s' % ax] for ax in 'ijk'])
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/frontends/maestro/data_structures.py
--- a/yt/frontends/maestro/data_structures.py
+++ b/yt/frontends/maestro/data_structures.py
@@ -102,17 +102,11 @@
self.Parent = None
def _setup_dx(self):
- # So first we figure out what the index is. We don't assume
- # that dx=dy=dz , at least here. We probably do elsewhere.
- id = self.id - self._id_offset
- if self.Parent is not None:
- self.dds = self.Parent[0].dds / self.pf.refine_by
- else:
- LE, RE = self.hierarchy.grid_left_edge[id,:], \
- self.hierarchy.grid_right_edge[id,:]
- self.dds = np.array((RE-LE)/self.ActiveDimensions)
- if self.pf.dimensionality < 2: self.dds[1] = 1.0
- if self.pf.dimensionality < 3: self.dds[2] = 1.0
+ # has already been read in and stored in hierarchy
+ dx = self.hierarchy.grid_dxs[self.index][0]
+ dy = self.hierarchy.grid_dys[self.index][0]
+ dz = self.hierarchy.grid_dzs[self.index][0]
+ self.dds = np.array([dx, dy, dz])
self.field_data['dx'], self.field_data['dy'], self.field_data['dz'] = self.dds
def __repr__(self):
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/frontends/nyx/data_structures.py
--- a/yt/frontends/nyx/data_structures.py
+++ b/yt/frontends/nyx/data_structures.py
@@ -100,18 +100,11 @@
self.Parent = None
def _setup_dx(self):
- # So first we figure out what the index is. We don't assume that
- # dx=dy=dz here.
- id = self.id - self._id_offset
- if self.Parent is not None:
- self.dds = self.Parent[0].dds / self.pf.refine_by
- else:
- LE, RE = self.hierarchy.grid_left_edge[id,:], \
- self.hierarchy.grid_right_edge[id,:]
- self.dds = np.array((RE - LE) / self.ActiveDimensions)
-
- if self.pf.dimensionality < 2: self.dds[1] = 1.0
- if self.pf.dimensionality < 3: self.dds[2] = 1.0
+ # has already been read in and stored in hierarchy
+ dx = self.hierarchy.grid_dxs[self.index][0]
+ dy = self.hierarchy.grid_dys[self.index][0]
+ dz = self.hierarchy.grid_dzs[self.index][0]
+ self.dds = np.array([dx, dy, dz])
self.field_data['dx'], self.field_data['dy'], self.field_data['dz'] = self.dds
def __repr__(self):
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/frontends/orion/data_structures.py
--- a/yt/frontends/orion/data_structures.py
+++ b/yt/frontends/orion/data_structures.py
@@ -99,17 +99,11 @@
self.Parent = None
def _setup_dx(self):
- # So first we figure out what the index is. We don't assume
- # that dx=dy=dz , at least here. We probably do elsewhere.
- id = self.id - self._id_offset
- if self.Parent is not None:
- self.dds = self.Parent[0].dds / self.pf.refine_by
- else:
- LE, RE = self.hierarchy.grid_left_edge[id,:], \
- self.hierarchy.grid_right_edge[id,:]
- self.dds = np.array((RE-LE)/self.ActiveDimensions)
- if self.pf.dimensionality < 2: self.dds[1] = 1.0
- if self.pf.dimensionality < 3: self.dds[2] = 1.0
+ # has already been read in and stored in hierarchy
+ dx = self.hierarchy.grid_dxs[self.index][0]
+ dy = self.hierarchy.grid_dys[self.index][0]
+ dz = self.hierarchy.grid_dzs[self.index][0]
+ self.dds = np.array([dx, dy, dz])
self.field_data['dx'], self.field_data['dy'], self.field_data['dz'] = self.dds
def __repr__(self):
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/testing.py
--- /dev/null
+++ b/yt/testing.py
@@ -0,0 +1,143 @@
+"""Provides utility and helper functions for testing in yt.
+
+Author: Anthony Scpatz <scopatz at gmail.com>
+Affiliation: The University of Chicago
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2012 Anthony Scopatz. 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/>.
+"""
+
+import numpy as np
+from yt.funcs import *
+from numpy.testing import assert_array_equal
+
+def amrspace(extent, levels=7, cells=8):
+ """Creates two numpy arrays representing the left and right bounds of
+ an AMR grid as well as an array for the AMR level of each cell.
+
+ Parameters
+ ----------
+ extent : array-like
+ This a sequence of length 2*ndims that is the bounds of each dimension.
+ For example, the 2D unit square would be given by [0.0, 1.0, 0.0, 1.0].
+ A 3D cylindrical grid may look like [0.0, 2.0, -1.0, 1.0, 0.0, 2*np.pi].
+ levels : int or sequence of ints, optional
+ This is the number of AMR refinement levels. If given as a sequence (of
+ length ndims), then each dimension will be refined down to this level.
+ All values in this array must be the same or zero. A zero valued dimension
+ indicates that this dim should not be refined. Taking the 3D cylindrical
+ example above if we don't want refine theta but want r and z at 5 we would
+ set levels=(5, 5, 0).
+ cells : int, optional
+ This is the number of cells per refinement level.
+
+ Returns
+ -------
+ left : float ndarray, shape=(npoints, ndims)
+ The left AMR grid points.
+ right : float ndarray, shape=(npoints, ndims)
+ The right AMR grid points.
+ level : int ndarray, shape=(npoints,)
+ The AMR level for each point.
+
+ Examples
+ --------
+ >>> l, r, lvl = amrspace([0.0, 2.0, 1.0, 2.0, 0.0, 3.14], levels=(3,3,0), cells=2)
+ >>> print l
+ [[ 0. 1. 0. ]
+ [ 0.25 1. 0. ]
+ [ 0. 1.125 0. ]
+ [ 0.25 1.125 0. ]
+ [ 0.5 1. 0. ]
+ [ 0. 1.25 0. ]
+ [ 0.5 1.25 0. ]
+ [ 1. 1. 0. ]
+ [ 0. 1.5 0. ]
+ [ 1. 1.5 0. ]]
+
+ """
+ extent = np.asarray(extent, dtype='f8')
+ dextent = extent[1::2] - extent[::2]
+ ndims = len(dextent)
+
+ if isinstance(levels, int):
+ minlvl = maxlvl = levels
+ levels = np.array([levels]*ndims, dtype='int32')
+ else:
+ levels = np.asarray(levels, dtype='int32')
+ minlvl = levels.min()
+ maxlvl = levels.max()
+ if minlvl != maxlvl and (minlvl != 0 or set([minlvl, maxlvl]) != set(levels)):
+ raise ValueError("all levels must have the same value or zero.")
+ dims_zero = (levels == 0)
+ dims_nonzero = ~dims_zero
+ ndims_nonzero = dims_nonzero.sum()
+
+ npoints = (cells**ndims_nonzero - 1)*maxlvl + 1
+ left = np.empty((npoints, ndims), dtype='float64')
+ right = np.empty((npoints, ndims), dtype='float64')
+ level = np.empty(npoints, dtype='int32')
+
+ # fill zero dims
+ left[:,dims_zero] = extent[::2][dims_zero]
+ right[:,dims_zero] = extent[1::2][dims_zero]
+
+ # fill non-zero dims
+ dcell = 1.0 / cells
+ left_slice = tuple([slice(extent[2*n], extent[2*n+1], extent[2*n+1]) if \
+ dims_zero[n] else slice(0.0,1.0,dcell) for n in range(ndims)])
+ right_slice = tuple([slice(extent[2*n+1], extent[2*n], -extent[2*n+1]) if \
+ dims_zero[n] else slice(dcell,1.0+dcell,dcell) for n in range(ndims)])
+ left_norm_grid = np.reshape(np.mgrid[left_slice].T.flat[ndims:], (-1, ndims))
+ lng_zero = left_norm_grid[:,dims_zero]
+ lng_nonzero = left_norm_grid[:,dims_nonzero]
+
+ right_norm_grid = np.reshape(np.mgrid[right_slice].T.flat[ndims:], (-1, ndims))
+ rng_zero = right_norm_grid[:,dims_zero]
+ rng_nonzero = right_norm_grid[:,dims_nonzero]
+
+ level[0] = maxlvl
+ left[0,:] = extent[::2]
+ right[0,dims_zero] = extent[1::2][dims_zero]
+ right[0,dims_nonzero] = (dcell**maxlvl)*dextent[dims_nonzero] + extent[::2][dims_nonzero]
+ for i, lvl in enumerate(range(maxlvl, 0, -1)):
+ start = (cells**ndims_nonzero - 1)*i + 1
+ stop = (cells**ndims_nonzero - 1)*(i+1) + 1
+ dsize = dcell**(lvl-1) * dextent[dims_nonzero]
+ level[start:stop] = lvl
+ left[start:stop,dims_zero] = lng_zero
+ left[start:stop,dims_nonzero] = lng_nonzero*dsize + extent[::2][dims_nonzero]
+ right[start:stop,dims_zero] = rng_zero
+ right[start:stop,dims_nonzero] = rng_nonzero*dsize + extent[::2][dims_nonzero]
+
+ return left, right, level
+
+def fake_random_pf(ndims, peak_value = 1.0, fields = ("Density",), negative = False):
+ from yt.frontends.stream.api import load_uniform_grid
+ if not iterable(ndims):
+ ndims = [ndims, ndims, ndims]
+ else:
+ assert(len(ndims) == 3)
+ if negative:
+ offset = 0.5
+ else:
+ offset = 0.0
+ data = dict((field, (np.random.random(ndims) - offset) * peak_value)
+ for field in fields)
+ ug = load_uniform_grid(data, ndims, 1.0)
+ return ug
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/utilities/flagging_methods.py
--- /dev/null
+++ b/yt/utilities/flagging_methods.py
@@ -0,0 +1,51 @@
+"""
+Utilities for flagging zones for refinement in a dataset
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: Columbia University
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2012 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/>.
+"""
+
+import numpy as np # For modern purposes
+
+flagging_method_registry = {}
+
+def flag_cells(grid, methods):
+ flagged = np.zeros(grid.ActiveDimensions, dtype="bool")
+ for method in methods:
+ flagged |= method(grid)
+ return flagged
+
+class FlaggingMethod(object):
+ _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:
+ flagging_method_registry[cls._type_name] = cls
+
+class OverDensity(FlaggingMethod):
+ _type_name = "overdensity"
+ def __init__(self, over_density):
+ self.over_density = over_density
+
+ def __call__(self, pf, grid):
+ rho = grid["Density"] / (pf.refine_by**grid.Level)
+ return (rho > self.over_density)
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/utilities/lib/fortran_reader.pyx
--- a/yt/utilities/lib/fortran_reader.pyx
+++ b/yt/utilities/lib/fortran_reader.pyx
@@ -53,8 +53,8 @@
@cython.boundscheck(False)
@cython.wraparound(False)
-def read_and_seek(char *filename, int offset1, int offset2,
- np.ndarray buffer, int bytes):
+def read_and_seek(char *filename, np.int64_t offset1,
+ np.int64_t offset2, np.ndarray buffer, int bytes):
cdef FILE *f = fopen(filename, "rb")
cdef void *buf = <void *> buffer.data
cdef char line[1024]
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/utilities/tests/test_flagging_methods.py
--- /dev/null
+++ b/yt/utilities/tests/test_flagging_methods.py
@@ -0,0 +1,12 @@
+from yt.testing import *
+from yt.utilities.flagging_methods import flagging_method_registry
+
+def setup():
+ global pf
+ pf = fake_random_pf(64)
+ pf.h
+
+def test_over_density():
+ od_flag = flagging_method_registry["overdensity"](0.75)
+ criterion = (pf.h.grids[0]["Density"] > 0.75)
+ assert( np.all( od_flag(pf, pf.h.grids[0]) == criterion) )
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/utilities/tests/test_interpolators.py
--- /dev/null
+++ b/yt/utilities/tests/test_interpolators.py
@@ -0,0 +1,27 @@
+from yt.testing import *
+import yt.utilities.linear_interpolators as lin
+
+def setup():
+ pass
+
+def test_linear_interpolator_1d():
+ random_data = np.random.random(64)
+ fv = {'x': np.mgrid[0.0:1.0:64j]}
+ ufi = lin.UnilinearFieldInterpolator(random_data, (0.0, 1.0), "x", True)
+ assert_array_equal(ufi(fv), random_data)
+
+def test_linear_interpolator_2d():
+ random_data = np.random.random((64, 64))
+ fv = dict((ax, v) for ax, v in zip("xyz",
+ np.mgrid[0.0:1.0:64j, 0.0:1.0:64j]))
+ bfi = lin.BilinearFieldInterpolator(random_data,
+ (0.0, 1.0, 0.0, 1.0), "xy", True)
+ assert_array_equal(bfi(fv), random_data)
+
+def test_linear_interpolator_3d():
+ random_data = np.random.random((64, 64, 64))
+ fv = dict((ax, v) for ax, v in zip("xyz",
+ np.mgrid[0.0:1.0:64j, 0.0:1.0:64j, 0.0:1.0:64j]))
+ tfi = lin.TrilinearFieldInterpolator(random_data,
+ (0.0, 1.0, 0.0, 1.0, 0.0, 1.0), "xyz", True)
+ assert_array_equal(tfi(fv), random_data)
diff -r 8fcee78bcc842c3dc21bf4eb796f1fd62bc97778 -r e6915de3e4eb9416758acf2203d281c71319b40b yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -853,11 +853,15 @@
return names
def _send_zmq(self):
- from IPython.zmq.pylab.backend_inline import \
- send_figure
+ try:
+ # pre-IPython v0.14
+ from IPython.zmq.pylab.backend_inline import send_figure as display
+ except ImportError:
+ # IPython v0.14+
+ from IPython.core.display import display
for k, v in sorted(self.plots.iteritems()):
canvas = FigureCanvasAgg(v.figure)
- send_figure(v.figure)
+ display(v.figure)
def show(self):
r"""This will send any existing plots to the IPython notebook.
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