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

Correct TiledDataset.plot mosaic ordering #504

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

eigenbrot
Copy link
Contributor

Currently TiledDataset.plot flattens the tile list and places them in a subplot based on matplotlib's ordering of the add_subplot index ordering. The result is a grid that starts in the upper left. Furthermore, the fix in this inventory PR will swap the MINDEX keys so that the current TiledDataset.plot method would plot a row-major grid, which is counter to the column-major intention of the MINDEX keys.

This PR fixes the first issue and prepares for the update mentioned in the second by using GridSpec to be more explicit about how the subplot grid should be laid our and exactly which tiles go into each subplot. The result is a (MAXIS1, MAXIS2)-shaped grid (FITS ordering) where the origin is in the bottom left and the subplot at grid position (x, y) corresponds to the tile with MINDEX1=x, MINDEX2=y.

As an additional refinement, there is also a new option (limits_from_wcs) to swap axis limits so that the minimum values of the WCS axes are also in the bottom left. This was written to help display some DLNIRSP data where the at-rest data array is oriented strangely, but it should be applicable to all instruments.

To show some before and after images I've taken headers from a real DLNIRSP dataset and modified the data arrays to simply show the (MINDEX1, MINDEX2) value of each tile. Here is .plot() as it is now:

dkist_DL_wrong

Note that the labels are upside down and backwards and the tiles are not organized in an intuitive grid.

Here are the same data after the fix for how the subplot grid is constructed

dkist_DL_right_raw_lims

Note that the tiles are now in the right places, but the labels are still flipped around. This is because the axes are "backward", in a WCS sense.

Finally here is the same plot with limits_from_wcs=True

dkist_DL_right

The labels are now readable because the smallest WCS values are now at the bottom left of each subplot.

@eigenbrot eigenbrot requested review from Cadair and SolarDrew January 22, 2025 20:49
@@ -184,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`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced limits_from_wcs is the best name for this option. Suggestions welcome!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps auto-rotate or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe auto_orient? I like where you're going, but I'm worried "rotate" might imply that it can rotate by something other than 180 degrees.

Copy link
Contributor

@SolarDrew SolarDrew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, @eigenbrot , it looks like a great fix. It needs some tests but no other comments from me 👍

@eigenbrot
Copy link
Contributor Author

Oops, I forgot about tests! Thanks for the reminder. I'll whip those up.

@eigenbrot eigenbrot force-pushed the better_tiled_dataset_plot branch from 7df7828 to d9bd0de Compare January 24, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants