Example #1
0
    def plot_event(self, event_name):
        """
        Plots information about one event on the map.
        """
        from lasif import visualization
        import matplotlib.pyplot as plt

        # Plot the domain.
        bounds = self.domain["bounds"]
        map = visualization.plot_domain(bounds["minimum_latitude"],
            bounds["maximum_latitude"], bounds["minimum_longitude"],
            bounds["maximum_longitude"], bounds["boundary_width_in_degree"],
            rotation_axis=self.domain["rotation_axis"],
            rotation_angle_in_degree=self.domain["rotation_angle"],
            plot_simulation_domain=False, show_plot=False, zoom=True)

        all_events = self.get_event_dict()
        if event_name not in all_events:
            msg = "Event '%s' not found in project." % event_name
            raise ValueError(msg)

        event = self.get_event(event_name)
        event_info = self.get_event_info(event_name)

        stations = self.get_stations_for_event(event_name)
        visualization.plot_stations_for_event(map_object=map,
            station_dict=stations, event_info=event_info)
        # Plot the beachball for one event.
        visualization.plot_events([event], map_object=map)

        plt.show()
Example #2
0
    def plot_event(self, event_name):
        """
        Plots information about one event on the map.
        """
        if not self.comm.events.has_event(event_name):
            msg = "Event '%s' not found in project." % event_name
            raise ValueError(msg)

        map_object = self.comm.project.domain.plot()

        from lasif import visualization

        # Get the event and extract information from it.
        event_info = self.comm.events.get(event_name)

        # Get a dictionary containing all stations that have data for the
        # current event.
        try:
            stations = self.comm.query.get_all_stations_for_event(event_name)
        except LASIFNotFoundError:
            pass
        else:
            # Plot the stations if it has some. This will also plot raypaths.
            visualization.plot_stations_for_event(map_object=map_object,
                                                  station_dict=stations,
                                                  event_info=event_info)

        # Plot the beachball for one event.
        visualization.plot_events(events=[event_info], map_object=map_object)
Example #3
0
    def plot_event(self, event_name):
        """
        Plots information about one event on the map.
        """
        if not self.comm.events.has_event(event_name):
            msg = "Event '%s' not found in project." % event_name
            raise ValueError(msg)

        map_object = self.comm.project.domain.plot()

        from lasif import visualization

        # Get the event and extract information from it.
        event_info = self.comm.events.get(event_name)

        # Get a dictionary containing all stations that have data for the
        # current event.
        try:
            stations = self.comm.query.get_all_stations_for_event(event_name)
        except LASIFNotFoundError:
            pass
        else:
            # Plot the stations if it has some. This will also plot raypaths.
            visualization.plot_stations_for_event(
                map_object=map_object, station_dict=stations,
                event_info=event_info)

        # Plot the beachball for one event.
        visualization.plot_events(events=[event_info], map_object=map_object)
Example #4
0
    def plot_events(self, plot_type="map"):
        """
        Plots the domain and beachballs for all events on the map.

        :param plot_type: Determines the type of plot created.
            * ``map`` (default) - a map view of the events
            * ``depth`` - a depth distribution histogram
            * ``time`` - a time distribution histogram
        """
        from lasif import visualization

        events = self.comm.events.get_all_events().values()

        if plot_type == "map":
            domain = self.comm.project.domain
            if domain == "global":
                map = visualization.plot_domain()
            else:
                bounds = domain["bounds"]
                map = visualization.plot_domain(
                    bounds["minimum_latitude"], bounds["maximum_latitude"],
                    bounds["minimum_longitude"], bounds["maximum_longitude"],
                    bounds["boundary_width_in_degree"],
                    rotation_axis=domain["rotation_axis"],
                    rotation_angle_in_degree=domain["rotation_angle"],
                    plot_simulation_domain=False, zoom=True)
            visualization.plot_events(events, map_object=map, project=self)
        elif plot_type == "depth":
            visualization.plot_event_histogram(events, "depth")
        elif plot_type == "time":
            visualization.plot_event_histogram(events, "time")
        else:
            msg = "Unknown plot_type"
            raise LASIFError(msg)
