Skip to content

Commit

Permalink
Add option to have correctly-ordered limits in tiled dataset plot
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenbrot committed Jan 22, 2025
1 parent c17883d commit d51a925
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion dkist/dataset/tiled_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.axes import Axes
from matplotlib.gridspec import GridSpec

import astropy
from astropy.table import vstack
from astropy.wcs.wcsapi import HighLevelWCSWrapper

from dkist.io.file_manager import FileManager, StripedExternalArray
from dkist.io.loaders import AstropyFITSLoader
Expand Down Expand Up @@ -168,7 +170,26 @@ def _get_axislabels(ax):
ylabel = coord.get_axislabel() or coord._get_default_axislabel()
return (xlabel, ylabel)

def plot(self, slice_index, share_zscale=False, fig=None, **kwargs):
@staticmethod
def _ensure_wcs_ordered_axis_lims(wcs: HighLevelWCSWrapper, ax: Axes) -> None:
"""
Adjust axis limits so the WCS values go from smaller numbers in the bottom left to higher numbers in the upper right.
"""
xmin, xmax = ax.get_xlim()
ymin, ymax = ax.get_ylim()

Check warning on line 179 in dkist/dataset/tiled_dataset.py

View check run for this annotation

Codecov / codecov/patch

dkist/dataset/tiled_dataset.py#L178-L179

Added lines #L178 - L179 were not covered by tests

world_xmin, world_ymin = wcs.low_level_wcs.pixel_to_world_values(xmin, ymin)
world_xmax, world_ymax = wcs.low_level_wcs.pixel_to_world_values(xmax, ymax)

Check warning on line 182 in dkist/dataset/tiled_dataset.py

View check run for this annotation

Codecov / codecov/patch

dkist/dataset/tiled_dataset.py#L181-L182

Added lines #L181 - L182 were not covered by tests

new_xmin, new_ymin = wcs.low_level_wcs.world_to_pixel_values(min(world_xmin, world_xmax), min(world_ymin, world_ymax))
new_xmax, new_ymax = wcs.low_level_wcs.world_to_pixel_values(max(world_xmin, world_xmax), max(world_ymin, world_ymax))

Check warning on line 185 in dkist/dataset/tiled_dataset.py

View check run for this annotation

Codecov / codecov/patch

dkist/dataset/tiled_dataset.py#L184-L185

Added lines #L184 - L185 were not covered by tests

ax.set_xlim(new_xmin, new_xmax)
ax.set_ylim(new_ymin, new_ymax)

Check warning on line 188 in dkist/dataset/tiled_dataset.py

View check run for this annotation

Codecov / codecov/patch

dkist/dataset/tiled_dataset.py#L187-L188

Added lines #L187 - L188 were not covered by tests

return

Check warning on line 190 in dkist/dataset/tiled_dataset.py

View check run for this annotation

Codecov / codecov/patch

dkist/dataset/tiled_dataset.py#L190

Added line #L190 was not covered by tests

def plot(self, slice_index, share_zscale=False, fig=None, limits_from_wcs=True, **kwargs):
"""
Plot a slice of each tile in the TiledDataset
Expand All @@ -185,6 +206,9 @@ def plot(self, slice_index, share_zscale=False, fig=None, **kwargs):
fig : `matplotlib.figure.Figure`
A figure to use for the plot. If not specified the current pyplot
figure will be used, or a new one created.
limits_from_wcs : `bool`
If ``True`` the plots will be adjusted so smaller WCS values in the lower left, increasing to the upper
right. If ``False`` then the raw orientation of the data is used.
"""
if isinstance(slice_index, int):
slice_index = (slice_index,)
Expand All @@ -202,6 +226,10 @@ def plot(self, slice_index, share_zscale=False, fig=None, **kwargs):
ax_gridspec = gridspec[dataset_nrows - row - 1, col]
ax = fig.add_subplot(ax_gridspec, projection=tile.wcs)
tile.plot(axes=ax, **kwargs)

Check warning on line 228 in dkist/dataset/tiled_dataset.py

View check run for this annotation

Codecov / codecov/patch

dkist/dataset/tiled_dataset.py#L220-L228

Added lines #L220 - L228 were not covered by tests

if limits_from_wcs:
self._ensure_wcs_ordered_axis_lims(tile.wcs, ax)

Check warning on line 231 in dkist/dataset/tiled_dataset.py

View check run for this annotation

Codecov / codecov/patch

dkist/dataset/tiled_dataset.py#L230-L231

Added lines #L230 - L231 were not covered by tests

if col == row == 0:
xlabel, ylabel = self._get_axislabels(ax)
fig.supxlabel(xlabel, y=0.05)
Expand Down

0 comments on commit d51a925

Please sign in to comment.