Exemple #1
0
    def plot_heat_all(self, array_path, dep_lim = None, map_background = True):
        """
        receives the path to a serialized array object 
        optionally receives a depth limit and a map background boolean, to 
        indicate wheter we use the map as background or the coast as background
        in order to study the mainshocks plot heat map for all regions
        """
        # obtain array of shocks within the depth limit 
        all_quakes = pickle.load(open(array_path, 'rb'))
        useful_quakes = []
        for index in range(len(all_quakes)):
            current_quake = all_quakes[index]
            if dep_lim != None and current_quake.depth > dep_lim:
                continue
            useful_quakes.append(current_quake)

        # get instance of classes that we'll need methods
        draw = Draw() 
        cat = Catalog()

        # get dictionary that for every region name gives bound and zoom for all regions
        regions = {}
        regions["japan"] = [cat.get_catalog_bounds('../catalogs/new_jma.txt'), 5, 100]
        regions["kanto"] = [cat.get_kanto_bounds(), 9, 25]
        regions["kansai"] = [cat.get_kansai_bounds(), 9, 25]
        regions["tohoku"] = [cat.get_tohoku_bounds(), 9, 25]
        regions["east_japan"] = [cat.get_east_japan_bounds(), 9, 25]
        
        # index to add legibility to the code
        BOUNDS = 0
        ZOOM = 1
        BINS = 2

        # set time bound on which to plot and which years to plot 
        year_bound = [[0.0, 12*366*24.0*3600]] # this way all years are considered

        # iterate through the years 
        for time in year_bound:
            
            # iterate through the regions
            for region, info in regions.items():

                # if we are using a map as background
                if map_background: 

                    # plot image for the region
                    draw.plot_image_quakes(useful_quakes, time, info[BOUNDS], info[ZOOM])
                    call(["pdftoppm", "-rx", "300", "-ry", "300", "-png", "Rplots.pdf", region + "_back_heat"])
                    call(["mv",  region + "_back_heat-1.png", "../images/"])
                    call(["rm", "Rplots.pdf"])
                    input("Edit the image and then press Enter")

                    # plot heat map for the region in the given year
                    self.plot_heat(useful_quakes, time, info[BOUNDS], info[BINS], "../images/" + region + "_back_heat-1.png",\
                            only_main = False)
                    # save it in the correct format, and do cleaning
                    call(["mv", "temp.png", "../images/" + region + "_heat.png"])

                else:
                    # plot image for the current region 
                    draw.plot_quakes_coast(useful_quakes, time, info[BOUNDS], dep_lim = dep_lim)
                    call(["mv", "temp.png", "../images/" + region + "_back_heat_coast-1.png"])
                    input("Edit the image and then press Enter")

                    # plot heat map for the region in the given year
                    self.plot_heat(useful_quakes, time, info[BOUNDS], info[BINS], "../images/" + region + "_back_heat_coast-1.png",\
                            only_main = False)
                    # save it in the correct format, and do cleaning
                    call(["mv", "temp.png", "../images/" + region + "_heat_coast.png"])
Exemple #2
0
    def plot_clusters_all(self, array_path, dep_lim = None, map_background = True):
        """
        receives a path to the array of quakes.

        optionally it receives a depth limit and a map_background boolean
        if map_background = True, then the cluster is plot with a background map
        if map_background = False, then the cluster is plot with the coast of japan 
        as background 
        
        in order to plot study the mainshocks and it's associated clusters,
        plot some clusters on the map 
        """
        # obtain array of shocks within the depth limit 
        all_quakes = pickle.load(open(array_path, 'rb'))
        useful_quakes = []
        for index in range(len(all_quakes)):
            current_quake = all_quakes[index]
            if dep_lim != None and current_quake.depth > dep_lim:
                continue
            useful_quakes.append(current_quake)

        # get instance of classes so we can access methods
        draw = Draw()
        cat = Catalog()

        # get dictionary that for every region name gives bound and zoom for all regions
        regions = {}
        regions["japan"] = [cat.get_catalog_bounds('../catalogs/new_jma.txt'), 5]
        regions["kanto"] = [cat.get_kanto_bounds(), 9]
        regions["kansai"] = [cat.get_kansai_bounds(), 9]
        regions["tohoku"] = [cat.get_tohoku_bounds(), 9]
        regions["east_japan"] = [cat.get_east_japan_bounds(), 9]
        
        # index to add legibility to the code
        BOUNDS = 0
        ZOOM = 1
        
        # set list of how many clusters to plot, and which years to plot 
        num_clusters = [10]
        year_bound = [[0.0, 12*366*24.0*3600]] # this way we consider all years

        # iterate through the list containing how many clusters we plot
        for num in num_clusters:

            # iterate through the years 
            for time in year_bound:
                
                # iterate through the regions
                for region, info in regions.items():
                    
                    # if we need to plot a map in the background
                    if map_background:

                        # plot image for the current region 
                        draw.plot_image_quakes(useful_quakes, time, info[BOUNDS], info[ZOOM], num_clusters = num, dep_lim = dep_lim)
                        call(["pdftoppm", "-rx", "300", "-ry", "300", "-png", "Rplots.pdf", region + "_back"])
                        call(["mv",  region + "_back-1.png", "../images/"])
                        call(["rm", "Rplots.pdf"])
                        input("Edit the image and then press Enter")

                        # plot cluster for current region in the given year, for the current number of clusters
                        self.plot_clusters(useful_quakes, num, time, info[BOUNDS],  "../images/" + region +"_back-1.png")
                        ## save it in the correct format, and do cleaning
                        call(["mv", "temp.png", "../images/" + region + "_clusters_map.png"])
                    
                    # if we dont want to plot a japan map in the background
                    else:

                        # plot image for the current region 
                        draw.plot_quakes_coast(useful_quakes, time, info[BOUNDS], num_clusters = num, dep_lim = dep_lim)
                        call(["mv", "temp.png", "../images/" + region + "_back_coast-1.png"])
                        input("Edit the image and then press Enter")

                        # plot cluster for current region in the given year, for the current number of clusters
                        self.plot_clusters(useful_quakes, num, time, info[BOUNDS],  "../images/" + region +"_back_coast-1.png")
                                
                        ## save it in the correct format, and do cleaning
                        call(["mv", "temp.png", "../images/" + region + "_clusters_coast.png"])