Example #5
0
    def __setup_plots(self):
        # Some actual plots.
        self.plot_axis_z = plt.subplot2grid((6, 20), (0, 0), colspan=18)
        self.plot_axis_n = plt.subplot2grid((6, 20), (1, 0), colspan=18)
        self.plot_axis_e = plt.subplot2grid((6, 20), (2, 0), colspan=18)

        self.misfit_axis = plt.subplot2grid((6, 20), (3, 0), colspan=11,
            rowspan=3)
        self.colorbar_axis = plt.subplot2grid((6, 20), (3, 12), colspan=1,
            rowspan=3)
        #self.adjoint_source_axis = plt.subplot2grid((6, 8), (4, 0), colspan=4,
            #rowspan=1)
        self.map_axis = plt.subplot2grid((6, 20), (3, 13), colspan=8,
            rowspan=3)

        # Plot the map and the beachball.
        bounds = self.project.domain["bounds"]
        self.map_obj = visualization.plot_domain(bounds["minimum_latitude"],
            bounds["maximum_latitude"], bounds["minimum_longitude"],
            bounds["maximum_longitude"], bounds["boundary_width_in_degree"],
            rotation_axis=self.project.domain["rotation_axis"],
            rotation_angle_in_degree=self.project.domain["rotation_angle"],
            plot_simulation_domain=False, show_plot=False, zoom=True)
        visualization.plot_events([self.event], map_object=self.map_obj)

        # All kinds of buttons [left, bottom, width, height]
        self.axnext = plt.axes([0.90, 0.95, 0.08, 0.03])
        self.axprev = plt.axes([0.90, 0.90, 0.08, 0.03])
        self.axreset = plt.axes([0.90, 0.85, 0.08, 0.03])
        self.bnext = Button(self.axnext, 'Next')
        self.bprev = Button(self.axprev, 'Prev')
        self.breset = Button(self.axreset, 'Reset Station')
Example #6
0
    def plot_raydensity(self, save_plot=True, plot_stations=False):
        """
        Plots the raydensity.
        """
        from lasif import visualization
        import matplotlib.pyplot as plt

        plt.figure(figsize=(20, 21))

        map_object = self.comm.project.domain.plot()

        event_stations = []
        for event_name, event_info in \
                self.comm.events.get_all_events().iteritems():
            try:
                stations = \
                    self.comm.query.get_all_stations_for_event(event_name)
            except LASIFError:
                stations = {}
            event_stations.append((event_info, stations))

        visualization.plot_raydensity(map_object=map_object,
                                      station_events=event_stations,
                                      domain=self.comm.project.domain)

        visualization.plot_events(self.comm.events.get_all_events().values(),
                                  map_object=map_object)

        if plot_stations:
            stations = itertools.chain.from_iterable(
                (_i[1].values() for _i in event_stations if _i[1]))
            # Remove duplicates
            stations = [(_i["latitude"], _i["longitude"]) for _i in stations]
            stations = set(stations)
            x, y = map_object([_i[1] for _i in stations],
                              [_i[0] for _i in stations])
            map_object.scatter(x,
                               y,
                               s=14**2,
                               color="#333333",
                               edgecolor="#111111",
                               alpha=0.6,
                               zorder=200,
                               marker="v")

        plt.tight_layout()

        if save_plot:
            outfile = os.path.join(
                self.comm.project.get_output_folder(type="raydensity_plots",
                                                    tag="raydensity"),
                "raydensity.png")
            plt.savefig(outfile, dpi=200, transparent=True)
            print "Saved picture at %s" % outfile
Example #7
0
    def plot_station_misfits(
        self,
        event_name: str,
        iteration: str,
        intersection_override=None,
    ):
        """
        Plot a map of the stations where misfit was computed for a specific
        event. The stations are colour coded by misfit.

        :param event_name: Name of event
        :type event_name: str
        :param iteration: Name of iteration
        :type iteration: str
        :param intersection_override: boolean to require to have the same
            stations recording all events, i.e. the intersection of receiver
            sets. The intersection will consider two stations equal i.f.f. the
            station codes AND coordinates (LAT, LON, Z) are equal. If None is
            passed, the value use_only_intersection from the projects'
            configuration file is used, defaults to None
        :type intersection_override: bool, optional
        """
        from lasif import visualization

        map_object, projection = self.plot_domain()
        event_info = self.comm.events.get(event_name)
        stations = self.comm.query.get_all_stations_for_event(
            event_name, intersection_override=intersection_override)
        long_iter = self.comm.iterations.get_long_iteration_name(iteration)
        misfit_toml = (self.comm.project.paths["iterations"] / long_iter /
                       "misfits.toml")
        iteration_misfits = toml.load(misfit_toml)
        station_misfits = iteration_misfits[
            event_info["event_name"]]["stations"]
        misfitted_stations = {k: stations[k] for k in station_misfits.keys()}
        for k in misfitted_stations.keys():
            misfitted_stations[k]["misfit"] = station_misfits[k]

        visualization.plot_stations_for_event(
            map_object=map_object,
            station_dict=misfitted_stations,
            event_info=event_info,
            plot_misfits=True,
            raypaths=False,
            print_title=True,
        )

        visualization.plot_events(
            events=[event_info],
            map_object=map_object,
        )
Example #8
0
    def plot_events(
        self,
        plot_type: str = "map",
        iteration: str = None,
        inner_boundary: bool = False,
    ):
        """
        Plots the domain and beachballs for all events on the map.

        :param plot_type: Determines the type of plot created.
            * ``map`` (default) - a map view of the events
            * ``depth`` - a depth distribution histogram
            * ``time`` - a time distribution histogram
        :type plot_type: str, optional
        :param iteration: Name of iteration, if given only events from that
            iteration will be plotted, defaults to None
        :type iteration: str, optional
        :param inner_boundary: Should we plot inner boundary of domain?
            defaults to False
        :type inner_boundary: bool, optional
        """
        from lasif import visualization

        if iteration:
            events_used = self.comm.events.list(iteration=iteration)
            events = {}
            for event in events_used:
                events[event] = self.comm.events.get(event)
            events = events.values()
        else:
            events = self.comm.events.get_all_events().values()

        if plot_type == "map":
            m, projection = self.plot_domain(inner_boundary=inner_boundary)
            visualization.plot_events(
                events,
                map_object=m,
            )
            if iteration:
                title = f"Event distribution for iteration: {iteration}"
            else:
                title = "Event distribution"
            m.set_title(title)
        elif plot_type == "depth":
            visualization.plot_event_histogram(events, "depth")
        elif plot_type == "time":
            visualization.plot_event_histogram(events, "time")
        else:
            msg = "Unknown plot_type"
            raise LASIFError(msg)
Example #9
0
    def plot_raydensity(self, save_plot=True, plot_stations=False):
        """
        Plots the raydensity.
        """
        from lasif import visualization
        import matplotlib.pyplot as plt

        plt.figure(figsize=(20, 21))

        map_object = self.comm.project.domain.plot()

        event_stations = []
        for event_name, event_info in \
                self.comm.events.get_all_events().iteritems():
            try:
                stations = \
                    self.comm.query.get_all_stations_for_event(event_name)
            except LASIFError:
                stations = {}
            event_stations.append((event_info, stations))

        visualization.plot_raydensity(map_object=map_object,
                                      station_events=event_stations,
                                      domain=self.comm.project.domain)

        visualization.plot_events(self.comm.events.get_all_events().values(),
                                  map_object=map_object)

        if plot_stations:
            stations = itertools.chain.from_iterable((
                _i[1].values() for _i in event_stations if _i[1]))
            # Remove duplicates
            stations = [(_i["latitude"], _i["longitude"]) for _i in stations]
            stations = set(stations)
            x, y = map_object([_i[1] for _i in stations],
                              [_i[0] for _i in stations])
            map_object.scatter(x, y, s=14 ** 2, color="#333333",
                               edgecolor="#111111", alpha=0.6, zorder=200,
                               marker="v")

        plt.tight_layout()

        if save_plot:
            outfile = os.path.join(
                self.comm.project.get_output_folder(
                    type="raydensity_plots", tag="raydensity"),
                "raydensity.png")
            plt.savefig(outfile, dpi=200, transparent=True)
            print "Saved picture at %s" % outfile
