[yt-svn] commit/yt: 20 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Nov 7 12:37:13 PST 2014
20 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/252ae4a41a6e/
Changeset: 252ae4a41a6e
Branch: yt
User: brittonsmith
Date: 2014-10-16 00:57:33+00:00
Summary: Adding requires_sim and can_run_sim to allow teseting of simulation time series.
Affected #: 1 file
diff -r 9d022af9c4de627a45b1250f8c5427b9d8562989 -r 252ae4a41a6e99e3438e05b508272dbbbb491696 yt/utilities/answer_testing/framework.py
--- a/yt/utilities/answer_testing/framework.py
+++ b/yt/utilities/answer_testing/framework.py
@@ -32,6 +32,7 @@
from yt.convenience import load, simulation
from yt.config import ytcfg
from yt.data_objects.static_output import Dataset
+from yt.data_objects.time_series import SimulationTimeSeries
from yt.utilities.logger import disable_stream_logging
from yt.utilities.command_line import get_yt_version
@@ -259,6 +260,22 @@
return False
return AnswerTestingTest.result_storage is not None
+def can_run_sim(sim_fn, sim_type, file_check = False):
+ if isinstance(sim_fn, SimulationTimeSeries):
+ return AnswerTestingTest.result_storage is not None
+ path = ytcfg.get("yt", "test_data_dir")
+ if not os.path.isdir(path):
+ return False
+ with temp_cwd(path):
+ if file_check:
+ return os.path.isfile(sim_fn) and \
+ AnswerTestingTest.result_storage is not None
+ try:
+ simulation(sim_fn, sim_type)
+ except YTOutputNotIdentified:
+ return False
+ return AnswerTestingTest.result_storage is not None
+
def data_dir_load(ds_fn, cls = None, args = None, kwargs = None):
path = ytcfg.get("yt", "test_data_dir")
if isinstance(ds_fn, Dataset): return ds_fn
@@ -727,7 +744,18 @@
def compare(self, new_result, old_result):
compare_image_lists(new_result, old_result, self.decimals)
-
+def requires_sim(sim_fn, sim_type, big_data = False, file_check = False):
+ def ffalse(func):
+ return lambda: None
+ def ftrue(func):
+ return func
+ if run_big_data == False and big_data == True:
+ return ffalse
+ elif not can_run_sim(sim_fn, sim_type, file_check):
+ return ffalse
+ else:
+ return ftrue
+
def requires_ds(ds_fn, big_data = False, file_check = False):
def ffalse(func):
return lambda: None
https://bitbucket.org/yt_analysis/yt/commits/a1e685eb0532/
Changeset: a1e685eb0532
Branch: yt
User: brittonsmith
Date: 2014-10-16 00:58:58+00:00
Summary: Adding answer test for conventional running of rockstar.
Affected #: 3 files
diff -r 252ae4a41a6e99e3438e05b508272dbbbb491696 -r a1e685eb0532eb18a5b845fd91dbde8433b136c2 yt/analysis_modules/halo_finding/tests/run_rockstar.py
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/tests/run_rockstar.py
@@ -0,0 +1,26 @@
+from mpi4py import MPI
+import yt
+from yt.analysis_modules.halo_finding.rockstar.api import \
+ RockstarHaloFinder
+from yt.data_objects.particle_filters import \
+ particle_filter
+yt.enable_parallelism()
+
+comm = MPI.Comm.Get_parent()
+
+ at particle_filter("dark_matter", requires=["creation_time"])
+def _dm_filter(pfilter, data):
+ return data["creation_time"] <= 0.0
+
+def setup_pf(pf):
+ pf.add_particle_filter("dark_matter")
+
+es = yt.simulation("Enzo_64/64.param", "Enzo")
+es.get_time_series(setup_function=setup_pf,
+ redshifts=[1., 0.])
+
+rh = RockstarHaloFinder(es, num_readers=1, num_writers=1,
+ particle_type="dark_matter")
+rh.run()
+
+comm.Disconnect()
diff -r 252ae4a41a6e99e3438e05b508272dbbbb491696 -r a1e685eb0532eb18a5b845fd91dbde8433b136c2 yt/analysis_modules/halo_finding/tests/test_rockstar.py
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/tests/test_rockstar.py
@@ -0,0 +1,24 @@
+import sys
+
+from yt.testing import *
+from yt.utilities.answer_testing.framework import \
+ FieldValuesTest, \
+ requires_sim
+
+_fields = ("particle_position_x", "particle_position_y",
+ "particle_position_z", "particle_mass")
+
+ at requires_sim("Enzo_64/64.param", "Enzo", big_data=True)
+def test_rockstar():
+ from mpi4py import MPI
+ comm = MPI.COMM_SELF.Spawn(sys.executable,
+ args=['run_rockstar.py'],
+ maxprocs=3)
+ comm.Disconnect()
+
+ h1 = "rockstar_halos/halos_0.0.bin"
+ for field in _fields:
+ yield FieldValuesTest(h1, field)
+ h2 = "rockstar_halos/halos_1.0.bin"
+ for field in _fields:
+ yield FieldValuesTest(h2, field)
https://bitbucket.org/yt_analysis/yt/commits/6105f1959df8/
Changeset: 6105f1959df8
Branch: yt
User: brittonsmith
Date: 2014-10-17 15:40:19+00:00
Summary: pf to ds.
Affected #: 1 file
diff -r a1e685eb0532eb18a5b845fd91dbde8433b136c2 -r 6105f1959df86fc5d42e682e6a807bb8641d53b3 yt/analysis_modules/halo_finding/tests/run_rockstar.py
--- a/yt/analysis_modules/halo_finding/tests/run_rockstar.py
+++ b/yt/analysis_modules/halo_finding/tests/run_rockstar.py
@@ -12,11 +12,11 @@
def _dm_filter(pfilter, data):
return data["creation_time"] <= 0.0
-def setup_pf(pf):
- pf.add_particle_filter("dark_matter")
+def setup_ds(ds):
+ ds.add_particle_filter("dark_matter")
es = yt.simulation("Enzo_64/64.param", "Enzo")
-es.get_time_series(setup_function=setup_pf,
+es.get_time_series(setup_function=setup_ds,
redshifts=[1., 0.])
rh = RockstarHaloFinder(es, num_readers=1, num_writers=1,
https://bitbucket.org/yt_analysis/yt/commits/9efac538f597/
Changeset: 9efac538f597
Branch: yt
User: brittonsmith
Date: 2014-10-17 15:41:25+00:00
Summary: Adding tests of the three supported halo finders using the HaloCatalog.
Affected #: 3 files
diff -r 6105f1959df86fc5d42e682e6a807bb8641d53b3 -r 9efac538f597677f7fc8d290965f04d3536d13ac yt/analysis_modules/halo_analysis/tests/run_halo_finder.py
--- /dev/null
+++ b/yt/analysis_modules/halo_analysis/tests/run_halo_finder.py
@@ -0,0 +1,29 @@
+from mpi4py import MPI
+import sys
+import yt
+from yt.analysis_modules.halo_analysis.api import \
+ HaloCatalog
+from yt.data_objects.particle_filters import \
+ particle_filter
+yt.enable_parallelism()
+
+method = sys.argv[1]
+comm = MPI.Comm.Get_parent()
+
+methods = {"fof": {}, "hop": {},
+ "rockstar": {"num_readers":1,
+ "num_writers":1,
+ "particle_type":"dark_matter"}}
+
+ at particle_filter("dark_matter", requires=["creation_time"])
+def _dm_filter(pfilter, data):
+ return data["creation_time"] <= 0.0
+
+ds = yt.load("Enzo_64/DD0043/data0043")
+ds.add_particle_filter("dark_matter")
+
+hc = HaloCatalog(data_ds=ds, output_dir="halo_catalogs/%s" % method,
+ finder_method=method, finder_kwargs=methods[method])
+hc.create()
+
+comm.Disconnect()
diff -r 6105f1959df86fc5d42e682e6a807bb8641d53b3 -r 9efac538f597677f7fc8d290965f04d3536d13ac yt/analysis_modules/halo_analysis/tests/test_halo_finders.py
--- /dev/null
+++ b/yt/analysis_modules/halo_analysis/tests/test_halo_finders.py
@@ -0,0 +1,27 @@
+import sys
+
+from yt.analysis_modules.halo_analysis.api import \
+ HaloCatalog
+from yt.testing import *
+from yt.utilities.answer_testing.framework import \
+ FieldValuesTest, \
+ requires_ds
+
+_fields = ("particle_position_x", "particle_position_y",
+ "particle_position_z", "particle_mass")
+
+methods = {"fof": 2, "hop": 2, "rockstar": 3}
+
+e64 = "Enzo_64/DD0043/data0043"
+ at requires_ds(e64, big_data=True)
+def test_halo_finders():
+ from mpi4py import MPI
+ for method in methods:
+ comm = MPI.COMM_SELF.Spawn(sys.executable,
+ args=['run_halo_finder.py', method],
+ maxprocs=methods[method])
+ comm.Disconnect()
+
+ fn = "halo_catalogs/%s/%s.0.h5" % (method, method)
+ for field in _fields:
+ yield FieldValuesTest(fn, field)
https://bitbucket.org/yt_analysis/yt/commits/e9ae5dca4d8d/
Changeset: e9ae5dca4d8d
Branch: yt
User: brittonsmith
Date: 2014-10-17 18:55:58+00:00
Summary: Merging.
Affected #: 4 files
diff -r 9efac538f597677f7fc8d290965f04d3536d13ac -r e9ae5dca4d8d595530c7644703a484d99e8fb382 setup.py
--- a/setup.py
+++ b/setup.py
@@ -6,6 +6,12 @@
import subprocess
import shutil
import glob
+
+if sys.version_info < (2, 7):
+ print("yt currently requires Python version 2.7")
+ print("certain features may fail unexpectedly and silently with older versions.")
+ sys.exit(1)
+
import setuptools
from distutils.version import StrictVersion
if StrictVersion(setuptools.__version__) < StrictVersion('0.7.0'):
diff -r 9efac538f597677f7fc8d290965f04d3536d13ac -r e9ae5dca4d8d595530c7644703a484d99e8fb382 yt/frontends/fits/data_structures.py
--- a/yt/frontends/fits/data_structures.py
+++ b/yt/frontends/fits/data_structures.py
@@ -157,6 +157,8 @@
naxis4 = 1
for i, fits_file in enumerate(self.dataset._handle._fits_files):
for j, hdu in enumerate(fits_file):
+ if isinstance(hdu, _astropy.pyfits.BinTableHDU):
+ continue
if self._ensure_same_dims(hdu):
units = self._determine_image_units(hdu.header, known_units)
try:
diff -r 9efac538f597677f7fc8d290965f04d3536d13ac -r e9ae5dca4d8d595530c7644703a484d99e8fb382 yt/frontends/stream/data_structures.py
--- a/yt/frontends/stream/data_structures.py
+++ b/yt/frontends/stream/data_structures.py
@@ -473,7 +473,8 @@
field_units[k] = v.units
new_data[k] = v.copy().d
data = new_data
- elif all([(len(val) == 2) for val in data.values()]):
+ elif all([((not isinstance(val, np.ndarray)) and (len(val) == 2))
+ for val in data.values()]):
new_data, field_units = {}, {}
for field in data:
try:
@@ -771,7 +772,7 @@
... g["density"] = np.random.random(g["dimensions"]) * 2**g["level"]
...
>>> units = dict(density='g/cm**3')
- >>> ds = load_amr_grids(grid_data, [8, 8, 8], field_units=units,
+ >>> ds = load_amr_grids(grid_data, [32, 32, 32], field_units=units,
... length_unit=1.0)
"""
diff -r 9efac538f597677f7fc8d290965f04d3536d13ac -r e9ae5dca4d8d595530c7644703a484d99e8fb382 yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -727,9 +727,14 @@
if dobj.left_edge[i] < dobj.ds.domain_left_edge[i] or \
dobj.right_edge[i] > dobj.ds.domain_right_edge[i]:
raise RuntimeError(
- "Error: bad Region in non-periodic domain along dimension %s. "
- "Region left edge = %s, Region right edge = %s"
- "Dataset left edge = %s, Dataset right edge = %s" % \
+ "Error: yt attempted to read outside the boundaries of "
+ "a non-periodic domain along dimension %s.\n"
+ "Region left edge = %s, Region right edge = %s\n"
+ "Dataset left edge = %s, Dataset right edge = %s\n\n"
+ "This commonly happens when trying to compute ghost cells "
+ "up to the domain boundary. Two possible solutions are to "
+ "load a smaller region that does not border the edge or "
+ "override the periodicity for this dataset." % \
(i, dobj.left_edge[i], dobj.right_edge[i],
dobj.ds.domain_left_edge[i], dobj.ds.domain_right_edge[i])
)
https://bitbucket.org/yt_analysis/yt/commits/5c2941d7feab/
Changeset: 5c2941d7feab
Branch: yt
User: brittonsmith
Date: 2014-10-18 15:53:11+00:00
Summary: Allowing answer test to accept loaded dataset and FieldValuesTest to test particle fields.
Affected #: 1 file
diff -r e9ae5dca4d8d595530c7644703a484d99e8fb382 -r 5c2941d7feab275a96311f1ac7a6a71f2d569895 yt/utilities/answer_testing/framework.py
--- a/yt/utilities/answer_testing/framework.py
+++ b/yt/utilities/answer_testing/framework.py
@@ -306,7 +306,10 @@
result_storage = None
prefix = ""
def __init__(self, ds_fn):
- self.ds = data_dir_load(ds_fn)
+ if isinstance(ds_fn, Dataset):
+ self.ds = ds_fn
+ else:
+ self.ds = data_dir_load(ds_fn)
def __call__(self):
nv = self.run()
@@ -377,16 +380,21 @@
_attrs = ("field", )
def __init__(self, ds_fn, field, obj_type = None,
- decimals = 10):
+ particle_type=False, decimals = 10):
super(FieldValuesTest, self).__init__(ds_fn)
self.obj_type = obj_type
self.field = field
+ self.particle_type = particle_type
self.decimals = decimals
def run(self):
obj = create_obj(self.ds, self.obj_type)
+ if self.particle_type:
+ weight_field = "particle_ones"
+ else:
+ weight_field = "ones"
avg = obj.quantities.weighted_average_quantity(
- self.field, weight="ones")
+ self.field, weight=weight_field)
mi, ma = obj.quantities.extrema(self.field)
return np.array([avg, mi, ma])
https://bitbucket.org/yt_analysis/yt/commits/3e108a65e817/
Changeset: 3e108a65e817
Branch: yt
User: brittonsmith
Date: 2014-10-18 15:53:43+00:00
Summary: Fixing paths in halo finder tests.
Affected #: 3 files
diff -r 5c2941d7feab275a96311f1ac7a6a71f2d569895 -r 3e108a65e8173bed4ce802a3fe7148c299bcd721 yt/analysis_modules/halo_analysis/tests/run_halo_finder.py
--- a/yt/analysis_modules/halo_analysis/tests/run_halo_finder.py
+++ b/yt/analysis_modules/halo_analysis/tests/run_halo_finder.py
@@ -1,4 +1,5 @@
from mpi4py import MPI
+import os
import sys
import yt
from yt.analysis_modules.halo_analysis.api import \
@@ -22,7 +23,9 @@
ds = yt.load("Enzo_64/DD0043/data0043")
ds.add_particle_filter("dark_matter")
-hc = HaloCatalog(data_ds=ds, output_dir="halo_catalogs/%s" % method,
+output_dir = os.path.join(os.path.dirname(__file__),
+ "halo_catalogs", method)
+hc = HaloCatalog(data_ds=ds, output_dir=output_dir,
finder_method=method, finder_kwargs=methods[method])
hc.create()
diff -r 5c2941d7feab275a96311f1ac7a6a71f2d569895 -r 3e108a65e8173bed4ce802a3fe7148c299bcd721 yt/analysis_modules/halo_analysis/tests/test_halo_finders.py
--- a/yt/analysis_modules/halo_analysis/tests/test_halo_finders.py
+++ b/yt/analysis_modules/halo_analysis/tests/test_halo_finders.py
@@ -1,14 +1,18 @@
+import os
import sys
from yt.analysis_modules.halo_analysis.api import \
HaloCatalog
+from yt.convenience import load
from yt.testing import *
from yt.utilities.answer_testing.framework import \
FieldValuesTest, \
requires_ds
-_fields = ("particle_position_x", "particle_position_y",
- "particle_position_z", "particle_mass")
+_fields = (("halos", "particle_position_x"),
+ ("halos", "particle_position_y"),
+ ("halos", "particle_position_z"),
+ ("halos", "particle_mass"))
methods = {"fof": 2, "hop": 2, "rockstar": 3}
@@ -16,12 +20,17 @@
@requires_ds(e64, big_data=True)
def test_halo_finders():
from mpi4py import MPI
+ filename = os.path.join(os.path.dirname(__file__),
+ "run_halo_finder.py")
for method in methods:
comm = MPI.COMM_SELF.Spawn(sys.executable,
- args=['run_halo_finder.py', method],
+ args=[filename, method],
maxprocs=methods[method])
comm.Disconnect()
- fn = "halo_catalogs/%s/%s.0.h5" % (method, method)
+ fn = os.path.join(os.path.dirname(__file__),
+ "halo_catalogs", method,
+ "%s.0.h5" % method)
+ ds = load(fn)
for field in _fields:
- yield FieldValuesTest(fn, field)
+ yield FieldValuesTest(ds, field, particle_type=True)
diff -r 5c2941d7feab275a96311f1ac7a6a71f2d569895 -r 3e108a65e8173bed4ce802a3fe7148c299bcd721 yt/analysis_modules/halo_finding/tests/test_rockstar.py
--- a/yt/analysis_modules/halo_finding/tests/test_rockstar.py
+++ b/yt/analysis_modules/halo_finding/tests/test_rockstar.py
@@ -1,24 +1,32 @@
+import os
import sys
+from yt.convenience import load
from yt.testing import *
from yt.utilities.answer_testing.framework import \
FieldValuesTest, \
requires_sim
-_fields = ("particle_position_x", "particle_position_y",
- "particle_position_z", "particle_mass")
+_fields = (("halos", "particle_position_x"),
+ ("halos", "particle_position_y"),
+ ("halos", "particle_position_z"),
+ ("halos", "particle_mass"))
@requires_sim("Enzo_64/64.param", "Enzo", big_data=True)
def test_rockstar():
from mpi4py import MPI
+ filename = os.path.join(os.path.dirname(__file__),
+ "run_rockstar.py")
comm = MPI.COMM_SELF.Spawn(sys.executable,
- args=['run_rockstar.py'],
+ args=[filename],
maxprocs=3)
comm.Disconnect()
h1 = "rockstar_halos/halos_0.0.bin"
+ d1 = load(h1)
for field in _fields:
- yield FieldValuesTest(h1, field)
+ yield FieldValuesTest(d1, field, particle_type=True)
h2 = "rockstar_halos/halos_1.0.bin"
+ d2 = load(h2)
for field in _fields:
- yield FieldValuesTest(h2, field)
+ yield FieldValuesTest(d2, field, particle_type=True)
https://bitbucket.org/yt_analysis/yt/commits/b505a4f4df1e/
Changeset: b505a4f4df1e
Branch: yt
User: brittonsmith
Date: 2014-10-18 15:57:43+00:00
Summary: Indicating particle_type for field tests.
Affected #: 1 file
diff -r 3e108a65e8173bed4ce802a3fe7148c299bcd721 -r b505a4f4df1ecf28d1e883899b2877666b6428d4 yt/frontends/halo_catalogs/owls_subfind/tests/test_outputs.py
--- a/yt/frontends/halo_catalogs/owls_subfind/tests/test_outputs.py
+++ b/yt/frontends/halo_catalogs/owls_subfind/tests/test_outputs.py
@@ -28,7 +28,7 @@
ds = data_dir_load(g8)
yield assert_equal, str(ds), "group_008.0.hdf5"
for field in _fields:
- yield FieldValuesTest(g8, field)
+ yield FieldValuesTest(g8, field, particle_type=True)
# a dataset with empty files
g3 = "owls_fof_halos/groups_003/group_003.0.hdf5"
@@ -37,4 +37,4 @@
ds = data_dir_load(g3)
yield assert_equal, str(ds), "group_003.0.hdf5"
for field in _fields:
- yield FieldValuesTest(g3, field)
+ yield FieldValuesTest(g3, field, particle_type=True)
https://bitbucket.org/yt_analysis/yt/commits/89e096cb16a0/
Changeset: 89e096cb16a0
Branch: yt
User: brittonsmith
Date: 2014-10-18 20:28:49+00:00
Summary: Adding validator for field.
Affected #: 1 file
diff -r b505a4f4df1ecf28d1e883899b2877666b6428d4 -r 89e096cb16a0366413dfb64e7d6883d70398b0e2 yt/analysis_modules/halo_analysis/fields.py
--- a/yt/analysis_modules/halo_analysis/fields.py
+++ b/yt/analysis_modules/halo_analysis/fields.py
@@ -38,4 +38,5 @@
registry.add_field(("index", "virial_radius"),
function=_virial_radius,
+ validators=[ValidateParameter("virial_radius")],
units="")
https://bitbucket.org/yt_analysis/yt/commits/38478be4aee1/
Changeset: 38478be4aee1
Branch: yt
User: brittonsmith
Date: 2014-10-19 12:54:02+00:00
Summary: Forgot to import the validator.
Affected #: 1 file
diff -r 89e096cb16a0366413dfb64e7d6883d70398b0e2 -r 38478be4aee1a508e45a8ade71a2fe350b5f4c52 yt/analysis_modules/halo_analysis/fields.py
--- a/yt/analysis_modules/halo_analysis/fields.py
+++ b/yt/analysis_modules/halo_analysis/fields.py
@@ -14,6 +14,8 @@
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
+from yt.fields.derived_field import \
+ ValidateParameter
from yt.fields.field_plugin_registry import \
register_field_plugin
https://bitbucket.org/yt_analysis/yt/commits/ef2f09eb0f24/
Changeset: ef2f09eb0f24
Branch: yt
User: brittonsmith
Date: 2014-10-19 16:09:36+00:00
Summary: Adding virial_radius field parameter to testing.
Affected #: 1 file
diff -r 38478be4aee1a508e45a8ade71a2fe350b5f4c52 -r ef2f09eb0f24be951670b35bfecadec5ee3ff4ab yt/fields/tests/test_fields.py
--- a/yt/fields/tests/test_fields.py
+++ b/yt/fields/tests/test_fields.py
@@ -6,7 +6,8 @@
mpc_conversion, sec_conversion
from yt.frontends.stream.fields import \
StreamFieldInfo
-from yt.units.yt_array import YTArray
+from yt.units.yt_array import \
+ YTArray, YTQuantity
def setup():
global base_ds
@@ -42,6 +43,7 @@
omega_baryon = 0.04,
observer_redshift = 0.0,
source_redshift = 3.0,
+ virial_radius = YTQuantity(1.0, "Mpc"),
)
_base_fields = (("gas", "density"),
https://bitbucket.org/yt_analysis/yt/commits/eaa4a80b1e31/
Changeset: eaa4a80b1e31
Branch: yt
User: brittonsmith
Date: 2014-11-06 16:50:31+00:00
Summary: Moving virial radius field to cosmology registry.
Affected #: 3 files
diff -r ef2f09eb0f24be951670b35bfecadec5ee3ff4ab -r eaa4a80b1e3145f4d86c8cba022b62bc53df975c yt/analysis_modules/halo_analysis/api.py
--- a/yt/analysis_modules/halo_analysis/api.py
+++ b/yt/analysis_modules/halo_analysis/api.py
@@ -28,5 +28,3 @@
from .halo_quantities import \
add_quantity
-
-from . import fields
diff -r ef2f09eb0f24be951670b35bfecadec5ee3ff4ab -r eaa4a80b1e3145f4d86c8cba022b62bc53df975c yt/analysis_modules/halo_analysis/fields.py
--- a/yt/analysis_modules/halo_analysis/fields.py
+++ /dev/null
@@ -1,44 +0,0 @@
-"""
-Cosmology related fields.
-
-
-
-
-"""
-
-#-----------------------------------------------------------------------------
-# Copyright (c) 2014, yt Development Team.
-#
-# Distributed under the terms of the Modified BSD License.
-#
-# The full license is in the file COPYING.txt, distributed with this software.
-#-----------------------------------------------------------------------------
-
-from yt.fields.derived_field import \
- ValidateParameter
-from yt.fields.field_plugin_registry import \
- register_field_plugin
-
- at register_field_plugin
-def setup_halo_analysis_fields(registry, ftype = "gas", slice_info = None):
- # slice_info would be the left, the right, and the factor.
- # For example, with the old Enzo-ZEUS fields, this would be:
- # slice(None, -2, None)
- # slice(1, -1, None)
- # 1.0
- # Otherwise, we default to a centered difference.
- if slice_info is None:
- sl_left = slice(None, -2, None)
- sl_right = slice(2, None, None)
- div_fac = 2.0
- else:
- sl_left, sl_right, div_fac = slice_info
-
- def _virial_radius(field, data):
- virial_radius = data.get_field_parameter("virial_radius")
- return data["radius"] / virial_radius
-
- registry.add_field(("index", "virial_radius"),
- function=_virial_radius,
- validators=[ValidateParameter("virial_radius")],
- units="")
diff -r ef2f09eb0f24be951670b35bfecadec5ee3ff4ab -r eaa4a80b1e3145f4d86c8cba022b62bc53df975c yt/fields/cosmology_fields.py
--- a/yt/fields/cosmology_fields.py
+++ b/yt/fields/cosmology_fields.py
@@ -106,6 +106,16 @@
registry.add_field((ftype, "matter_overdensity"),
function=_matter_overdensity,
units="")
+
+ # r / r_vir
+ def _virial_radius(field, data):
+ virial_radius = data.get_field_parameter("virial_radius")
+ return data["radius"] / virial_radius
+
+ registry.add_field(("index", "virial_radius"),
+ function=_virial_radius,
+ validators=[ValidateParameter("virial_radius")],
+ units="")
# Weak lensing convergence.
# Eqn 4 of Metzler, White, & Loken (2001, ApJ, 547, 560).
https://bitbucket.org/yt_analysis/yt/commits/473014cf71be/
Changeset: 473014cf71be
Branch: yt
User: brittonsmith
Date: 2014-11-06 18:17:58+00:00
Summary: Renaming virial_radius field to virial_radius_fraction as it is more correct and avoids collision with another field.
Affected #: 1 file
diff -r eaa4a80b1e3145f4d86c8cba022b62bc53df975c -r 473014cf71be4032f477a065aa5f3a44715d8dbf yt/fields/cosmology_fields.py
--- a/yt/fields/cosmology_fields.py
+++ b/yt/fields/cosmology_fields.py
@@ -108,12 +108,12 @@
units="")
# r / r_vir
- def _virial_radius(field, data):
+ def _virial_radius_fraction(field, data):
virial_radius = data.get_field_parameter("virial_radius")
return data["radius"] / virial_radius
- registry.add_field(("index", "virial_radius"),
- function=_virial_radius,
+ registry.add_field(("index", "virial_radius_fraction"),
+ function=_virial_radius_fraction,
validators=[ValidateParameter("virial_radius")],
units="")
https://bitbucket.org/yt_analysis/yt/commits/30e1624d5bb5/
Changeset: 30e1624d5bb5
Branch: yt
User: brittonsmith
Date: 2014-11-06 18:18:51+00:00
Summary: Making sure apply units converts to desired units if possible before applying a unit system.
Affected #: 1 file
diff -r 473014cf71be4032f477a065aa5f3a44715d8dbf -r 30e1624d5bb57ad92906fe6b093ce90f471e32fa yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -150,6 +150,8 @@
self.field_parameters[parameter]
def apply_units(self, arr, units):
+ if hasattr(arr, "units"):
+ return self.ds.arr(arr.in_units(units), input_units = units)
return self.ds.arr(arr, input_units = units)
def _set_center(self, center):
https://bitbucket.org/yt_analysis/yt/commits/4108392ee530/
Changeset: 4108392ee530
Branch: yt
User: brittonsmith
Date: 2014-11-06 22:27:06+00:00
Summary: Merging.
Affected #: 13 files
diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 yt/analysis_modules/halo_analysis/api.py
--- a/yt/analysis_modules/halo_analysis/api.py
+++ b/yt/analysis_modules/halo_analysis/api.py
@@ -28,5 +28,3 @@
from .halo_quantities import \
add_quantity
-
-from . import fields
diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 yt/analysis_modules/halo_analysis/fields.py
--- a/yt/analysis_modules/halo_analysis/fields.py
+++ /dev/null
@@ -1,41 +0,0 @@
-"""
-Cosmology related fields.
-
-
-
-
-"""
-
-#-----------------------------------------------------------------------------
-# Copyright (c) 2014, yt Development Team.
-#
-# Distributed under the terms of the Modified BSD License.
-#
-# The full license is in the file COPYING.txt, distributed with this software.
-#-----------------------------------------------------------------------------
-
-from yt.fields.field_plugin_registry import \
- register_field_plugin
-
- at register_field_plugin
-def setup_halo_analysis_fields(registry, ftype = "gas", slice_info = None):
- # slice_info would be the left, the right, and the factor.
- # For example, with the old Enzo-ZEUS fields, this would be:
- # slice(None, -2, None)
- # slice(1, -1, None)
- # 1.0
- # Otherwise, we default to a centered difference.
- if slice_info is None:
- sl_left = slice(None, -2, None)
- sl_right = slice(2, None, None)
- div_fac = 2.0
- else:
- sl_left, sl_right, div_fac = slice_info
-
- def _virial_radius(field, data):
- virial_radius = data.get_field_parameter("virial_radius")
- return data["radius"] / virial_radius
-
- registry.add_field(("index", "virial_radius"),
- function=_virial_radius,
- units="")
diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 yt/analysis_modules/halo_analysis/tests/run_halo_finder.py
--- /dev/null
+++ b/yt/analysis_modules/halo_analysis/tests/run_halo_finder.py
@@ -0,0 +1,32 @@
+from mpi4py import MPI
+import os
+import sys
+import yt
+from yt.analysis_modules.halo_analysis.api import \
+ HaloCatalog
+from yt.data_objects.particle_filters import \
+ particle_filter
+yt.enable_parallelism()
+
+method = sys.argv[1]
+comm = MPI.Comm.Get_parent()
+
+methods = {"fof": {}, "hop": {},
+ "rockstar": {"num_readers":1,
+ "num_writers":1,
+ "particle_type":"dark_matter"}}
+
+ at particle_filter("dark_matter", requires=["creation_time"])
+def _dm_filter(pfilter, data):
+ return data["creation_time"] <= 0.0
+
+ds = yt.load("Enzo_64/DD0043/data0043")
+ds.add_particle_filter("dark_matter")
+
+output_dir = os.path.join(os.path.dirname(__file__),
+ "halo_catalogs", method)
+hc = HaloCatalog(data_ds=ds, output_dir=output_dir,
+ finder_method=method, finder_kwargs=methods[method])
+hc.create()
+
+comm.Disconnect()
diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 yt/analysis_modules/halo_analysis/tests/test_halo_finders.py
--- /dev/null
+++ b/yt/analysis_modules/halo_analysis/tests/test_halo_finders.py
@@ -0,0 +1,36 @@
+import os
+import sys
+
+from yt.analysis_modules.halo_analysis.api import \
+ HaloCatalog
+from yt.convenience import load
+from yt.testing import *
+from yt.utilities.answer_testing.framework import \
+ FieldValuesTest, \
+ requires_ds
+
+_fields = (("halos", "particle_position_x"),
+ ("halos", "particle_position_y"),
+ ("halos", "particle_position_z"),
+ ("halos", "particle_mass"))
+
+methods = {"fof": 2, "hop": 2, "rockstar": 3}
+
+e64 = "Enzo_64/DD0043/data0043"
+ at requires_ds(e64, big_data=True)
+def test_halo_finders():
+ from mpi4py import MPI
+ filename = os.path.join(os.path.dirname(__file__),
+ "run_halo_finder.py")
+ for method in methods:
+ comm = MPI.COMM_SELF.Spawn(sys.executable,
+ args=[filename, method],
+ maxprocs=methods[method])
+ comm.Disconnect()
+
+ fn = os.path.join(os.path.dirname(__file__),
+ "halo_catalogs", method,
+ "%s.0.h5" % method)
+ ds = load(fn)
+ for field in _fields:
+ yield FieldValuesTest(ds, field, particle_type=True)
diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 yt/analysis_modules/halo_finding/tests/run_rockstar.py
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/tests/run_rockstar.py
@@ -0,0 +1,26 @@
+from mpi4py import MPI
+import yt
+from yt.analysis_modules.halo_finding.rockstar.api import \
+ RockstarHaloFinder
+from yt.data_objects.particle_filters import \
+ particle_filter
+yt.enable_parallelism()
+
+comm = MPI.Comm.Get_parent()
+
+ at particle_filter("dark_matter", requires=["creation_time"])
+def _dm_filter(pfilter, data):
+ return data["creation_time"] <= 0.0
+
+def setup_ds(ds):
+ ds.add_particle_filter("dark_matter")
+
+es = yt.simulation("Enzo_64/64.param", "Enzo")
+es.get_time_series(setup_function=setup_ds,
+ redshifts=[1., 0.])
+
+rh = RockstarHaloFinder(es, num_readers=1, num_writers=1,
+ particle_type="dark_matter")
+rh.run()
+
+comm.Disconnect()
diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 yt/analysis_modules/halo_finding/tests/test_rockstar.py
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/tests/test_rockstar.py
@@ -0,0 +1,32 @@
+import os
+import sys
+
+from yt.convenience import load
+from yt.testing import *
+from yt.utilities.answer_testing.framework import \
+ FieldValuesTest, \
+ requires_sim
+
+_fields = (("halos", "particle_position_x"),
+ ("halos", "particle_position_y"),
+ ("halos", "particle_position_z"),
+ ("halos", "particle_mass"))
+
+ at requires_sim("Enzo_64/64.param", "Enzo", big_data=True)
+def test_rockstar():
+ from mpi4py import MPI
+ filename = os.path.join(os.path.dirname(__file__),
+ "run_rockstar.py")
+ comm = MPI.COMM_SELF.Spawn(sys.executable,
+ args=[filename],
+ maxprocs=3)
+ comm.Disconnect()
+
+ h1 = "rockstar_halos/halos_0.0.bin"
+ d1 = load(h1)
+ for field in _fields:
+ yield FieldValuesTest(d1, field, particle_type=True)
+ h2 = "rockstar_halos/halos_1.0.bin"
+ d2 = load(h2)
+ for field in _fields:
+ yield FieldValuesTest(d2, field, particle_type=True)
diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -159,6 +159,8 @@
self.field_parameters[parameter]
def apply_units(self, arr, units):
+ if hasattr(arr, "units"):
+ return self.ds.arr(arr.in_units(units), input_units = units)
return self.ds.arr(arr, input_units = units)
def _set_center(self, center):
diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 yt/fields/cosmology_fields.py
--- a/yt/fields/cosmology_fields.py
+++ b/yt/fields/cosmology_fields.py
@@ -106,6 +106,16 @@
registry.add_field((ftype, "matter_overdensity"),
function=_matter_overdensity,
units="")
+
+ # r / r_vir
+ def _virial_radius_fraction(field, data):
+ virial_radius = data.get_field_parameter("virial_radius")
+ return data["radius"] / virial_radius
+
+ registry.add_field(("index", "virial_radius_fraction"),
+ function=_virial_radius_fraction,
+ validators=[ValidateParameter("virial_radius")],
+ units="")
# Weak lensing convergence.
# Eqn 4 of Metzler, White, & Loken (2001, ApJ, 547, 560).
diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 yt/fields/tests/test_fields.py
--- a/yt/fields/tests/test_fields.py
+++ b/yt/fields/tests/test_fields.py
@@ -6,7 +6,8 @@
mpc_conversion, sec_conversion
from yt.frontends.stream.fields import \
StreamFieldInfo
-from yt.units.yt_array import YTArray
+from yt.units.yt_array import \
+ YTArray, YTQuantity
def setup():
global base_ds
@@ -42,6 +43,7 @@
omega_baryon = 0.04,
observer_redshift = 0.0,
source_redshift = 3.0,
+ virial_radius = YTQuantity(1.0, "Mpc"),
)
_base_fields = (("gas", "density"),
diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 yt/frontends/owls_subfind/tests/test_outputs.py
--- a/yt/frontends/owls_subfind/tests/test_outputs.py
+++ b/yt/frontends/owls_subfind/tests/test_outputs.py
@@ -28,7 +28,7 @@
ds = data_dir_load(g8)
yield assert_equal, str(ds), "group_008.0.hdf5"
for field in _fields:
- yield FieldValuesTest(g8, field)
+ yield FieldValuesTest(g8, field, particle_type=True)
# a dataset with empty files
g3 = "owls_fof_halos/groups_003/group_003.0.hdf5"
@@ -37,4 +37,4 @@
ds = data_dir_load(g3)
yield assert_equal, str(ds), "group_003.0.hdf5"
for field in _fields:
- yield FieldValuesTest(g3, field)
+ yield FieldValuesTest(g3, field, particle_type=True)
diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 yt/utilities/answer_testing/framework.py
--- a/yt/utilities/answer_testing/framework.py
+++ b/yt/utilities/answer_testing/framework.py
@@ -32,6 +32,7 @@
from yt.convenience import load, simulation
from yt.config import ytcfg
from yt.data_objects.static_output import Dataset
+from yt.data_objects.time_series import SimulationTimeSeries
from yt.utilities.logger import disable_stream_logging
from yt.utilities.command_line import get_yt_version
@@ -259,6 +260,22 @@
return False
return AnswerTestingTest.result_storage is not None
+def can_run_sim(sim_fn, sim_type, file_check = False):
+ if isinstance(sim_fn, SimulationTimeSeries):
+ return AnswerTestingTest.result_storage is not None
+ path = ytcfg.get("yt", "test_data_dir")
+ if not os.path.isdir(path):
+ return False
+ with temp_cwd(path):
+ if file_check:
+ return os.path.isfile(sim_fn) and \
+ AnswerTestingTest.result_storage is not None
+ try:
+ simulation(sim_fn, sim_type)
+ except YTOutputNotIdentified:
+ return False
+ return AnswerTestingTest.result_storage is not None
+
def data_dir_load(ds_fn, cls = None, args = None, kwargs = None):
path = ytcfg.get("yt", "test_data_dir")
if isinstance(ds_fn, Dataset): return ds_fn
@@ -289,7 +306,10 @@
result_storage = None
prefix = ""
def __init__(self, ds_fn):
- self.ds = data_dir_load(ds_fn)
+ if isinstance(ds_fn, Dataset):
+ self.ds = ds_fn
+ else:
+ self.ds = data_dir_load(ds_fn)
def __call__(self):
nv = self.run()
@@ -360,16 +380,21 @@
_attrs = ("field", )
def __init__(self, ds_fn, field, obj_type = None,
- decimals = 10):
+ particle_type=False, decimals = 10):
super(FieldValuesTest, self).__init__(ds_fn)
self.obj_type = obj_type
self.field = field
+ self.particle_type = particle_type
self.decimals = decimals
def run(self):
obj = create_obj(self.ds, self.obj_type)
+ if self.particle_type:
+ weight_field = "particle_ones"
+ else:
+ weight_field = "ones"
avg = obj.quantities.weighted_average_quantity(
- self.field, weight="ones")
+ self.field, weight=weight_field)
mi, ma = obj.quantities.extrema(self.field)
return np.array([avg, mi, ma])
@@ -727,7 +752,18 @@
def compare(self, new_result, old_result):
compare_image_lists(new_result, old_result, self.decimals)
-
+def requires_sim(sim_fn, sim_type, big_data = False, file_check = False):
+ def ffalse(func):
+ return lambda: None
+ def ftrue(func):
+ return func
+ if run_big_data == False and big_data == True:
+ return ffalse
+ elif not can_run_sim(sim_fn, sim_type, file_check):
+ return ffalse
+ else:
+ return ftrue
+
def requires_ds(ds_fn, big_data = False, file_check = False):
def ffalse(func):
return lambda: None
https://bitbucket.org/yt_analysis/yt/commits/fd74535237ec/
Changeset: fd74535237ec
Branch: yt
User: brittonsmith
Date: 2014-11-06 23:09:09+00:00
Summary: Undoing last change and fixing units of virial radius in test dataset.
Affected #: 2 files
diff -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 -r fd74535237ec4f243f87aeda790ec246e780b292 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -159,8 +159,6 @@
self.field_parameters[parameter]
def apply_units(self, arr, units):
- if hasattr(arr, "units"):
- return self.ds.arr(arr.in_units(units), input_units = units)
return self.ds.arr(arr, input_units = units)
def _set_center(self, center):
diff -r 4108392ee5309e0b1b3c9645057f09a7855d6ab0 -r fd74535237ec4f243f87aeda790ec246e780b292 yt/fields/tests/test_fields.py
--- a/yt/fields/tests/test_fields.py
+++ b/yt/fields/tests/test_fields.py
@@ -43,7 +43,7 @@
omega_baryon = 0.04,
observer_redshift = 0.0,
source_redshift = 3.0,
- virial_radius = YTQuantity(1.0, "Mpc"),
+ virial_radius = YTQuantity(1.0, "cm"),
)
_base_fields = (("gas", "density"),
https://bitbucket.org/yt_analysis/yt/commits/adfb3f2495f5/
Changeset: adfb3f2495f5
Branch: yt
User: brittonsmith
Date: 2014-11-06 23:09:51+00:00
Summary: Merging.
Affected #: 13 files
diff -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 -r adfb3f2495f57db95efabb02079cd356f901a85d yt/analysis_modules/halo_analysis/api.py
--- a/yt/analysis_modules/halo_analysis/api.py
+++ b/yt/analysis_modules/halo_analysis/api.py
@@ -28,5 +28,3 @@
from .halo_quantities import \
add_quantity
-
-from . import fields
diff -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 -r adfb3f2495f57db95efabb02079cd356f901a85d yt/analysis_modules/halo_analysis/fields.py
--- a/yt/analysis_modules/halo_analysis/fields.py
+++ /dev/null
@@ -1,41 +0,0 @@
-"""
-Cosmology related fields.
-
-
-
-
-"""
-
-#-----------------------------------------------------------------------------
-# Copyright (c) 2014, yt Development Team.
-#
-# Distributed under the terms of the Modified BSD License.
-#
-# The full license is in the file COPYING.txt, distributed with this software.
-#-----------------------------------------------------------------------------
-
-from yt.fields.field_plugin_registry import \
- register_field_plugin
-
- at register_field_plugin
-def setup_halo_analysis_fields(registry, ftype = "gas", slice_info = None):
- # slice_info would be the left, the right, and the factor.
- # For example, with the old Enzo-ZEUS fields, this would be:
- # slice(None, -2, None)
- # slice(1, -1, None)
- # 1.0
- # Otherwise, we default to a centered difference.
- if slice_info is None:
- sl_left = slice(None, -2, None)
- sl_right = slice(2, None, None)
- div_fac = 2.0
- else:
- sl_left, sl_right, div_fac = slice_info
-
- def _virial_radius(field, data):
- virial_radius = data.get_field_parameter("virial_radius")
- return data["radius"] / virial_radius
-
- registry.add_field(("index", "virial_radius"),
- function=_virial_radius,
- units="")
diff -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 -r adfb3f2495f57db95efabb02079cd356f901a85d yt/analysis_modules/halo_analysis/tests/run_halo_finder.py
--- /dev/null
+++ b/yt/analysis_modules/halo_analysis/tests/run_halo_finder.py
@@ -0,0 +1,32 @@
+from mpi4py import MPI
+import os
+import sys
+import yt
+from yt.analysis_modules.halo_analysis.api import \
+ HaloCatalog
+from yt.data_objects.particle_filters import \
+ particle_filter
+yt.enable_parallelism()
+
+method = sys.argv[1]
+comm = MPI.Comm.Get_parent()
+
+methods = {"fof": {}, "hop": {},
+ "rockstar": {"num_readers":1,
+ "num_writers":1,
+ "particle_type":"dark_matter"}}
+
+ at particle_filter("dark_matter", requires=["creation_time"])
+def _dm_filter(pfilter, data):
+ return data["creation_time"] <= 0.0
+
+ds = yt.load("Enzo_64/DD0043/data0043")
+ds.add_particle_filter("dark_matter")
+
+output_dir = os.path.join(os.path.dirname(__file__),
+ "halo_catalogs", method)
+hc = HaloCatalog(data_ds=ds, output_dir=output_dir,
+ finder_method=method, finder_kwargs=methods[method])
+hc.create()
+
+comm.Disconnect()
diff -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 -r adfb3f2495f57db95efabb02079cd356f901a85d yt/analysis_modules/halo_analysis/tests/test_halo_finders.py
--- /dev/null
+++ b/yt/analysis_modules/halo_analysis/tests/test_halo_finders.py
@@ -0,0 +1,36 @@
+import os
+import sys
+
+from yt.analysis_modules.halo_analysis.api import \
+ HaloCatalog
+from yt.convenience import load
+from yt.testing import *
+from yt.utilities.answer_testing.framework import \
+ FieldValuesTest, \
+ requires_ds
+
+_fields = (("halos", "particle_position_x"),
+ ("halos", "particle_position_y"),
+ ("halos", "particle_position_z"),
+ ("halos", "particle_mass"))
+
+methods = {"fof": 2, "hop": 2, "rockstar": 3}
+
+e64 = "Enzo_64/DD0043/data0043"
+ at requires_ds(e64, big_data=True)
+def test_halo_finders():
+ from mpi4py import MPI
+ filename = os.path.join(os.path.dirname(__file__),
+ "run_halo_finder.py")
+ for method in methods:
+ comm = MPI.COMM_SELF.Spawn(sys.executable,
+ args=[filename, method],
+ maxprocs=methods[method])
+ comm.Disconnect()
+
+ fn = os.path.join(os.path.dirname(__file__),
+ "halo_catalogs", method,
+ "%s.0.h5" % method)
+ ds = load(fn)
+ for field in _fields:
+ yield FieldValuesTest(ds, field, particle_type=True)
diff -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 -r adfb3f2495f57db95efabb02079cd356f901a85d yt/analysis_modules/halo_finding/tests/run_rockstar.py
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/tests/run_rockstar.py
@@ -0,0 +1,26 @@
+from mpi4py import MPI
+import yt
+from yt.analysis_modules.halo_finding.rockstar.api import \
+ RockstarHaloFinder
+from yt.data_objects.particle_filters import \
+ particle_filter
+yt.enable_parallelism()
+
+comm = MPI.Comm.Get_parent()
+
+ at particle_filter("dark_matter", requires=["creation_time"])
+def _dm_filter(pfilter, data):
+ return data["creation_time"] <= 0.0
+
+def setup_ds(ds):
+ ds.add_particle_filter("dark_matter")
+
+es = yt.simulation("Enzo_64/64.param", "Enzo")
+es.get_time_series(setup_function=setup_ds,
+ redshifts=[1., 0.])
+
+rh = RockstarHaloFinder(es, num_readers=1, num_writers=1,
+ particle_type="dark_matter")
+rh.run()
+
+comm.Disconnect()
diff -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 -r adfb3f2495f57db95efabb02079cd356f901a85d yt/analysis_modules/halo_finding/tests/test_rockstar.py
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/tests/test_rockstar.py
@@ -0,0 +1,32 @@
+import os
+import sys
+
+from yt.convenience import load
+from yt.testing import *
+from yt.utilities.answer_testing.framework import \
+ FieldValuesTest, \
+ requires_sim
+
+_fields = (("halos", "particle_position_x"),
+ ("halos", "particle_position_y"),
+ ("halos", "particle_position_z"),
+ ("halos", "particle_mass"))
+
+ at requires_sim("Enzo_64/64.param", "Enzo", big_data=True)
+def test_rockstar():
+ from mpi4py import MPI
+ filename = os.path.join(os.path.dirname(__file__),
+ "run_rockstar.py")
+ comm = MPI.COMM_SELF.Spawn(sys.executable,
+ args=[filename],
+ maxprocs=3)
+ comm.Disconnect()
+
+ h1 = "rockstar_halos/halos_0.0.bin"
+ d1 = load(h1)
+ for field in _fields:
+ yield FieldValuesTest(d1, field, particle_type=True)
+ h2 = "rockstar_halos/halos_1.0.bin"
+ d2 = load(h2)
+ for field in _fields:
+ yield FieldValuesTest(d2, field, particle_type=True)
diff -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 -r adfb3f2495f57db95efabb02079cd356f901a85d yt/fields/cosmology_fields.py
--- a/yt/fields/cosmology_fields.py
+++ b/yt/fields/cosmology_fields.py
@@ -106,6 +106,16 @@
registry.add_field((ftype, "matter_overdensity"),
function=_matter_overdensity,
units="")
+
+ # r / r_vir
+ def _virial_radius_fraction(field, data):
+ virial_radius = data.get_field_parameter("virial_radius")
+ return data["radius"] / virial_radius
+
+ registry.add_field(("index", "virial_radius_fraction"),
+ function=_virial_radius_fraction,
+ validators=[ValidateParameter("virial_radius")],
+ units="")
# Weak lensing convergence.
# Eqn 4 of Metzler, White, & Loken (2001, ApJ, 547, 560).
diff -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 -r adfb3f2495f57db95efabb02079cd356f901a85d yt/fields/tests/test_fields.py
--- a/yt/fields/tests/test_fields.py
+++ b/yt/fields/tests/test_fields.py
@@ -6,7 +6,8 @@
mpc_conversion, sec_conversion
from yt.frontends.stream.fields import \
StreamFieldInfo
-from yt.units.yt_array import YTArray
+from yt.units.yt_array import \
+ YTArray, YTQuantity
def setup():
global base_ds
@@ -42,6 +43,7 @@
omega_baryon = 0.04,
observer_redshift = 0.0,
source_redshift = 3.0,
+ virial_radius = YTQuantity(1.0, "cm"),
)
_base_fields = (("gas", "density"),
diff -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 -r adfb3f2495f57db95efabb02079cd356f901a85d yt/frontends/owls_subfind/tests/test_outputs.py
--- a/yt/frontends/owls_subfind/tests/test_outputs.py
+++ b/yt/frontends/owls_subfind/tests/test_outputs.py
@@ -28,7 +28,7 @@
ds = data_dir_load(g8)
yield assert_equal, str(ds), "group_008.0.hdf5"
for field in _fields:
- yield FieldValuesTest(g8, field)
+ yield FieldValuesTest(g8, field, particle_type=True)
# a dataset with empty files
g3 = "owls_fof_halos/groups_003/group_003.0.hdf5"
@@ -37,4 +37,4 @@
ds = data_dir_load(g3)
yield assert_equal, str(ds), "group_003.0.hdf5"
for field in _fields:
- yield FieldValuesTest(g3, field)
+ yield FieldValuesTest(g3, field, particle_type=True)
diff -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 -r adfb3f2495f57db95efabb02079cd356f901a85d yt/utilities/answer_testing/framework.py
--- a/yt/utilities/answer_testing/framework.py
+++ b/yt/utilities/answer_testing/framework.py
@@ -32,6 +32,7 @@
from yt.convenience import load, simulation
from yt.config import ytcfg
from yt.data_objects.static_output import Dataset
+from yt.data_objects.time_series import SimulationTimeSeries
from yt.utilities.logger import disable_stream_logging
from yt.utilities.command_line import get_yt_version
@@ -259,6 +260,22 @@
return False
return AnswerTestingTest.result_storage is not None
+def can_run_sim(sim_fn, sim_type, file_check = False):
+ if isinstance(sim_fn, SimulationTimeSeries):
+ return AnswerTestingTest.result_storage is not None
+ path = ytcfg.get("yt", "test_data_dir")
+ if not os.path.isdir(path):
+ return False
+ with temp_cwd(path):
+ if file_check:
+ return os.path.isfile(sim_fn) and \
+ AnswerTestingTest.result_storage is not None
+ try:
+ simulation(sim_fn, sim_type)
+ except YTOutputNotIdentified:
+ return False
+ return AnswerTestingTest.result_storage is not None
+
def data_dir_load(ds_fn, cls = None, args = None, kwargs = None):
path = ytcfg.get("yt", "test_data_dir")
if isinstance(ds_fn, Dataset): return ds_fn
@@ -289,7 +306,10 @@
result_storage = None
prefix = ""
def __init__(self, ds_fn):
- self.ds = data_dir_load(ds_fn)
+ if isinstance(ds_fn, Dataset):
+ self.ds = ds_fn
+ else:
+ self.ds = data_dir_load(ds_fn)
def __call__(self):
nv = self.run()
@@ -360,16 +380,21 @@
_attrs = ("field", )
def __init__(self, ds_fn, field, obj_type = None,
- decimals = 10):
+ particle_type=False, decimals = 10):
super(FieldValuesTest, self).__init__(ds_fn)
self.obj_type = obj_type
self.field = field
+ self.particle_type = particle_type
self.decimals = decimals
def run(self):
obj = create_obj(self.ds, self.obj_type)
+ if self.particle_type:
+ weight_field = "particle_ones"
+ else:
+ weight_field = "ones"
avg = obj.quantities.weighted_average_quantity(
- self.field, weight="ones")
+ self.field, weight=weight_field)
mi, ma = obj.quantities.extrema(self.field)
return np.array([avg, mi, ma])
@@ -727,7 +752,18 @@
def compare(self, new_result, old_result):
compare_image_lists(new_result, old_result, self.decimals)
-
+def requires_sim(sim_fn, sim_type, big_data = False, file_check = False):
+ def ffalse(func):
+ return lambda: None
+ def ftrue(func):
+ return func
+ if run_big_data == False and big_data == True:
+ return ffalse
+ elif not can_run_sim(sim_fn, sim_type, file_check):
+ return ffalse
+ else:
+ return ftrue
+
def requires_ds(ds_fn, big_data = False, file_check = False):
def ffalse(func):
return lambda: None
https://bitbucket.org/yt_analysis/yt/commits/bd7fefdb52b1/
Changeset: bd7fefdb52b1
Branch: yt
User: brittonsmith
Date: 2014-11-07 10:46:33+00:00
Summary: Merging.
Affected #: 1 file
diff -r adfb3f2495f57db95efabb02079cd356f901a85d -r bd7fefdb52b1301930ba7a2e242dc7f199ff8b18 yt/frontends/api.py
--- a/yt/frontends/api.py
+++ b/yt/frontends/api.py
@@ -33,6 +33,7 @@
'owls',
#'pluto',
'ramses',
+ 'rockstar',
'sdf',
'stream',
'tipsy',
https://bitbucket.org/yt_analysis/yt/commits/9b001e77ba55/
Changeset: 9b001e77ba55
Branch: yt
User: brittonsmith
Date: 2014-11-07 16:50:49+00:00
Summary: Fixing field name in recipe.
Affected #: 1 file
diff -r bd7fefdb52b1301930ba7a2e242dc7f199ff8b18 -r 9b001e77ba55d4183d45395ba2ce949546577873 doc/source/cookbook/halo_profiler.py
--- a/doc/source/cookbook/halo_profiler.py
+++ b/doc/source/cookbook/halo_profiler.py
@@ -32,7 +32,7 @@
field_params = dict(virial_radius=('quantity', 'radius_200'))
hc.add_callback('sphere', radius_field='radius_200', factor=5,
field_parameters=field_params)
-hc.add_callback('profile', ['virial_radius'],
+hc.add_callback('profile', ['virial_radius_fraction'],
[('gas', 'temperature')],
storage='virial_profiles',
weight_field='cell_mass',
https://bitbucket.org/yt_analysis/yt/commits/9153a5a32dce/
Changeset: 9153a5a32dce
Branch: yt
User: xarthisius
Date: 2014-11-07 20:37:03+00:00
Summary: Merged in brittonsmith/yt (pull request #1253)
Adding answer tests for halo finders.
Affected #: 14 files
diff -r 842c2af2225c100e6f869bb50337ca89a141c2a6 -r 9153a5a32dce19164cc66f8073a26d460aa74cbe doc/source/cookbook/halo_profiler.py
--- a/doc/source/cookbook/halo_profiler.py
+++ b/doc/source/cookbook/halo_profiler.py
@@ -32,7 +32,7 @@
field_params = dict(virial_radius=('quantity', 'radius_200'))
hc.add_callback('sphere', radius_field='radius_200', factor=5,
field_parameters=field_params)
-hc.add_callback('profile', ['virial_radius'],
+hc.add_callback('profile', ['virial_radius_fraction'],
[('gas', 'temperature')],
storage='virial_profiles',
weight_field='cell_mass',
diff -r 842c2af2225c100e6f869bb50337ca89a141c2a6 -r 9153a5a32dce19164cc66f8073a26d460aa74cbe yt/analysis_modules/halo_analysis/api.py
--- a/yt/analysis_modules/halo_analysis/api.py
+++ b/yt/analysis_modules/halo_analysis/api.py
@@ -28,5 +28,3 @@
from .halo_quantities import \
add_quantity
-
-from . import fields
diff -r 842c2af2225c100e6f869bb50337ca89a141c2a6 -r 9153a5a32dce19164cc66f8073a26d460aa74cbe yt/analysis_modules/halo_analysis/fields.py
--- a/yt/analysis_modules/halo_analysis/fields.py
+++ /dev/null
@@ -1,41 +0,0 @@
-"""
-Cosmology related fields.
-
-
-
-
-"""
-
-#-----------------------------------------------------------------------------
-# Copyright (c) 2014, yt Development Team.
-#
-# Distributed under the terms of the Modified BSD License.
-#
-# The full license is in the file COPYING.txt, distributed with this software.
-#-----------------------------------------------------------------------------
-
-from yt.fields.field_plugin_registry import \
- register_field_plugin
-
- at register_field_plugin
-def setup_halo_analysis_fields(registry, ftype = "gas", slice_info = None):
- # slice_info would be the left, the right, and the factor.
- # For example, with the old Enzo-ZEUS fields, this would be:
- # slice(None, -2, None)
- # slice(1, -1, None)
- # 1.0
- # Otherwise, we default to a centered difference.
- if slice_info is None:
- sl_left = slice(None, -2, None)
- sl_right = slice(2, None, None)
- div_fac = 2.0
- else:
- sl_left, sl_right, div_fac = slice_info
-
- def _virial_radius(field, data):
- virial_radius = data.get_field_parameter("virial_radius")
- return data["radius"] / virial_radius
-
- registry.add_field(("index", "virial_radius"),
- function=_virial_radius,
- units="")
diff -r 842c2af2225c100e6f869bb50337ca89a141c2a6 -r 9153a5a32dce19164cc66f8073a26d460aa74cbe yt/analysis_modules/halo_analysis/tests/run_halo_finder.py
--- /dev/null
+++ b/yt/analysis_modules/halo_analysis/tests/run_halo_finder.py
@@ -0,0 +1,32 @@
+from mpi4py import MPI
+import os
+import sys
+import yt
+from yt.analysis_modules.halo_analysis.api import \
+ HaloCatalog
+from yt.data_objects.particle_filters import \
+ particle_filter
+yt.enable_parallelism()
+
+method = sys.argv[1]
+comm = MPI.Comm.Get_parent()
+
+methods = {"fof": {}, "hop": {},
+ "rockstar": {"num_readers":1,
+ "num_writers":1,
+ "particle_type":"dark_matter"}}
+
+ at particle_filter("dark_matter", requires=["creation_time"])
+def _dm_filter(pfilter, data):
+ return data["creation_time"] <= 0.0
+
+ds = yt.load("Enzo_64/DD0043/data0043")
+ds.add_particle_filter("dark_matter")
+
+output_dir = os.path.join(os.path.dirname(__file__),
+ "halo_catalogs", method)
+hc = HaloCatalog(data_ds=ds, output_dir=output_dir,
+ finder_method=method, finder_kwargs=methods[method])
+hc.create()
+
+comm.Disconnect()
diff -r 842c2af2225c100e6f869bb50337ca89a141c2a6 -r 9153a5a32dce19164cc66f8073a26d460aa74cbe yt/analysis_modules/halo_analysis/tests/test_halo_finders.py
--- /dev/null
+++ b/yt/analysis_modules/halo_analysis/tests/test_halo_finders.py
@@ -0,0 +1,36 @@
+import os
+import sys
+
+from yt.analysis_modules.halo_analysis.api import \
+ HaloCatalog
+from yt.convenience import load
+from yt.testing import *
+from yt.utilities.answer_testing.framework import \
+ FieldValuesTest, \
+ requires_ds
+
+_fields = (("halos", "particle_position_x"),
+ ("halos", "particle_position_y"),
+ ("halos", "particle_position_z"),
+ ("halos", "particle_mass"))
+
+methods = {"fof": 2, "hop": 2, "rockstar": 3}
+
+e64 = "Enzo_64/DD0043/data0043"
+ at requires_ds(e64, big_data=True)
+def test_halo_finders():
+ from mpi4py import MPI
+ filename = os.path.join(os.path.dirname(__file__),
+ "run_halo_finder.py")
+ for method in methods:
+ comm = MPI.COMM_SELF.Spawn(sys.executable,
+ args=[filename, method],
+ maxprocs=methods[method])
+ comm.Disconnect()
+
+ fn = os.path.join(os.path.dirname(__file__),
+ "halo_catalogs", method,
+ "%s.0.h5" % method)
+ ds = load(fn)
+ for field in _fields:
+ yield FieldValuesTest(ds, field, particle_type=True)
diff -r 842c2af2225c100e6f869bb50337ca89a141c2a6 -r 9153a5a32dce19164cc66f8073a26d460aa74cbe yt/analysis_modules/halo_finding/tests/run_rockstar.py
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/tests/run_rockstar.py
@@ -0,0 +1,26 @@
+from mpi4py import MPI
+import yt
+from yt.analysis_modules.halo_finding.rockstar.api import \
+ RockstarHaloFinder
+from yt.data_objects.particle_filters import \
+ particle_filter
+yt.enable_parallelism()
+
+comm = MPI.Comm.Get_parent()
+
+ at particle_filter("dark_matter", requires=["creation_time"])
+def _dm_filter(pfilter, data):
+ return data["creation_time"] <= 0.0
+
+def setup_ds(ds):
+ ds.add_particle_filter("dark_matter")
+
+es = yt.simulation("Enzo_64/64.param", "Enzo")
+es.get_time_series(setup_function=setup_ds,
+ redshifts=[1., 0.])
+
+rh = RockstarHaloFinder(es, num_readers=1, num_writers=1,
+ particle_type="dark_matter")
+rh.run()
+
+comm.Disconnect()
diff -r 842c2af2225c100e6f869bb50337ca89a141c2a6 -r 9153a5a32dce19164cc66f8073a26d460aa74cbe yt/analysis_modules/halo_finding/tests/test_rockstar.py
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/tests/test_rockstar.py
@@ -0,0 +1,32 @@
+import os
+import sys
+
+from yt.convenience import load
+from yt.testing import *
+from yt.utilities.answer_testing.framework import \
+ FieldValuesTest, \
+ requires_sim
+
+_fields = (("halos", "particle_position_x"),
+ ("halos", "particle_position_y"),
+ ("halos", "particle_position_z"),
+ ("halos", "particle_mass"))
+
+ at requires_sim("Enzo_64/64.param", "Enzo", big_data=True)
+def test_rockstar():
+ from mpi4py import MPI
+ filename = os.path.join(os.path.dirname(__file__),
+ "run_rockstar.py")
+ comm = MPI.COMM_SELF.Spawn(sys.executable,
+ args=[filename],
+ maxprocs=3)
+ comm.Disconnect()
+
+ h1 = "rockstar_halos/halos_0.0.bin"
+ d1 = load(h1)
+ for field in _fields:
+ yield FieldValuesTest(d1, field, particle_type=True)
+ h2 = "rockstar_halos/halos_1.0.bin"
+ d2 = load(h2)
+ for field in _fields:
+ yield FieldValuesTest(d2, field, particle_type=True)
diff -r 842c2af2225c100e6f869bb50337ca89a141c2a6 -r 9153a5a32dce19164cc66f8073a26d460aa74cbe yt/fields/cosmology_fields.py
--- a/yt/fields/cosmology_fields.py
+++ b/yt/fields/cosmology_fields.py
@@ -106,6 +106,16 @@
registry.add_field((ftype, "matter_overdensity"),
function=_matter_overdensity,
units="")
+
+ # r / r_vir
+ def _virial_radius_fraction(field, data):
+ virial_radius = data.get_field_parameter("virial_radius")
+ return data["radius"] / virial_radius
+
+ registry.add_field(("index", "virial_radius_fraction"),
+ function=_virial_radius_fraction,
+ validators=[ValidateParameter("virial_radius")],
+ units="")
# Weak lensing convergence.
# Eqn 4 of Metzler, White, & Loken (2001, ApJ, 547, 560).
diff -r 842c2af2225c100e6f869bb50337ca89a141c2a6 -r 9153a5a32dce19164cc66f8073a26d460aa74cbe yt/fields/tests/test_fields.py
--- a/yt/fields/tests/test_fields.py
+++ b/yt/fields/tests/test_fields.py
@@ -6,7 +6,8 @@
mpc_conversion, sec_conversion
from yt.frontends.stream.fields import \
StreamFieldInfo
-from yt.units.yt_array import YTArray
+from yt.units.yt_array import \
+ YTArray, YTQuantity
def setup():
global base_ds
@@ -42,6 +43,7 @@
omega_baryon = 0.04,
observer_redshift = 0.0,
source_redshift = 3.0,
+ virial_radius = YTQuantity(1.0, "cm"),
)
_base_fields = (("gas", "density"),
diff -r 842c2af2225c100e6f869bb50337ca89a141c2a6 -r 9153a5a32dce19164cc66f8073a26d460aa74cbe yt/frontends/owls_subfind/tests/test_outputs.py
--- a/yt/frontends/owls_subfind/tests/test_outputs.py
+++ b/yt/frontends/owls_subfind/tests/test_outputs.py
@@ -28,7 +28,7 @@
ds = data_dir_load(g8)
yield assert_equal, str(ds), "group_008.0.hdf5"
for field in _fields:
- yield FieldValuesTest(g8, field)
+ yield FieldValuesTest(g8, field, particle_type=True)
# a dataset with empty files
g3 = "owls_fof_halos/groups_003/group_003.0.hdf5"
@@ -37,4 +37,4 @@
ds = data_dir_load(g3)
yield assert_equal, str(ds), "group_003.0.hdf5"
for field in _fields:
- yield FieldValuesTest(g3, field)
+ yield FieldValuesTest(g3, field, particle_type=True)
diff -r 842c2af2225c100e6f869bb50337ca89a141c2a6 -r 9153a5a32dce19164cc66f8073a26d460aa74cbe yt/utilities/answer_testing/framework.py
--- a/yt/utilities/answer_testing/framework.py
+++ b/yt/utilities/answer_testing/framework.py
@@ -32,6 +32,7 @@
from yt.convenience import load, simulation
from yt.config import ytcfg
from yt.data_objects.static_output import Dataset
+from yt.data_objects.time_series import SimulationTimeSeries
from yt.utilities.logger import disable_stream_logging
from yt.utilities.command_line import get_yt_version
@@ -259,6 +260,22 @@
return False
return AnswerTestingTest.result_storage is not None
+def can_run_sim(sim_fn, sim_type, file_check = False):
+ if isinstance(sim_fn, SimulationTimeSeries):
+ return AnswerTestingTest.result_storage is not None
+ path = ytcfg.get("yt", "test_data_dir")
+ if not os.path.isdir(path):
+ return False
+ with temp_cwd(path):
+ if file_check:
+ return os.path.isfile(sim_fn) and \
+ AnswerTestingTest.result_storage is not None
+ try:
+ simulation(sim_fn, sim_type)
+ except YTOutputNotIdentified:
+ return False
+ return AnswerTestingTest.result_storage is not None
+
def data_dir_load(ds_fn, cls = None, args = None, kwargs = None):
path = ytcfg.get("yt", "test_data_dir")
if isinstance(ds_fn, Dataset): return ds_fn
@@ -289,7 +306,10 @@
result_storage = None
prefix = ""
def __init__(self, ds_fn):
- self.ds = data_dir_load(ds_fn)
+ if isinstance(ds_fn, Dataset):
+ self.ds = ds_fn
+ else:
+ self.ds = data_dir_load(ds_fn)
def __call__(self):
nv = self.run()
@@ -360,16 +380,21 @@
_attrs = ("field", )
def __init__(self, ds_fn, field, obj_type = None,
- decimals = 10):
+ particle_type=False, decimals = 10):
super(FieldValuesTest, self).__init__(ds_fn)
self.obj_type = obj_type
self.field = field
+ self.particle_type = particle_type
self.decimals = decimals
def run(self):
obj = create_obj(self.ds, self.obj_type)
+ if self.particle_type:
+ weight_field = "particle_ones"
+ else:
+ weight_field = "ones"
avg = obj.quantities.weighted_average_quantity(
- self.field, weight="ones")
+ self.field, weight=weight_field)
mi, ma = obj.quantities.extrema(self.field)
return np.array([avg, mi, ma])
@@ -727,7 +752,18 @@
def compare(self, new_result, old_result):
compare_image_lists(new_result, old_result, self.decimals)
-
+def requires_sim(sim_fn, sim_type, big_data = False, file_check = False):
+ def ffalse(func):
+ return lambda: None
+ def ftrue(func):
+ return func
+ if run_big_data == False and big_data == True:
+ return ffalse
+ elif not can_run_sim(sim_fn, sim_type, file_check):
+ return ffalse
+ else:
+ return ftrue
+
def requires_ds(ds_fn, big_data = False, file_check = False):
def ffalse(func):
return lambda: None
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