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

Merged
merged 14 commits into from
Feb 6, 2025

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
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
dkist/dataset/tests/test_tiled_dataset.py Outdated Show resolved Hide resolved
dkist/dataset/tests/test_tiled_dataset.py Show resolved Hide resolved
dkist/dataset/tiled_dataset.py Outdated Show resolved Hide resolved
dkist/dataset/tiled_dataset.py Outdated Show resolved Hide resolved
dkist/dataset/tiled_dataset.py Outdated Show resolved Hide resolved
dkist/dataset/tiled_dataset.py Outdated Show resolved Hide resolved
dkist/dataset/tiled_dataset.py Outdated Show resolved Hide resolved

return

def plot(self, slice_index, share_zscale=False, fig=None, limits_from_wcs=True, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

I would like to throw a warning here if the user loads an old ASDF file with this new .plot to go and tell them to redownload a new ADSF.

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 fine with this idea, but I'm not sure how to implement it. A user will get wrong plots (and should thus be warned) iff these two conditions are BOTH true:

  1. dkist-processing-vbi version is < 1.19.0
  2. dkist-inventory version is < 1.?.?

We can check 1 easily, but I don't know about checking the dkist-inventory version. Ideas?

Copy link
Member

Choose a reason for hiding this comment

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

Given the current implementation of #513 I think this check would be something along the lines of:

if len(self.meta.get("history", {}).get("entries", [])):

which would check for any asdf which has the extra history entries.

Copy link
Member

@Cadair Cadair left a comment

Choose a reason for hiding this comment

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

I am going to put this on hold until I can chat to @astrofrog about the best way to do the WCSAxes flipping.

dkist/dataset/tiled_dataset.py Outdated Show resolved Hide resolved
dkist/dataset/tiled_dataset.py Outdated Show resolved Hide resolved
The automatic logic was becoming increasingly fragile and complicated. Much
easier to let the user decide what they want to do.
Copy link
Member

@Cadair Cadair left a comment

Choose a reason for hiding this comment

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

This is now blocked on needing a warning if this changed plot ordering is used with currently available ASDF files.

Otherwise looks good.

changelog/504.feature.2.rst Outdated Show resolved Hide resolved
@Cadair Cadair added this to the v1.10.0 milestone Feb 5, 2025
@Cadair Cadair merged commit e08c307 into DKISTDC:main Feb 6, 2025
22 checks passed
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.

3 participants