Example #10
0
    def __setup_plots(self):

        # Some actual plots.
        self.plot_axis_z = plt.subplot2grid((6, 20), (0, 0), colspan=18)
        self.plot_axis_n = plt.subplot2grid((6, 20), (1, 0), colspan=18)
        self.plot_axis_e = plt.subplot2grid((6, 20), (2, 0), colspan=18)

        # Append another attribute to the plot axis to be able to later on
        # identify which component they belong to.
        self.plot_axis_z.seismic_component = "Z"
        self.plot_axis_n.seismic_component = "N"
        self.plot_axis_e.seismic_component = "E"

        self._activate_multicursor()

        self.misfit_axis = plt.subplot2grid((6, 20), (3, 0), colspan=11,
                                            rowspan=3)
        self.colorbar_axis = plt.subplot2grid((6, 20), (3, 12), colspan=1,
                                              rowspan=3)
        # self.adjoint_source_axis = plt.subplot2grid((6, 8), (4, 0),
        # colspan=4, rowspan=1)
        self.map_axis = plt.subplot2grid((6, 20), (3, 14), colspan=7,
                                         rowspan=3)

        # Plot the map and the beachball.
        bounds = self.project.domain["bounds"]
        self.map_obj = visualization.plot_domain(
            bounds["minimum_latitude"], bounds["maximum_latitude"],
            bounds["minimum_longitude"], bounds["maximum_longitude"],
            bounds["boundary_width_in_degree"],
            rotation_axis=self.project.domain["rotation_axis"],
            rotation_angle_in_degree=self.project.domain["rotation_angle"],
            plot_simulation_domain=False, zoom=True)
        visualization.plot_events([self.event], map_object=self.map_obj)

        # All kinds of buttons [left, bottom, width, height]
        self.axnext = plt.axes([0.90, 0.95, 0.08, 0.03])
        self.axprev = plt.axes([0.90, 0.90, 0.08, 0.03])
        self.axreset = plt.axes([0.90, 0.85, 0.08, 0.03])
        self.axautopick = plt.axes([0.90, 0.80, 0.08, 0.03])
        self.bnext = Button(self.axnext, 'Next')
        self.bprev = Button(self.axprev, 'Prev')
        self.breset = Button(self.axreset, 'Reset Station')
        self.bautopick = Button(self.axautopick, 'Autoselect')

        # Axis displaying the current weight
        self.axweight = plt.axes([0.90, 0.75, 0.08, 0.03])
        self._update_current_weight(1.0)
Example #11
0
    def plot_raydensity(self, save_plot=True):
        """
        Plots the raydensity.
        """
        from lasif import visualization
        import matplotlib.pyplot as plt

        plt.figure(figsize=(20, 21))

        domain = self.comm.project.domain
        bounds = domain["bounds"]
        map_object = visualization.plot_domain(
            bounds["minimum_latitude"], bounds["maximum_latitude"],
            bounds["minimum_longitude"], bounds["maximum_longitude"],
            bounds["boundary_width_in_degree"],
            rotation_axis=domain["rotation_axis"],
            rotation_angle_in_degree=domain["rotation_angle"],
            plot_simulation_domain=False, zoom=True,
            resolution="l")

        event_stations = []
        for event_name, event_info in \
                self.comm.events.get_all_events().iteritems():
            try:
                stations = \
                    self.comm.query.get_all_stations_for_event(event_name)
            except LASIFError:
                stations = {}
            event_stations.append((event_info, stations))

        visualization.plot_raydensity(
            map_object, event_stations, bounds["minimum_latitude"],
            bounds["maximum_latitude"], bounds["minimum_longitude"],
            bounds["maximum_longitude"], domain["rotation_axis"],
            domain["rotation_angle"])

        visualization.plot_events(self.comm.events.get_all_events().values(),
                                  map_object=map_object)

        plt.tight_layout()

        if save_plot:
            outfile = os.path.join(
                self.comm.project.get_output_folder("raydensity_plot"),
                "raydensity.png")
            plt.savefig(outfile, dpi=200, transparent=True)
            print "Saved picture at %s" % outfile
Example #12
0
    def plot_events(self):
        """
        Plots the domain and beachballs for all events on the map.
        """
        from lasif import visualization
        import matplotlib.pyplot as plt

        bounds = self.domain["bounds"]
        map = visualization.plot_domain(bounds["minimum_latitude"],
            bounds["maximum_latitude"], bounds["minimum_longitude"],
            bounds["maximum_longitude"], bounds["boundary_width_in_degree"],
            rotation_axis=self.domain["rotation_axis"],
            rotation_angle_in_degree=self.domain["rotation_angle"],
            plot_simulation_domain=False, show_plot=False, zoom=True)
        events = self.get_all_events()
        visualization.plot_events(events, map_object=map)
        plt.show()
