Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn velocity plot test into a figure test #325

Merged
merged 4 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions punchbowl/level3/tests/test_velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ def test_shape_matching(synthetic_data):
assert result.data.shape[0] == len(ycens)


@pytest.mark.mpl_image_compare(style="default")
def test_wind_plot(synthetic_data):
"""Tests that wind plots are generated and output to file."""
files = synthetic_data
ycens = np.arange(7, 14.5, 0.5)
result = track_velocity(files, ycens=ycens)

plot_flow_map(THIS_DIRECTORY / 'wind_map.png', result)

assert os.path.exists(THIS_DIRECTORY / 'wind_map.png')
return plot_flow_map(None, result)


def test_no_nans_or_negatives(synthetic_data):
Expand Down
13 changes: 10 additions & 3 deletions punchbowl/level3/velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,21 +365,26 @@
return avg_speeds, sigmas


def plot_flow_map(filename: str, data: NDCube, cmap: str = "magma") -> None:
def plot_flow_map(filename: str | None, data: NDCube, cmap: str = "magma") -> None:
"""
Plot polar maps of the radial flows.

Parameters
----------
filename: str
Output plot filename
Output plot filename. If None, the figure is not saved out.

data: NDCube
Flow tracking data NDCube

cmap : str, optional
Colormap for the plot (default is 'magma')

Returns
-------
fig
The generated Matplotlib Figure

"""
speeds = data.data
sigmas = data.uncertainty.array
Expand Down Expand Up @@ -418,7 +423,9 @@

cbar_ax = fig.add_axes([0.11, 0.2, 0.8, 0.03])
plt.colorbar(mapper, cax=cbar_ax, orientation="horizontal").ax.set_xlabel("Speed (km/s)")
plt.savefig(filename)
if filename is not None:
plt.savefig(filename)

Check warning on line 427 in punchbowl/level3/velocity.py

View check run for this annotation

Codecov / codecov/patch

punchbowl/level3/velocity.py#L427

Added line #L427 was not covered by tests
return fig


def track_velocity(files: list[str],
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --mpl