Ejemplo n.º 1
0
    def get_event(self,
                  dsn,
                  orid=None,
                  evid=None,
                  origin=True,
                  magnitude=True,
                  pick=False,
                  focal_mechanism=False,
                  anss=False):
        # pylint: disable=unused-argument, too-many-arguments
        """
        Run conversion with config
        """
        # IF REGULAR EVENT, USE DATABASE
        #######################################################################
        # Make db Connection -- wrap in context
        # with connect(dsn, row_factory=OrderedDictRow,
        #              CONVERT_NULL=True) as conn:

        with connect(dsn) as conn:
            db = DatabaseConverter(conn, self._conv)
            event = db.extract_origin(orid,
                                      origin=origin,
                                      magnitude=magnitude,
                                      pick=pick,
                                      focal_mechanism=focal_mechanism,
                                      anss=anss)

        # Set preferreds. The extract method should return in reversed time
        # order, so always choosing the first origin, mag, should be an OK
        # default. Need to use an algorithm for a preferred mag type. For
        # focalmechs, should be mt solutions in reversed time order, then
        # first motions in reveresed time order. This means that a default
        # would be any latest MT, then any latest FM. Or writecustom algorithm.

        try:
            event['preferredOriginID'] = event['origin'][0]['@publicID']
            event['preferredMagnitudeID'] = qml.find_preferred_mag(
                event['magnitude'][::-1], self.preferred_magtypes)
            if event.get('focalMechanism'):
                event['preferredFocalMechanismID'] = \
                    event['focalMechanism'][0]['@publicID']
        except Exception as ex:
            self.logger.exception(ex)

        #
        # Try the nearest places thing...
        #
        if self.placesdb and os.path.exists(self.placesdb):
            try:
                orig = event['origin'][0]
                ncd = get_nearest_place(
                    self.placesdb,
                    (orig['longitude']['value'], orig['latitude']['value']))
                event['description'] = self._conv.description(ncd)
            except Exception as ex:
                self.logger.exception(ex)

        return event
Ejemplo n.º 2
0
def test_find_preferred_mag():
    """Get mag id given list of types"""
    mags = [
        {
            "@publicID": "smi:local.test/netmag/123",
            "type": "md",
        },
        {
            "@publicID": "smi:local.test/netmag/121",
            "type": "mw",
        },
        {
            "@publicID": "smi:local.test/netmag/124",
            "type": "mw",
        },
        {
            "@publicID": "smi:local.test/netmag/122",
            "type": "ml",
        },
    ]
    pid = qml.find_preferred_mag(mags, ['mw', 'ml'])
    assert pid == "smi:local.test/netmag/124"
    pid = qml.find_preferred_mag(mags, ['mr', 'ml', 'md'])
    assert pid == "smi:local.test/netmag/122"