Example #13
0
    def plot_raydensity(self):
        """
        Plots the raydensity.
        """
        from lasif import visualization
        import matplotlib.pyplot as plt

        plt.figure(figsize=(20, 21))

        bounds = self.domain["bounds"]
        map = visualization.plot_domain(
            bounds["minimum_latitude"],
            bounds["maximum_latitude"],
            bounds["minimum_longitude"],
            bounds["maximum_longitude"],
            bounds["boundary_width_in_degree"],
            rotation_axis=self.domain["rotation_axis"],
            rotation_angle_in_degree=self.domain["rotation_angle"],
            plot_simulation_domain=False,
            show_plot=False,
            zoom=True,
            resolution="l")

        event_stations = []
        for event_name in self.get_event_dict().keys():
            event = self.get_event(event_name)
            stations = self.get_stations_for_event(event_name)
            event_stations.append((event, stations))

        visualization.plot_raydensity(
            map, event_stations, bounds["minimum_latitude"],
            bounds["maximum_latitude"], bounds["minimum_longitude"],
            bounds["maximum_longitude"], self.domain["rotation_axis"],
            self.domain["rotation_angle"])

        events = self.get_all_events()
        visualization.plot_events(events, map_object=map)

        plt.tight_layout()

        outfile = os.path.join(self.get_output_folder("raydensity_plot"),
                               "raydensity.png")
        plt.savefig(outfile, dpi=200)
        print "Saved picture at %s" % outfile
Example #14
0
    def __setup_plots(self):
        # Some actual plots.
        self.plot_axis_z = plt.subplot2grid((6, 20), (0, 0), colspan=18)
        self.plot_axis_n = plt.subplot2grid((6, 20), (1, 0), colspan=18)
        self.plot_axis_e = plt.subplot2grid((6, 20), (2, 0), colspan=18)

        self.misfit_axis = plt.subplot2grid((6, 20), (3, 0),
                                            colspan=11,
                                            rowspan=3)
        self.colorbar_axis = plt.subplot2grid((6, 20), (3, 12),
                                              colspan=1,
                                              rowspan=3)
        #self.adjoint_source_axis = plt.subplot2grid((6, 8), (4, 0), colspan=4,
        #rowspan=1)
        self.map_axis = plt.subplot2grid((6, 20), (3, 13),
                                         colspan=8,
                                         rowspan=3)

        # Plot the map and the beachball.
        bounds = self.project.domain["bounds"]
        self.map_obj = visualization.plot_domain(
            bounds["minimum_latitude"],
            bounds["maximum_latitude"],
            bounds["minimum_longitude"],
            bounds["maximum_longitude"],
            bounds["boundary_width_in_degree"],
            rotation_axis=self.project.domain["rotation_axis"],
            rotation_angle_in_degree=self.project.domain["rotation_angle"],
            plot_simulation_domain=False,
            show_plot=False,
            zoom=True)
        visualization.plot_events([self.event], map_object=self.map_obj)

        # All kinds of buttons [left, bottom, width, height]
        self.axnext = plt.axes([0.90, 0.95, 0.08, 0.03])
        self.axprev = plt.axes([0.90, 0.90, 0.08, 0.03])
        self.axreset = plt.axes([0.90, 0.85, 0.08, 0.03])
        self.bnext = Button(self.axnext, 'Next')
        self.bprev = Button(self.axprev, 'Prev')
        self.breset = Button(self.axreset, 'Reset Station')
Example #15
0
    def plot_events(self):
        """
        Plots the domain and beachballs for all events on the map.
        """
        from lasif import visualization
        import matplotlib.pyplot as plt

        bounds = self.domain["bounds"]
        map = visualization.plot_domain(
            bounds["minimum_latitude"],
            bounds["maximum_latitude"],
            bounds["minimum_longitude"],
            bounds["maximum_longitude"],
            bounds["boundary_width_in_degree"],
            rotation_axis=self.domain["rotation_axis"],
            rotation_angle_in_degree=self.domain["rotation_angle"],
            plot_simulation_domain=False,
            show_plot=False,
            zoom=True)
        events = self.get_all_events()
        visualization.plot_events(events, map_object=map)
        plt.show()
