[yt-svn] commit/yt: ngoldbaum: Merged in chummels/yt (pull request #2303)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Sun Jul 24 08:28:22 PDT 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/585aa2c18066/
Changeset: 585aa2c18066
Branch: yt
User: ngoldbaum
Date: 2016-07-24 15:27:52+00:00
Summary: Merged in chummels/yt (pull request #2303)
[bugfix] Re-enabling compound LightRays with gadget frontend. Closes #1251
Affected #: 3 files
diff -r 119f0e32709181f5fc5606a85abdd208c3a5e14e -r 585aa2c180666410619882922d795ea09cc05dc3 tests/tests.yaml
--- a/tests/tests.yaml
+++ b/tests/tests.yaml
@@ -67,9 +67,11 @@
local_ytdata_000:
- yt/frontends/ytdata
- local_absorption_spectrum_000:
+ local_absorption_spectrum_001:
- yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py:test_absorption_spectrum_non_cosmo
- yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py:test_absorption_spectrum_cosmo
+ - yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py:test_absorption_spectrum_non_cosmo_sph
+ - yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py:test_absorption_spectrum_cosmo_sph
other_tests:
unittests:
diff -r 119f0e32709181f5fc5606a85abdd208c3a5e14e -r 585aa2c180666410619882922d795ea09cc05dc3 yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py
--- a/yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py
+++ b/yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py
@@ -26,17 +26,21 @@
import shutil
from yt.utilities.on_demand_imports import \
_h5py as h5
+from yt.convenience import load
COSMO_PLUS = "enzo_cosmology_plus/AMRCosmology.enzo"
COSMO_PLUS_SINGLE = "enzo_cosmology_plus/RD0009/RD0009"
+GIZMO_PLUS = "gizmo_cosmology_plus/N128L16.param"
+GIZMO_PLUS_SINGLE = "gizmo_cosmology_plus/snap_N128L16_151.hdf5"
@requires_file(COSMO_PLUS)
@requires_answer_testing()
def test_absorption_spectrum_cosmo():
"""
- This test generates an absorption spectrum from a cosmological light ray
+ This test generates an absorption spectrum from a compound light ray on a
+ grid dataset
"""
# Set up in a temp dir
tmpdir = tempfile.mkdtemp()
@@ -92,7 +96,8 @@
@requires_answer_testing()
def test_absorption_spectrum_non_cosmo():
"""
- This test generates an absorption spectrum from a non-cosmological light ray
+ This test generates an absorption spectrum from a simple light ray on a
+ grid dataset
"""
# Set up in a temp dir
@@ -244,3 +249,114 @@
a = 1.7e-4
x = np.linspace(5.0, -3.6, 60)
yield assert_allclose_units, voigt_old(a, x), voigt_scipy(a, x), 1e-8
+
+ at requires_file(GIZMO_PLUS)
+ at requires_answer_testing()
+def test_absorption_spectrum_cosmo_sph():
+ """
+ This test generates an absorption spectrum from a compound light ray on a
+ particle dataset
+ """
+ # Set up in a temp dir
+ tmpdir = tempfile.mkdtemp()
+ curdir = os.getcwd()
+ os.chdir(tmpdir)
+
+ lr = LightRay(GIZMO_PLUS, 'Gadget', 0.0, 0.01)
+
+ lr.make_light_ray(seed=1234567,
+ fields=[('gas', 'temperature'),
+ ('gas', 'H_number_density')],
+ data_filename='lightray.h5')
+
+ sp = AbsorptionSpectrum(900.0, 1800.0, 10000)
+
+ my_label = 'HI Lya'
+ field = ('gas', 'H_number_density')
+ wavelength = 1215.6700 # Angstromss
+ f_value = 4.164E-01
+ gamma = 6.265e+08
+ mass = 1.00794
+
+ sp.add_line(my_label, field, wavelength, f_value,
+ gamma, mass, label_threshold=1.e10)
+
+ my_label = 'HI Lya'
+ field = ('gas', 'H_number_density')
+ wavelength = 912.323660 # Angstroms
+ normalization = 1.6e17
+ index = 3.0
+
+ sp.add_continuum(my_label, field, wavelength, normalization, index)
+
+ wavelength, flux = sp.make_spectrum('lightray.h5',
+ output_file='spectrum.h5',
+ line_list_file='lines.txt',
+ use_peculiar_velocity=True)
+
+ # load just-generated hdf5 file of spectral data (for consistency)
+ data = h5.File('spectrum.h5', 'r')
+
+ for key in data.keys():
+ func = lambda x=key: data[x][:]
+ func.__name__ = "{}_cosmo_sph".format(key)
+ test = GenericArrayTest(None, func)
+ test_absorption_spectrum_cosmo_sph.__name__ = test.description
+ yield test
+
+ # clean up
+ os.chdir(curdir)
+ shutil.rmtree(tmpdir)
+
+ at requires_file(GIZMO_PLUS_SINGLE)
+ at requires_answer_testing()
+def test_absorption_spectrum_non_cosmo_sph():
+ """
+ This test generates an absorption spectrum from a simple light ray on a
+ particle dataset
+ """
+
+ # Set up in a temp dir
+ tmpdir = tempfile.mkdtemp()
+ curdir = os.getcwd()
+ os.chdir(tmpdir)
+
+ ds = load(GIZMO_PLUS_SINGLE)
+ lr = LightRay(ds)
+ ray_start = ds.domain_left_edge
+ ray_end = ds.domain_right_edge
+ lr.make_light_ray(start_position=ray_start, end_position=ray_end,
+ fields=[('gas', 'temperature'),
+ ('gas', 'H_number_density')],
+ data_filename='lightray.h5')
+
+ sp = AbsorptionSpectrum(1200.0, 1300.0, 10001)
+
+ my_label = 'HI Lya'
+ field = ('gas', 'H_number_density')
+ wavelength = 1215.6700 # Angstromss
+ f_value = 4.164E-01
+ gamma = 6.265e+08
+ mass = 1.00794
+
+ sp.add_line(my_label, field, wavelength, f_value,
+ gamma, mass, label_threshold=1.e10)
+
+ wavelength, flux = sp.make_spectrum('lightray.h5',
+ output_file='spectrum.h5',
+ line_list_file='lines.txt',
+ use_peculiar_velocity=True)
+
+ # load just-generated hdf5 file of spectral data (for consistency)
+ data = h5.File('spectrum.h5', 'r')
+
+ for key in data.keys():
+ func = lambda x=key: data[x][:]
+ func.__name__ = "{}_non_cosmo_sph".format(key)
+ test = GenericArrayTest(None, func)
+ test_absorption_spectrum_non_cosmo_sph.__name__ = test.description
+ yield test
+
+ # clean up
+ os.chdir(curdir)
+ shutil.rmtree(tmpdir)
diff -r 119f0e32709181f5fc5606a85abdd208c3a5e14e -r 585aa2c180666410619882922d795ea09cc05dc3 yt/frontends/gadget/simulation_handling.py
--- a/yt/frontends/gadget/simulation_handling.py
+++ b/yt/frontends/gadget/simulation_handling.py
@@ -97,7 +97,11 @@
dimensions.length, "\\rm{%s}/(1+z)" % my_unit)
self.length_unit = self.quan(self.unit_base["UnitLength_in_cm"],
"cmcm / h", registry=self.unit_registry)
- self.box_size *= self.length_unit.in_units("Mpccm / h")
+ self.mass_unit = self.quan(self.unit_base["UnitMass_in_g"],
+ "g / h", registry=self.unit_registry)
+ self.box_size = self.box_size * self.length_unit
+ self.domain_left_edge = self.domain_left_edge * self.length_unit
+ self.domain_right_edge = self.domain_right_edge * self.length_unit
else:
# Read time from file for non-cosmological sim
self.time_unit = self.quan(
@@ -322,6 +326,9 @@
self.parameters[param] = vals
+ # Domain dimensions for Gadget datasets are always 2x2x2 for octree
+ self.domain_dimensions = np.array([2,2,2])
+
if self.parameters["ComovingIntegrationOn"]:
cosmo_attr = {"box_size": "BoxSize",
"omega_lambda": "OmegaLambda",
@@ -334,22 +341,36 @@
if v not in self.parameters:
raise MissingParameter(self.parameter_filename, v)
setattr(self, a, self.parameters[v])
+ self.domain_left_edge = np.array([0., 0., 0.])
+ self.domain_right_edge = np.array([1., 1., 1.]) * self.parameters['BoxSize']
else:
self.cosmological_simulation = 0
self.omega_lambda = self.omega_matter = \
self.hubble_constant = 0.0
+ def _find_data_dir(self):
+ """
+ Find proper location for datasets. First look where parameter file
+ points, but if this doesn't exist then default to the current
+ directory.
+ """
+ if self.parameters["OutputDir"].startswith("/"):
+ data_dir = self.parameters["OutputDir"]
+ else:
+ data_dir = os.path.join(self.directory,
+ self.parameters["OutputDir"])
+ if not os.path.exists(data_dir):
+ mylog.info("OutputDir not found at %s, instead using %s." %
+ (data_dir, self.directory))
+ data_dir = self.directory
+ self.data_dir = data_dir
+
def _snapshot_format(self, index=None):
"""
The snapshot filename for a given index. Modify this for different
naming conventions.
"""
- if self.parameters["OutputDir"].startswith("/"):
- data_dir = self.parameters["OutputDir"]
- else:
- data_dir = os.path.join(self.directory,
- self.parameters["OutputDir"])
if self.parameters["NumFilesPerSnapshot"] > 1:
suffix = ".0"
else:
@@ -362,20 +383,25 @@
count = "%03d" % index
filename = "%s_%s%s" % (self.parameters["SnapshotFileBase"],
count, suffix)
- return os.path.join(data_dir, filename)
+ return os.path.join(self.data_dir, filename)
def _get_all_outputs(self, find_outputs=False):
"""
Get all potential datasets and combine into a time-sorted list.
"""
+ # Find the data directory where the outputs are
+ self._find_data_dir()
+
# Create the set of outputs from which further selection will be done.
if find_outputs:
self._find_outputs()
else:
if self.parameters["OutputListOn"]:
a_values = [float(a) for a in
- open(self.parameters["OutputListFilename"], "r").readlines()]
+ open(os.path.join(self.data_dir,
+ self.parameters["OutputListFilename"]),
+ "r").readlines()]
else:
a_values = [float(self.parameters["TimeOfFirstSnapshot"])]
time_max = float(self.parameters["TimeMax"])
@@ -437,7 +463,6 @@
Search for directories matching the data dump keywords.
If found, get dataset times py opening the ds.
"""
-
potential_outputs = glob.glob(self._snapshot_format())
self.all_outputs = self._check_for_outputs(potential_outputs)
self.all_outputs.sort(key=lambda obj: obj["time"])
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