cds-astro / mocpy

Python library to easily create and manipulate MOCs (Multi-Order Coverage maps)
https://cds-astro.github.io/mocpy/
BSD 3-Clause "New" or "Revised" License
59 stars 33 forks source link

MOC sky area #128

Closed mcoughlin closed 4 months ago

mcoughlin commented 4 months ago

It wasn't immediately clear from the docs how to get the sky area covered by the MOC. I would guess there is a MOC.area() equivalent somewhere but I do not see it?

ManonMarchand commented 4 months ago

You can do

from mocpy import MOC
MOC.from_string("0/0-11").sky_fraction
1.0
and-santos commented 4 months ago

If you want something in sq-deg, there is a nice way to do so by making use of astropy.units and the sky_fraction method of a moc

import astropy.units as u
from mocpy import MOC

moc = MOC.from_string("0/0-11") # any other MOC instance will work
ALL_SKY = 4 * np.pi * u.steradian
area = moc.sky_fraction * ALL_SKY
area = area.to(u.deg**2).value
ManonMarchand commented 4 months ago

Better, thanks! Would you be interested in contributing your snippet to the documentation? (I can also do it if you prefer) This could go well as a new subsection here: https://github.com/cds-astro/mocpy/blob/a32c9a199ddc74887d0566b7c78e34e6d4c66043/docs/examples/user_documentation.rst?plain=1#L28

and-santos commented 4 months ago

Yes, I would be happy to contribute! I will create a PR with this example.

ManonMarchand commented 4 months ago

Perfect, thanks!