Repository navigation
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
alasdairwilson
left a comment
There was a problem hiding this comment.
So this is good...really good.
It breaks loads of our stuff but in a good way I think... we will have to work around it but like I said this is so much better. ❤️
|
I think the general strategy on our side to have code that works both pre and post this PR being released. is to change where we are doing stuff like: to so if we are on pre #20779 astropy then we are fine because wcs units are assumed and the unit is dropped and post is of course fine because we are sending a Quantity anyway.
Yeah... part of the problem when we were discussing #20777 yesterday was that we used code that assumed degrees and it was fine because it WAS degrees and we realised when writing sunpy/sunpy#8819 and related branches in that stack PR that astropy was now assuming wcs units.... We can fix all our internal code in the manner I described above, the problem is, as you point out, that we taught people by example to do this conversion to u.deg and we can't undo that teaching so those people were gonna be bitten by our 8.1 release anyway. So the good news is then that even though more user code will break due to this...it hasn't made the user-facing problem much worse for us, they were already going to have problems if they were passing degrees to maps that are now in arcsec and at least this way if they update astropy and as long as they are passing the values as a Quantity, they might not even notice. |
mhvk
left a comment
There was a problem hiding this comment.
Very nice! I wondered a bit about astropy.visualization.quantity_support, but now see that you are using some of its functionality internally. So, in a way, you just turn it on by default, which makes sense.
Inline a small comment, and a small query.
| def convert(val, unit, axis): | ||
| # Pixel coordinates are plotted with the default transform, which does | ||
| # not use the world units | ||
| if isinstance(val, u.Quantity) and val.unit == u.pix: |
There was a problem hiding this comment.
Probably very unlikely to happen in practice, but someone might put in a quantity in "kpix", so perhaps it is worth doing val.unit.is_equivalent(u.pix) and val.to_value(u.pix) instead?
| return MplQuantityConverter.convert(val, unit, axis) | ||
|
|
||
|
|
||
| # A single instance, since Matplotlib refuses to replace an explicitly set |
There was a problem hiding this comment.
Should that be considered a bug in matplotlib? Worth reporting?
Is it why you cannot use MplQuantityConverter more directly?
There was a problem hiding this comment.
I don't think this is a bug, I think it's just by design
…orms to the world units of the WCS.
…ount check in WCSAxes.
…it to the angular units of the axes.
…erting them to the world units.
…es and clarify why the unit converter is a single instance.
8af16f7 to
e7dbb8a
Compare
|
@alasdairwilson @Cadair - as we are a week away from feature freeze, I'd like us to make a decision on this. I was wondering if you could confirm if sunpy is happy with this and we can go ahead or whether it will be too disruptive? |
Description
We never really supported passing quantities to e.g.
ax.scatterorax.plotbut as described in #20777, quantities were being silently ignored. I realized that we could actually make this work by leveraging the ability for Matplotlib to have hooks for unit conversion on the axes.With this PR, several things happen:
scatterandplot.get_transformas being in degrees when passing a celestial frame, so we properly recognize e.g. arcsec inputSphericalCircleandQuadranglepatches have been updated to also recognize unit converters on the axes, as they don't go through the unit conversion machinery automaticallyThings that haven't changed:
u.pixare still pixelsplot_coord,scatter_coordand coordinate grid overlays are unchangedThis needs to be carefully tested with sunpy, ndcube, and dkist at least - @hayesla @ricardogando
@alasdairwilson - you might want to check this since it changes a little the behavior after #20600. The following:
will now assume that the bare values are in arcsec, not in degrees (basically bare values, when using a celestial transform, are assumed to be in the WCS units.
Because this is not a trivial fix and might break some corner cases, we should not backport it (nor is it easy to go through deprecation)
Fixes #20777
AI Disclosure
If AI tools were used to develop this pull request, describe the tools including specific model and version, how they were used, and what content is AI generated. Otherwise enter "N/A".
Assisted by Claude Opus 5.5
Merge method