Code Monkey home page Code Monkey logo

Comments (5)

duytnguyendtn avatar duytnguyendtn commented on July 28, 2024

Hi all, came across this issue when trying to lookup if mocpy supported searching for contained coordinates using astropy regions, something like mocpy.contains_region(CircleSkyRegion(my_region)).

Looks like y'all might already have some working code over on cds-astro/ipyaladin#88 (comment). Wanted to throw my interest and support onto this issue, as it would be incredibly useful for our work at NASA HEASARC/STScI

from mocpy.

ManonMarchand avatar ManonMarchand commented on July 28, 2024

Hi, we meet again!

Just to be clear about your needs, the function you suggest would return True only if the region is entirely comprised in the MOC?
Cause you can already do a bit of a workaround with the existing code:

# Let's create a CircleSkyRegion
from regions import CircleSkyRegion
from astropy.coordinates import SkyCoord, Angle
center = SkyCoord.from_name("m1")
angle = Angle("2d")
circle = CircleSkyRegion(center, radius)

# Now we convert it into a MOC
from mocpy import MOC
small_circle_moc = MOC.from_cone(circle.center.ra, circle.center.dec, radius=circle.radius, max_depth=13)

# Let's define a bigger MOC that encloses it
big_circle_moc = MOC.from_cone(circle.center.ra, circle.center.dec, radius=Angle("4d"), max_depth=13)

# And one that is disjoint
other_part_of_the_sky = MOC.from_str("5/12")

# Let's define the test to see if the small moc is in the big one
def contains(moc1, moc2):
    return moc1.union(moc2) == moc1

# And voilà
print(contains(big_circle_moc, small_circle_moc))
print(contains(other_part_of_the_sky, small_circle_moc))
True
False

It is not entirely precise because of the way the cells in the border of the MOC are chosen with respect to the region delimitation, but you might be able to tweak things in your way with the extended and contracted methods?

@fxpineau : What do you think about implementing this? We might need bmocs.

from mocpy.

ManonMarchand avatar ManonMarchand commented on July 28, 2024

(and otherwise, the from_regions methods is very high on our lists of things to add. It should come after we converge in ipyaladin)

from mocpy.

duytnguyendtn avatar duytnguyendtn commented on July 28, 2024

Thanks @ManonMarchand!

Our particular usecase is more "if the region contains any intersection with the MOC" but I imagine that can be easily tweaked by modifying the contains method you posted.

I think first-order a True/False return (and thus your above snippet) would be sufficient, many thanks! For second order, a formal method that (1) abstracts the above from the user, and possibly (2) returns a mask over the intersection, like the other contains methods would be a useful feature to have.

from mocpy.

ManonMarchand avatar ManonMarchand commented on July 28, 2024

Hi!

We added the support for astropy-regions and this feature will be in the next mocpy's release.
It is now possible to:

  • create a moc from an astropy-regions
  • test weather this moc intersects or is contained in an other moc with the existing operations between mocs (ex: union, intersect, difference...)

Could you explain a bit more your second point though because I'm not sure I get it.

from mocpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.