Skip to content

Commit

Permalink
Merge pull request #95 from trident-project/sph-viz
Browse files Browse the repository at this point in the history
Mergin sph-viz into master
  • Loading branch information
brittonsmith committed Sep 22, 2019
2 parents 494e1d2 + 3d9e4e0 commit ff34a76
Show file tree
Hide file tree
Showing 22 changed files with 236 additions and 549 deletions.
24 changes: 7 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ env:
TRIDENT_ION_DATA=$HOME/.trident
TRIDENT_ANSWER_DATA=$HOME/answer_test_data
TRIDENT_CONFIG=$TRIDENT_ION_DATA/config.tri
YT_GOLD=953248239966
YT_HEAD=master
TRIDENT_GOLD=test-standard-v4
YT_GOLD=4f56c4c9b534106fd45e8dfe644280755236fb5d
YT_HEAD=yt-4.0
TRIDENT_GOLD=test-standard-sph-viz-v3

before_install:
- |
Expand All @@ -44,13 +44,13 @@ install:
pip install --upgrade setuptools
pip install cython scipy
# Install dependencies
# install yt
# install yt-4.0 branch
if [ ! -f $YT_DIR/README.md ]; then
git clone --branch=master https://github.com/yt-project/yt $YT_DIR
git clone --branch=yt-4.0 https://github.com/yt-project/yt $YT_DIR
fi
pushd $YT_DIR
git checkout master
git pull origin master
git checkout $YT_HEAD
git pull origin $YT_HEAD
git checkout $YT_GOLD
pip install -e .
popd
Expand Down Expand Up @@ -103,11 +103,6 @@ script:
jobs:
include:
- stage: tests
name: "tests with Python 2.7 and yt-dev"
python: 2.7
env: YT_VER=$YT_HEAD

- stage: tests
name: "tests with Python 3.5 and yt-dev"
python: 3.5
Expand All @@ -119,11 +114,6 @@ jobs:
env: YT_VER=$YT_HEAD
after_success: coveralls

- stage: tests
name: "tests with Python 2.7 and yt stable"
python: 2.7
env: YT_VER=$YT_GOLD

- stage: tests
name: "tests with Python 3.5 and yt stable"
python: 3.5
Expand Down
1 change: 0 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

from __future__ import absolute_import
import sys
import os
import shlex
Expand Down
9 changes: 4 additions & 5 deletions examples/gizmo_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# Set the dataset filename, load it into yt and define the trajectory
# of the LightRay. This uses the maximum density location as the one end of
# the ray. Define desired spectral features to include # all H, C, N, O, and
# the ray. Define desired spectral features to include all H, C, N, O, and
# Mg lines.
fn = 'FIRE_M12i_ref11/snapshot_600.hdf5'
ds = yt.load(fn)
Expand All @@ -22,15 +22,14 @@
# Make a LightRay object including all necessary fields so you can add
# all H, C, N, O, and Mg fields to the resulting spectrum from your dataset.
# Save LightRay to ray.h5 and use it locally as ray object.
# Note: We use PartType0, the gas particle field type as our ftype!
ray = trident.make_simple_ray(ds, start_position=ray_start,
end_position=ray_end, data_filename='ray.h5',
lines=line_list, ftype='PartType0')
lines=line_list)

# Create a projection of the dataset in density along the x axis,
# overplot the trajectory of the ray, and save it.
# Note that this is using the 'gas' field type, which is the field deposited
# to the grid.
# Note that this is using the 'gas' field type, the field aliased to the
# particle field.
p = yt.ProjectionPlot(ds, 'x', ('gas', 'density'))
p.annotate_ray(ray, arrow=True)
p.save('projection.png')
Expand Down
2 changes: 1 addition & 1 deletion examples/working_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Save LightRay to ray.h5 and use it locally as ray object.
ray = trident.make_simple_ray(ds, start_position=ray_start,
end_position=ray_end, data_filename='ray.h5',
lines=line_list, ftype='gas')
lines=line_list)

# Create a projection of the dataset in density along the x axis,
# overplot the trajectory of the ray, and save it.
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def get_version(filename):
},
install_requires=[
'astropy',
'future',
'h5py',
'matplotlib',
'numpy!=1.14.0',
Expand Down
1 change: 0 additions & 1 deletion tests/gold_standard_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# The full license is in the file LICENSE, distributed with this software.
#-----------------------------------------------------------------------------

from __future__ import print_function
from trident import path as trident_path
import os

Expand Down
2 changes: 0 additions & 2 deletions tests/test_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# The full license is in the file LICENSE, distributed with this software.
#-----------------------------------------------------------------------------

from __future__ import absolute_import
from __future__ import print_function
from trident.instrument import Instrument

def test_instrument():
Expand Down
57 changes: 25 additions & 32 deletions tests/test_ion_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# The full license is in the file LICENSE, distributed with this software.
#-----------------------------------------------------------------------------

from __future__ import absolute_import
from trident.ion_balance import \
add_ion_fraction_field, \
add_ion_number_density_field, \
Expand Down Expand Up @@ -46,10 +45,9 @@ def test_add_ion_fraction_field_to_grid_ds():
"velocity_z", "temperature", "metallicity"),
units= ('g/cm**3', 'cm/s', 'cm/s',
'cm/s', 'K', ''))
ftype = 'stream'
ad = ds.all_data()
add_ion_fraction_field('O', 6, ds, ftype=ftype)
field = ('stream', 'O_p5_ion_fraction')
add_ion_fraction_field('O', 6, ds)
field = ('gas', 'O_p5_ion_fraction')
assert field in ds.derived_field_list
assert isinstance(ad[field], np.ndarray)

