Skip to content

Commit

Permalink
ENH: improve API consistency for ProjectionPlot VS SlicePlot:
Browse files Browse the repository at this point in the history
- rename ProjectionPlot -> AxisAlignedProejctionPlot
- make SlicePlot a dispatch class instead of a factory function
- a similar dispatch class with the name ProjectionPlot
- add an abstract layer (NormalPlot) as a common ancestor
  for plot classes with a "normal"/"axis" argument
  • Loading branch information
neutrinoceros committed Aug 31, 2021
1 parent c76b657 commit 7573a12
Show file tree
Hide file tree
Showing 12 changed files with 391 additions and 215 deletions.
15 changes: 11 additions & 4 deletions doc/source/analyzing/fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -643,16 +643,23 @@ this will be handled automatically:
.. code-block:: python
prj = yt.ProjectionPlot(
ds, "z", ("gas", "velocity_los"), weight_field=("gas", "density")
ds,
"z",
fields=("gas", "velocity_los"),
weight_field=("gas", "density"),
)
Which, because the axis is ``"z"``, will give you the same result if you had
projected the ``"velocity_z"`` field. This also works for off-axis projections:
projected the ``"velocity_z"`` field. This also works for off-axis projections,
using an arbitrary normal vector

.. code-block:: python
prj = yt.OffAxisProjectionPlot(
ds, [0.1, -0.2, 0.3], ("gas", "velocity_los"), weight_field=("gas", "density")
prj = yt.ProjectionPlot(
ds,
[0.1, -0.2, 0.3],
fields=("gas", "velocity_los"),
weight_field=("gas", "density"),
)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/complex_plots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ with a fourth entering for particle data that is deposited onto a mesh
is inherited by
:class:`~yt.visualization.plot_window.AxisAlignedSlicePlot`,
:class:`~yt.visualization.plot_window.OffAxisSlicePlot`,
:class:`~yt.visualization.plot_window.ProjectionPlot`, and
:class:`~yt.visualization.plot_window.AxiAlignedProjectionPlot`, and
:class:`~yt.visualization.plot_window.OffAxisProjectionPlot`. This
controls the number of resolution elements in the
:class:`~yt.visualization.fixed_resolution.FixedResolutionBuffer`,
Expand Down
4 changes: 3 additions & 1 deletion doc/source/cookbook/simple_off_axis_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@

# Create an OffAxisProjectionPlot of density centered on the object with the L
# vector as its normal and a width of 25 kpc on a side
p = yt.OffAxisProjectionPlot(ds, L, ("gas", "density"), sp.center, (25, "kpc"))
p = yt.ProjectionPlot(
ds, L, fields=("gas", "density"), center=sp.center, width=(25, "kpc")
)
p.save()
1 change: 1 addition & 0 deletions doc/source/reference/api/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SlicePlot and ProjectionPlot
~yt.visualization.plot_window.AxisAlignedSlicePlot
~yt.visualization.plot_window.OffAxisSlicePlot
~yt.visualization.plot_window.ProjectionPlot
~yt.visualization.plot_window.AxisAlignedProjectionPlot
~yt.visualization.plot_window.OffAxisProjectionPlot
~yt.visualization.plot_window.WindowPlotMPL
~yt.visualization.plot_window.PlotWindow
Expand Down
4 changes: 3 additions & 1 deletion doc/source/visualizing/callbacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ lines, text, markers, streamlines, velocity vectors, contours, and more.
Callbacks can be applied to plots created with
:class:`~yt.visualization.plot_window.SlicePlot`,
:class:`~yt.visualization.plot_window.ProjectionPlot`,
:class:`~yt.visualization.plot_window.AxisAlignedSlicePlot`,
:class:`~yt.visualization.plot_window.AxisAlignedProjectionPlot`,
:class:`~yt.visualization.plot_window.OffAxisSlicePlot`, or
:class:`~yt.visualization.plot_window.OffAxisProjectionPlot` by calling
:class:`~yt.visualization.plot_window.OffAxisProjectionPlot`, by calling
one of the ``annotate_`` methods that hang off of the plot object.
The ``annotate_`` methods are dynamically generated based on the list
of available callbacks. For example:
Expand Down
8 changes: 4 additions & 4 deletions doc/source/visualizing/plots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ Here, ``W`` is the width of the projection in the x, y, *and* z
directions.

One can also generate annotated off axis projections using
:class:`~yt.visualization.plot_window.OffAxisProjectionPlot`. These
:class:`~yt.visualization.plot_window.ProjectionPlot`. These
plots can be created in much the same way as an
``OffAxisSlicePlot``, requiring only an open dataset, a direction
to project along, and a field to project. For example:
Expand All @@ -429,12 +429,12 @@ to project along, and a field to project. For example:
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
L = [1, 1, 0] # vector normal to cutting plane
north_vector = [-1, 1, 0]
prj = yt.OffAxisProjectionPlot(
prj = yt.ProjectionPlot(
ds, L, ("gas", "density"), width=(25, "kpc"), north_vector=north_vector
)
prj.save()

OffAxisProjectionPlots can also be created with a number of
``OffAxisProjectionPlot`` objects can also be created with a number of
keyword arguments, as described in
:class:`~yt.visualization.plot_window.OffAxisProjectionPlot`

Expand Down Expand Up @@ -584,7 +584,7 @@ Note, the change in the field name from ``("deposit", "nbody_mass")`` to

fn = cg.save_as_dataset(fields=[("deposit", "nbody_mass")])
ds_grid = yt.load(fn)
p = yt.OffAxisProjectionPlot(ds_grid, [1, 1, 1], ("grid", "nbody_mass"))
p = yt.ProjectionPlot(ds_grid, [1, 1, 1], ("grid", "nbody_mass"))
p.save()

Plot Customization: Recentering, Resizing, Colormaps, and More
Expand Down
2 changes: 1 addition & 1 deletion doc/source/yt4differences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ centre of the pixel and using the standard SPH smoothing formula. The heavy
lifting in these functions is undertaken by cython functions.

It is now possible to generate slice plots, projection plots, covering grids and
arbitrary grids of smoothed quanitities using these operations. The following
arbitrary grids of smoothed quantities using these operations. The following
code demonstrates how this could be achieved. The following would use the scatter
method:

Expand Down
1 change: 1 addition & 0 deletions yt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@

# Now individual component imports from the visualization API
from yt.visualization.api import (
AxisAlignedProjectionPlot,
AxisAlignedSlicePlot,
FITSImageData,
FITSOffAxisProjection,
Expand Down
8 changes: 2 additions & 6 deletions yt/fields/tests/test_field_access.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from yt.data_objects.profiles import create_profile
from yt.testing import assert_equal, fake_random_ds
from yt.visualization.plot_window import (
OffAxisProjectionPlot,
ProjectionPlot,
SlicePlot,
)
from yt.visualization.plot_window import ProjectionPlot, SlicePlot
from yt.visualization.profile_plotter import PhasePlot, ProfilePlot


Expand All @@ -29,7 +25,7 @@ def test_field_access():
s = SlicePlot(ds, 2, field)
oas = SlicePlot(ds, [1, 1, 1], field)
p = ProjectionPlot(ds, 2, field)
oap = OffAxisProjectionPlot(ds, [1, 1, 1], field)
oap = ProjectionPlot(ds, [1, 1, 1], field)

for plot_object in [s, oas, p, oap, prof, phase]:
plot_object._setup_plots()
Expand Down
1 change: 1 addition & 0 deletions yt/visualization/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .particle_plots import ParticlePhasePlot, ParticlePlot, ParticleProjectionPlot
from .plot_modifications import PlotCallback, callback_registry
from .plot_window import (
AxisAlignedProjectionPlot,
AxisAlignedSlicePlot,
OffAxisProjectionPlot,
OffAxisSlicePlot,
Expand Down
Loading

0 comments on commit 7573a12

Please sign in to comment.