Comments (8)
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.
@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.
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.
@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.
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.
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.
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.
Very clear, the method perfectly works in my scripts.
Many thanks.
from mocpy.
Related Issues (20)
- Using moc objects sent to a multiprocessing task fails HOT 1
- Create spatial MOCs from astropy regions HOT 5
- Change TMOC notebook
- numpy 2.0 will be out soon
- remove python 3.7 (end of life was June 2023)
- Wrong frame for wide fov plots HOT 1
- TypeError: argument 'lon': 'float64' object cannot be converted to 'PyArray<T, D>' HOT 3
- Improve from_fits_images when working with MEF
- Create a MOC from STC-S string HOT 4
- CI fails for external contributors HOT 5
- Make deprecated write call save HOT 1
- `new_empty` is not implemented for STMOCs
- rewrite doc of MOC.from_ methods
- (corner case) Ban negative indices
- MOC to STC-S HOT 3
- MOC.from_valued_healpix_cells is broken in mocpy 0.12.0 HOT 2
- IntervalSet Depracated HOT 17
- Sections we'll want in the README for v1.0.0 HOT 3
- MOC.wcs() has issues with non-squared figures HOT 3
- sum(of_lots_of_MOCs) returns an error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mocpy.