Expand All @@ -65,10 +63,9 @@ def test_add_ion_number_density_field_to_grid_ds():
"velocity_z", "temperature", "metallicity"),
units= ('g/cm**3', 'cm/s', 'cm/s',
'cm/s', 'K', ''))
ftype = 'stream'
ad = ds.all_data()
add_ion_mass_field('O', 6, ds, ftype=ftype)
field = ('stream', 'O_p5_number_density')
add_ion_mass_field('O', 6, ds)
field = ('gas', 'O_p5_number_density')
assert field in ds.derived_field_list
assert isinstance(ad[field], np.ndarray)

Expand All @@ -84,10 +81,9 @@ def test_add_ion_density_field_to_grid_ds():
"velocity_z", "temperature", "metallicity"),
units= ('g/cm**3', 'cm/s', 'cm/s',
'cm/s', 'K', ''))
ftype = 'stream'
ad = ds.all_data()
add_ion_mass_field('O', 6, ds, ftype=ftype)
field = ('stream', 'O_p5_density')
add_ion_mass_field('O', 6, ds)
field = ('gas', 'O_p5_density')
assert field in ds.derived_field_list
assert isinstance(ad[field], np.ndarray)

Expand All @@ -103,10 +99,9 @@ def test_add_ion_mass_field_to_grid_ds():
"velocity_z", "temperature", "metallicity"),
units= ('g/cm**3', 'cm/s', 'cm/s',
'cm/s', 'K', ''))
ftype = 'stream'
ad = ds.all_data()
add_ion_mass_field('O', 6, ds, ftype=ftype)
field = ('stream', 'O_p5_mass')
add_ion_mass_field('O', 6, ds, ftype='gas')
field = ('gas', 'O_p5_mass')
assert field in ds.derived_field_list
assert isinstance(ad[field], np.ndarray)

Expand All @@ -120,10 +115,9 @@ def test_add_ion_fraction_fields_to_amr_ds():
"""
ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_y",
"velocity_z", "temperature", "metallicity"))
ftype = 'stream'
ad = ds.all_data()
add_ion_fraction_field('O', 6, ds, ftype=ftype)
field = ('stream', 'O_p5_ion_fraction')
add_ion_fraction_field('O', 6, ds)
field = ('gas', 'O_p5_ion_fraction')
assert field in ds.derived_field_list
assert isinstance(ad[field], np.ndarray)

Expand All @@ -137,10 +131,9 @@ def test_add_ion_number_density_fields_to_amr_ds():
"""
ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_y",
"velocity_z", "temperature", "metallicity"))
ftype = 'stream'
ad = ds.all_data()
add_ion_number_density_field('O', 6, ds, ftype=ftype)
field = ('stream', 'O_p5_number_density')
add_ion_number_density_field('O', 6, ds)
field = ('gas', 'O_p5_number_density')
assert field in ds.derived_field_list
assert isinstance(ad[field], np.ndarray)

Expand All @@ -154,10 +147,9 @@ def test_add_ion_density_fields_to_amr_ds():
"""
ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_y",
"velocity_z", "temperature", "metallicity"))
ftype = 'stream'
ad = ds.all_data()
add_ion_density_field('O', 6, ds, ftype=ftype)
field = ('stream', 'O_p5_density')
add_ion_density_field('O', 6, ds)
field = ('gas', 'O_p5_density')
assert field in ds.derived_field_list
assert isinstance(ad[field], np.ndarray)

Expand All @@ -171,10 +163,9 @@ def test_add_ion_mass_fields_to_amr_ds():
"""
ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_y",
"velocity_z", "temperature", "metallicity"))
ftype = 'stream'
ad = ds.all_data()
add_ion_mass_field('O', 6, ds, ftype=ftype)
field = ('stream', 'O_p5_mass')
add_ion_mass_field('O', 6, ds)
field = ('gas', 'O_p5_mass')
assert field in ds.derived_field_list
assert isinstance(ad[field], np.ndarray)

