コード例 #1
0
 def test_pcat1_cleared_preferreds(self, cat1_cleared_preferreds):
     """cleared preferreds should be reset to last in list"""
     cat = cat1_cleared_preferreds
     validate_catalog(cat)
     self.preferred_ids_are_set(cat)
     # make sure it is the last ones in the list
     ev = cat[0]
     if len(ev.origins):
         assert ev.preferred_origin() == ev.origins[-1]
     if len(ev.magnitudes):
         assert ev.preferred_magnitude() == ev.magnitudes[-1]
     if len(cat[0].focal_mechanisms):
         assert ev.preferred_focal_mechanism() == ev.focal_mechanisms[-1]
コード例 #2
0
    def getHypocenterMag(self):

        from matplotlib.dates import date2num

        nevents = self.events.count()
        hypocenters = numpy.zeros((nevents, 3), dtype=numpy.float)
        mag = numpy.zeros((nevents, ), dtype=numpy.float)
        t = numpy.zeros((nevents, ), dtype=numpy.float)
        for i, event in enumerate(self.events):
            origin = event.preferred_origin()
            hypocenters[i, :] = (origin.longitude, origin.latitude,
                                 origin.depth)
            t[i] = date2num(origin.time)
            mag[i] = event.preferred_magnitude().mag
        return (hypocenters, mag, t)
コード例 #3
0
    def _printEvent(self, event):

        magnitude = event.preferred_magnitude()
        origin = event.preferred_origin()
        if hasattr(event, 'extra') and hasattr(event.extra,
                                               'mainshock_distance'):
            mainshockDist = 1.0e-3 * event.extra.mainshock_distance.value
            mainshockAzimuth = event.extra.mainshock_azimuth.value
            directionStr = "(%4.1fkm %s)" % (
                mainshockDist, self._azimuthToString(mainshockAzimuth))
        else:
            directionStr = "            "
        print("%s   %8.3f %6.3f %s  %4.1fkm  %4.2f %s" %
              (self._localTimestamp(origin.time), origin.longitude,
               origin.latitude, directionStr, 1.0e-3 * origin.depth,
               magnitude.mag, magnitude.magnitude_type))
        return
コード例 #4
0
    def addDistanceAzimuth(self, mainshock):
        if self.events is None:
            return

        from obspy.core import AttribDict
        ns = "http://earthquake.usgs.gov/xmlns/1.0"

        origin = mainshock.preferred_origin()
        utmZone = int(math.floor((origin.longitude + 180) / 6) + 1)
        proj = pyproj.Proj(proj="utm", zone=utmZone, ellps='WGS84')
        x0, y0 = proj(origin.longitude, origin.latitude)

        for event in self.events:
            origin = event.preferred_origin()
            xE, yE = proj(origin.longitude, origin.latitude)
            dx = xE - x0
            dy = yE - y0

            dist = ((xE - x0)**2 + (yE - y0)**2)**0.5
            distAttrib = AttribDict({
                'type': "attribute",
                'namespace': ns,
                'value': dist
            })

            azimuth = 180.0 * math.atan2(dx, dy) / math.pi
            if azimuth < 0.0:
                azimuth += 360.0

            azimuthAttrib = AttribDict({
                'type': "attribute",
                'namespace': ns,
                'value': azimuth
            })

            if hasattr(event, 'extra'):
                extraAttrib = event.extra
            else:
                extraAttrib = AttribDict()
                event.extra = extraAttrib

            extraAttrib.mainshock_distance = distAttrib
            extraAttrib.mainshock_azimuth = azimuthAttrib

        return
コード例 #5
0
ファイル: main.py プロジェクト: SeismicData/asdf_sextant
    def build_event_tree_view(self):
        if not hasattr(self, "ds") or not self.ds:
            return
        self.events = self.ds.events
        self.ui.event_tree_widget.clear()

        items = []
        self._state["quake_ids"] = {}

        for event in self.events:
            if event.origins:
                org = event.preferred_origin() or event.origins[0]

                js_call = "addEvent('{event_id}', {latitude}, {longitude});"\
                    .format(event_id=event.resource_id.id,
                            latitude=org.latitude,
                            longitude=org.longitude)
                self.ui.events_web_view.page().mainFrame().evaluateJavaScript(
                    js_call)

            event_item = QtGui.QTreeWidgetItem(
                [event.resource_id.id],
                type=EVENT_VIEW_ITEM_TYPES["EVENT"])
            self._state["quake_ids"][event.resource_id.id] = event_item

            origin_item = QtGui.QTreeWidgetItem(["Origins"], type=-1)
            magnitude_item = QtGui.QTreeWidgetItem(["Magnitudes"], type=-1)
            focmec_item = QtGui.QTreeWidgetItem(["Focal Mechanisms"], type=-1)

            org_items = []
            for origin in event.origins:
                org_items.append(
                    QtGui.QTreeWidgetItem(
                        [origin.resource_id.id],
                        type=EVENT_VIEW_ITEM_TYPES["ORIGIN"]))
                self._state["quake_ids"][origin.resource_id.id] = org_items[-1]
            origin_item.addChildren(org_items)

            mag_items = []
            for magnitude in event.magnitudes:
                mag_items.append(
                    QtGui.QTreeWidgetItem(
                        [magnitude.resource_id.id],
                        type=EVENT_VIEW_ITEM_TYPES["MAGNITUDE"]))
                self._state["quake_ids"][magnitude.resource_id.id] = \
                    mag_items[-1]
            magnitude_item.addChildren(mag_items)

            focmec_items = []
            for focmec in event.focal_mechanisms:
                focmec_items.append(
                    QtGui.QTreeWidgetItem(
                        [focmec.resource_id.id],
                        type=EVENT_VIEW_ITEM_TYPES["FOCMEC"]))
                self._state["quake_ids"][focmec.resource_id.id] = \
                    focmec_items[-1]
            focmec_item.addChildren(focmec_items)

            event_item.addChildren([origin_item, magnitude_item, focmec_item])
            items.append(event_item)

        self.ui.event_tree_widget.insertTopLevelItems(0, items)
