[yt-svn] commit/yt: 6 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Feb 17 09:04:42 PST 2016
6 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/a0e522c4887f/
Changeset: a0e522c4887f
Branch: yt
User: yihaochen
Date: 2016-02-09 22:15:20+00:00
Summary: Allow add_deposited_particle_field to take a user-specified weighting field .
Affected #: 1 file
diff -r d47150dfbde64f0262903d954fc90f87ce95ca39 -r a0e522c4887faebaec31b278ee54243fac2bc428 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -988,7 +988,8 @@
deps, _ = self.field_info.check_derived_fields([name])
self.field_dependencies.update(deps)
- def add_deposited_particle_field(self, deposit_field, method, kernel_name='cubic'):
+ def add_deposited_particle_field(self, deposit_field, method,
+ weight_field='particle_mass', kernel_name='cubic'):
"""Add a new deposited particle field
Creates a new deposited field based on the particle *deposit_field*.
@@ -1005,6 +1006,8 @@
`particle_deposit` namespace as `methodname_deposit`. Current
methods include `count`, `simple_smooth`, `sum`, `std`, `cic`,
`weighted_mean`, `mesh_id`, and `nearest`.
+ weight_field : string, default 'particle_mass'
+ Weighting field name for deposition other than method `count`.
kernel_name : string, default 'cubic'
This is the name of the smoothing kernel to use. It is only used for
the `simple_smooth` method and is otherwise ignored. Current
@@ -1025,13 +1028,13 @@
def _deposit_field(field, data):
"""
- Create a grid field for particle wuantities weighted by particle
- mass, using cloud-in-cell deposition.
+ Create a grid field for particle quantities weighted by the weight_field
+ (default particle_mass), using cloud-in-cell deposition.
"""
pos = data[ptype, "particle_position"]
# get back into density
if method != 'count':
- pden = data[ptype, "particle_mass"]
+ pden = data[ptype, weight_field]
top = data.deposit(pos, [data[(ptype, deposit_field)]*pden],
method=method, kernel_name=kernel_name)
bottom = data.deposit(pos, [pden], method=method,
https://bitbucket.org/yt_analysis/yt/commits/c14ed91f7234/
Changeset: c14ed91f7234
Branch: yt
User: yihaochen
Date: 2016-02-09 22:41:31+00:00
Summary: Changed the sequence of the keyword arguments in add_deposited_particle_field.
Affected #: 1 file
diff -r a0e522c4887faebaec31b278ee54243fac2bc428 -r c14ed91f7234bc48f4685f967cb80e993739669b yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -988,8 +988,8 @@
deps, _ = self.field_info.check_derived_fields([name])
self.field_dependencies.update(deps)
- def add_deposited_particle_field(self, deposit_field, method,
- weight_field='particle_mass', kernel_name='cubic'):
+ def add_deposited_particle_field(self, deposit_field, method, kernel_name='cubic',
+ weight_field='particle_mass'):
"""Add a new deposited particle field
Creates a new deposited field based on the particle *deposit_field*.
@@ -1006,13 +1006,13 @@
`particle_deposit` namespace as `methodname_deposit`. Current
methods include `count`, `simple_smooth`, `sum`, `std`, `cic`,
`weighted_mean`, `mesh_id`, and `nearest`.
- weight_field : string, default 'particle_mass'
- Weighting field name for deposition other than method `count`.
kernel_name : string, default 'cubic'
This is the name of the smoothing kernel to use. It is only used for
the `simple_smooth` method and is otherwise ignored. Current
supported kernel names include `cubic`, `quartic`, `quintic`,
`wendland2`, `wendland4`, and `wendland6`.
+ weight_field : string, default 'particle_mass'
+ Weighting field name for deposition other than method `count`.
Returns
-------
https://bitbucket.org/yt_analysis/yt/commits/fbf4faa34c79/
Changeset: fbf4faa34c79
Branch: yt
User: yihaochen
Date: 2016-02-11 00:06:47+00:00
Summary: Fixing add_deposited_particle_field and adapting its test function
Affected #: 2 files
diff -r c14ed91f7234bc48f4685f967cb80e993739669b -r fbf4faa34c7971cc3b735f1ee6eb643243d757f4 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -1004,15 +1004,15 @@
method : string
This is the "method name" which will be looked up in the
`particle_deposit` namespace as `methodname_deposit`. Current
- methods include `count`, `simple_smooth`, `sum`, `std`, `cic`,
- `weighted_mean`, `mesh_id`, and `nearest`.
+ methods include `simple_smooth`, `sum`, `std`, `cic`, `weighted_mean`,
+ `mesh_id`, and `nearest`.
kernel_name : string, default 'cubic'
This is the name of the smoothing kernel to use. It is only used for
the `simple_smooth` method and is otherwise ignored. Current
supported kernel names include `cubic`, `quartic`, `quintic`,
`wendland2`, `wendland4`, and `wendland6`.
weight_field : string, default 'particle_mass'
- Weighting field name for deposition other than method `count`.
+ Weighting field name for deposition method `weighted_mean`.
Returns
-------
@@ -1024,31 +1024,28 @@
ptype, deposit_field = deposit_field[0], deposit_field[1]
else:
raise RuntimeError
+
units = self.field_info[ptype, deposit_field].units
def _deposit_field(field, data):
"""
- Create a grid field for particle quantities weighted by the weight_field
- (default particle_mass), using cloud-in-cell deposition.
+ Create a grid field for particle quantities using given method.
"""
pos = data[ptype, "particle_position"]
- # get back into density
- if method != 'count':
- pden = data[ptype, weight_field]
- top = data.deposit(pos, [data[(ptype, deposit_field)]*pden],
- method=method, kernel_name=kernel_name)
- bottom = data.deposit(pos, [pden], method=method,
- kernel_name=kernel_name)
- top[bottom == 0] = 0.0
- bnz = bottom.nonzero()
- top[bnz] /= bottom[bnz]
- d = data.ds.arr(top, input_units=units)
+ if method == 'weighted_mean':
+ d = data.ds.arr(data.deposit(pos, [data[ptype, deposit_field],
+ data[ptype, weight_field]],
+ method=method, kernel_name=kernel_name),
+ input_units=units)
+ d[np.isnan(d)] = 0.0
else:
d = data.ds.arr(data.deposit(pos, [data[ptype, deposit_field]],
- method=method,
- kernel_name=kernel_name))
+ method=method, kernel_name=kernel_name),
+ input_units=units)
return d
- name_map = {"cic": "cic", "sum": "nn", "count": "count"}
+
+ name_map = {"sum": "sum", "std":"std", "cic": "cic", "weighted_mean": "avg",
+ "nearest": "nn", "simple_smooth": "ss"}
field_name = "%s_" + name_map[method] + "_%s"
field_name = field_name % (ptype, deposit_field.replace('particle_', ''))
self.add_field(
diff -r c14ed91f7234bc48f4685f967cb80e993739669b -r fbf4faa34c7971cc3b735f1ee6eb643243d757f4 yt/fields/tests/test_fields.py
--- a/yt/fields/tests/test_fields.py
+++ b/yt/fields/tests/test_fields.py
@@ -33,7 +33,7 @@
fields.append(("gas", fname))
units.append(code_units)
- base_ds = fake_random_ds(4, fields=fields, units=units, particles=10)
+ base_ds = fake_random_ds(4, fields=fields, units=units, particles=20)
base_ds.index
base_ds.cosmological_simulation = 1
@@ -195,12 +195,29 @@
yield TestFieldAccess(field, nproc)
def test_add_deposited_particle_field():
+ # NOT tested: "std", "mesh_id", "nearest" and "simple_smooth"
global base_ds
- fn = base_ds.add_deposited_particle_field(('io', 'particle_ones'), 'count')
- assert_equal(fn, ('deposit', 'io_count_ones'))
+ # Test "count" method
+ ad = base_ds.all_data()
+ ret = ad[("deposit", "io_count")]
+ assert_equal(ret.sum(), ad['particle_ones'].sum())
+
+ # Test "sum" and "cic" method
+ for method in ["sum", "cic"]:
+ fn = base_ds.add_deposited_particle_field(('io', 'particle_mass'), method)
+ assert_equal(fn, ('deposit', 'io_%s_mass' % method))
+ ad = base_ds.all_data()
+ ret = ad[fn]
+ assert_almost_equal(ret.sum(), ad['particle_mass'].sum())
+
+ # Test "weighted_mean" method
+ fn = base_ds.add_deposited_particle_field(('io', 'particle_ones'), 'weighted_mean',
+ weight_field='particle_ones')
+ assert_equal(fn, ('deposit', 'io_avg_ones'))
ad = base_ds.all_data()
ret = ad[fn]
- assert_equal(ret.sum(), ad['particle_ones'].sum())
+ # The sum should equal the number of cells that have particles
+ assert_equal(ret.sum(), np.count_nonzero(ad[("deposit", "io_count")]))
@requires_file('GadgetDiskGalaxy/snapshot_200.hdf5')
def test_add_smoothed_particle_field():
https://bitbucket.org/yt_analysis/yt/commits/53e203a42f31/
Changeset: 53e203a42f31
Branch: yt
User: yihaochen
Date: 2016-02-11 19:05:27+00:00
Summary: Handle the method "count" properly in add_deposited_particle_field.
Affected #: 2 files
diff -r fbf4faa34c7971cc3b735f1ee6eb643243d757f4 -r 53e203a42f317abe1e63854eee7436fb177c5043 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -1026,6 +1026,20 @@
raise RuntimeError
units = self.field_info[ptype, deposit_field].units
+ take_log = self.field_info[ptype, deposit_field].take_log
+ name_map = {"sum": "sum", "std":"std", "cic": "cic", "weighted_mean": "avg",
+ "nearest": "nn", "simple_smooth": "ss", "count": "count"}
+ field_name = "%s_" + name_map[method] + "_%s"
+ field_name = field_name % (ptype, deposit_field.replace('particle_', ''))
+
+ if method == "count":
+ field_name = "%s_count" % ptype
+ if ("deposit", field_name) in self.field_info:
+ mylog.warning("The deposited field %s already exist" % field_name)
+ return ("deposit", field_name)
+ else:
+ units = "dimensionless"
+ take_log = False
def _deposit_field(field, data):
"""
@@ -1044,15 +1058,11 @@
input_units=units)
return d
- name_map = {"sum": "sum", "std":"std", "cic": "cic", "weighted_mean": "avg",
- "nearest": "nn", "simple_smooth": "ss"}
- field_name = "%s_" + name_map[method] + "_%s"
- field_name = field_name % (ptype, deposit_field.replace('particle_', ''))
self.add_field(
("deposit", field_name),
function=_deposit_field,
units=units,
- take_log=False,
+ take_log=take_log,
validators=[ValidateSpatial()])
return ("deposit", field_name)
diff -r fbf4faa34c7971cc3b735f1ee6eb643243d757f4 -r 53e203a42f317abe1e63854eee7436fb177c5043 yt/fields/tests/test_fields.py
--- a/yt/fields/tests/test_fields.py
+++ b/yt/fields/tests/test_fields.py
@@ -197,24 +197,23 @@
def test_add_deposited_particle_field():
# NOT tested: "std", "mesh_id", "nearest" and "simple_smooth"
global base_ds
- # Test "count" method
ad = base_ds.all_data()
- ret = ad[("deposit", "io_count")]
- assert_equal(ret.sum(), ad['particle_ones'].sum())
- # Test "sum" and "cic" method
- for method in ["sum", "cic"]:
+ # Test "count", "sum" and "cic" method
+ for method in ["count", "sum", "cic"]:
fn = base_ds.add_deposited_particle_field(('io', 'particle_mass'), method)
- assert_equal(fn, ('deposit', 'io_%s_mass' % method))
- ad = base_ds.all_data()
+ expected_fn = 'io_%s' if method == "count" else 'io_%s_mass'
+ assert_equal(fn, ('deposit', expected_fn % method))
ret = ad[fn]
- assert_almost_equal(ret.sum(), ad['particle_mass'].sum())
+ if method == "count":
+ assert_equal(ret.sum(), ad['particle_ones'].sum())
+ else:
+ assert_almost_equal(ret.sum(), ad['particle_mass'].sum())
# Test "weighted_mean" method
fn = base_ds.add_deposited_particle_field(('io', 'particle_ones'), 'weighted_mean',
weight_field='particle_ones')
assert_equal(fn, ('deposit', 'io_avg_ones'))
- ad = base_ds.all_data()
ret = ad[fn]
# The sum should equal the number of cells that have particles
assert_equal(ret.sum(), np.count_nonzero(ad[("deposit", "io_count")]))
https://bitbucket.org/yt_analysis/yt/commits/84e602770bf0/
Changeset: 84e602770bf0
Branch: yt
User: yihaochen
Date: 2016-02-11 19:14:57+00:00
Summary: Minor language fix.
Affected #: 1 file
diff -r 53e203a42f317abe1e63854eee7436fb177c5043 -r 84e602770bf01437c9c345f3108826b5d9b104e4 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -1035,7 +1035,7 @@
if method == "count":
field_name = "%s_count" % ptype
if ("deposit", field_name) in self.field_info:
- mylog.warning("The deposited field %s already exist" % field_name)
+ mylog.warning("The deposited field %s already exists" % field_name)
return ("deposit", field_name)
else:
units = "dimensionless"
https://bitbucket.org/yt_analysis/yt/commits/a7cce4a6f076/
Changeset: a7cce4a6f076
Branch: yt
User: xarthisius
Date: 2016-02-17 17:04:30+00:00
Summary: Merged in yihaochen/yt (pull request #1988)
Fixing add_deposited_particle_field. Closes #1170
Affected #: 2 files
diff -r af128f1c867d7f72132699e5d243a37583c36570 -r a7cce4a6f076ddd2a1f122c5ea9cf8fde71aed8e yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -988,7 +988,8 @@
deps, _ = self.field_info.check_derived_fields([name])
self.field_dependencies.update(deps)
- def add_deposited_particle_field(self, deposit_field, method, kernel_name='cubic'):
+ def add_deposited_particle_field(self, deposit_field, method, kernel_name='cubic',
+ weight_field='particle_mass'):
"""Add a new deposited particle field
Creates a new deposited field based on the particle *deposit_field*.
@@ -1003,13 +1004,15 @@
method : string
This is the "method name" which will be looked up in the
`particle_deposit` namespace as `methodname_deposit`. Current
- methods include `count`, `simple_smooth`, `sum`, `std`, `cic`,
- `weighted_mean`, `mesh_id`, and `nearest`.
+ methods include `simple_smooth`, `sum`, `std`, `cic`, `weighted_mean`,
+ `mesh_id`, and `nearest`.
kernel_name : string, default 'cubic'
This is the name of the smoothing kernel to use. It is only used for
the `simple_smooth` method and is otherwise ignored. Current
supported kernel names include `cubic`, `quartic`, `quintic`,
`wendland2`, `wendland4`, and `wendland6`.
+ weight_field : string, default 'particle_mass'
+ Weighting field name for deposition method `weighted_mean`.
Returns
-------
@@ -1021,38 +1024,45 @@
ptype, deposit_field = deposit_field[0], deposit_field[1]
else:
raise RuntimeError
+
units = self.field_info[ptype, deposit_field].units
+ take_log = self.field_info[ptype, deposit_field].take_log
+ name_map = {"sum": "sum", "std":"std", "cic": "cic", "weighted_mean": "avg",
+ "nearest": "nn", "simple_smooth": "ss", "count": "count"}
+ field_name = "%s_" + name_map[method] + "_%s"
+ field_name = field_name % (ptype, deposit_field.replace('particle_', ''))
+
+ if method == "count":
+ field_name = "%s_count" % ptype
+ if ("deposit", field_name) in self.field_info:
+ mylog.warning("The deposited field %s already exists" % field_name)
+ return ("deposit", field_name)
+ else:
+ units = "dimensionless"
+ take_log = False
def _deposit_field(field, data):
"""
- Create a grid field for particle wuantities weighted by particle
- mass, using cloud-in-cell deposition.
+ Create a grid field for particle quantities using given method.
"""
pos = data[ptype, "particle_position"]
- # get back into density
- if method != 'count':
- pden = data[ptype, "particle_mass"]
- top = data.deposit(pos, [data[(ptype, deposit_field)]*pden],
- method=method, kernel_name=kernel_name)
- bottom = data.deposit(pos, [pden], method=method,
- kernel_name=kernel_name)
- top[bottom == 0] = 0.0
- bnz = bottom.nonzero()
- top[bnz] /= bottom[bnz]
- d = data.ds.arr(top, input_units=units)
+ if method == 'weighted_mean':
+ d = data.ds.arr(data.deposit(pos, [data[ptype, deposit_field],
+ data[ptype, weight_field]],
+ method=method, kernel_name=kernel_name),
+ input_units=units)
+ d[np.isnan(d)] = 0.0
else:
d = data.ds.arr(data.deposit(pos, [data[ptype, deposit_field]],
- method=method,
- kernel_name=kernel_name))
+ method=method, kernel_name=kernel_name),
+ input_units=units)
return d
- name_map = {"cic": "cic", "sum": "nn", "count": "count"}
- field_name = "%s_" + name_map[method] + "_%s"
- field_name = field_name % (ptype, deposit_field.replace('particle_', ''))
+
self.add_field(
("deposit", field_name),
function=_deposit_field,
units=units,
- take_log=False,
+ take_log=take_log,
validators=[ValidateSpatial()])
return ("deposit", field_name)
diff -r af128f1c867d7f72132699e5d243a37583c36570 -r a7cce4a6f076ddd2a1f122c5ea9cf8fde71aed8e yt/fields/tests/test_fields.py
--- a/yt/fields/tests/test_fields.py
+++ b/yt/fields/tests/test_fields.py
@@ -33,7 +33,7 @@
fields.append(("gas", fname))
units.append(code_units)
- base_ds = fake_random_ds(4, fields=fields, units=units, particles=10)
+ base_ds = fake_random_ds(4, fields=fields, units=units, particles=20)
base_ds.index
base_ds.cosmological_simulation = 1
@@ -195,12 +195,28 @@
yield TestFieldAccess(field, nproc)
def test_add_deposited_particle_field():
+ # NOT tested: "std", "mesh_id", "nearest" and "simple_smooth"
global base_ds
- fn = base_ds.add_deposited_particle_field(('io', 'particle_ones'), 'count')
- assert_equal(fn, ('deposit', 'io_count_ones'))
ad = base_ds.all_data()
+
+ # Test "count", "sum" and "cic" method
+ for method in ["count", "sum", "cic"]:
+ fn = base_ds.add_deposited_particle_field(('io', 'particle_mass'), method)
+ expected_fn = 'io_%s' if method == "count" else 'io_%s_mass'
+ assert_equal(fn, ('deposit', expected_fn % method))
+ ret = ad[fn]
+ if method == "count":
+ assert_equal(ret.sum(), ad['particle_ones'].sum())
+ else:
+ assert_almost_equal(ret.sum(), ad['particle_mass'].sum())
+
+ # Test "weighted_mean" method
+ fn = base_ds.add_deposited_particle_field(('io', 'particle_ones'), 'weighted_mean',
+ weight_field='particle_ones')
+ assert_equal(fn, ('deposit', 'io_avg_ones'))
ret = ad[fn]
- assert_equal(ret.sum(), ad['particle_ones'].sum())
+ # The sum should equal the number of cells that have particles
+ assert_equal(ret.sum(), np.count_nonzero(ad[("deposit", "io_count")]))
@requires_file('GadgetDiskGalaxy/snapshot_200.hdf5')
def test_add_smoothed_particle_field():
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