ppinard/matplotlib-scalebar

Add angular units

enourbakhsh opened this issue · 5 comments

It would be very useful for astronomers to have a scale bar showing angular scales such as degree (°), arcmin (') and arcsec ('').

For example, this can be done by adding the so-called pixel scale in the units of arc seconds per pixel (or even more available units) as an input. For example pixel scale = 0.2 implies that each pixel spans 0.2 arcsec. Here is the best I could do with the current version of matplotlib-scalebar.

scalebar

Thank you for this request. I made a first implementation in the branch angular. There is a new dimension Angular where the units can either be degree (°), minute of arc (′, 1/60 of °) or second of arc (′′, 1/3600 of °).

Here is how it looks like:

example_angular

Please let me know if this addresses your issue. If so, I will merge the branch and make a new release.

What's about using the pint library to manage the units and prefixes?

@ericpre Regarding using pint, could you explain a bit more what you had in mind? I am not sure I would like to add a dependency to the project for something as simple as defining the conversion factor between units. While pint could be used to discover possible units within a unit group (e.g. [length]), I think the list of units available for a scale bar needs to be customized, hence the Dimension class. For instance, having "mile", "nautical mile" and "us nautical mile" as available units would be confusing for a scale bar.

This was a quick suggestion and I haven't thought properly about it but I find it convenient to use! I don't have anything particular in mind other than it is very convenient to get the appropriate prefix and a nice formatting, for example:

from pint import UnitRegistry
ureg = UnitRegistry()
length = 1550 * ureg.nm
print(f'{length.to_compact():~}')

Pint does more than what is needed here but it is pure python library and has no dependency, so it does not cost much to add it as dependencies!

Code merged. Please re-open if it doesn't address the original issue.