[yt-svn] commit/yt: 15 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Aug 15 08:13:55 PDT 2014
15 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/126c62f63255/
Changeset: 126c62f63255
Branch: yt
User: MatthewTurk
Date: 2014-08-12 22:39:31
Summary: Be more careful about periodicity for cylindrical selection.
Affected #: 1 file
diff -r d5b14180936148e2400ac1c495f429b8d58ba62b -r 126c62f6325585696574627f5aa8a62976c43049 yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -799,12 +799,17 @@
@cython.wraparound(False)
@cython.cdivision(True)
cdef int select_point(self, np.float64_t pos[3]) nogil:
- cdef np.float64_t h, d, r2, temp
- cdef int i
+ cdef np.float64_t h, d, r2, temp, spos
+ cdef int i, j, k
h = d = 0
- for i in range(3):
- temp = self.difference(pos[i], self.center[i], i)
- h += temp * self.norm_vec[i]
+ for ax in range(3):
+ temp = 1e30
+ for i in range(3):
+ if self.periodicity[ax] == 0 and i != 1: continue
+ spos = pos[ax] + (i-1)*self.domain_width[ax]
+ if fabs(spos - self.center[ax]) < fabs(temp):
+ temp = spos - self.center[ax]
+ h += temp * self.norm_vec[ax]
d += temp*temp
r2 = (d - h*h)
if fabs(h) <= self.height and r2 <= self.radius2: return 1
https://bitbucket.org/yt_analysis/yt/commits/141c8f1496be/
Changeset: 141c8f1496be
Branch: yt
User: MatthewTurk
Date: 2014-08-12 22:40:24
Summary: Be less careful about cylindrical bbox selection.
Affected #: 1 file
diff -r 126c62f6325585696574627f5aa8a62976c43049 -r 141c8f1496be73fca60092bac027fd1998a20537 yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -836,6 +836,8 @@
@cython.cdivision(True)
cdef int select_bbox(self, np.float64_t left_edge[3],
np.float64_t right_edge[3]) nogil:
+ # Until we can get our OBB/OBB intersection correct, disable this.
+ return 1
cdef np.float64_t *arr[2]
cdef np.float64_t pos[3], H, D, R2, temp
cdef int i, j, k, n
https://bitbucket.org/yt_analysis/yt/commits/be2141f80565/
Changeset: be2141f80565
Branch: yt
User: MatthewTurk
Date: 2014-08-14 18:53:41
Summary: Minor change to field_parameter_state.
This enables overriding, but not without checking, from base data_sources.
Affected #: 1 file
diff -r d85047922d9e1cbfc557566e8c00c8ae54d1779e -r be2141f8056512887494f032e5e643f2d8a2b692 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -447,8 +447,14 @@
@contextmanager
def _field_parameter_state(self, field_parameters):
+ # What we're doing here is making a copy of the incoming field
+ # parameters, and then updating it with our own. This means that we'll
+ # be using our own center, if set, rather than the supplied one. But
+ # it also means that any additionally set values can override it.
old_field_parameters = self.field_parameters
- self.field_parameters = field_parameters
+ new_field_parameters = field_parameters.copy()
+ new_field_parameters.update(old_field_parameters)
+ self.field_parameters = new_field_parameters
yield
self.field_parameters = old_field_parameters
https://bitbucket.org/yt_analysis/yt/commits/472fe6fc3450/
Changeset: 472fe6fc3450
Branch: yt
User: brittonsmith
Date: 2014-08-13 17:59:28
Summary: Merging.
Affected #: 4 files
diff -r 141c8f1496be73fca60092bac027fd1998a20537 -r 472fe6fc3450acd384f4871c3994c4fb8a8e7ba4 doc/source/analyzing/particle_filter.ipynb
--- a/doc/source/analyzing/particle_filter.ipynb
+++ b/doc/source/analyzing/particle_filter.ipynb
@@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
- "signature": "sha256:4d705a81671d5692ed6691b3402115edbe9c98af815af5bb160ddf551bf02c76"
+ "signature": "sha256:427da1e1d02deb543246218dc8cce991268b518b25cfdd5944a4a436695f874b"
},
"nbformat": 3,
"nbformat_minor": 0,
@@ -40,11 +40,13 @@
"source": [
"We will filter these into young stars and old stars by masking on the ('Stars', 'creation_time') field. \n",
"\n",
- "In order to do this, we first make a function which applies our desired cut. This function must accept two arguments: `pfilter` and `data`. The second argument is a yt data container and is usually the only one used in a filter definition.\n",
+ "In order to do this, we first make a function which applies our desired cut. This function must accept two arguments: `pfilter` and `data`. The first argument is a `ParticleFilter` object that contains metadata about the filter its self. The second argument is a yt data container.\n",
"\n",
- "Let's call \"young\" stars only those stars with ages less 5 million years. Since Tipsy assigns a very large `creation_time` for stars in the initial conditions, we need to also exclude stars with negative ages.\n",
+ "Let's call \"young\" stars only those stars with ages less 5 million years. Since Tipsy assigns a very large `creation_time` for stars in the initial conditions, we need to also exclude stars with negative ages. \n",
"\n",
- "Old stars either formed dynamically in the simulation (ages greater than 5 Myr) or were present in the initial conditions (negative ages)."
+ "Conversely, let's define \"old\" stars as those stars formed dynamically in the simulation with ages greater than 5 Myr. We also include stars with negative ages, since these stars were included in the simulation initial conditions.\n",
+ "\n",
+ "We make use of `pfilter.filtered_type` so that the filter definition will use the same particle type as the one specified in the call to `add_particle_filter` below. This makes the filter definition usable for arbitrary particle types. Since we're only filtering the `\"Stars\"` particle type in this example, we could have also replaced `pfilter.filtered_type` with `\"Stars\"` and gotten the same result."
]
},
{
@@ -52,12 +54,12 @@
"collapsed": false,
"input": [
"def young_stars(pfilter, data):\n",
- " age = data.ds.current_time - data[\"Stars\", \"creation_time\"]\n",
+ " age = data.ds.current_time - data[pfilter.filtered_type, \"creation_time\"]\n",
" filter = np.logical_and(age.in_units('Myr') <= 5, age >= 0)\n",
" return filter\n",
"\n",
"def old_stars(pfilter, data):\n",
- " age = data.ds.current_time - data[\"Stars\", \"creation_time\"]\n",
+ " age = data.ds.current_time - data[pfilter.filtered_type, \"creation_time\"]\n",
" filter = np.logical_or(age.in_units('Myr') >= 5, age < 0)\n",
" return filter"
],
@@ -140,4 +142,4 @@
"metadata": {}
}
]
-}
+}
\ No newline at end of file
diff -r 141c8f1496be73fca60092bac027fd1998a20537 -r 472fe6fc3450acd384f4871c3994c4fb8a8e7ba4 doc/source/developing/creating_derived_fields.rst
--- a/doc/source/developing/creating_derived_fields.rst
+++ b/doc/source/developing/creating_derived_fields.rst
@@ -179,6 +179,38 @@
fields or that get aliased to themselves, we can specify a different
desired output unit than the unit found on disk.
+Debugging a Derived Field
+-------------------------
+
+If your derived field is not behaving as you would like, you can insert a call
+to ``data._debug()`` to spawn an interactive interpreter whenever that line is
+reached. Note that this is slightly different from calling
+``pdb.set_trace()``, as it will *only* trigger when the derived field is being
+called on an actual data object, rather than during the field detection phase.
+The starting position will be one function lower in the stack than you are
+likely interested in, but you can either step through back to the derived field
+function, or simply type ``u`` to go up a level in the stack.
+
+For instance, if you had defined this derived field:
+
+.. code-block:: python
+
+ @yt.derived_field(name = "funthings")
+ def funthings(field, data):
+ return data["sillythings"] + data["humorousthings"]**2.0
+
+And you wanted to debug it, you could do:
+
+.. code-block:: python
+
+ @yt.derived_field(name = "funthings")
+ def funthings(field, data):
+ data._debug()
+ return data["sillythings"] + data["humorousthings"]**2.0
+
+And now, when that derived field is actually used, you will be placed into a
+debugger.
+
Units for Cosmological Datasets
-------------------------------
diff -r 141c8f1496be73fca60092bac027fd1998a20537 -r 472fe6fc3450acd384f4871c3994c4fb8a8e7ba4 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -129,6 +129,15 @@
self._index = self.ds.index
return self._index
+ def _debug(self):
+ """
+ When called from within a derived field, this will run pdb. However,
+ during field detection, it will not. This allows you to more easily
+ debug fields that are being called on actual objects.
+ """
+ import pdb
+ pdb.set_trace()
+
def _set_default_field_parameters(self):
self.field_parameters = {}
for k,v in self._default_field_parameters.items():
diff -r 141c8f1496be73fca60092bac027fd1998a20537 -r 472fe6fc3450acd384f4871c3994c4fb8a8e7ba4 yt/fields/field_detector.py
--- a/yt/fields/field_detector.py
+++ b/yt/fields/field_detector.py
@@ -148,6 +148,10 @@
self[item] = self._read_data(item)
return self[item]
+ def _debug(self):
+ # We allow this to pass through.
+ return
+
def deposit(self, *args, **kwargs):
return np.random.random((self.nd, self.nd, self.nd))
https://bitbucket.org/yt_analysis/yt/commits/4d0d0018d24b/
Changeset: 4d0d0018d24b
Branch: yt
User: brittonsmith
Date: 2014-08-13 21:33:44
Summary: Adding a periodic radius vector function and applying to cylindrical radius function. Also, changing the field parameter used for getting centers to _center to avoid collision with plots.
Affected #: 4 files
diff -r 472fe6fc3450acd384f4871c3994c4fb8a8e7ba4 -r 4d0d0018d24bea2520debd9c89f666e75f820514 yt/data_objects/selection_data_containers.py
--- a/yt/data_objects/selection_data_containers.py
+++ b/yt/data_objects/selection_data_containers.py
@@ -543,12 +543,13 @@
>>> disk = ds.disk(c, [1,0,0], (1, 'kpc'), (10, 'kpc'))
"""
_type_name = "disk"
- _con_args = ('center', '_norm_vec', '_radius', '_height')
+ _con_args = ('_center', '_norm_vec', '_radius', '_height')
def __init__(self, center, normal, radius, height, fields=None,
ds=None, **kwargs):
YTSelectionContainer3D.__init__(self, center, fields, ds, **kwargs)
self._norm_vec = np.array(normal)/np.sqrt(np.dot(normal,normal))
self.set_field_parameter("normal", self._norm_vec)
+ self.set_field_parameter("_center", self.center)
self._height = fix_length(height, self.ds)
self._radius = fix_length(radius, self.ds)
self._d = -1.0 * np.dot(self._norm_vec, self.center)
diff -r 472fe6fc3450acd384f4871c3994c4fb8a8e7ba4 -r 4d0d0018d24bea2520debd9c89f666e75f820514 yt/fields/field_functions.py
--- a/yt/fields/field_functions.py
+++ b/yt/fields/field_functions.py
@@ -15,6 +15,9 @@
import numpy as np
+from yt.utilities.lib.geometry_utils import \
+ obtain_rvec
+
def get_radius(data, field_prefix):
center = data.get_field_parameter("center").in_units("cm")
DW = (data.ds.domain_right_edge - data.ds.domain_left_edge).in_units("cm")
@@ -43,3 +46,17 @@
# Alias it, just for clarity.
radius = radius2
return radius
+
+def get_periodic_rvec(data):
+ coords = obtain_rvec(data)
+ if sum(data.ds.periodicity) == 0: return coords
+ le = data.ds.domain_left_edge.in_units("code_length").d
+ dw = data.ds.domain_width.in_units("code_length").d
+ for i in range(coords.shape[0]):
+ if not data.ds.periodicity[i]: continue
+ coords[i, ...] -= le[i]
+ coords[i, ...] = np.min([np.abs(np.mod(coords[i, ...], dw[i])),
+ np.abs(np.mod(coords[i, ...], -dw[i]))],
+ axis=0)
+ coords[i, ...] += le[i]
+ return coords
diff -r 472fe6fc3450acd384f4871c3994c4fb8a8e7ba4 -r 4d0d0018d24bea2520debd9c89f666e75f820514 yt/fields/geometric_fields.py
--- a/yt/fields/geometric_fields.py
+++ b/yt/fields/geometric_fields.py
@@ -22,6 +22,7 @@
ValidateSpatial
from .field_functions import \
+ get_periodic_rvec, \
get_radius
from .field_plugin_registry import \
@@ -136,17 +137,13 @@
### cylindrical coordinates: R (radius in the cylinder's plane)
def _cylindrical_r(field, data):
- center = data.get_field_parameter("center")
normal = data.get_field_parameter("normal")
- coords = obtain_rvec(data)
- coords[0,...] -= center[0]
- coords[1,...] -= center[1]
- coords[2,...] -= center[2]
+ coords = get_periodic_rvec(data)
return data.ds.arr(get_cyl_r(coords, normal), "code_length").in_cgs()
registry.add_field(("index", "cylindrical_r"),
function=_cylindrical_r,
- validators=[ValidateParameter("center"),
+ validators=[ValidateParameter("_center"),
ValidateParameter("normal")],
units="cm")
diff -r 472fe6fc3450acd384f4871c3994c4fb8a8e7ba4 -r 4d0d0018d24bea2520debd9c89f666e75f820514 yt/utilities/lib/geometry_utils.pyx
--- a/yt/utilities/lib/geometry_utils.pyx
+++ b/yt/utilities/lib/geometry_utils.pyx
@@ -85,7 +85,7 @@
cdef np.ndarray[np.float64_t, ndim=4] rg
cdef np.float64_t c[3]
cdef int i, j, k
- center = data.get_field_parameter("center")
+ center = data.get_field_parameter("_center")
c[0] = center[0]; c[1] = center[1]; c[2] = center[2]
if len(data['x'].shape) == 1:
# One dimensional data
https://bitbucket.org/yt_analysis/yt/commits/5aec75f09ac9/
Changeset: 5aec75f09ac9
Branch: yt
User: brittonsmith
Date: 2014-08-13 21:39:41
Summary: Fixing cylindrical_z field.
Affected #: 1 file
diff -r 4d0d0018d24bea2520debd9c89f666e75f820514 -r 5aec75f09ac9b5e7ee8faf451edb23b9f48f1786 yt/fields/geometric_fields.py
--- a/yt/fields/geometric_fields.py
+++ b/yt/fields/geometric_fields.py
@@ -149,13 +149,9 @@
### cylindrical coordinates: z (height above the cylinder's plane)
def _cylindrical_z(field, data):
- center = data.get_field_parameter("center")
normal = data.get_field_parameter("normal")
- coords = data.ds.arr(obtain_rvec(data), "code_length")
- coords[0,...] -= center[0]
- coords[1,...] -= center[1]
- coords[2,...] -= center[2]
- return get_cyl_z(coords, normal).in_cgs()
+ coords = get_periodic_rvec(data)
+ return data.ds.arr(get_cyl_z(coords, normal), "code_length").in_cgs()
registry.add_field(("index", "cylindrical_z"),
function=_cylindrical_z,
https://bitbucket.org/yt_analysis/yt/commits/f11aef56fd95/
Changeset: f11aef56fd95
Branch: yt
User: brittonsmith
Date: 2014-08-13 22:04:41
Summary: Fixing spherical radius field for periodicity.
Affected #: 2 files
diff -r 5aec75f09ac9b5e7ee8faf451edb23b9f48f1786 -r f11aef56fd957fb715754758498fe1bb35341e19 yt/data_objects/selection_data_containers.py
--- a/yt/data_objects/selection_data_containers.py
+++ b/yt/data_objects/selection_data_containers.py
@@ -619,7 +619,7 @@
>>> sphere = ds.sphere(c,1.*ds['kpc'])
"""
_type_name = "sphere"
- _con_args = ('center', 'radius')
+ _con_args = ('_center', '_radius')
def __init__(self, center, radius, ds = None, field_parameters = None):
super(YTSphereBase, self).__init__(center, ds, field_parameters)
# Unpack the radius, if necessary
@@ -627,7 +627,8 @@
if radius < self.index.get_smallest_dx():
raise YTSphereTooSmall(ds, radius.in_units("code_length"),
self.index.get_smallest_dx().in_units("code_length"))
- self.set_field_parameter('radius',radius)
+ self.set_field_parameter('_radius',radius)
+ self.set_field_parameter("_center", self.center)
self.radius = radius
class YTEllipsoidBase(YTSelectionContainer3D):
diff -r 5aec75f09ac9b5e7ee8faf451edb23b9f48f1786 -r f11aef56fd957fb715754758498fe1bb35341e19 yt/fields/geometric_fields.py
--- a/yt/fields/geometric_fields.py
+++ b/yt/fields/geometric_fields.py
@@ -93,12 +93,8 @@
### spherical coordinates: r (radius)
def _spherical_r(field, data):
- center = data.get_field_parameter("center")
- coords = data.ds.arr(obtain_rvec(data), "code_length")
- coords[0,...] -= center[0]
- coords[1,...] -= center[1]
- coords[2,...] -= center[2]
- return get_sph_r(coords).in_cgs()
+ coords = get_periodic_rvec(data)
+ return data.ds.arr(get_sph_r(coords), "code_length").in_cgs()
registry.add_field(("index", "spherical_r"),
function=_spherical_r,
https://bitbucket.org/yt_analysis/yt/commits/d9638df6bb11/
Changeset: d9638df6bb11
Branch: yt
User: brittonsmith
Date: 2014-08-13 22:10:59
Summary: Fixing theta and phi fields.
Affected #: 1 file
diff -r f11aef56fd957fb715754758498fe1bb35341e19 -r d9638df6bb1178601c86be90a8413975a1acb6c9 yt/fields/geometric_fields.py
--- a/yt/fields/geometric_fields.py
+++ b/yt/fields/geometric_fields.py
@@ -40,9 +40,6 @@
get_sph_theta, get_sph_phi, \
periodic_dist, euclidean_dist
-from yt.utilities.lib.geometry_utils import \
- obtain_rvec
-
@register_field_plugin
def setup_geometric_fields(registry, ftype = "gas", slice_info = None):
@@ -98,37 +95,29 @@
registry.add_field(("index", "spherical_r"),
function=_spherical_r,
- validators=[ValidateParameter("center")],
+ validators=[ValidateParameter("_center")],
units="cm")
### spherical coordinates: theta (angle with respect to normal)
def _spherical_theta(field, data):
- center = data.get_field_parameter("center")
normal = data.get_field_parameter("normal")
- coords = obtain_rvec(data)
- coords[0,...] -= center[0]
- coords[1,...] -= center[1]
- coords[2,...] -= center[2]
+ coords = get_periodic_rvec(data)
return get_sph_theta(coords, normal)
registry.add_field(("index", "spherical_theta"),
function=_spherical_theta,
- validators=[ValidateParameter("center"),
- ValidateParameter("normal")])
+ validators=[ValidateParameter("_center"),
+ ValidateParameter("normal")])
### spherical coordinates: phi (angle in the plane perpendicular to the normal)
def _spherical_phi(field, data):
- center = data.get_field_parameter("center")
normal = data.get_field_parameter("normal")
- coords = obtain_rvec(data)
- coords[0,...] -= center[0]
- coords[1,...] -= center[1]
- coords[2,...] -= center[2]
+ coords = get_periodic_rvec(data)
return get_sph_phi(coords, normal)
registry.add_field(("index", "spherical_phi"),
function=_spherical_phi,
- validators=[ValidateParameter("center"),
+ validators=[ValidateParameter("_center"),
ValidateParameter("normal")])
### cylindrical coordinates: R (radius in the cylinder's plane)
@@ -140,7 +129,7 @@
registry.add_field(("index", "cylindrical_r"),
function=_cylindrical_r,
validators=[ValidateParameter("_center"),
- ValidateParameter("normal")],
+ ValidateParameter("normal")],
units="cm")
### cylindrical coordinates: z (height above the cylinder's plane)
@@ -157,17 +146,13 @@
### cylindrical coordinates: theta (angle in the cylinder's plane)
def _cylindrical_theta(field, data):
- center = data.get_field_parameter("center")
normal = data.get_field_parameter("normal")
- coords = obtain_rvec(data)
- coords[0,...] -= center[0]
- coords[1,...] -= center[1]
- coords[2,...] -= center[2]
+ coords = get_periodic_rvec(data)
return get_cyl_theta(coords, normal)
registry.add_field(("index", "cylindrical_theta"),
function=_cylindrical_theta,
- validators=[ValidateParameter("center"),
+ validators=[ValidateParameter("_center"),
ValidateParameter("normal")],
units = "")
https://bitbucket.org/yt_analysis/yt/commits/9f12477ff725/
Changeset: 9f12477ff725
Branch: yt
User: brittonsmith
Date: 2014-08-13 22:16:13
Summary: Fixing up sphere and disk docstrings.
Affected #: 1 file
diff -r d9638df6bb1178601c86be90a8413975a1acb6c9 -r 9f12477ff72561df1a31e9606d32d2d83cb9f774 yt/data_objects/selection_data_containers.py
--- a/yt/data_objects/selection_data_containers.py
+++ b/yt/data_objects/selection_data_containers.py
@@ -517,15 +517,15 @@
Parameters
----------
center : array_like
- coordinate to which the normal, radius, and height all reference; in
- the center of one of the bases of the cylinder
+ coordinate to which the normal, radius, and height all reference
normal : array_like
the normal vector defining the direction of lengthwise part of the
cylinder
radius : float
the radius of the cylinder
height : float
- the height of the lengthwise part of the cylinder
+ the distance from the midplane of the cylinder to the top and
+ bottom planes
fields : array of fields, optional
any fields to be pre-loaded in the cylinder object
ds: Dataset, optional
@@ -616,7 +616,7 @@
>>> import yt
>>> ds = yt.load("RedshiftOutput0005")
>>> c = [0.5,0.5,0.5]
- >>> sphere = ds.sphere(c,1.*ds['kpc'])
+ >>> sphere = ds.sphere(c, (1., "kpc"))
"""
_type_name = "sphere"
_con_args = ('_center', '_radius')
https://bitbucket.org/yt_analysis/yt/commits/5b6394179b8e/
Changeset: 5b6394179b8e
Branch: yt
User: brittonsmith
Date: 2014-08-15 13:34:51
Summary: No longer overriding field parameters.
Affected #: 1 file
diff -r 9f12477ff72561df1a31e9606d32d2d83cb9f774 -r 5b6394179b8e6f87fdf6bce4fba6d53a216b310e yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -447,10 +447,7 @@
@contextmanager
def _field_parameter_state(self, field_parameters):
- old_field_parameters = self.field_parameters
- self.field_parameters = field_parameters
yield
- self.field_parameters = old_field_parameters
@contextmanager
def _field_type_state(self, ftype, finfo, obj = None):
https://bitbucket.org/yt_analysis/yt/commits/4e4c15194b36/
Changeset: 4e4c15194b36
Branch: yt
User: brittonsmith
Date: 2014-08-15 13:35:12
Summary: Returning attributes and field_parameters to old names.
Affected #: 4 files
diff -r 5b6394179b8e6f87fdf6bce4fba6d53a216b310e -r 4e4c15194b36e77992dba22b8bb346d234be5611 yt/data_objects/selection_data_containers.py
--- a/yt/data_objects/selection_data_containers.py
+++ b/yt/data_objects/selection_data_containers.py
@@ -543,15 +543,15 @@
>>> disk = ds.disk(c, [1,0,0], (1, 'kpc'), (10, 'kpc'))
"""
_type_name = "disk"
- _con_args = ('_center', '_norm_vec', '_radius', '_height')
+ _con_args = ('center', '_norm_vec', 'radius', 'height')
def __init__(self, center, normal, radius, height, fields=None,
ds=None, **kwargs):
YTSelectionContainer3D.__init__(self, center, fields, ds, **kwargs)
self._norm_vec = np.array(normal)/np.sqrt(np.dot(normal,normal))
self.set_field_parameter("normal", self._norm_vec)
- self.set_field_parameter("_center", self.center)
- self._height = fix_length(height, self.ds)
- self._radius = fix_length(radius, self.ds)
+ self.set_field_parameter("center", self.center)
+ self.height = fix_length(height, self.ds)
+ self.radius = fix_length(radius, self.ds)
self._d = -1.0 * np.dot(self._norm_vec, self.center)
class YTRegionBase(YTSelectionContainer3D):
@@ -619,7 +619,7 @@
>>> sphere = ds.sphere(c, (1., "kpc"))
"""
_type_name = "sphere"
- _con_args = ('_center', '_radius')
+ _con_args = ('center', 'radius')
def __init__(self, center, radius, ds = None, field_parameters = None):
super(YTSphereBase, self).__init__(center, ds, field_parameters)
# Unpack the radius, if necessary
@@ -627,8 +627,8 @@
if radius < self.index.get_smallest_dx():
raise YTSphereTooSmall(ds, radius.in_units("code_length"),
self.index.get_smallest_dx().in_units("code_length"))
- self.set_field_parameter('_radius',radius)
- self.set_field_parameter("_center", self.center)
+ self.set_field_parameter('radius',radius)
+ self.set_field_parameter("center", self.center)
self.radius = radius
class YTEllipsoidBase(YTSelectionContainer3D):
diff -r 5b6394179b8e6f87fdf6bce4fba6d53a216b310e -r 4e4c15194b36e77992dba22b8bb346d234be5611 yt/fields/geometric_fields.py
--- a/yt/fields/geometric_fields.py
+++ b/yt/fields/geometric_fields.py
@@ -95,7 +95,7 @@
registry.add_field(("index", "spherical_r"),
function=_spherical_r,
- validators=[ValidateParameter("_center")],
+ validators=[ValidateParameter("center")],
units="cm")
### spherical coordinates: theta (angle with respect to normal)
@@ -106,7 +106,7 @@
registry.add_field(("index", "spherical_theta"),
function=_spherical_theta,
- validators=[ValidateParameter("_center"),
+ validators=[ValidateParameter("center"),
ValidateParameter("normal")])
### spherical coordinates: phi (angle in the plane perpendicular to the normal)
@@ -117,7 +117,7 @@
registry.add_field(("index", "spherical_phi"),
function=_spherical_phi,
- validators=[ValidateParameter("_center"),
+ validators=[ValidateParameter("center"),
ValidateParameter("normal")])
### cylindrical coordinates: R (radius in the cylinder's plane)
@@ -128,7 +128,7 @@
registry.add_field(("index", "cylindrical_r"),
function=_cylindrical_r,
- validators=[ValidateParameter("_center"),
+ validators=[ValidateParameter("center"),
ValidateParameter("normal")],
units="cm")
@@ -152,7 +152,7 @@
registry.add_field(("index", "cylindrical_theta"),
function=_cylindrical_theta,
- validators=[ValidateParameter("_center"),
+ validators=[ValidateParameter("center"),
ValidateParameter("normal")],
units = "")
diff -r 5b6394179b8e6f87fdf6bce4fba6d53a216b310e -r 4e4c15194b36e77992dba22b8bb346d234be5611 yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -785,9 +785,9 @@
for i in range(3):
self.norm_vec[i] = dobj._norm_vec[i]
self.center[i] = _ensure_code(dobj.center[i])
- self.radius = _ensure_code(dobj._radius)
+ self.radius = _ensure_code(dobj.radius)
self.radius2 = self.radius * self.radius
- self.height = _ensure_code(dobj._height)
+ self.height = _ensure_code(dobj.height)
@cython.boundscheck(False)
@cython.wraparound(False)
diff -r 5b6394179b8e6f87fdf6bce4fba6d53a216b310e -r 4e4c15194b36e77992dba22b8bb346d234be5611 yt/utilities/lib/geometry_utils.pyx
--- a/yt/utilities/lib/geometry_utils.pyx
+++ b/yt/utilities/lib/geometry_utils.pyx
@@ -85,7 +85,7 @@
cdef np.ndarray[np.float64_t, ndim=4] rg
cdef np.float64_t c[3]
cdef int i, j, k
- center = data.get_field_parameter("_center")
+ center = data.get_field_parameter("center")
c[0] = center[0]; c[1] = center[1]; c[2] = center[2]
if len(data['x'].shape) == 1:
# One dimensional data
https://bitbucket.org/yt_analysis/yt/commits/57c8833f5dad/
Changeset: 57c8833f5dad
Branch: yt
User: brittonsmith
Date: 2014-08-15 14:41:56
Summary: Undoing stuff.
Affected #: 1 file
diff -r 4e4c15194b36e77992dba22b8bb346d234be5611 -r 57c8833f5dadbf95a97c869c86ae7af8831a6c09 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -447,7 +447,10 @@
@contextmanager
def _field_parameter_state(self, field_parameters):
+ old_field_parameters = self.field_parameters
+ self.field_parameters = field_parameters
yield
+ self.field_parameters = old_field_parameters
@contextmanager
def _field_type_state(self, ftype, finfo, obj = None):
https://bitbucket.org/yt_analysis/yt/commits/592ab04ed985/
Changeset: 592ab04ed985
Branch: yt
User: brittonsmith
Date: 2014-08-15 14:43:13
Summary: Merging.
Affected #: 4 files
diff -r 57c8833f5dadbf95a97c869c86ae7af8831a6c09 -r 592ab04ed985da2e6824f00a8d583d871001f539 yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
--- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
+++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum_fit.py
@@ -1,8 +1,10 @@
-from scipy import optimize
-import numpy as na
+import numpy as np
import h5py
from yt.analysis_modules.absorption_spectrum.absorption_line \
import voigt
+from yt.utilities.on_demand_imports import _scipy
+
+optimize = _scipy.optimize
def generate_total_fit(x, fluxData, orderFits, speciesDicts,
minError=1E-4, complexLim=.995,
@@ -83,7 +85,7 @@
x0,xRes=x[0],x[1]-x[0]
#Empty fit without any lines
- yFit = na.ones(len(fluxData))
+ yFit = np.ones(len(fluxData))
#Force the first and last flux pixel to be 1 to prevent OOB
fluxData[0]=1
@@ -98,10 +100,10 @@
#Fit all species one at a time in given order from low to high wavelength
for species in orderFits:
speciesDict = speciesDicts[species]
- speciesLines = {'N':na.array([]),
- 'b':na.array([]),
- 'z':na.array([]),
- 'group#':na.array([])}
+ speciesLines = {'N':np.array([]),
+ 'b':np.array([]),
+ 'z':np.array([]),
+ 'group#':np.array([])}
#Set up wavelengths for species
initWl = speciesDict['wavelength'][0]
@@ -131,7 +133,7 @@
yFitBounded,z,speciesDict,
minSize,minError)
- if na.size(newLinesP)> 0:
+ if np.size(newLinesP)> 0:
#Check for EXPLOOOOSIIONNNSSS
newLinesP = _check_numerical_instability(x, newLinesP, speciesDict,b)
@@ -150,12 +152,12 @@
#Add new group to all fitted lines
- if na.size(newLinesP)>0:
- speciesLines['N']=na.append(speciesLines['N'],newLinesP[:,0])
- speciesLines['b']=na.append(speciesLines['b'],newLinesP[:,1])
- speciesLines['z']=na.append(speciesLines['z'],newLinesP[:,2])
- groupNums = b_i*na.ones(na.size(newLinesP[:,0]))
- speciesLines['group#']=na.append(speciesLines['group#'],groupNums)
+ if np.size(newLinesP)>0:
+ speciesLines['N']=np.append(speciesLines['N'],newLinesP[:,0])
+ speciesLines['b']=np.append(speciesLines['b'],newLinesP[:,1])
+ speciesLines['z']=np.append(speciesLines['z'],newLinesP[:,2])
+ groupNums = b_i*np.ones(np.size(newLinesP[:,0]))
+ speciesLines['group#']=np.append(speciesLines['group#'],groupNums)
allSpeciesLines[species]=speciesLines
@@ -226,7 +228,7 @@
initP[0] = speciesDict['init_N']
initP[1] = speciesDict['init_b']
initP[2]=initz
- initP=na.array([initP])
+ initP=np.array([initP])
linesP = initP
@@ -259,7 +261,7 @@
#Set results of optimization
- linesP = na.reshape(fitP,(-1,3))
+ linesP = np.reshape(fitP,(-1,3))
#Generate difference between current best fit and data
yNewFit=_gen_flux_lines(x,linesP,speciesDict)
@@ -288,7 +290,7 @@
break
#If too many lines
- if na.shape(linesP)[0]>8 or na.size(linesP)+3>=len(x):
+ if np.shape(linesP)[0]>8 or np.size(linesP)+3>=len(x):
#If its fitable by flag tools and still bad, use flag tools
if errSq >1E2*errBound and speciesDict['name']=='HI lya':
return [],True
@@ -315,17 +317,17 @@
newP[0] = speciesDict['init_N']
newP[1] = speciesDict['init_b']
newP[2]=(x[dif.argmax()]-wl0)/wl0
- linesP=na.append(linesP,[newP],axis=0)
+ linesP=np.append(linesP,[newP],axis=0)
#Check the parameters of all lines to see if they fall in an
# acceptable range, as given in dict ref
remove=[]
for i,p in enumerate(linesP):
- check=_check_params(na.array([p]),speciesDict,x)
+ check=_check_params(np.array([p]),speciesDict,x)
if check:
remove.append(i)
- linesP = na.delete(linesP,remove,axis=0)
+ linesP = np.delete(linesP,remove,axis=0)
return linesP,flag
@@ -377,7 +379,7 @@
#Iterate through test line guesses
for initLines in lineTests:
if initLines[1,0]==0:
- initLines = na.delete(initLines,1,axis=0)
+ initLines = np.delete(initLines,1,axis=0)
#Do fitting with initLines as first guess
linesP,flag=_complex_fit(x,yDat,yFit,initz,
@@ -421,7 +423,7 @@
"""
#Set up a bunch of empty lines
- testP = na.zeros((10,2,3))
+ testP = np.zeros((10,2,3))
testP[0,0,:]=[1E18,20,initz]
testP[1,0,:]=[1E18,40,initz]
@@ -542,7 +544,7 @@
errBound = 10*errBound*len(yb)
#Generate a fit and find the difference to data
- yFitb=_gen_flux_lines(xb,na.array([p]),speciesDict)
+ yFitb=_gen_flux_lines(xb,np.array([p]),speciesDict)
dif =yb-yFitb
@@ -557,7 +559,7 @@
break
#Remove all bad line fits
- linesP = na.delete(linesP,removeLines,axis=0)
+ linesP = np.delete(linesP,removeLines,axis=0)
return linesP
@@ -755,7 +757,7 @@
if firstLine:
break
- flux = na.exp(-y)
+ flux = np.exp(-y)
return flux
def _gen_tau(t, p, f, Gamma, lambda_unshifted):
@@ -768,7 +770,7 @@
a=7.95774715459E-15*Gamma*lambda_unshifted/b
x=299792.458/b*(lambda_unshifted*(1+z)/t-1)
- H = na.zeros(len(x))
+ H = np.zeros(len(x))
H = voigt(a,x)
tau = tau_o*H
@@ -910,9 +912,9 @@
# Make the final line parameters. Its annoying because
# one or both regions may have fit to nothing
- if na.size(p1)> 0 and na.size(p2)>0:
- p = na.r_[p1,p2]
- elif na.size(p1) > 0:
+ if np.size(p1)> 0 and np.size(p2)>0:
+ p = np.r_[p1,p2]
+ elif np.size(p1) > 0:
p = p1
else:
p = p2
@@ -952,7 +954,7 @@
# max and min to prevent boundary errors
flux = _gen_flux_lines(x,[line],speciesDict,firstLine=True)
- flux = na.r_[flux[:max(b[1]-10,0)], flux[min(b[2]+10,len(x)):]]
+ flux = np.r_[flux[:max(b[1]-10,0)], flux[min(b[2]+10,len(x)):]]
#Find regions that are absorbing outside the region we fit
flux_dif = 1 - flux
@@ -971,7 +973,7 @@
remove_lines.append(i)
if remove_lines:
- p = na.delete(p, remove_lines, axis=0)
+ p = np.delete(p, remove_lines, axis=0)
return p
diff -r 57c8833f5dadbf95a97c869c86ae7af8831a6c09 -r 592ab04ed985da2e6824f00a8d583d871001f539 yt/analysis_modules/photon_simulator/spectral_models.py
--- a/yt/analysis_modules/photon_simulator/spectral_models.py
+++ b/yt/analysis_modules/photon_simulator/spectral_models.py
@@ -22,14 +22,10 @@
except ImportError:
pass
-try:
- import xspec
- from scipy.integrate import cumtrapz
- from scipy import stats
-except ImportError:
- pass
-from yt.utilities.on_demand_imports import _astropy
+from yt.utilities.on_demand_imports import _astropy, _scipy
+
pyfits = _astropy.pyfits
+stats = _scipy.stats
from yt.utilities.physical_constants import hcgs, clight, erg_per_keV, amu_cgs
@@ -212,11 +208,14 @@
try:
self.line_handle = pyfits.open(self.linefile)
except IOError:
- mylog.error("LINE file %s does not exist" % (self.linefile))
+ mylog.error("LINE file %s does not exist" % self.linefile)
+ raise IOError("LINE file %s does not exist" % self.linefile)
try:
self.coco_handle = pyfits.open(self.cocofile)
except IOError:
- mylog.error("COCO file %s does not exist" % (self.cocofile))
+ mylog.error("COCO file %s does not exist" % self.cocofile)
+ raise IOError("COCO file %s does not exist" % self.cocofile)
+
self.Tvals = self.line_handle[1].data.field("kT")
self.dTvals = np.diff(self.Tvals)
self.minlam = self.wvbins.min()
@@ -224,18 +223,18 @@
def _make_spectrum(self, element, tindex):
- tmpspec = np.zeros((self.nchan))
+ tmpspec = np.zeros(self.nchan)
i = np.where((self.line_handle[tindex].data.field('element') == element) &
(self.line_handle[tindex].data.field('lambda') > self.minlam) &
(self.line_handle[tindex].data.field('lambda') < self.maxlam))[0]
- vec = np.zeros((self.nchan))
+ vec = np.zeros(self.nchan)
E0 = hc.value/self.line_handle[tindex].data.field('lambda')[i]
amp = self.line_handle[tindex].data.field('epsilon')[i]
ebins = self.ebins.ndarray_view()
if self.thermal_broad:
- vec = np.zeros((self.nchan))
+ vec = np.zeros(self.nchan)
sigma = E0*np.sqrt(self.Tvals[tindex]*erg_per_keV/(self.A[element]*amu_cgs))/clight.value
for E, sig, a in zip(E0, sigma, amp):
cdf = stats.norm(E,sig).cdf(ebins)
@@ -270,10 +269,10 @@
"""
Get the thermal emission spectrum given a temperature *kT* in keV.
"""
- cspec_l = np.zeros((self.nchan))
- mspec_l = np.zeros((self.nchan))
- cspec_r = np.zeros((self.nchan))
- mspec_r = np.zeros((self.nchan))
+ cspec_l = np.zeros(self.nchan)
+ mspec_l = np.zeros(self.nchan)
+ cspec_r = np.zeros(self.nchan)
+ mspec_r = np.zeros(self.nchan)
tindex = np.searchsorted(self.Tvals, kT)-1
if tindex >= self.Tvals.shape[0]-1 or tindex < 0:
return cspec_l*cm3/units.s, mspec_l*cm3/units.s
diff -r 57c8833f5dadbf95a97c869c86ae7af8831a6c09 -r 592ab04ed985da2e6824f00a8d583d871001f539 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -447,8 +447,14 @@
@contextmanager
def _field_parameter_state(self, field_parameters):
+ # What we're doing here is making a copy of the incoming field
+ # parameters, and then updating it with our own. This means that we'll
+ # be using our own center, if set, rather than the supplied one. But
+ # it also means that any additionally set values can override it.
old_field_parameters = self.field_parameters
- self.field_parameters = field_parameters
+ new_field_parameters = field_parameters.copy()
+ new_field_parameters.update(old_field_parameters)
+ self.field_parameters = new_field_parameters
yield
self.field_parameters = old_field_parameters
diff -r 57c8833f5dadbf95a97c869c86ae7af8831a6c09 -r 592ab04ed985da2e6824f00a8d583d871001f539 yt/utilities/on_demand_imports.py
--- a/yt/utilities/on_demand_imports.py
+++ b/yt/utilities/on_demand_imports.py
@@ -10,7 +10,20 @@
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
+class NotAModule(object):
+ """
+ A class to implement an informative error message that will be outputted if
+ someone tries to use an on-demand import without having the requisite package installed.
+ """
+ def __init__(self, pkg_name):
+ self.pkg_name = pkg_name
+
+ def __getattr__(self, item):
+ raise ImportError("This functionality requires the %s package to be installed."
+ % self.pkg_name)
+
class astropy_imports:
+ _name = "astropy"
_pyfits = None
@property
def pyfits(self):
@@ -19,7 +32,7 @@
import astropy.io.fits as pyfits
self.log
except ImportError:
- pyfits = None
+ pyfits = NotAModule(self._name)
self._pyfits = pyfits
return self._pyfits
@@ -31,7 +44,7 @@
import astropy.wcs as pywcs
self.log
except ImportError:
- pywcs = None
+ pywcs = NotAModule(self._name)
self._pywcs = pywcs
return self._pywcs
@@ -44,7 +57,7 @@
if log.exception_logging_enabled():
log.disable_exception_logging()
except ImportError:
- log = None
+ log = NotAModule(self._name)
self._log = log
return self._log
@@ -55,7 +68,7 @@
try:
from astropy import units
except ImportError:
- units = None
+ units = NotAModule(self._name)
self._units = units
return self._units
@@ -67,8 +80,56 @@
import astropy.convolution as conv
self.log
except ImportError:
- conv = None
+ conv = NotAModule(self._name)
self._conv = conv
return self._conv
-_astropy = astropy_imports()
\ No newline at end of file
+_astropy = astropy_imports()
+
+class scipy_imports:
+ _name = "scipy"
+ _integrate = None
+ @property
+ def integrate(self):
+ if self._integrate is None:
+ try:
+ import scipy.integrate as integrate
+ except ImportError:
+ integrate = NotAModule(self._name)
+ self._integrate = integrate
+ return self._integrate
+
+ _stats = None
+ @property
+ def stats(self):
+ if self._stats is None:
+ try:
+ import scipy.stats as stats
+ except ImportError:
+ stats = NotAModule(self._name)
+ self._stats = stats
+ return self._stats
+
+ _optimize = None
+ @property
+ def optimize(self):
+ if self._optimize is None:
+ try:
+ import scipy.optimize as optimize
+ except ImportError:
+ optimize = NotAModule(self._name)
+ self._optimize = optimize
+ return self._optimize
+
+ _interpolate = None
+ @property
+ def interpolate(self):
+ if self._interpolate is None:
+ try:
+ import scipy.interpolate as interpolate
+ except ImportError:
+ interpolate = NotAModule(self._name)
+ self._interpolate = interpolate
+ return self._interpolate
+
+_scipy = scipy_imports()
\ No newline at end of file
https://bitbucket.org/yt_analysis/yt/commits/f68d67333566/
Changeset: f68d67333566
Branch: yt
User: MatthewTurk
Date: 2014-08-15 17:12:25
Summary: This fixes radial_velocity.
Affected #: 1 file
diff -r 592ab04ed985da2e6824f00a8d583d871001f539 -r f68d67333566d7f44bde8c36f18c39bb6030cb12 yt/fields/vector_operations.py
--- a/yt/fields/vector_operations.py
+++ b/yt/fields/vector_operations.py
@@ -116,7 +116,11 @@
"bulk_%s" % basename)
theta = data['index', 'spherical_theta']
phi = data['index', 'spherical_phi']
- return get_sph_r_component(vectors, theta, phi, normal)
+ rv = get_sph_r_component(vectors, theta, phi, normal)
+ # Now, anywhere that radius is in fact zero, we want to zero out our
+ # return values.
+ rv[np.isnan(theta)] = 0.0
+ return rv
def _radial_absolute(field, data):
return np.abs(data[ftype, "radial_%s" % basename])
https://bitbucket.org/yt_analysis/yt/commits/59353afbaf66/
Changeset: 59353afbaf66
Branch: yt
User: MatthewTurk
Date: 2014-08-15 17:12:42
Summary: Merging
Affected #: 1 file
diff -r f68d67333566d7f44bde8c36f18c39bb6030cb12 -r 59353afbaf666dbfdd918372322749fd5e8fee4b yt/analysis_modules/setup.py
--- a/yt/analysis_modules/setup.py
+++ b/yt/analysis_modules/setup.py
@@ -6,6 +6,7 @@
config.make_config_py() # installs __config__.py
config.add_subpackage("absorption_spectrum")
config.add_subpackage("cosmological_observation")
+ config.add_subpackage("halo_analysis")
config.add_subpackage("halo_finding")
config.add_subpackage("halo_mass_function")
config.add_subpackage("level_sets")
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