Expand All @@ -190,10 +181,10 @@ def test_add_ion_fields_to_grid_ds():
"velocity_z", "temperature", "metallicity"),
units= ('g/cm**3', 'cm/s', 'cm/s',
'cm/s', 'K', ''))
ftype = 'stream'
ftype = 'gas'
ad = ds.all_data()
ions = ['H', 'O', 'N V']
add_ion_fields(ds, ions, ftype=ftype)
add_ion_fields(ds, ions)
fields = ['H_ion_fraction', 'H_p0_number_density', 'O_p5_mass', 'N_p4_density']
# Assure that a sampling of fields are added and can be sliced
dirpath = tempfile.mkdtemp()
Expand All @@ -212,9 +203,9 @@ def test_add_all_ion_fields_to_grid_ds():
"velocity_z", "temperature", "metallicity"),
units= ('g/cm**3', 'cm/s', 'cm/s',
'cm/s', 'K', ''))
ftype = 'stream'
ftype = 'gas'
ad = ds.all_data()
add_ion_fields(ds, 'all', ftype=ftype)
add_ion_fields(ds, 'all')
fields = ['H_ion_fraction', 'H_p0_number_density', 'O_p5_mass', 'N_p4_density']
# Assure that a sampling of fields are added and can be sliced
dirpath = tempfile.mkdtemp()
Expand All @@ -233,7 +224,7 @@ def test_add_all_ion_fields_to_grid_ds_from_file():
"velocity_z", "temperature", "metallicity"),
units= ('g/cm**3', 'cm/s', 'cm/s',
'cm/s', 'K', ''))
ftype = 'stream'
ftype = 'gas'
ad = ds.all_data()
add_ion_fields(ds, 'all', ftype=ftype, line_database='lines.txt')
fields = ['H_ion_fraction', 'H_p0_number_density', 'O_p5_mass', 'N_p4_density']
Expand All @@ -252,7 +243,7 @@ def test_add_all_ion_fields_to_amr_ds():
"""
ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_y",
"velocity_z", "temperature", "metallicity"))
ftype = 'stream'
ftype = 'gas'
ad = ds.all_data()
ions = ['H', 'O', 'N V']
add_ion_fields(ds, ions, ftype=ftype)
Expand Down Expand Up @@ -317,7 +308,9 @@ def test_to_not_overwrite_fields_for_grid():
Test to not overwrite an existing ion field
"""
ds = load(ISO_GALAXY)
val_before = ds.r['H_p0_number_density'][0]
# temporary fix until p0 fields are fixed in yt
# val_before = ds.r['H_p0_number_density'][0]
val_before = ds.r['H_number_density'][0]
add_ion_fields(ds, ['H'], ftype='gas')
val_after = ds.r['H_p0_number_density'][0]
assert val_before == val_after
Expand Down
12 changes: 12 additions & 0 deletions tests/test_light_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"enzo_cosmology_plus/AMRCosmology.enzo")
COSMO_PLUS_SINGLE = os.path.join(answer_test_data_dir,
"enzo_cosmology_plus/RD0009/RD0009")
GIZMO_COSMO_SINGLE = os.path.join(answer_test_data_dir,
"gizmo_cosmology_plus/snap_N128L16_150.hdf5")

def compare_light_ray_solutions(lr1, lr2):
assert len(lr1.light_ray_solution) == len(lr2.light_ray_solution)
Expand Down Expand Up @@ -129,3 +131,13 @@ def test_light_ray_non_cosmo_from_dataset(self):

ds = load('lightray.h5')
compare_light_ray_solutions(lr, ds)

def test_light_ray_redshift_coverage(self):
"""
Tests to assure a light ray covers the full redshift range appropriate
for that comoving line of sight distance. Was not always so!
"""
ds = load(GIZMO_COSMO_SINGLE)
ray = make_simple_ray(ds, start_position=ds.domain_left_edge, end_position=ds.domain_right_edge, lines=['H'])
assert_almost_equal(ray.r['redshift'][0], 0.00489571, decimal=8)
assert_almost_equal(ray.r['redshift'][-1], -0.00416831, decimal=8)
3 changes: 0 additions & 3 deletions tests/test_line_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# The full license is in the file LICENSE, distributed with this software.
#-----------------------------------------------------------------------------

from __future__ import absolute_import
from __future__ import print_function
from trident.line_database import \
uniquify, \
Line, \
Expand All @@ -22,7 +20,6 @@
import numpy as np
from shutil import copyfile
import os.path
from six.moves import range

def test_uniquify():
"""
Expand Down
2 changes: 0 additions & 2 deletions tests/test_lsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# The full license is in the file LICENSE, distributed with this software.
#-----------------------------------------------------------------------------

from __future__ import absolute_import
from __future__ import print_function
import pytest
from trident.lsf import LSF
import numpy as np
Expand Down

0 comments on commit ff34a76

Please sign in to comment.