예제 #1
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
예제 #2
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
예제 #3
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
예제 #4
0
파일: project.py 프로젝트: msimon00/LASIF
    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
예제 #5
0
파일: project.py 프로젝트: msimon00/LASIF
    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
예제 #6
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()