[yt-svn] commit/yt: 10 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Sat May 3 11:01:10 PDT 2014
10 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/56c9cdbb1dcc/
Changeset: 56c9cdbb1dcc
Branch: yt-3.0
User: ngoldbaum
Date: 2014-04-30 22:26:04
Summary: Fixing an issue where the deposited particle mass field had incorrect units.
Affected #: 1 file
diff -r 5affa74d80f34e32c9137bd4ed03821b7ac17570 -r 56c9cdbb1dccc05f8b606932b946673e5e323e11 yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -1,5 +1,5 @@
"""
-These are common particle deposition fields.
+These are common particle fields.
@@ -84,7 +84,8 @@
def particle_mass(field, data):
pos = data[ptype, coord_name]
- d = data.deposit(pos, [data[ptype, mass_name]], method = "sum")
+ pmass = data[ptype, mass_name].in_units(field.units)
+ d = data.deposit(pos, [pmass], method = "sum")
return data.apply_units(d, field.units)
registry.add_field(("deposit", "%s_mass" % ptype),
https://bitbucket.org/yt_analysis/yt/commits/059a6345a79a/
Changeset: 059a6345a79a
Branch: yt-3.0
User: ngoldbaum
Date: 2014-04-30 22:26:28
Summary: Fixing an issue where array_like_field would strip units if passed a YTArray.
Affected #: 1 file
diff -r 56c9cdbb1dccc05f8b606932b946673e5e323e11 -r 059a6345a79ae58386a8a8db70e53a65ee0a02fa yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -884,6 +884,10 @@
units = data.pf._get_field_info(field[0],field[1]).units
else:
units = data.pf._get_field_info(field).units
+ if isinstance(x, YTArray):
+ arr = copy.deepcopy(x)
+ arr.units.registry = data.pf.unit_registry
+ return arr.in_units(units)
if isinstance(x, np.ndarray):
return data.pf.arr(x, units)
else:
https://bitbucket.org/yt_analysis/yt/commits/af533895550d/
Changeset: af533895550d
Branch: yt-3.0
User: ngoldbaum
Date: 2014-04-30 22:27:28
Summary: Whitespace cleanup in profiles.py
Affected #: 1 file
diff -r 059a6345a79ae58386a8a8db70e53a65ee0a02fa -r af533895550d7e3533f3046db7ceb184f4c4a490 yt/data_objects/profiles.py
--- a/yt/data_objects/profiles.py
+++ b/yt/data_objects/profiles.py
@@ -157,7 +157,7 @@
"""
def __init__(self, data_source, n_bins, bin_field,
lower_bound, upper_bound,
- log_space = True,
+ log_space = True,
end_collect=False):
BinnedProfile.__init__(self, data_source)
self.bin_field = bin_field
@@ -212,7 +212,7 @@
# summing up all of the histograms and dividing by the
# weights. Accumulation likely doesn't work with weighted
# average fields.
- if accumulation:
+ if accumulation:
binned_field = np.add.accumulate(binned_field)
return binned_field, weight_field, q_field, \
used_field.astype("bool")
@@ -237,12 +237,12 @@
bin_indices = np.clip(bin_indices, 0, self.n_bins - 1)
else: #throw away outside values
bin_indices -= 1
-
+
return (mi, bin_indices)
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
x = self.field_data[self.bin_field]
@@ -259,7 +259,7 @@
return x
def write_out(self, filename, format="%0.16e", bin_style='left'):
- '''
+ '''
Write out data in ascii file, using *format* and
*bin_style* (left, right, center, both).
'''
@@ -268,12 +268,12 @@
fields.remove(self.bin_field)
fid.write("\t".join(["#"] + [self.bin_field] + fields + ["\n"]))
- field_data = np.array(self.choose_bins(bin_style))
+ field_data = np.array(self.choose_bins(bin_style))
if bin_style is 'both':
field_data = np.append([field_data], np.array([self.field_data[field] for field in fields]), axis=0)
- else:
+ else:
field_data = np.append([field_data], np.array([self.field_data[field][:-1] for field in fields]), axis=0)
-
+
for line in range(field_data.shape[1]):
field_data[:,line].tofile(fid, sep="\t", format=format)
fid.write("\n")
@@ -296,10 +296,10 @@
name = "%s-1d" % (self.bin_field)
else:
name = "%s-%s-1d" % (group_prefix, self.bin_field)
-
- if name in fid:
+
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
- del fid[name]
+ del fid[name]
group = fid.create_group(name)
group.attrs["x-axis-%s" % self.bin_field] = self.choose_bins(bin_style)
for field in fields:
@@ -421,7 +421,7 @@
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
@@ -492,9 +492,9 @@
name = "%s-%s-2d" % (self.y_bin_field, self.x_bin_field)
else:
name = "%s-%s-%s-2d" % (group_prefix, self.y_bin_field, self.x_bin_field)
- if name in fid:
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
- del fid[name]
+ del fid[name]
group = fid.create_group(name)
xbins, ybins = self.choose_bins(bin_style)
@@ -520,11 +520,11 @@
or a straight sum of a field in a bin defined by two other
fields. In the case of a weighted average, we have: p_i =
sum( w_i * v_i ) / sum(w_i)
-
+
We accept a *data_source*, which will be binned into
*(x,y,z)_n_bins* by the field *(x,y,z)_bin_field* between the
*(x,y,z)_lower_bound* and the *(x,y,z)_upper_bound*. These bins may or
- may not be equally divided in log-space as specified by *(x,y,z)_log*.
+ may not be equally divided in log-space as specified by *(x,y,z)_log*.
If *end_collect* is True, take all values outside the given bounds and
store them in the 0 and *n_bins*-1 values.
"""
@@ -641,7 +641,7 @@
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
@@ -688,14 +688,14 @@
attributes.
"""
fid = h5py.File(filename)
- fields = [field for field in sorted(self.field_data.keys())
+ fields = [field for field in sorted(self.field_data.keys())
if (field != "UsedBins" and field != self.x_bin_field and field != self.y_bin_field and field != self.z_bin_field)]
if group_prefix is None:
name = "%s-%s-%s-3d" % (self.z_bin_field, self.y_bin_field, self.x_bin_field)
else:
name = "%s-%s-%s-%s-3d" % (group_prefix,self.z_bin_field, self.y_bin_field, self.x_bin_field)
- if name in fid:
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
del fid[name]
group = fid.create_group(name)
@@ -704,7 +704,7 @@
group.attrs["x-axis-%s" % self.x_bin_field] = xbins
group.attrs["y-axis-%s" % self.y_bin_field] = ybins
group.attrs["z-axis-%s" % self.z_bin_field] = zbins
-
+
for field in fields:
dset = group.create_dataset("%s" % field, data=self.field_data[field][:-1,:-1,:-1])
fid.close()
@@ -826,7 +826,7 @@
filter &= (data > mi)
filter &= (data < ma)
return filter, [data[filter] for data in bin_fields]
-
+
def _get_data(self, chunk, fields):
# We are using chunks now, which will manage the field parameters and
# the like.
@@ -843,7 +843,7 @@
else:
weight_data = np.ones(chunk.ires.size, dtype="float64")
weight_data = weight_data[filter]
- # So that we can pass these into
+ # So that we can pass these into
return arr, weight_data, bin_fields
def __getitem__(self, field):
@@ -857,7 +857,7 @@
def items(self):
return [(k,self[k]) for k in self.field_data.keys()]
-
+
def __iter__(self):
return sorted(self.items())
@@ -1065,7 +1065,7 @@
r"""
Create a 1, 2, or 3D profile object.
- The dimensionality of the profile object is chosen by the number of
+ The dimensionality of the profile object is chosen by the number of
fields given in the bin_fields argument.
Parameters
@@ -1077,7 +1077,7 @@
fields : list of strings
The fields to be profiled.
n : int or list of ints
- The number of bins in each dimension. If None, 64 bins for
+ The number of bins in each dimension. If None, 64 bins for
each bin are used for each bin field.
Default: 64.
extrema : dict of min, max tuples
@@ -1091,24 +1091,24 @@
units : dict of strings
The units of the fields in the profiles, including the bin_fields.
weight_field : str
- The weight field for computing weighted average for the profile
- values. If None, the profile values are sums of the data in
+ The weight field for computing weighted average for the profile
+ values. If None, the profile values are sums of the data in
each bin.
accumulation : bool or list of bools
- If True, the profile values for a bin n are the cumulative sum of
- all the values from bin 0 to n. If -True, the sum is reversed so
- that the value for bin n is the cumulative sum from bin N (total bins)
- to n. If the profile is 2D or 3D, a list of values can be given to
+ If True, the profile values for a bin n are the cumulative sum of
+ all the values from bin 0 to n. If -True, the sum is reversed so
+ that the value for bin n is the cumulative sum from bin N (total bins)
+ to n. If the profile is 2D or 3D, a list of values can be given to
control the summation in each dimension independently.
Default: False.
- fractional : If True the profile values are divided by the sum of all
- the profile data such that the profile represents a probability
+ fractional : If True the profile values are divided by the sum of all
+ the profile data such that the profile represents a probability
distribution function.
Examples
--------
- Create a 1d profile. Access bin field from profile.x and field
+ Create a 1d profile. Access bin field from profile.x and field
data from profile.field_data.
>>> pf = load("DD0046/DD0046")
@@ -1118,7 +1118,7 @@
... fields=["temperature", "velocity_x"]))
>>> print profile.x
>>> print profile.field_data["temperature"]
-
+
"""
bin_fields = ensure_list(bin_fields)
fields = ensure_list(fields)
@@ -1139,7 +1139,7 @@
if not iterable(accumulation):
accumulation = [accumulation] * len(bin_fields)
if logs is None:
- logs = [data_source.pf._get_field_info(f[0],f[1]).take_log
+ logs = [data_source.pf._get_field_info(f[0],f[1]).take_log
for f in bin_fields]
else:
logs = [logs[bin_field[-1]] for bin_field in bin_fields]
@@ -1161,7 +1161,7 @@
ex.append(field_ex)
args = [data_source]
for f, n, (mi, ma), l in zip(bin_fields, n_bins, ex, logs):
- args += [f, n, mi, ma, l]
+ args += [f, n, mi, ma, l]
obj = cls(*args, weight_field = weight_field)
setattr(obj, "accumulation", accumulation)
setattr(obj, "fractional", fractional)
https://bitbucket.org/yt_analysis/yt/commits/3672effe259d/
Changeset: 3672effe259d
Branch: yt-3.0
User: ngoldbaum
Date: 2014-04-30 22:28:07
Summary: Adding a units kwarg for create_profile.
It looks like @jzuhone intended to add this, but never got around to implementing it.
Affected #: 1 file
diff -r af533895550d7e3533f3046db7ceb184f4c4a490 -r 3672effe259d41d494ba61864de19740688119c5 yt/data_objects/profiles.py
--- a/yt/data_objects/profiles.py
+++ b/yt/data_objects/profiles.py
@@ -1058,10 +1058,10 @@
self.z_bins.convert_to_units(new_unit)
self.z = 0.5*(self.z_bins[1:]+self.z_bins[:-1])
-def create_profile(data_source, bin_fields, fields, n_bins = 64,
- extrema = None, logs = None,
- weight_field = "cell_mass",
- accumulation = False, fractional = False):
+def create_profile(data_source, bin_fields, fields, n_bins=64,
+ extrema=None, logs=None, units=None,
+ weight_field="cell_mass",
+ accumulation=False, fractional=False):
r"""
Create a 1, 2, or 3D profile object.
@@ -1181,6 +1181,18 @@
temp = temp[::-1]
temp = np.rollaxis(temp, axis)
obj.field_data[field] = temp
-
+ if units is not None:
+ for field, unit in units.iteritems():
+ field = data_source._determine_fields(field)[0]
+ if field == obj.x_field:
+ obj.set_x_unit(unit)
+ elif hasattr(obj, 'y_field'):
+ if field == obj.y_field:
+ obj.set_y_unit(unit)
+ elif hasattr(obj, 'z_field'):
+ if field == obj.z_field:
+ obj.set_z_unit(unit)
+ else:
+ obj.set_field_unit(field, unit)
return obj
https://bitbucket.org/yt_analysis/yt/commits/3670aa466c5c/
Changeset: 3670aa466c5c
Branch: yt-3.0
User: ngoldbaum
Date: 2014-05-02 07:44:00
Summary: Fixing two minor units issues.
Affected #: 2 files
diff -r 893a689ff45f9d951b367be0f3b6a8ebb9a74b18 -r 3670aa466c5c206ddbb67f838afb7ba7e6a0d059 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -812,12 +812,12 @@
center = self.pf.arr(center, 'code_length')
if iterable(width):
w, u = width
- width = self.pf.arr(w, input_units = u)
+ width = self.pf.quan(w, input_units = u)
if height is None:
height = width
elif iterable(height):
h, u = height
- height = self.pf.arr(w, input_units = u)
+ height = self.pf.quan(w, input_units = u)
if not iterable(resolution):
resolution = (resolution, resolution)
from yt.visualization.fixed_resolution import FixedResolutionBuffer
diff -r 893a689ff45f9d951b367be0f3b6a8ebb9a74b18 -r 3670aa466c5c206ddbb67f838afb7ba7e6a0d059 yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -227,8 +227,8 @@
"""
image = func(image)
if color_bounds is None:
- mi = np.nanmin(image[~np.isinf(image)])
- ma = np.nanmax(image[~np.isinf(image)])
+ mi = np.nanmin(image[~np.isinf(image)])*image.uq
+ ma = np.nanmax(image[~np.isinf(image)])*image.uq
color_bounds = mi, ma
else:
color_bounds = [func(c) for c in color_bounds]
https://bitbucket.org/yt_analysis/yt/commits/5a48f7fb83a2/
Changeset: 5a48f7fb83a2
Branch: yt-3.0
User: ngoldbaum
Date: 2014-05-01 06:34:03
Summary: Merging.
Affected #: 3 files
diff -r f228e5bea67d968ec1ca2d2cc755883481b43dce -r 5a48f7fb83a2cf7300c88582bb949e8bf209e09a yt/data_objects/profiles.py
--- a/yt/data_objects/profiles.py
+++ b/yt/data_objects/profiles.py
@@ -157,7 +157,7 @@
"""
def __init__(self, data_source, n_bins, bin_field,
lower_bound, upper_bound,
- log_space = True,
+ log_space = True,
end_collect=False):
BinnedProfile.__init__(self, data_source)
self.bin_field = bin_field
@@ -212,7 +212,7 @@
# summing up all of the histograms and dividing by the
# weights. Accumulation likely doesn't work with weighted
# average fields.
- if accumulation:
+ if accumulation:
binned_field = np.add.accumulate(binned_field)
return binned_field, weight_field, q_field, \
used_field.astype("bool")
@@ -237,12 +237,12 @@
bin_indices = np.clip(bin_indices, 0, self.n_bins - 1)
else: #throw away outside values
bin_indices -= 1
-
+
return (mi, bin_indices)
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
x = self.field_data[self.bin_field]
@@ -259,7 +259,7 @@
return x
def write_out(self, filename, format="%0.16e", bin_style='left'):
- '''
+ '''
Write out data in ascii file, using *format* and
*bin_style* (left, right, center, both).
'''
@@ -268,12 +268,12 @@
fields.remove(self.bin_field)
fid.write("\t".join(["#"] + [self.bin_field] + fields + ["\n"]))
- field_data = np.array(self.choose_bins(bin_style))
+ field_data = np.array(self.choose_bins(bin_style))
if bin_style is 'both':
field_data = np.append([field_data], np.array([self.field_data[field] for field in fields]), axis=0)
- else:
+ else:
field_data = np.append([field_data], np.array([self.field_data[field][:-1] for field in fields]), axis=0)
-
+
for line in range(field_data.shape[1]):
field_data[:,line].tofile(fid, sep="\t", format=format)
fid.write("\n")
@@ -296,10 +296,10 @@
name = "%s-1d" % (self.bin_field)
else:
name = "%s-%s-1d" % (group_prefix, self.bin_field)
-
- if name in fid:
+
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
- del fid[name]
+ del fid[name]
group = fid.create_group(name)
group.attrs["x-axis-%s" % self.bin_field] = self.choose_bins(bin_style)
for field in fields:
@@ -421,7 +421,7 @@
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
@@ -492,9 +492,9 @@
name = "%s-%s-2d" % (self.y_bin_field, self.x_bin_field)
else:
name = "%s-%s-%s-2d" % (group_prefix, self.y_bin_field, self.x_bin_field)
- if name in fid:
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
- del fid[name]
+ del fid[name]
group = fid.create_group(name)
xbins, ybins = self.choose_bins(bin_style)
@@ -520,11 +520,11 @@
or a straight sum of a field in a bin defined by two other
fields. In the case of a weighted average, we have: p_i =
sum( w_i * v_i ) / sum(w_i)
-
+
We accept a *data_source*, which will be binned into
*(x,y,z)_n_bins* by the field *(x,y,z)_bin_field* between the
*(x,y,z)_lower_bound* and the *(x,y,z)_upper_bound*. These bins may or
- may not be equally divided in log-space as specified by *(x,y,z)_log*.
+ may not be equally divided in log-space as specified by *(x,y,z)_log*.
If *end_collect* is True, take all values outside the given bounds and
store them in the 0 and *n_bins*-1 values.
"""
@@ -641,7 +641,7 @@
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
@@ -688,14 +688,14 @@
attributes.
"""
fid = h5py.File(filename)
- fields = [field for field in sorted(self.field_data.keys())
+ fields = [field for field in sorted(self.field_data.keys())
if (field != "UsedBins" and field != self.x_bin_field and field != self.y_bin_field and field != self.z_bin_field)]
if group_prefix is None:
name = "%s-%s-%s-3d" % (self.z_bin_field, self.y_bin_field, self.x_bin_field)
else:
name = "%s-%s-%s-%s-3d" % (group_prefix,self.z_bin_field, self.y_bin_field, self.x_bin_field)
- if name in fid:
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
del fid[name]
group = fid.create_group(name)
@@ -704,7 +704,7 @@
group.attrs["x-axis-%s" % self.x_bin_field] = xbins
group.attrs["y-axis-%s" % self.y_bin_field] = ybins
group.attrs["z-axis-%s" % self.z_bin_field] = zbins
-
+
for field in fields:
dset = group.create_dataset("%s" % field, data=self.field_data[field][:-1,:-1,:-1])
fid.close()
@@ -826,7 +826,7 @@
filter &= (data > mi)
filter &= (data < ma)
return filter, [data[filter] for data in bin_fields]
-
+
def _get_data(self, chunk, fields):
# We are using chunks now, which will manage the field parameters and
# the like.
@@ -843,7 +843,7 @@
else:
weight_data = np.ones(chunk.ires.size, dtype="float64")
weight_data = weight_data[filter]
- # So that we can pass these into
+ # So that we can pass these into
return arr, weight_data, bin_fields
def __getitem__(self, field):
@@ -857,7 +857,7 @@
def items(self):
return [(k,self[k]) for k in self.field_data.keys()]
-
+
def __iter__(self):
return sorted(self.items())
@@ -1058,14 +1058,14 @@
self.z_bins.convert_to_units(new_unit)
self.z = 0.5*(self.z_bins[1:]+self.z_bins[:-1])
-def create_profile(data_source, bin_fields, fields, n_bins = 64,
- extrema = None, logs = None,
- weight_field = "cell_mass",
- accumulation = False, fractional = False):
+def create_profile(data_source, bin_fields, fields, n_bins=64,
+ extrema=None, logs=None, units=None,
+ weight_field="cell_mass",
+ accumulation=False, fractional=False):
r"""
Create a 1, 2, or 3D profile object.
- The dimensionality of the profile object is chosen by the number of
+ The dimensionality of the profile object is chosen by the number of
fields given in the bin_fields argument.
Parameters
@@ -1077,7 +1077,7 @@
fields : list of strings
The fields to be profiled.
n : int or list of ints
- The number of bins in each dimension. If None, 64 bins for
+ The number of bins in each dimension. If None, 64 bins for
each bin are used for each bin field.
Default: 64.
extrema : dict of min, max tuples
@@ -1091,24 +1091,24 @@
units : dict of strings
The units of the fields in the profiles, including the bin_fields.
weight_field : str
- The weight field for computing weighted average for the profile
- values. If None, the profile values are sums of the data in
+ The weight field for computing weighted average for the profile
+ values. If None, the profile values are sums of the data in
each bin.
accumulation : bool or list of bools
- If True, the profile values for a bin n are the cumulative sum of
- all the values from bin 0 to n. If -True, the sum is reversed so
- that the value for bin n is the cumulative sum from bin N (total bins)
- to n. If the profile is 2D or 3D, a list of values can be given to
+ If True, the profile values for a bin n are the cumulative sum of
+ all the values from bin 0 to n. If -True, the sum is reversed so
+ that the value for bin n is the cumulative sum from bin N (total bins)
+ to n. If the profile is 2D or 3D, a list of values can be given to
control the summation in each dimension independently.
Default: False.
- fractional : If True the profile values are divided by the sum of all
- the profile data such that the profile represents a probability
+ fractional : If True the profile values are divided by the sum of all
+ the profile data such that the profile represents a probability
distribution function.
Examples
--------
- Create a 1d profile. Access bin field from profile.x and field
+ Create a 1d profile. Access bin field from profile.x and field
data from profile.field_data.
>>> pf = load("DD0046/DD0046")
@@ -1118,7 +1118,7 @@
... fields=["temperature", "velocity_x"]))
>>> print profile.x
>>> print profile.field_data["temperature"]
-
+
"""
bin_fields = ensure_list(bin_fields)
fields = ensure_list(fields)
@@ -1139,7 +1139,7 @@
if not iterable(accumulation):
accumulation = [accumulation] * len(bin_fields)
if logs is None:
- logs = [data_source.pf._get_field_info(f[0],f[1]).take_log
+ logs = [data_source.pf._get_field_info(f[0],f[1]).take_log
for f in bin_fields]
else:
logs = [logs[bin_field[-1]] for bin_field in bin_fields]
@@ -1161,7 +1161,7 @@
ex.append(field_ex)
args = [data_source]
for f, n, (mi, ma), l in zip(bin_fields, n_bins, ex, logs):
- args += [f, n, mi, ma, l]
+ args += [f, n, mi, ma, l]
obj = cls(*args, weight_field = weight_field)
setattr(obj, "accumulation", accumulation)
setattr(obj, "fractional", fractional)
@@ -1181,6 +1181,18 @@
temp = temp[::-1]
temp = np.rollaxis(temp, axis)
obj.field_data[field] = temp
-
+ if units is not None:
+ for field, unit in units.iteritems():
+ field = data_source._determine_fields(field)[0]
+ if field == obj.x_field:
+ obj.set_x_unit(unit)
+ elif hasattr(obj, 'y_field'):
+ if field == obj.y_field:
+ obj.set_y_unit(unit)
+ elif hasattr(obj, 'z_field'):
+ if field == obj.z_field:
+ obj.set_z_unit(unit)
+ else:
+ obj.set_field_unit(field, unit)
return obj
diff -r f228e5bea67d968ec1ca2d2cc755883481b43dce -r 5a48f7fb83a2cf7300c88582bb949e8bf209e09a yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -1,5 +1,5 @@
"""
-These are common particle deposition fields.
+These are common particle fields.
@@ -84,7 +84,8 @@
def particle_mass(field, data):
pos = data[ptype, coord_name]
- d = data.deposit(pos, [data[ptype, mass_name]], method = "sum")
+ pmass = data[ptype, mass_name].in_units(field.units)
+ d = data.deposit(pos, [pmass], method = "sum")
return data.apply_units(d, field.units)
registry.add_field(("deposit", "%s_mass" % ptype),
diff -r f228e5bea67d968ec1ca2d2cc755883481b43dce -r 5a48f7fb83a2cf7300c88582bb949e8bf209e09a yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -884,6 +884,10 @@
units = data.pf._get_field_info(field[0],field[1]).units
else:
units = data.pf._get_field_info(field).units
+ if isinstance(x, YTArray):
+ arr = copy.deepcopy(x)
+ arr.units.registry = data.pf.unit_registry
+ return arr.in_units(units)
if isinstance(x, np.ndarray):
return data.pf.arr(x, units)
else:
https://bitbucket.org/yt_analysis/yt/commits/a635e8280384/
Changeset: a635e8280384
Branch: yt-3.0
User: ngoldbaum
Date: 2014-05-02 07:47:49
Summary: Merging.
Affected #: 3 files
diff -r 3670aa466c5c206ddbb67f838afb7ba7e6a0d059 -r a635e82803845c7c1e038f91d16c844584d87940 yt/data_objects/profiles.py
--- a/yt/data_objects/profiles.py
+++ b/yt/data_objects/profiles.py
@@ -157,7 +157,7 @@
"""
def __init__(self, data_source, n_bins, bin_field,
lower_bound, upper_bound,
- log_space = True,
+ log_space = True,
end_collect=False):
BinnedProfile.__init__(self, data_source)
self.bin_field = bin_field
@@ -212,7 +212,7 @@
# summing up all of the histograms and dividing by the
# weights. Accumulation likely doesn't work with weighted
# average fields.
- if accumulation:
+ if accumulation:
binned_field = np.add.accumulate(binned_field)
return binned_field, weight_field, q_field, \
used_field.astype("bool")
@@ -237,12 +237,12 @@
bin_indices = np.clip(bin_indices, 0, self.n_bins - 1)
else: #throw away outside values
bin_indices -= 1
-
+
return (mi, bin_indices)
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
x = self.field_data[self.bin_field]
@@ -259,7 +259,7 @@
return x
def write_out(self, filename, format="%0.16e", bin_style='left'):
- '''
+ '''
Write out data in ascii file, using *format* and
*bin_style* (left, right, center, both).
'''
@@ -268,12 +268,12 @@
fields.remove(self.bin_field)
fid.write("\t".join(["#"] + [self.bin_field] + fields + ["\n"]))
- field_data = np.array(self.choose_bins(bin_style))
+ field_data = np.array(self.choose_bins(bin_style))
if bin_style is 'both':
field_data = np.append([field_data], np.array([self.field_data[field] for field in fields]), axis=0)
- else:
+ else:
field_data = np.append([field_data], np.array([self.field_data[field][:-1] for field in fields]), axis=0)
-
+
for line in range(field_data.shape[1]):
field_data[:,line].tofile(fid, sep="\t", format=format)
fid.write("\n")
@@ -296,10 +296,10 @@
name = "%s-1d" % (self.bin_field)
else:
name = "%s-%s-1d" % (group_prefix, self.bin_field)
-
- if name in fid:
+
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
- del fid[name]
+ del fid[name]
group = fid.create_group(name)
group.attrs["x-axis-%s" % self.bin_field] = self.choose_bins(bin_style)
for field in fields:
@@ -421,7 +421,7 @@
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
@@ -492,9 +492,9 @@
name = "%s-%s-2d" % (self.y_bin_field, self.x_bin_field)
else:
name = "%s-%s-%s-2d" % (group_prefix, self.y_bin_field, self.x_bin_field)
- if name in fid:
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
- del fid[name]
+ del fid[name]
group = fid.create_group(name)
xbins, ybins = self.choose_bins(bin_style)
@@ -520,11 +520,11 @@
or a straight sum of a field in a bin defined by two other
fields. In the case of a weighted average, we have: p_i =
sum( w_i * v_i ) / sum(w_i)
-
+
We accept a *data_source*, which will be binned into
*(x,y,z)_n_bins* by the field *(x,y,z)_bin_field* between the
*(x,y,z)_lower_bound* and the *(x,y,z)_upper_bound*. These bins may or
- may not be equally divided in log-space as specified by *(x,y,z)_log*.
+ may not be equally divided in log-space as specified by *(x,y,z)_log*.
If *end_collect* is True, take all values outside the given bounds and
store them in the 0 and *n_bins*-1 values.
"""
@@ -641,7 +641,7 @@
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
@@ -688,14 +688,14 @@
attributes.
"""
fid = h5py.File(filename)
- fields = [field for field in sorted(self.field_data.keys())
+ fields = [field for field in sorted(self.field_data.keys())
if (field != "UsedBins" and field != self.x_bin_field and field != self.y_bin_field and field != self.z_bin_field)]
if group_prefix is None:
name = "%s-%s-%s-3d" % (self.z_bin_field, self.y_bin_field, self.x_bin_field)
else:
name = "%s-%s-%s-%s-3d" % (group_prefix,self.z_bin_field, self.y_bin_field, self.x_bin_field)
- if name in fid:
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
del fid[name]
group = fid.create_group(name)
@@ -704,7 +704,7 @@
group.attrs["x-axis-%s" % self.x_bin_field] = xbins
group.attrs["y-axis-%s" % self.y_bin_field] = ybins
group.attrs["z-axis-%s" % self.z_bin_field] = zbins
-
+
for field in fields:
dset = group.create_dataset("%s" % field, data=self.field_data[field][:-1,:-1,:-1])
fid.close()
@@ -826,7 +826,7 @@
filter &= (data > mi)
filter &= (data < ma)
return filter, [data[filter] for data in bin_fields]
-
+
def _get_data(self, chunk, fields):
# We are using chunks now, which will manage the field parameters and
# the like.
@@ -843,7 +843,7 @@
else:
weight_data = np.ones(chunk.ires.size, dtype="float64")
weight_data = weight_data[filter]
- # So that we can pass these into
+ # So that we can pass these into
return arr, weight_data, bin_fields
def __getitem__(self, field):
@@ -857,7 +857,7 @@
def items(self):
return [(k,self[k]) for k in self.field_data.keys()]
-
+
def __iter__(self):
return sorted(self.items())
@@ -1058,14 +1058,14 @@
self.z_bins.convert_to_units(new_unit)
self.z = 0.5*(self.z_bins[1:]+self.z_bins[:-1])
-def create_profile(data_source, bin_fields, fields, n_bins = 64,
- extrema = None, logs = None,
- weight_field = "cell_mass",
- accumulation = False, fractional = False):
+def create_profile(data_source, bin_fields, fields, n_bins=64,
+ extrema=None, logs=None, units=None,
+ weight_field="cell_mass",
+ accumulation=False, fractional=False):
r"""
Create a 1, 2, or 3D profile object.
- The dimensionality of the profile object is chosen by the number of
+ The dimensionality of the profile object is chosen by the number of
fields given in the bin_fields argument.
Parameters
@@ -1077,7 +1077,7 @@
fields : list of strings
The fields to be profiled.
n : int or list of ints
- The number of bins in each dimension. If None, 64 bins for
+ The number of bins in each dimension. If None, 64 bins for
each bin are used for each bin field.
Default: 64.
extrema : dict of min, max tuples
@@ -1091,24 +1091,24 @@
units : dict of strings
The units of the fields in the profiles, including the bin_fields.
weight_field : str
- The weight field for computing weighted average for the profile
- values. If None, the profile values are sums of the data in
+ The weight field for computing weighted average for the profile
+ values. If None, the profile values are sums of the data in
each bin.
accumulation : bool or list of bools
- If True, the profile values for a bin n are the cumulative sum of
- all the values from bin 0 to n. If -True, the sum is reversed so
- that the value for bin n is the cumulative sum from bin N (total bins)
- to n. If the profile is 2D or 3D, a list of values can be given to
+ If True, the profile values for a bin n are the cumulative sum of
+ all the values from bin 0 to n. If -True, the sum is reversed so
+ that the value for bin n is the cumulative sum from bin N (total bins)
+ to n. If the profile is 2D or 3D, a list of values can be given to
control the summation in each dimension independently.
Default: False.
- fractional : If True the profile values are divided by the sum of all
- the profile data such that the profile represents a probability
+ fractional : If True the profile values are divided by the sum of all
+ the profile data such that the profile represents a probability
distribution function.
Examples
--------
- Create a 1d profile. Access bin field from profile.x and field
+ Create a 1d profile. Access bin field from profile.x and field
data from profile.field_data.
>>> pf = load("DD0046/DD0046")
@@ -1118,7 +1118,7 @@
... fields=["temperature", "velocity_x"]))
>>> print profile.x
>>> print profile.field_data["temperature"]
-
+
"""
bin_fields = ensure_list(bin_fields)
fields = ensure_list(fields)
@@ -1139,7 +1139,7 @@
if not iterable(accumulation):
accumulation = [accumulation] * len(bin_fields)
if logs is None:
- logs = [data_source.pf._get_field_info(f[0],f[1]).take_log
+ logs = [data_source.pf._get_field_info(f[0],f[1]).take_log
for f in bin_fields]
else:
logs = [logs[bin_field[-1]] for bin_field in bin_fields]
@@ -1161,7 +1161,7 @@
ex.append(field_ex)
args = [data_source]
for f, n, (mi, ma), l in zip(bin_fields, n_bins, ex, logs):
- args += [f, n, mi, ma, l]
+ args += [f, n, mi, ma, l]
obj = cls(*args, weight_field = weight_field)
setattr(obj, "accumulation", accumulation)
setattr(obj, "fractional", fractional)
@@ -1181,6 +1181,18 @@
temp = temp[::-1]
temp = np.rollaxis(temp, axis)
obj.field_data[field] = temp
-
+ if units is not None:
+ for field, unit in units.iteritems():
+ field = data_source._determine_fields(field)[0]
+ if field == obj.x_field:
+ obj.set_x_unit(unit)
+ elif hasattr(obj, 'y_field'):
+ if field == obj.y_field:
+ obj.set_y_unit(unit)
+ elif hasattr(obj, 'z_field'):
+ if field == obj.z_field:
+ obj.set_z_unit(unit)
+ else:
+ obj.set_field_unit(field, unit)
return obj
diff -r 3670aa466c5c206ddbb67f838afb7ba7e6a0d059 -r a635e82803845c7c1e038f91d16c844584d87940 yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -1,5 +1,5 @@
"""
-These are common particle deposition fields.
+These are common particle fields.
@@ -84,7 +84,8 @@
def particle_mass(field, data):
pos = data[ptype, coord_name]
- d = data.deposit(pos, [data[ptype, mass_name]], method = "sum")
+ pmass = data[ptype, mass_name].in_units(field.units)
+ d = data.deposit(pos, [pmass], method = "sum")
return data.apply_units(d, field.units)
registry.add_field(("deposit", "%s_mass" % ptype),
diff -r 3670aa466c5c206ddbb67f838afb7ba7e6a0d059 -r a635e82803845c7c1e038f91d16c844584d87940 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -884,6 +884,10 @@
units = data.pf._get_field_info(field[0],field[1]).units
else:
units = data.pf._get_field_info(field).units
+ if isinstance(x, YTArray):
+ arr = copy.deepcopy(x)
+ arr.units.registry = data.pf.unit_registry
+ return arr.in_units(units)
if isinstance(x, np.ndarray):
return data.pf.arr(x, units)
else:
https://bitbucket.org/yt_analysis/yt/commits/452b5eebeccb/
Changeset: 452b5eebeccb
Branch: yt-3.0
User: ngoldbaum
Date: 2014-05-02 20:54:40
Summary: Ensure the image and color bounds have appropriate units when applying a colormap.
Affected #: 1 file
diff -r a635e82803845c7c1e038f91d16c844584d87940 -r 452b5eebeccb8a54fac1458fe4d2a045a8d2ca65 yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -225,13 +225,14 @@
to_plot : uint8 image with colorbar applied.
"""
- image = func(image)
+ from yt.data_objects.image_array import ImageArray
+ image = ImageArray(func(image))
if color_bounds is None:
mi = np.nanmin(image[~np.isinf(image)])*image.uq
ma = np.nanmax(image[~np.isinf(image)])*image.uq
color_bounds = mi, ma
else:
- color_bounds = [func(c) for c in color_bounds]
+ color_bounds = [YTQuantity(func(c), image.units) for c in color_bounds]
image = (image - color_bounds[0])/(color_bounds[1] - color_bounds[0])
to_plot = map_to_colors(image, cmap_name)
to_plot = np.clip(to_plot, 0, 255)
https://bitbucket.org/yt_analysis/yt/commits/9510515c34fe/
Changeset: 9510515c34fe
Branch: yt-3.0
User: ngoldbaum
Date: 2014-05-02 21:05:24
Summary: Responding to PR comments regarding profiles.
Affected #: 2 files
diff -r 452b5eebeccb8a54fac1458fe4d2a045a8d2ca65 -r 9510515c34fe1c06bc71b7fc0be44823c7d9e03f yt/data_objects/profiles.py
--- a/yt/data_objects/profiles.py
+++ b/yt/data_objects/profiles.py
@@ -1186,12 +1186,10 @@
field = data_source._determine_fields(field)[0]
if field == obj.x_field:
obj.set_x_unit(unit)
- elif hasattr(obj, 'y_field'):
- if field == obj.y_field:
- obj.set_y_unit(unit)
- elif hasattr(obj, 'z_field'):
- if field == obj.z_field:
- obj.set_z_unit(unit)
+ elif field == getattr(obj, "y_field", None):
+ obj.set_y_unit(unit)
+ elif field == getattr(obj, "z_field", None):
+ obj.set_z_unit(unit)
else:
obj.set_field_unit(field, unit)
return obj
diff -r 452b5eebeccb8a54fac1458fe4d2a045a8d2ca65 -r 9510515c34fe1c06bc71b7fc0be44823c7d9e03f yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -886,8 +886,8 @@
units = data.pf._get_field_info(field).units
if isinstance(x, YTArray):
arr = copy.deepcopy(x)
- arr.units.registry = data.pf.unit_registry
- return arr.in_units(units)
+ arr.convert_to_units(units)
+ return arr
if isinstance(x, np.ndarray):
return data.pf.arr(x, units)
else:
https://bitbucket.org/yt_analysis/yt/commits/c05e890f4867/
Changeset: c05e890f4867
Branch: yt-3.0
User: samskillman
Date: 2014-05-03 20:01:01
Summary: Merged in ngoldbaum/yt/yt-3.0 (pull request #860)
Fixes for profiles
Affected #: 5 files
diff -r 9a0500caa575676cb27e0d88550d473937388b70 -r c05e890f48672898e8afd3f6a4c9d81a8a28b892 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -812,12 +812,12 @@
center = self.pf.arr(center, 'code_length')
if iterable(width):
w, u = width
- width = self.pf.arr(w, input_units = u)
+ width = self.pf.quan(w, input_units = u)
if height is None:
height = width
elif iterable(height):
h, u = height
- height = self.pf.arr(w, input_units = u)
+ height = self.pf.quan(w, input_units = u)
if not iterable(resolution):
resolution = (resolution, resolution)
from yt.visualization.fixed_resolution import FixedResolutionBuffer
diff -r 9a0500caa575676cb27e0d88550d473937388b70 -r c05e890f48672898e8afd3f6a4c9d81a8a28b892 yt/data_objects/profiles.py
--- a/yt/data_objects/profiles.py
+++ b/yt/data_objects/profiles.py
@@ -157,7 +157,7 @@
"""
def __init__(self, data_source, n_bins, bin_field,
lower_bound, upper_bound,
- log_space = True,
+ log_space = True,
end_collect=False):
BinnedProfile.__init__(self, data_source)
self.bin_field = bin_field
@@ -212,7 +212,7 @@
# summing up all of the histograms and dividing by the
# weights. Accumulation likely doesn't work with weighted
# average fields.
- if accumulation:
+ if accumulation:
binned_field = np.add.accumulate(binned_field)
return binned_field, weight_field, q_field, \
used_field.astype("bool")
@@ -237,12 +237,12 @@
bin_indices = np.clip(bin_indices, 0, self.n_bins - 1)
else: #throw away outside values
bin_indices -= 1
-
+
return (mi, bin_indices)
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
x = self.field_data[self.bin_field]
@@ -259,7 +259,7 @@
return x
def write_out(self, filename, format="%0.16e", bin_style='left'):
- '''
+ '''
Write out data in ascii file, using *format* and
*bin_style* (left, right, center, both).
'''
@@ -268,12 +268,12 @@
fields.remove(self.bin_field)
fid.write("\t".join(["#"] + [self.bin_field] + fields + ["\n"]))
- field_data = np.array(self.choose_bins(bin_style))
+ field_data = np.array(self.choose_bins(bin_style))
if bin_style is 'both':
field_data = np.append([field_data], np.array([self.field_data[field] for field in fields]), axis=0)
- else:
+ else:
field_data = np.append([field_data], np.array([self.field_data[field][:-1] for field in fields]), axis=0)
-
+
for line in range(field_data.shape[1]):
field_data[:,line].tofile(fid, sep="\t", format=format)
fid.write("\n")
@@ -296,10 +296,10 @@
name = "%s-1d" % (self.bin_field)
else:
name = "%s-%s-1d" % (group_prefix, self.bin_field)
-
- if name in fid:
+
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
- del fid[name]
+ del fid[name]
group = fid.create_group(name)
group.attrs["x-axis-%s" % self.bin_field] = self.choose_bins(bin_style)
for field in fields:
@@ -421,7 +421,7 @@
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
@@ -492,9 +492,9 @@
name = "%s-%s-2d" % (self.y_bin_field, self.x_bin_field)
else:
name = "%s-%s-%s-2d" % (group_prefix, self.y_bin_field, self.x_bin_field)
- if name in fid:
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
- del fid[name]
+ del fid[name]
group = fid.create_group(name)
xbins, ybins = self.choose_bins(bin_style)
@@ -520,11 +520,11 @@
or a straight sum of a field in a bin defined by two other
fields. In the case of a weighted average, we have: p_i =
sum( w_i * v_i ) / sum(w_i)
-
+
We accept a *data_source*, which will be binned into
*(x,y,z)_n_bins* by the field *(x,y,z)_bin_field* between the
*(x,y,z)_lower_bound* and the *(x,y,z)_upper_bound*. These bins may or
- may not be equally divided in log-space as specified by *(x,y,z)_log*.
+ may not be equally divided in log-space as specified by *(x,y,z)_log*.
If *end_collect* is True, take all values outside the given bounds and
store them in the 0 and *n_bins*-1 values.
"""
@@ -641,7 +641,7 @@
def choose_bins(self, bin_style):
# Depending on the bin_style, choose from bin edges 0...N either:
- # both: 0...N, left: 0...N-1, right: 1...N
+ # both: 0...N, left: 0...N-1, right: 1...N
# center: N bins that are the average (both in linear or log
# space) of each pair of left/right edges
@@ -688,14 +688,14 @@
attributes.
"""
fid = h5py.File(filename)
- fields = [field for field in sorted(self.field_data.keys())
+ fields = [field for field in sorted(self.field_data.keys())
if (field != "UsedBins" and field != self.x_bin_field and field != self.y_bin_field and field != self.z_bin_field)]
if group_prefix is None:
name = "%s-%s-%s-3d" % (self.z_bin_field, self.y_bin_field, self.x_bin_field)
else:
name = "%s-%s-%s-%s-3d" % (group_prefix,self.z_bin_field, self.y_bin_field, self.x_bin_field)
- if name in fid:
+ if name in fid:
mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack")
del fid[name]
group = fid.create_group(name)
@@ -704,7 +704,7 @@
group.attrs["x-axis-%s" % self.x_bin_field] = xbins
group.attrs["y-axis-%s" % self.y_bin_field] = ybins
group.attrs["z-axis-%s" % self.z_bin_field] = zbins
-
+
for field in fields:
dset = group.create_dataset("%s" % field, data=self.field_data[field][:-1,:-1,:-1])
fid.close()
@@ -826,7 +826,7 @@
filter &= (data > mi)
filter &= (data < ma)
return filter, [data[filter] for data in bin_fields]
-
+
def _get_data(self, chunk, fields):
# We are using chunks now, which will manage the field parameters and
# the like.
@@ -843,7 +843,7 @@
else:
weight_data = np.ones(chunk.ires.size, dtype="float64")
weight_data = weight_data[filter]
- # So that we can pass these into
+ # So that we can pass these into
return arr, weight_data, bin_fields
def __getitem__(self, field):
@@ -857,7 +857,7 @@
def items(self):
return [(k,self[k]) for k in self.field_data.keys()]
-
+
def __iter__(self):
return sorted(self.items())
@@ -1058,14 +1058,14 @@
self.z_bins.convert_to_units(new_unit)
self.z = 0.5*(self.z_bins[1:]+self.z_bins[:-1])
-def create_profile(data_source, bin_fields, fields, n_bins = 64,
- extrema = None, logs = None,
- weight_field = "cell_mass",
- accumulation = False, fractional = False):
+def create_profile(data_source, bin_fields, fields, n_bins=64,
+ extrema=None, logs=None, units=None,
+ weight_field="cell_mass",
+ accumulation=False, fractional=False):
r"""
Create a 1, 2, or 3D profile object.
- The dimensionality of the profile object is chosen by the number of
+ The dimensionality of the profile object is chosen by the number of
fields given in the bin_fields argument.
Parameters
@@ -1077,7 +1077,7 @@
fields : list of strings
The fields to be profiled.
n : int or list of ints
- The number of bins in each dimension. If None, 64 bins for
+ The number of bins in each dimension. If None, 64 bins for
each bin are used for each bin field.
Default: 64.
extrema : dict of min, max tuples
@@ -1091,24 +1091,24 @@
units : dict of strings
The units of the fields in the profiles, including the bin_fields.
weight_field : str
- The weight field for computing weighted average for the profile
- values. If None, the profile values are sums of the data in
+ The weight field for computing weighted average for the profile
+ values. If None, the profile values are sums of the data in
each bin.
accumulation : bool or list of bools
- If True, the profile values for a bin n are the cumulative sum of
- all the values from bin 0 to n. If -True, the sum is reversed so
- that the value for bin n is the cumulative sum from bin N (total bins)
- to n. If the profile is 2D or 3D, a list of values can be given to
+ If True, the profile values for a bin n are the cumulative sum of
+ all the values from bin 0 to n. If -True, the sum is reversed so
+ that the value for bin n is the cumulative sum from bin N (total bins)
+ to n. If the profile is 2D or 3D, a list of values can be given to
control the summation in each dimension independently.
Default: False.
- fractional : If True the profile values are divided by the sum of all
- the profile data such that the profile represents a probability
+ fractional : If True the profile values are divided by the sum of all
+ the profile data such that the profile represents a probability
distribution function.
Examples
--------
- Create a 1d profile. Access bin field from profile.x and field
+ Create a 1d profile. Access bin field from profile.x and field
data from profile.field_data.
>>> pf = load("DD0046/DD0046")
@@ -1118,7 +1118,7 @@
... fields=["temperature", "velocity_x"]))
>>> print profile.x
>>> print profile.field_data["temperature"]
-
+
"""
bin_fields = ensure_list(bin_fields)
fields = ensure_list(fields)
@@ -1139,7 +1139,7 @@
if not iterable(accumulation):
accumulation = [accumulation] * len(bin_fields)
if logs is None:
- logs = [data_source.pf._get_field_info(f[0],f[1]).take_log
+ logs = [data_source.pf._get_field_info(f[0],f[1]).take_log
for f in bin_fields]
else:
logs = [logs[bin_field[-1]] for bin_field in bin_fields]
@@ -1161,7 +1161,7 @@
ex.append(field_ex)
args = [data_source]
for f, n, (mi, ma), l in zip(bin_fields, n_bins, ex, logs):
- args += [f, n, mi, ma, l]
+ args += [f, n, mi, ma, l]
obj = cls(*args, weight_field = weight_field)
setattr(obj, "accumulation", accumulation)
setattr(obj, "fractional", fractional)
@@ -1181,6 +1181,16 @@
temp = temp[::-1]
temp = np.rollaxis(temp, axis)
obj.field_data[field] = temp
-
+ if units is not None:
+ for field, unit in units.iteritems():
+ field = data_source._determine_fields(field)[0]
+ if field == obj.x_field:
+ obj.set_x_unit(unit)
+ elif field == getattr(obj, "y_field", None):
+ obj.set_y_unit(unit)
+ elif field == getattr(obj, "z_field", None):
+ obj.set_z_unit(unit)
+ else:
+ obj.set_field_unit(field, unit)
return obj
diff -r 9a0500caa575676cb27e0d88550d473937388b70 -r c05e890f48672898e8afd3f6a4c9d81a8a28b892 yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -1,5 +1,5 @@
"""
-These are common particle deposition fields.
+These are common particle fields.
@@ -84,7 +84,8 @@
def particle_mass(field, data):
pos = data[ptype, coord_name]
- d = data.deposit(pos, [data[ptype, mass_name]], method = "sum")
+ pmass = data[ptype, mass_name].in_units(field.units)
+ d = data.deposit(pos, [pmass], method = "sum")
return data.apply_units(d, field.units)
registry.add_field(("deposit", "%s_mass" % ptype),
diff -r 9a0500caa575676cb27e0d88550d473937388b70 -r c05e890f48672898e8afd3f6a4c9d81a8a28b892 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -884,6 +884,10 @@
units = data.pf._get_field_info(field[0],field[1]).units
else:
units = data.pf._get_field_info(field).units
+ if isinstance(x, YTArray):
+ arr = copy.deepcopy(x)
+ arr.convert_to_units(units)
+ return arr
if isinstance(x, np.ndarray):
return data.pf.arr(x, units)
else:
diff -r 9a0500caa575676cb27e0d88550d473937388b70 -r c05e890f48672898e8afd3f6a4c9d81a8a28b892 yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -225,13 +225,14 @@
to_plot : uint8 image with colorbar applied.
"""
- image = func(image)
+ from yt.data_objects.image_array import ImageArray
+ image = ImageArray(func(image))
if color_bounds is None:
- mi = np.nanmin(image[~np.isinf(image)])
- ma = np.nanmax(image[~np.isinf(image)])
+ mi = np.nanmin(image[~np.isinf(image)])*image.uq
+ ma = np.nanmax(image[~np.isinf(image)])*image.uq
color_bounds = mi, ma
else:
- color_bounds = [func(c) for c in color_bounds]
+ color_bounds = [YTQuantity(func(c), image.units) for c in color_bounds]
image = (image - color_bounds[0])/(color_bounds[1] - color_bounds[0])
to_plot = map_to_colors(image, cmap_name)
to_plot = np.clip(to_plot, 0, 255)
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