Example #16
0
    def plot_event(self, event_name):
        """
        Plots information about one event on the map.
        """
        if not self.comm.events.has_event(event_name):
            msg = "Event '%s' not found in project." % event_name
            raise ValueError(msg)

        from lasif import visualization

        # Plot the domain.
        domain = self.comm.project.domain
        if domain == "global":
            map_object = visualization.plot_domain()
        else:
            bounds = domain["bounds"]
            map_object = visualization.plot_domain(
                bounds["minimum_latitude"], bounds["maximum_latitude"],
                bounds["minimum_longitude"], bounds["maximum_longitude"],
                bounds["boundary_width_in_degree"],
                rotation_axis=domain["rotation_axis"],
                rotation_angle_in_degree=domain["rotation_angle"],
                plot_simulation_domain=False, zoom=True)

        # Get the event and extract information from it.
        event_info = self.comm.events.get(event_name)

        # Get a dictionary containing all stations that have data for the
        # current event.
        stations = self.comm.query.get_all_stations_for_event(event_name)

        # Plot the stations. This will also plot raypaths.
        visualization.plot_stations_for_event(
            map_object=map_object, station_dict=stations,
            event_info=event_info, project=self)

        # Plot the beachball for one event.
        visualization.plot_events([event_info], map_object=map_object)
Example #17
0
    def plot_raydensity(self):
        """
        Plots the raydensity.
        """
        from lasif import visualization
        import matplotlib.pyplot as plt

        plt.figure(figsize=(20, 21))

        bounds = self.domain["bounds"]
        map = visualization.plot_domain(bounds["minimum_latitude"],
            bounds["maximum_latitude"], bounds["minimum_longitude"],
            bounds["maximum_longitude"], bounds["boundary_width_in_degree"],
            rotation_axis=self.domain["rotation_axis"],
            rotation_angle_in_degree=self.domain["rotation_angle"],
            plot_simulation_domain=False, show_plot=False, zoom=True,
            resolution="l")

        event_stations = []
        for event_name in self.get_event_dict().keys():
            event = self.get_event(event_name)
            stations = self.get_stations_for_event(event_name)
            event_stations.append((event, stations))

        visualization.plot_raydensity(map, event_stations,
            bounds["minimum_latitude"], bounds["maximum_latitude"],
            bounds["minimum_longitude"], bounds["maximum_longitude"],
            self.domain["rotation_axis"], self.domain["rotation_angle"])

        events = self.get_all_events()
        visualization.plot_events(events, map_object=map)

        plt.tight_layout()

        outfile = os.path.join(self.get_output_folder("raydensity_plot"),
            "raydensity.png")
        plt.savefig(outfile, dpi=200)
        print "Saved picture at %s" % outfile
Example #18
0
    def plot_events(self, plot_type="map"):
        """
        Plots the domain and beachballs for all events on the map.

        :param plot_type: Determines the type of plot created.
            * ``map`` (default) - a map view of the events
            * ``depth`` - a depth distribution histogram
            * ``time`` - a time distribution histogram
        """
        from lasif import visualization

        events = self.comm.events.get_all_events().values()

        if plot_type == "map":
            m = self.comm.project.domain.plot()
            visualization.plot_events(events, map_object=m)
        elif plot_type == "depth":
            visualization.plot_event_histogram(events, "depth")
        elif plot_type == "time":
            visualization.plot_event_histogram(events, "time")
        else:
            msg = "Unknown plot_type"
            raise LASIFError(msg)
Example #19
0
    def plot_events(self, plot_type="map"):
        """
        Plots the domain and beachballs for all events on the map.

        :param plot_type: Determines the type of plot created.
            * ``map`` (default) - a map view of the events
            * ``depth`` - a depth distribution histogram
            * ``time`` - a time distribution histogram
        """
        from lasif import visualization

        events = self.comm.events.get_all_events().values()

        if plot_type == "map":
            m = self.comm.project.domain.plot()
            visualization.plot_events(events, map_object=m)
        elif plot_type == "depth":
            visualization.plot_event_histogram(events, "depth")
        elif plot_type == "time":
            visualization.plot_event_histogram(events, "time")
        else:
            msg = "Unknown plot_type"
            raise LASIFError(msg)
Example #20
0
    def plot_event(self, event_name):
        """
        Plots information about one event on the map.
        """
        from lasif import visualization
        import matplotlib.pyplot as plt

        # Plot the domain.
        bounds = self.domain["bounds"]
        map = visualization.plot_domain(
            bounds["minimum_latitude"],
            bounds["maximum_latitude"],
            bounds["minimum_longitude"],
            bounds["maximum_longitude"],
            bounds["boundary_width_in_degree"],
            rotation_axis=self.domain["rotation_axis"],
            rotation_angle_in_degree=self.domain["rotation_angle"],
            plot_simulation_domain=False,
            show_plot=False,
            zoom=True)

        all_events = self.get_event_dict()
        if event_name not in all_events:
            msg = "Event '%s' not found in project." % event_name
            raise ValueError(msg)

        event = self.get_event(event_name)
        event_info = self.get_event_info(event_name)

        stations = self.get_stations_for_event(event_name)
        visualization.plot_stations_for_event(map_object=map,
                                              station_dict=stations,
                                              event_info=event_info)
        # Plot the beachball for one event.
        visualization.plot_events([event], map_object=map)

        plt.show()
