Skip to content

Commit

Permalink
Merge pull request #4440 from jzuhone/offaxis_particle
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros authored May 26, 2023
2 parents 6c3bc26 + 48ef3ec commit de65439
Show file tree
Hide file tree
Showing 12 changed files with 540 additions and 138 deletions.
55 changes: 31 additions & 24 deletions doc/source/visualizing/FITSImageData.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@
{
"cell_type": "markdown",
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
"collapsed": false
},
"source": [
"## Making FITS images from Particle Projections"
Expand All @@ -149,10 +146,7 @@
"`FITSParticleProjection`:"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
"collapsed": false
}
},
{
Expand All @@ -167,10 +161,7 @@
"prjp_fits.writeto(\"prjp.fits\", overwrite=True)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
"collapsed": false
}
},
{
Expand All @@ -183,10 +174,7 @@
"for example), supply the ``density`` keyword argument:"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
"collapsed": false
}
},
{
Expand All @@ -200,10 +188,32 @@
"prjpd_fits.writeto(\"prjpd.fits\", overwrite=True)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"`FITSParticleOffAxisProjection` can be used to make a projection along any arbitrary sight line:"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"L = [1, -1, 1] # normal or \"line of sight\" vector\n",
"N = [0, 0, 1] # north or \"up\" vector\n",
"poff_fits = yt.FITSParticleOffAxisProjection(\n",
" dsp, L, (\"PartType1\", \"particle_mass\"), deposition=\"cic\", north_vector=N\n",
")\n",
"poff_fits.writeto(\"poff.fits\", overwrite=True)"
],
"metadata": {
"collapsed": false
}
},
{
Expand All @@ -212,10 +222,7 @@
"## Using `HDUList` Methods"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
"collapsed": false
}
},
{
Expand Down
20 changes: 19 additions & 1 deletion doc/source/visualizing/plots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,25 @@ domain:
p.set_unit(("all", "particle_mass"), "Msun")
p.save()

and here is an example of using the ``data_source`` argument to :class:`~yt.visualization.particle_plots.ParticlePhasePlot`
Using :class:`~yt.visualization.particle_plots.ParticleProjectionPlot`, you can also plot particles
along an off-axis direction:

.. python-script::

import yt

ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")

L = [1, 1, 1] # normal or "line of sight" vector
N = [0, 1, 0] # north or "up" vector

p = yt.ParticleProjectionPlot(
ds, L, [("all", "particle_mass")], width=(0.05, 0.05), depth=0.3, north_vector=N
)
p.set_unit(("all", "particle_mass"), "Msun")
p.save()

Here is an example of using the ``data_source`` argument to :class:`~yt.visualization.particle_plots.ParticlePhasePlot`
to only consider the particles that lie within a 50 kpc sphere around the domain center:

.. python-script::
Expand Down
3 changes: 2 additions & 1 deletion tests/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ answer_tests:
- yt/frontends/owls/tests/test_outputs.py:test_snapshot_033
- yt/frontends/owls/tests/test_outputs.py:test_OWLS_particlefilter

local_pw_048: # PR 4417
local_pw_049: # PR 4440
- yt/visualization/tests/test_plotwindow.py:test_attributes
- yt/visualization/tests/test_particle_plot.py:test_particle_projection_answers
- yt/visualization/tests/test_particle_plot.py:test_particle_offaxis_projection_answers
- yt/visualization/tests/test_particle_plot.py:test_particle_projection_filter
- yt/visualization/tests/test_particle_plot.py:test_particle_phase_answers
- yt/visualization/tests/test_callbacks.py:test_axis_manipulations
Expand Down
1 change: 1 addition & 0 deletions yt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def run_nose(*args, **kwargs):
FITSImageData,
FITSOffAxisProjection,
FITSOffAxisSlice,
FITSParticleOffAxisProjection,
FITSParticleProjection,
FITSProjection,
FITSSlice,
Expand Down
53 changes: 35 additions & 18 deletions yt/utilities/lib/pixelization_routines.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1781,24 +1781,13 @@ def pixelize_element_mesh_line(np.ndarray[np.float64_t, ndim=2] coords,

@cython.boundscheck(False)
@cython.wraparound(False)
def off_axis_projection_SPH(np.float64_t[:] px,
np.float64_t[:] py,
np.float64_t[:] pz,
np.float64_t[:] particle_masses,
np.float64_t[:] particle_densities,
np.float64_t[:] smoothing_lengths,
bounds,
center,
width,
np.float64_t[:] quantity_to_smooth,
np.float64_t[:, :] projection_array,
normal_vector,
north_vector,
weight_field=None):
# Do nothing in event of a 0 normal vector
if np.allclose(normal_vector, np.array([0., 0., 0.]), rtol=1e-09):
return

def rotate_particle_coord(np.float64_t[:] px,
np.float64_t[:] py,
np.float64_t[:] pz,
center,
width,
normal_vector,
north_vector):
# We want to do two rotations, one to first rotate our coordinates to have
# the normal vector be the z-axis (i.e., the viewer's perspective), and then
# another rotation to make the north-vector be the y-axis (i.e., north).
Expand Down Expand Up @@ -1839,6 +1828,34 @@ def off_axis_projection_SPH(np.float64_t[:] px,
px_rotated[i] = rotated_coordinates[0]
py_rotated[i] = rotated_coordinates[1]

return px_rotated, py_rotated, rot_bounds_x0, rot_bounds_x1, rot_bounds_y0, rot_bounds_y1


@cython.boundscheck(False)
@cython.wraparound(False)
def off_axis_projection_SPH(np.float64_t[:] px,
np.float64_t[:] py,
np.float64_t[:] pz,
np.float64_t[:] particle_masses,
np.float64_t[:] particle_densities,
np.float64_t[:] smoothing_lengths,
bounds,
center,
width,
np.float64_t[:] quantity_to_smooth,
np.float64_t[:, :] projection_array,
normal_vector,
north_vector,
weight_field=None):
# Do nothing in event of a 0 normal vector
if np.allclose(normal_vector, 0.):
return

px_rotated, py_rotated, \
rot_bounds_x0, rot_bounds_x1, \
rot_bounds_y0, rot_bounds_y1 = rotate_particle_coord(px, py, pz,
center, width, normal_vector, north_vector)

pixelize_sph_kernel_projection(projection_array,
px_rotated,
py_rotated,
Expand Down
1 change: 1 addition & 0 deletions yt/visualization/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
FITSImageData,
FITSOffAxisProjection,
FITSOffAxisSlice,
FITSParticleOffAxisProjection,
FITSParticleProjection,
FITSProjection,
FITSSlice,
Expand Down
Loading

0 comments on commit de65439

Please sign in to comment.