コード例 #6
0
ファイル: main.py プロジェクト: outdoorpet/asdf_sextant
    def build_event_tree_view(self):
        if not hasattr(self, "ds") or not self.ds:
            return
        self.events = self.ds.events
        self.ui.event_tree_widget.clear()

        items = []
        self._state["quake_ids"] = {}

        for event in self.events:
            if event.origins:
                org = event.preferred_origin() or event.origins[0]

                js_call = "addEvent('{event_id}', {latitude}, {longitude});"\
                    .format(event_id=event.resource_id.id,
                            latitude=org.latitude,
                            longitude=org.longitude)
                self.ui.events_web_view.page().mainFrame().evaluateJavaScript(
                    js_call)

            event_item = QtGui.QTreeWidgetItem(
                [event.resource_id.id],
                type=EVENT_VIEW_ITEM_TYPES["EVENT"])
            self._state["quake_ids"][event.resource_id.id] = event_item

            origin_item = QtGui.QTreeWidgetItem(["Origins"], type=-1)
            magnitude_item = QtGui.QTreeWidgetItem(["Magnitudes"], type=-1)
            focmec_item = QtGui.QTreeWidgetItem(["Focal Mechanisms"], type=-1)

            org_items = []
            for origin in event.origins:
                org_items.append(
                    QtGui.QTreeWidgetItem(
                        [origin.resource_id.id],
                        type=EVENT_VIEW_ITEM_TYPES["ORIGIN"]))
                self._state["quake_ids"][origin.resource_id.id] = org_items[-1]
            origin_item.addChildren(org_items)

            mag_items = []
            for magnitude in event.magnitudes:
                mag_items.append(
                    QtGui.QTreeWidgetItem(
                        [magnitude.resource_id.id],
                        type=EVENT_VIEW_ITEM_TYPES["MAGNITUDE"]))
                self._state["quake_ids"][magnitude.resource_id.id] = \
                    mag_items[-1]
            magnitude_item.addChildren(mag_items)

            focmec_items = []
            for focmec in event.focal_mechanisms:
                focmec_items.append(
                    QtGui.QTreeWidgetItem(
                        [focmec.resource_id.id],
                        type=EVENT_VIEW_ITEM_TYPES["FOCMEC"]))
                self._state["quake_ids"][focmec.resource_id.id] = \
                    focmec_items[-1]
            focmec_item.addChildren(focmec_items)

            event_item.addChildren([origin_item, magnitude_item, focmec_item])
            items.append(event_item)

        self.ui.event_tree_widget.insertTopLevelItems(0, items)
コード例 #7
0
ファイル: main.py プロジェクト: GeoSinoLMU/asdf_sextant
    def build_event_tree_view(self):
        events = {}
        for v in self._open_files.values():
            for event in v["events"]:
                res_id = str(event.resource_id)
                if res_id in events:
                    continue
                events[res_id] = event
        self.ui.event_tree_widget.clear()

        items = []
        self._state["quake_ids"] = {}

        for event in events.values():
            if event.origins:
                org = event.preferred_origin() or event.origins[0]

                js_call = "addEvent('{event_id}', {latitude}, {longitude});".format(  # NOQA
                    event_id=event.resource_id.id,
                    latitude=org.latitude,
                    longitude=org.longitude,
                )
                self.ui.events_web_engine_view.page().runJavaScript(js_call)

            event_item = QtGui.QTreeWidgetItem(
                [event.resource_id.id], type=EVENT_VIEW_ITEM_TYPES["EVENT"]
            )
            self._state["quake_ids"][event.resource_id.id] = event_item

            origin_item = QtGui.QTreeWidgetItem(["Origins"], type=-1)
            magnitude_item = QtGui.QTreeWidgetItem(["Magnitudes"], type=-1)
            focmec_item = QtGui.QTreeWidgetItem(["Focal Mechanisms"], type=-1)

            org_items = []
            for origin in event.origins:
                org_items.append(
                    QtGui.QTreeWidgetItem(
                        [origin.resource_id.id],
                        type=EVENT_VIEW_ITEM_TYPES["ORIGIN"],
                    )
                )
                self._state["quake_ids"][origin.resource_id.id] = org_items[-1]
            origin_item.addChildren(org_items)

            mag_items = []
            for magnitude in event.magnitudes:
                mag_items.append(
                    QtGui.QTreeWidgetItem(
                        [magnitude.resource_id.id],
                        type=EVENT_VIEW_ITEM_TYPES["MAGNITUDE"],
                    )
                )
                self._state["quake_ids"][magnitude.resource_id.id] = mag_items[
                    -1
                ]
            magnitude_item.addChildren(mag_items)

            focmec_items = []
            for focmec in event.focal_mechanisms:
                focmec_items.append(
                    QtGui.QTreeWidgetItem(
                        [focmec.resource_id.id],
                        type=EVENT_VIEW_ITEM_TYPES["FOCMEC"],
                    )
                )
                self._state["quake_ids"][focmec.resource_id.id] = focmec_items[
                    -1
                ]
            focmec_item.addChildren(focmec_items)

            event_item.addChildren([origin_item, magnitude_item, focmec_item])
            items.append(event_item)

        self.ui.event_tree_widget.insertTopLevelItems(0, items)