Example #21
0
    def plot_event(
        self,
        event_name: str,
        weight_set: str = None,
        intersection_override: bool = None,
        inner_boundary: bool = False,
    ):
        """
        Plots information about one event on the map.

        :param event_name: Name of event
        :type event_name: str
        :param weight_set: Name of station weights set, defaults to None
        :type weight_set: str, optional
        :param intersection_override: boolean to require to have the same
            stations recording all events, i.e. the intersection of receiver
            sets. The intersection will consider two stations equal i.f.f. the
            station codes AND coordinates (LAT, LON, Z) are equal. If None is
            passed, the value use_only_intersection from the projects'
            configuration file is used, defaults to None
        :type intersection_override: bool, optional
        :param inner_boundary: binary whether the inner boundary should be drawn
            Only works well for convex domains, defaults to False
        :type inner_boundary: bool, optional
        """
        if not self.comm.events.has_event(event_name):
            msg = "Event '%s' not found in project." % event_name
            raise ValueError(msg)

        if weight_set:
            if not self.comm.weights.has_weight_set(weight_set):
                msg = f"Weight set {weight_set} not found in project."
                raise ValueError(msg)
            weight_set = self.comm.weights.get(weight_set)

        map_object, projection = self.plot_domain(
            inner_boundary=inner_boundary)

        from lasif import visualization

        # Get the event and extract information from it.
        event_info = self.comm.events.get(event_name)

        # Get a dictionary containing all stations that have data for the
        # current event.
        try:
            stations = self.comm.query.get_all_stations_for_event(
                event_name, intersection_override=intersection_override)
        except LASIFNotFoundError:
            pass
        else:
            # Plot the stations if it has some. This will also plot raypaths.
            visualization.plot_stations_for_event(
                map_object=map_object,
                station_dict=stations,
                event_info=event_info,
                weight_set=weight_set,
                print_title=True,
            )

        # Plot the earthquake star for one event.
        visualization.plot_events(
            events=[event_info],
            map_object=map_object,
        )
Example #22
0
    def plot_all_rays(
        self,
        save_plot: bool = True,
        iteration: str = None,
        plot_stations: bool = True,
        intersection_override: bool = None,
    ):
        """
        Plot all the rays that are in the project or in a specific iteration.
        This is typically slower than the plot_raydensity function as this one
        is non-parallel

        :param save_plot: Should plot be saved, defaults to True
        :type save_plot: bool, optional
        :param iteration: Only events from an iteration, defaults to None
        :type iteration: str, optional
        :param plot_stations: Whether stations are plotted on top, defaults to
            True
        :type plot_stations: bool, optional
        :param intersection_override: boolean to require to have the same
            stations recording all events, i.e. the intersection of receiver
            sets. The intersection will consider two stations equal i.f.f. the
            station codes AND coordinates (LAT, LON, Z) are equal. If None is
            passed, the value use_only_intersection from the projects'
            configuration file is used, defaults to None
        :type intersection_override: bool, optional
        """
        from lasif import visualization
        import matplotlib.pyplot as plt

        plt.figure(figsize=(20, 12))

        map_object, projection = self.plot_domain()

        event_stations = []
        use_only_intersection = self.comm.project.stacking_settings[
            "use_only_intersection"]
        if intersection_override is not None:
            use_only_intersection = intersection_override

        # If we should intersect, precompute the stations for all events,
        # since the stations are equal for all events if using intersect.
        if use_only_intersection:
            intersect_with = self.comm.events.list()
            stations = self.comm.query.get_all_stations_for_event(
                intersect_with[0], intersection_override=True)

        for event_name, event_info in self.comm.events.get_all_events(
                iteration).items():

            # If we're not intersecting, re-query all stations per event, as
            # the stations might change
            if not use_only_intersection:
                try:
                    stations = self.comm.query.get_all_stations_for_event(
                        event_name,
                        intersection_override=use_only_intersection)
                except LASIFError:
                    stations = {}
            event_stations.append((event_info, stations))

        visualization.plot_all_rays(
            map_object=map_object,
            station_events=event_stations,
        )
        visualization.plot_events(
            events=self.comm.events.get_all_events(iteration).values(),
            map_object=map_object,
        )
        if plot_stations:
            visualization.plot_all_stations(
                map_object=map_object,
                event_stations=event_stations,
            )
        if save_plot:
            if iteration:
                outfile = os.path.join(
                    self.comm.project.paths["output"],
                    "ray_plots",
                    f"ITERATION_{iteration}",
                    "all_rays.png",
                )
                outfolder, _ = os.path.split(outfile)
                if not os.path.exists(outfolder):
                    os.makedirs(outfolder)
            else:
                outfile = os.path.join(
                    self.comm.project.get_output_folder(type="ray_plots",
                                                        tag="all_rays"),
                    "all_rays.png",
                )
            if os.path.isfile(outfile):
                os.remove(outfile)
            plt.savefig(outfile, dpi=200, transparent=False, overwrite=True)
            print("Saved picture at %s" % outfile)
        else:
            plt.show()
