Code Monkey home page Code Monkey logo

Comments (8)

ggreco77 avatar ggreco77 commented on June 23, 2024

I tried to add a new method to the class AbstractMoc named union_moc_list for fast union of a list of moc

def union_moc_list(self, another_mocs = [] ):
    """
    Union between self and a list of mocs

    Parameters
    ----------
    another_mocs : `~mocpy.abstract_moc.AbstractMoc`
        a list of MOC/TimeMoc to bind to self

    Returns
    -------
    result : `~mocpy.moc.MOC` or `~mocpy.tmoc.TimeMoc`
        MOC object whose interval set corresponds to : self | ``moc``

    """
    for another_moc in another_mocs:
        iv_set_union = self._interval_set.union(another_moc._interval_set)
        result = self.__class__.from_interval_set(iv_set_union)
        self = result

    return result

from mocpy.

bmatthieu3 avatar bmatthieu3 commented on June 23, 2024

@ggreco77 What do you think of redefining the current AbstractMOC.union method like that:
def union(self, *args)

You can call the method like that:
moc1.union(moc2, moc3, ..., mocN)
Or if you have a list of MOCs :
moc1.union(*moc_l)

from mocpy.

bmatthieu3 avatar bmatthieu3 commented on June 23, 2024

Or even like that def union(self, another_moc, *args) so that at least one moc is mandatory for computing an union of MOCs.

from mocpy.

tboch avatar tboch commented on June 23, 2024

@ggreco77 What do you think of redefining the current AbstractMOC.union method like that:
def union(self, *args)

You can call the method like that:
moc1.union(moc2, moc3, ..., mocN)
Or if you have a list of MOCs :
moc1.union(*moc_l)

That would be my preferred API, def union(self, another_moc, *args) looks less natural to me.

from mocpy.

ggreco77 avatar ggreco77 commented on June 23, 2024

Let me show you an real application of such new method
http://nbviewer.jupyter.org/gist/ggreco77/c114dd9f7364a216bd83602cee156ca3
as reported in "Ex. 1 Group the Observation in g filter - measure the sky area and the skymap intersection"
in the first lines

many thanks

from mocpy.

ggreco77 avatar ggreco77 commented on June 23, 2024

I got some troubles with the union method implemented as union(self, another_moc, *args);

mocs= [moc1, moc2, moc3, moc4]

for moc in mocs: uni_mocs = MOC.union(moc)

How can obtain such statement using for or similar passing a list?

thanks!

from mocpy.

bmatthieu3 avatar bmatthieu3 commented on June 23, 2024

Union/difference/intersection are not static (hmm just thinking it may be a good idea to do static functions taking multiple mocs through *args).

But for now if you have one moc object and a list of other mocs other_mocs_l=[moc2, ..., mocN] you can do the union of moc with the list by doing:
uni_mocs = moc.union(*other_mocs_l) or uni_mocs = moc.union(moc2, moc3, ..., mocN)
The * operator transforms a list say l=[1,2,3] in the following of values 1, 2, 3 that can be given in a function through the *args parameter name.
uni_mocs stores the result. moc is not changed after the method call. No needs to do a for loop.

from mocpy.

ggreco77 avatar ggreco77 commented on June 23, 2024

Very clear, the method perfectly works in my scripts.
Many thanks.

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.