cds-astro / cds-healpix-python

cdshealpix python package
https://cds-astro.github.io/cds-healpix-python/
BSD 3-Clause "New" or "Revised" License
6 stars 3 forks source link

HEALPix value map plotting functionality #26

Open smcguire-cmu opened 2 months ago

smcguire-cmu commented 2 months ago

We've previously been using healpy, but due to compatibility and licensing issues, we're trying to migrate away from it. We've been enjoying using this library and mocpy, but one feature that we haven't been able to implement is plot HEALPix value maps, where each healpix pixel has its own color, similar to this healpy function.

Would it be possible to add this functionality?

ManonMarchand commented 2 months ago

Thanks for the proposition!

Maybe this could be added to the library. What were your issues when trying to implement it? Did you use vertices? Was is broken or too slow?

smcguire-cmu commented 2 months ago

I tried to follow how the fill method in mocpy works, but generating a matplotlib Path object per tile and using them in a PathCollection to allow for different colors. I think the vertices performance is fine, the matplotlib part gets a bit slower at larger depths, but I think the solution to that would be to degrade to a lower resolution.

The bigger problem I faced is with backwards facing cells. I know in mocpy there's a method that deals with them, but I wasn't sure exactly how to adapt that for this case.

ManonMarchand commented 2 months ago

The idea is:

  1. project the vertices in the pixel space (with skycoord_to_pixel)
  2. in this space, the front-facing cells are in the configuration
A-----B
|     |
D-----C

so the cross product of all the sides should be positive whereas the back-facing ones will be

A-----D
|     |
B-----C

so the cross product of all the sides will be negative. You can filter these out.

Would you be interested in contributing a method? We could discuss the API / where this should be in the code base. Otherwise we'll do it, but not before a few months.

smcguire-cmu commented 2 months ago

Thank you for the help! I'd be happy to try contributing it.

I've used a few methods from mocpy that fill uses, so it could live as a function somewhere in mocpy. I'm not sure how related to mocs this functionality is though, and if it's more appropriate to live in this library, but that would probably involve moving some of the plotting functions from mocpy to here. What do you think would be best?

As for the API, I imagine it could work similarly to the mocpy methods that have ax and wcs arguments that it plots onto. The healpy function that we were using before took the value map as a single array of values, and it would use the index of the values as the healpix ipix, and infer the depth from the length of the array. We could use the same interface, but I'm not a huge fan as it doesn't support maps with multiple orders, or sparse maps. From what I've seen of your codebase, I'd suggest an appropriate interface would be 3 arrays of ipix, depth and values as inputs, but I'd love to hear what you think.

bmatthieu3 commented 2 months ago

That would be a nice method to have to plot healpix cells directly from cdshealpix, healpy is already doing it. I do not know whether it would be simple or not to share those plotting methods between mocpy and cdshealpix. I would tend to say first to put the code into cdshealpix and then, as mocpy has cdshealpix as a dep, to factorise later the mocpy fill's method with what has be put in cdshealpix.

For the API I like the 3 arrays option as it seems to be consistent with other method arguments. So values contains color values that would correspond to a color picked from a colormap ?

Another possible API is the have the 2 HEALPix arrays (ipix and depth) and then define a color (really like mocpy's fill method). I suppose that with this case there would be different calls to that method with the same mpl ax and wcs as you may be would like to draw a list of pixels in one color but another list of pixels in another color.

ManonMarchand commented 2 months ago

We should have a call sometime next week. Sending you all an email.

ManonMarchand commented 2 months ago

TODO, move from mocpy (should support nested and ring to be integrated in this library)

ManonMarchand commented 1 month ago

It's not flexible at all, but there is a quick plotting of skymap method in the new release. It's only mollview and all-sky. You can chose the resolution and the frame (between icrs and galactic). What are your thoughts?

smcguire-cmu commented 1 month ago

It looks good, thanks! I think that's very similar to the functionality in healpy.

For our use cases though we're interested in the additional functionality that something like the mocpy plotting allows, e.g. specifying the WCS and extra matplotlib parameters. We've been working on integrating our version of the skymap plotting based on the code I sent in our email discussion into our code base, with the idea that we could contribute it into cds-healpix-python once you were ready. If you're still interested in that, I'm happy to move forward with it when you would like.