Example #23
0
    def plot_raydensity(
        self,
        save_plot: bool = True,
        plot_stations: bool = False,
        iteration: str = None,
        intersection_override: bool = None,
    ):
        """
        Plots the raydensity. The plot will have number of ray crossings
        indicated with a brighter colour.

        :param save_plot: Whether plot should be saved or displayed,
            defaults to True (saved)
        :type save_plot: bool, optional
        :param plot_stations: Do you want to plot stations on top of rays?
            defaults to False
        :type plot_stations: bool, optional
        :param iteration: Name of iteration that you only want events from,
            defaults to None
        :type iteration: str, optional
        :param intersection_override: boolean to require to have the same
            stations recording all events, i.e. the intersection of receiver
            sets. The intersection will consider two stations equal i.f.f. the
            station codes AND coordinates (LAT, LON, Z) are equal. If None is
            passed, the value use_only_intersection from the projects'
            configuration file is used, defaults to None
        :type intersection_override: bool, optional
        """
        from lasif import visualization
        import matplotlib.pyplot as plt

        plt.figure(figsize=(20, 12))

        map_object, projection = self.plot_domain()

        event_stations = []

        # We could just pass intersection_override to the
        # self.comm.query.get_all_stations_for_event call within the event loop
        # and get rid of the more complicated statement before it, however
        # precomputing stations when they're equal anyway saves a lot of time.

        # Determine if we should intersect or not
        use_only_intersection = self.comm.project.stacking_settings[
            "use_only_intersection"]
        if intersection_override is not None:
            use_only_intersection = intersection_override

        # If we should intersect, precompute the stations for all events,
        # since the stations are equal for all events if using intersect.
        if use_only_intersection:
            intersect_with = self.comm.events.list()
            stations = self.comm.query.get_all_stations_for_event(
                intersect_with[0], intersection_override=True)

        for event_name, event_info in self.comm.events.get_all_events(
                iteration).items():

            # If we're not intersecting, re-query all stations per event, as
            # the stations might change
            if not use_only_intersection:
                try:
                    stations = self.comm.query.get_all_stations_for_event(
                        event_name,
                        intersection_override=use_only_intersection)
                except LASIFError:
                    stations = {}
            event_stations.append((event_info, stations))

        visualization.plot_raydensity(
            map_object=map_object,
            station_events=event_stations,
            domain=self.comm.project.domain,
            projection=projection,
        )

        visualization.plot_events(
            self.comm.events.get_all_events(iteration).values(),
            map_object=map_object,
        )

        if plot_stations:
            visualization.plot_all_stations(
                map_object=map_object,
                event_stations=event_stations,
            )

        if save_plot:
            if iteration:
                outfile = os.path.join(
                    self.comm.project.paths["output"],
                    "raydensity_plots",
                    f"ITERATION_{iteration}",
                    "raydensity.png",
                )
                outfolder, _ = os.path.split(outfile)
                if not os.path.exists(outfolder):
                    os.makedirs(outfolder)
            else:
                outfile = os.path.join(
                    self.comm.project.get_output_folder(
                        type="raydensity_plots", tag="raydensity"),
                    "raydensity.png",
                )
            if os.path.isfile(outfile):
                os.remove(outfile)
            plt.savefig(outfile, dpi=200, transparent=False, overwrite=True)
            print("Saved picture at %s" % outfile)
        else:
            plt.show()