outs1der / minbar

Tools and software for building, accessing and analysing the Multi-INstrument Burst ARchive (MINBAR)
GNU General Public License v3.0
8 stars 0 forks source link

modify Bursts and Observations classes to be singletons #1

Closed outs1der closed 1 month ago

outs1der commented 4 years ago

No need for separate instances of the MINBAR burst and observation data objects, excluding the IDL/non-IDL versions. There seem a couple of relatively-complicated ways to achieve this; see e.g.

https://python-3-patterns-idioms-test.readthedocs.io/en/latest/Singleton.html

https://stackoverflow.com/questions/42237752/single-instance-of-class-in-python

outs1der commented 1 month ago

Not really sure if this is still required, but as a workaround the Observations class now also loads a copy of the burst table, available as the bursts attribute, like so:

>>> import minbar as mb
o>>> o = mb.Observations()
INFO:minbar:loading observations, please wait...
WARNING:minbar:only got matched source path names for 41/85 sources
WARNING:minbar:only got matched source path names for 41/85 sources
>>> o.bursts
<minbar.Bursts object at 0x102939040>
>>> o.bursts.show()
Multi-INstrument Burst ARchive (MINBAR) (7111 bursts from 85 sources)
entry          name             obsid      instr sflag     time    rexp
                                                            d          
----- --------------------- -------------- ----- ----- ----------- ----
 2203               GX 17+2 10065-01-01-01   XPa     - 50121.67857  2.0
 2204            4U 1728-34 10073-01-01-00   XPa     - 50128.74874  2.0
 2205            4U 1728-34 10073-01-01-00   XPa     - 50128.88217  2.0
 2206            4U 1728-34 10073-01-02-00   XPa     - 50129.16469  1.0

so you only really need define an Observations object and then you've got both in one