[obspy-users] subclass of obspy.core.event.magnitude.Magnitude object (or other event object)

Christian BAILLARD christian_baillard at hotmail.com
Tue Mar 5 00:02:02 CET 2019


Dear obspy users,

I'm working on some magnitude estimates and I would like do create a subclass inheriting from "magnitude.Magnitude" obspy object. At this point I just want to have the same attributes as the parent class plus some very simple new attributes such as "corner frequency", "omega_0"...

I just did the following:

class Magnitude_User(_Magnitude):
    def __init__(self,*args, **kwargs):
        # initialization code
        self.fc=kwargs.get('fc')
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            super().__init__(*args, **kwargs)

I wanted to get rid of the warning, but I still get the following:

UserWarning: Setting attribute "fc" which is not a default attribute

What would you advise for defining a new attribute for an obspy class without directly modifying the parent class? Is that the best approach? If yes, how can I get rid of the "warnings.warn"?

I thought about using the AttribDict() and the "extra" attribute but I'm not really interested in writing any xml for now and I would prefer a more direct approach.

Thanks for your help,

Christian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.swapbytes.de/pipermail/obspy-users/attachments/20190304/37546dfb/attachment.html>


More information about the obspy-users mailing list