Exemplo n.º 1
0
def plot_husid(acceleration, time_step, start_level=0., end_level=1.0,
        figure_size=(7, 5), filename=None, filetype="png", dpi=300):
    """
    Creates a Husid plot for the record
    :param tuple figure_size:
        Size of the output figure (Width, Height)
    :param str filename:
        Name of the file to export
    :param str filetype:
        Type of file for export
    :param int dpi:
        FIgure resolution in dots per inch.
    """
    plt.figure(figsize=figure_size)
    husid, time_vector = get_husid(acceleration, time_step)
    husid_norm = husid / husid[-1]
    idx = np.where(np.logical_and(husid_norm >= start_level,
                                  husid_norm <= end_level))[0]
    plt.plot(time_vector, husid_norm, "b-", linewidth=2.0,
             label="Original Record")
    plt.plot(time_vector[idx], husid_norm[idx], "r-", linewidth=2.0,
             label="%5.3f - %5.3f Arias" % (start_level, end_level))
    plt.xlabel("Time (s)", fontsize=14)
    plt.ylabel("Fraction of Arias Intensity", fontsize=14)
    plt.title("Husid Plot")
    plt.legend(loc=4, fontsize=14)
    _save_image(filename, filetype, dpi)
    plt.show()
Exemplo n.º 2
0
 def plot_model_configuration(self, marker_style="o", figure_size=(7, 5), 
         filename=None, filetype="png", dpi=300):
     """
     Produces a 3D plot of the current model configuration
     """
     fig = plt.figure(figsize=figure_size)
     ax = fig.add_subplot(111, projection='3d')
     # Wireframe rupture surface mesh
     rupture_mesh = self.surface.get_mesh()
     ax.plot_wireframe(rupture_mesh.lons,
                       rupture_mesh.lats, 
                       -rupture_mesh.depths,
                       rstride=1,
                       cstride=1)
     # Scatter the target sites
     ax.scatter(self.target_sites.mesh.lons,
                self.target_sites.mesh.lats,
                np.ones_like(self.target_sites.mesh.lons),
                c='r',
                marker=marker_style)
     ax.set_xlabel('Longitude')
     ax.set_ylabel('Latitude')
     ax.set_zlabel('Depth (km)')
     _save_image(filename, filetype, dpi)
     plt.show()
Exemplo n.º 3
0
    def create_plot(self):
        """

        """
        data = self.residuals.residuals[self.gmpe][self.imt]
        if not data:
            print("No residuals found for %s (%s)" % (self.gmpe, self.imt))
            return

        fig = plt.figure(figsize=self.figure_size)
        fig.set_tight_layout(True)
        if self.num_plots > 1:
            nrow = 3
            ncol = 1
        else:
            nrow = 1
            ncol = 1
        tloc = 1
        for res_type in data.keys():
            vs30 = self._get_vs30(self.gmpe, self.imt, res_type)
            self._residual_plot(
                plt.subplot(nrow, ncol, tloc),
                vs30,
                data,
                res_type)
            tloc += 1
        _save_image(self.filename, self.filetype, self.dpi)
        if self.show:
            plt.show()
Exemplo n.º 4
0
 def create_plot(self, bin_width=0.5):
     """
     Creates a histogram plot
     """
     data = self.residuals.residuals[self.gmpe][self.imt]
     if not data:
         print("No residuals found for %s (%s)" % (self.gmpe, self.imt))
         return
     statistics = self.residuals.get_residual_statistics()
     fig = plt.figure(figsize=self.figure_size)
     fig.set_tight_layout(True)
     if self.num_plots > 1:
         nrow = 2
         ncol = 2
     else:
         nrow = 1
         ncol = 1
     tloc = 1
     for res_type in data.keys():
         self._density_plot(
             plt.subplot(nrow, ncol, tloc),
             data,
             res_type,
             statistics,
             bin_width)
         tloc += 1
     _save_image(self.filename, self.filetype, self.dpi)
     if self.show:
         plt.show()
Exemplo n.º 5
0
def db_magnitude_distance_by_site(db1, dist_type, classification="NEHRP",
        figure_size=(7, 5), filename=None, filetype="png", dpi=300):
    """
    Plot magnitude-distance comparison by site NEHRP or Eurocode 8 Site class   
    """ 
    if classification == "NEHRP":
        site_bounds = NEHRP_BOUNDS
    elif classification == "EC8":
        site_bounds = EC8_BOUNDS
    else:
        raise ValueError("Unrecognised Site Classifier!")
    selector = SMRecordSelector(db1)
    plt.figure(figsize=figure_size)
    total_idx = []
    for site_class in site_bounds.keys():
        site_idx = _site_selection(db1, site_class, classification)
        if site_idx:
            site_db = selector.select_records(site_idx, as_db=True)
            mags, dists = get_magnitude_distances(site_db, dist_type)
            plt.plot(np.array(dists), np.array(mags), "o", mec='k',
                     mew=0.5, label="Site Class %s" % site_class)
            total_idx.extend(site_idx)
    unc_idx = set(range(db1.number_records())).difference(set(total_idx))
    unc_db = selector.select_records(unc_idx, as_db=True)
    mag, dists = get_magnitude_distances(site_db, dist_type)
    plt.semilogx(np.array(dists), np.array(mags), "o", mfc="None", mec='k',
                 mew=0.5, label="Unclassified", zorder=0)
    plt.xlabel(DISTANCE_LABEL[dist_type], fontsize=14)
    plt.ylabel("Magnitude", fontsize=14)
    plt.grid()
    plt.legend(ncol=2,loc="lower right", numpoints=1)
    plt.title("Magnitude vs Distance (by %s Site Class)" % classification,
              fontsize=18)
    _save_image(filename, filetype, dpi)
    plt.show()
Exemplo n.º 6
0
 def create_plot(self, bin_width=0.5):
     """
     Creates a histogram plot
     """
     data = self.residuals.residuals[self.gmpe][self.imt]
     statistics = self.residuals.get_residual_statistics()
     fig = plt.figure(figsize=self.figure_size)
     fig.set_tight_layout(True)
     if self.num_plots > 1:
         nrow = 2
         ncol = 2
     else:
         nrow = 1
         ncol = 1
     tloc = 1
     for res_type in data.keys():
         self._density_plot(
             plt.subplot(nrow, ncol, tloc),
             data,
             res_type,
             statistics,
             bin_width)
         tloc += 1
     _save_image(self.filename, self.filetype, self.dpi)
     plt.show()
Exemplo n.º 7
0
def db_magnitude_distance_by_trt(db1,
                                 dist_type,
                                 figure_size=(7, 5),
                                 filename=None,
                                 filetype="png",
                                 dpi=300):
    """
    Plot magnitude-distance comparison by tectonic region
    """
    trts = []
    for i in db1.records:
        trts.append(i.event.tectonic_region)
    trt_types = list(set(trts))
    selector = SMRecordSelector(db1)
    plt.figure(figsize=figure_size)
    for trt in trt_types:
        subdb = selector.select_trt_type(trt, as_db=True)
        mag, dists = get_magnitude_distances(subdb, dist_type)
        plt.semilogx(dists, mag, "o", mec='k', mew=0.5, label=trt)
    plt.xlabel(DISTANCE_LABEL[dist_type], fontsize=14)
    plt.ylabel("Magnitude", fontsize=14)
    plt.title("Magnitude vs Distance by Tectonic Region", fontsize=18)
    plt.legend(loc='lower right', numpoints=1)
    plt.grid()
    _save_image(filename, plt.gcf(), filetype, dpi)
    plt.show()
Exemplo n.º 8
0
    def plot_model_configuration(self, marker_style="o", figure_size=(7, 5), 
            filename=None, filetype="png", dpi=300):
        """
        Produces a 3D plot of the current model configuration
        """
        fig = plt.figure(figsize=figure_size)
        ax = fig.add_subplot(111, projection='3d')
        # Wireframe rupture surface mesh
        lons = []
        lats = []
        depths = []
        for pnt in [self.surface.top_left, self.surface.top_right,
                    self.surface.bottom_right, self.surface.bottom_left,
                    self.surface.top_left]:
            lons.append(pnt.longitude)
            lats.append(pnt.latitude)
            depths.append(-pnt.depth)
        ax.plot(lons, lats, depths, "k-", lw=2)

        # Scatter the target sites
        ax.scatter(self.target_sites.mesh.lons,
                   self.target_sites.mesh.lats,
                   np.ones_like(self.target_sites.mesh.lons),
                   c='r',
                   marker=marker_style)
        ax.set_xlabel('Longitude')
        ax.set_ylabel('Latitude')
        ax.set_zlabel('Depth (km)')
        ax.set_zlim(np.floor(min(depths)), 0.0)
        _save_image(filename, filetype, dpi)
        plt.show()
def plot_husid(acceleration, time_step, start_level=0., end_level=1.0,
        figure_size=(7, 5), filename=None, filetype="png", dpi=300):
    """
    Creates a Husid plot for the record
    :param tuple figure_size:
        Size of the output figure (Width, Height)
    :param str filename:
        Name of the file to export
    :param str filetype:
        Type of file for export
    :param int dpi:
        FIgure resolution in dots per inch.
    """
    plt.figure(figsize=figure_size)
    husid, time_vector = get_husid(acceleration, time_step)
    husid_norm = husid / husid[-1]
    idx = np.where(np.logical_and(husid_norm >= start_level,
                                  husid_norm <= end_level))[0]
    plt.plot(time_vector, husid_norm, "b-", linewidth=2.0,
             label="Original Record")
    plt.plot(time_vector[idx], husid_norm[idx], "r-", linewidth=2.0,
             label="%5.3f - %5.3f Arias" % (start_level, end_level))
    plt.xlabel("Time (s)", fontsize=14)
    plt.ylabel("Fraction of Arias Intensity", fontsize=14)
    plt.title("Husid Plot")
    plt.legend(loc=4, fontsize=14)
    _save_image(filename, filetype, dpi)
    plt.show()
Exemplo n.º 10
0
    def plot_model_configuration(self,
                                 marker_style="o",
                                 figure_size=(7, 5),
                                 filename=None,
                                 filetype="png",
                                 dpi=300):
        """
        Produces a 3D plot of the current model configuration
        """
        fig = plt.figure(figsize=figure_size)
        ax = fig.add_subplot(111, projection='3d')
        # Wireframe rupture surface mesh
        rupture_mesh = self.surface.get_mesh()
        ax.plot_wireframe(rupture_mesh.lons,
                          rupture_mesh.lats,
                          -rupture_mesh.depths,
                          rstride=1,
                          cstride=1)

        # Scatter the target sites
        ax.scatter(self.target_sites.mesh.lons,
                   self.target_sites.mesh.lats,
                   np.ones_like(self.target_sites.mesh.lons),
                   c='r',
                   marker=marker_style)
        ax.set_xlabel('Longitude')
        ax.set_ylabel('Latitude')
        ax.set_zlabel('Depth (km)')
        ax.set_zlim(-np.ceil(np.max(rupture_mesh.depths)), 0.0)
        _save_image(filename, filetype, dpi)
        plt.show()
Exemplo n.º 11
0
    def plot_distance_comparisons(self,
                                  distance1,
                                  distance2,
                                  logaxis=False,
                                  figure_size=(7, 5),
                                  filename=None,
                                  filetype="png",
                                  dpi=300):
        """
        Creates a plot comparing different distance metrics for the 
        specific rupture and target site combination
        """
        xdist = self._calculate_distance(distance1)
        ydist = self._calculate_distance(distance2)
        plt.figure(figsize=figure_size)

        if logaxis:
            plt.loglog(xdist, ydist, color='b', marker='o', linestyle='None')
        else:
            plt.plot(xdist, ydist, color='b', marker='o', linestyle='None')

        plt.xlabel("%s (km)" % distance1, size='medium')
        plt.ylabel("%s (km)" % distance2, size='medium')
        plt.title('Rupture: M=%6.1f, Dip=%3.0f, Ztor=%4.1f, Aspect=%5.2f' %
                  (self.magnitude, self.dip, self.ztor, self.aspect))
        _save_image(filename, filetype, dpi)
        plt.show()
Exemplo n.º 12
0
 def create_plot(self, bin_width=0.1):
     """
     Creates a histogram plot
     """
     #data = self.residuals.residuals[self.gmpe][self.imt]
     lh_vals, statistics = self.residuals.get_likelihood_values()
     lh_vals = lh_vals[self.gmpe][self.imt]
     statistics = statistics[self.gmpe][self.imt]
     fig = plt.figure(figsize=self.figure_size)
     fig.set_tight_layout(True)
     if self.num_plots > 1:
         nrow = 2
         ncol = 2
     else:
         nrow = 1
         ncol = 1
     tloc = 1
     for res_type in lh_vals.keys():
         self._density_plot(
             plt.subplot(nrow, ncol, tloc),
             lh_vals[res_type],
             res_type,
             statistics[res_type],
             bin_width)
         tloc += 1
     _save_image(self.filename, self.filetype, self.dpi)
     if self.show:
         plt.show()
Exemplo n.º 13
0
    def plot_model_configuration(self, marker_style="o", figure_size=(7, 5), 
            filename=None, filetype="png", dpi=300):
        """
        Produces a 3D plot of the current model configuration
        """
        fig = plt.figure(figsize=figure_size)
        ax = fig.add_subplot(111, projection='3d')
        # Wireframe rupture surface mesh
        lons = []
        lats = []
        depths = []
        for pnt in [self.surface.top_left, self.surface.top_right,
                    self.surface.bottom_right, self.surface.bottom_left,
                    self.surface.top_left]:
            lons.append(pnt.longitude)
            lats.append(pnt.latitude)
            depths.append(-pnt.depth)
        ax.plot(lons, lats, depths, "k-", lw=2)

        # Scatter the target sites
        ax.scatter(self.target_sites.mesh.lons,
                   self.target_sites.mesh.lats,
                   np.ones_like(self.target_sites.mesh.lons),
                   c='r',
                   marker=marker_style)
        ax.set_xlabel('Longitude')
        ax.set_ylabel('Latitude')
        ax.set_zlabel('Depth (km)')
        ax.set_zlim(np.floor(min(depths)), 0.0)
        _save_image(filename, filetype, dpi)
        plt.show()
Exemplo n.º 14
0
 def create_plot(self, bin_width=0.1):
     """
     Creates a histogram plot
     """
     #data = self.residuals.residuals[self.gmpe][self.imt]
     lh_vals, statistics = self.residuals.get_likelihood_values()
     lh_vals = lh_vals[self.gmpe][self.imt]
     statistics = statistics[self.gmpe][self.imt]
     fig = plt.figure(figsize=self.figure_size)
     fig.set_tight_layout(True)
     if self.num_plots > 1:
         nrow = 2
         ncol = 2
     else:
         nrow = 1
         ncol = 1
     tloc = 1
     for res_type in lh_vals.keys():
         self._density_plot(
             plt.subplot(nrow, ncol, tloc),
             lh_vals[res_type],
             res_type,
             statistics[res_type],
             bin_width)
         tloc += 1
     _save_image(self.filename, self.filetype, self.dpi)
     plt.show()
Exemplo n.º 15
0
def plot_time_series(acceleration,
                     time_step,
                     velocity=[],
                     displacement=[],
                     units="cm/s/s",
                     figure_size=(8, 6),
                     filename=None,
                     filetype="png",
                     dpi=300,
                     linewidth=1.5):
    """
    Creates a plot of acceleration, velocity and displacement for a specific
    ground motion record
    """
    acceleration = convert_accel_units(acceleration, units)
    accel_time = get_time_vector(time_step, len(acceleration))
    if not len(velocity):
        velocity, dspl = get_velocity_displacement(time_step, acceleration)
    vel_time = get_time_vector(time_step, len(velocity))
    if not len(displacement):
        displacement = dspl
    disp_time = get_time_vector(time_step, len(displacement))
    fig = plt.figure(figsize=figure_size)
    fig.set_tight_layout(True)
    ax = plt.subplot(3, 1, 1)
    # Accleration
    ax.plot(accel_time, acceleration, 'k-', linewidth=linewidth)
    ax.set_xlabel("Time (s)", fontsize=12)
    ax.set_ylabel("Acceleration (cm/s/s)", fontsize=12)
    end_time = np.max(np.array([accel_time[-1], vel_time[-1], disp_time[-1]]))
    pga = np.max(np.fabs(acceleration))
    ax.set_xlim(0, end_time)
    ax.set_ylim(-1.1 * pga, 1.1 * pga)
    ax.grid()
    # Velocity
    ax = plt.subplot(3, 1, 2)
    ax.plot(vel_time, velocity, 'b-', linewidth=linewidth)
    ax.set_xlabel("Time (s)", fontsize=12)
    ax.set_ylabel("Velocity (cm/s)", fontsize=12)
    pgv = np.max(np.fabs(velocity))
    ax.set_xlim(0, end_time)
    ax.set_ylim(-1.1 * pgv, 1.1 * pgv)
    ax.grid()
    # Displacement
    ax = plt.subplot(3, 1, 3)
    ax.plot(disp_time, displacement, 'r-', linewidth=linewidth)
    ax.set_xlabel("Time (s)", fontsize=12)
    ax.set_ylabel("Displacement (cm)", fontsize=12)
    pgd = np.max(np.fabs(displacement))
    ax.set_xlim(0, end_time)
    ax.set_ylim(-1.1 * pgd, 1.1 * pgd)
    ax.grid()
    _save_image(filename, filetype, dpi)
    plt.show()
Exemplo n.º 16
0
def plot_fourier_spectrum(time_series, time_step, figure_size=(7, 5), filename=None, filetype="png", dpi=300):
    """
    Plots the Fourier spectrum of a time series 
    """
    freq, amplitude = get_fourier_spectrum(time_series, time_step)
    plt.figure(figsize=figure_size)
    plt.loglog(freq, amplitude, "b-")
    plt.xlabel("Frequency (Hz)", fontsize=14)
    plt.ylabel("Fourier Amplitude", fontsize=14)
    _save_image(filename, filetype, dpi)
    plt.show()
Exemplo n.º 17
0
def plot_fourier_spectrum(time_series, time_step, figure_size=(7, 5),
        filename=None, filetype="png", dpi=300):
    """
    Plots the Fourier spectrum of a time series 
    """
    freq, amplitude = get_fourier_spectrum(time_series, time_step)
    plt.figure(figsize=figure_size)
    plt.loglog(freq, amplitude, 'b-')
    plt.xlabel("Frequency (Hz)", fontsize=14)
    plt.ylabel("Fourier Amplitude", fontsize=14)
    _save_image(filename, filetype, dpi)
    plt.show()
Exemplo n.º 18
0
    def create_plot(self):
        """
        Creates the plot
        """
        phi_ss, phi_s2ss = self.residuals.residual_statistics()
        data = self._get_site_data()
        fig = plt.figure(figsize=self.figure_size)
        fig.set_tight_layout(True)

        self._residual_plot(fig, data, phi_ss[self.gmpe][self.imt], phi_s2ss[self.gmpe][self.imt])
        _save_image(self.filename, self.filetype, self.dpi)
        if self.show:
            plt.show()
Exemplo n.º 19
0
    def create_plot(self):
        """
        Creates the plot
        """
        phi_ss, phi_s2ss = self.residuals.residual_statistics()
        data = self._get_site_data()
        fig = plt.figure(figsize=self.figure_size)
        fig.set_tight_layout(True)

        self._residual_plot(fig, data, phi_ss[self.gmpe][self.imt],
                            phi_s2ss[self.gmpe][self.imt])
        _save_image(self.filename, self.filetype, self.dpi)
        plt.show()
Exemplo n.º 20
0
 def create_plot(self):
     """
     Creates a residual plot
     """
     data = self.get_plot_data()
     # statistics = self.residuals.get_residual_statistics()
     fig = plt.figure(figsize=self.figure_size)
     fig.set_tight_layout(True)
     nrow, ncol = self.get_subplots_rowcols()
     for tloc, res_type in enumerate(data.keys(), 1):
         self._residual_plot(plt.subplot(nrow, ncol, tloc), data[res_type],
                             res_type)
     _save_image(self.filename, plt.gcf(), self.filetype, self.dpi)
     if self.show:
         plt.show()
Exemplo n.º 21
0
def db_magnitude_distance(db1, dist_type, figure_size=(7, 5),
        figure_title=None,filename=None, filetype="png", dpi=300):
    """
    Creates a plot of magnitude verses distance for a strong motion database
    """
    plt.figure(figsize=figure_size)
    mags, dists = get_magnitude_distances(db1, dist_type)
    plt.semilogx(np.array(dists), np.array(mags), "o", mec='k', mew=0.5)
    plt.xlabel(DISTANCE_LABEL[dist_type], fontsize=14)
    plt.ylabel("Magnitude", fontsize=14)
    if figure_title:
        plt.title(figure_title, fontsize=18)
    _save_image(filename, filetype, dpi)
    plt.grid()
    plt.show()
Exemplo n.º 22
0
 def create_plot(self):
     """
     Creates a residual plot
     """
     data = self.get_plot_data()
     # statistics = self.residuals.get_residual_statistics()
     fig = plt.figure(figsize=self.figure_size)
     fig.set_tight_layout(True)
     nrow, ncol = self.get_subplots_rowcols()
     for tloc, res_type in enumerate(data.keys(), 1):
         self._residual_plot(plt.subplot(nrow, ncol, tloc), data[res_type],
                             res_type)
     _save_image(self.filename, self.filetype, self.dpi)
     if self.show:
         plt.show()
Exemplo n.º 23
0
def plot_time_series(acceleration, time_step, velocity=[], displacement=[],
        units="cm/s/s", figure_size=(8, 6), filename=None, filetype="png",
        dpi=300, linewidth=1.5):
    """
    Creates a plot of acceleration, velocity and displacement for a specific
    ground motion record
    """
    acceleration = convert_accel_units(acceleration, units)
    accel_time = get_time_vector(time_step, len(acceleration))
    if not len(velocity):
        velocity, dspl = get_velocity_displacement(time_step, acceleration)
    vel_time = get_time_vector(time_step, len(velocity))
    if not len(displacement):
        displacement = dspl
    disp_time = get_time_vector(time_step, len(displacement))
    fig = plt.figure(figsize=figure_size)
    fig.set_tight_layout(True)
    ax = plt.subplot(3, 1, 1)
    # Accleration
    ax.plot(accel_time, acceleration, 'k-', linewidth=linewidth)
    ax.set_xlabel("Time (s)", fontsize=12)
    ax.set_ylabel("Acceleration (cm/s/s)", fontsize=12)
    end_time = np.max(np.array([accel_time[-1], vel_time[-1], disp_time[-1]]))
    pga = np.max(np.fabs(acceleration))
    ax.set_xlim(0, end_time)
    ax.set_ylim(-1.1 * pga, 1.1 * pga)
    ax.grid()
    # Velocity
    ax = plt.subplot(3, 1, 2)
    ax.plot(vel_time, velocity, 'b-', linewidth=linewidth)
    ax.set_xlabel("Time (s)", fontsize=12)
    ax.set_ylabel("Velocity (cm/s)", fontsize=12)
    pgv = np.max(np.fabs(velocity))
    ax.set_xlim(0, end_time)
    ax.set_ylim(-1.1 * pgv, 1.1 * pgv)
    ax.grid()
    # Displacement
    ax = plt.subplot(3, 1, 3)
    ax.plot(disp_time, displacement, 'r-', linewidth=linewidth)
    ax.set_xlabel("Time (s)", fontsize=12)
    ax.set_ylabel("Displacement (cm)", fontsize=12)
    pgd = np.max(np.fabs(displacement))
    ax.set_xlim(0, end_time)
    ax.set_ylim(-1.1 * pgd, 1.1 * pgd)
    ax.grid()
    _save_image(filename, filetype, dpi)
    plt.show()
Exemplo n.º 24
0
def plot_husid(acceleration, time_step, start_level=0., end_level=1.0,
        figure_size=(7, 5), filename=None, filetype="png", dpi=300):
    """
    Creates a Husid plot for the record
    """
    plt.figure(figsize=figure_size)
    husid, time_vector = get_husid(acceleration, time_step)
    husid_norm = husid / husid[-1]
    idx = np.where(np.logical_and(husid_norm >= start_level,
                                  husid_norm <= end_level))[0]
    plt.plot(time_vector, husid_norm, "b-", linewidth=2.0,
             label="Original Record")
    plt.plot(time_vector[idx], husid_norm[idx], "r-", linewidth=2.0,
             label="%5.3f - %5.3f Arias" % (start_level, end_level))
    plt.xlabel("Time (s)", fontsize=14)
    plt.ylabel("Fraction of Arias Intensity", fontsize=14)
    plt.title("Husid Plot")
    plt.legend(loc=4, fontsize=14)
    _save_image(filename, filetype, dpi)
    plt.show()
Exemplo n.º 25
0
    def create_plot(self):
        """

        """
        phi_ss, phi_s2ss = self.residuals.residual_statistics()
        data = self._get_site_data()
        fig = plt.figure(figsize=self.figure_size)
        fig.set_tight_layout(True)
        if self.num_plots > 1:
            nrow = 3
            ncol = 1
        else:
            nrow = 1
            ncol = 1
        tloc = 1
        for res_type in self.residuals.types[self.gmpe][self.imt]:
            self._residual_plot(fig.add_subplot(nrow, ncol, tloc), data,
                                res_type)
            tloc += 1
        _save_image(self.filename, self.filetype, self.dpi)
        plt.show()
Exemplo n.º 26
0
    def create_plot(self):
        """

        """
        data = self.residuals.residuals[self.gmpe][self.imt]
        vs30 = self._get_vs30()
        fig = plt.figure(figsize=self.figure_size)
        fig.set_tight_layout(True)
        if self.num_plots > 1:
            nrow = 3
            ncol = 1
        else:
            nrow = 1
            ncol = 1
        tloc = 1
        for res_type in data.keys():
            self._residual_plot(plt.subplot(nrow, ncol, tloc), vs30, data,
                                res_type)
            tloc += 1
        _save_image(self.filename, self.filetype, self.dpi)
        plt.show()
Exemplo n.º 27
0
    def create_plot(self):
        """

        """
        phi_ss, phi_s2ss = self.residuals.residual_statistics()
        data = self._get_site_data()
        fig = plt.figure(figsize=self.figure_size)
        fig.set_tight_layout(True)
        if self.num_plots > 1:
            nrow = 3
            ncol = 1
        else:
            nrow = 1
            ncol = 1
        tloc = 1
        for res_type in self.residuals.types[self.gmpe][self.imt]:
            self._residual_plot(fig.add_subplot(nrow, ncol, tloc), data, res_type)
            tloc += 1
        _save_image(self.filename, self.filetype, self.dpi)
        if self.show:
            plt.show()
Exemplo n.º 28
0
    def plot_distance_comparisons(self, distance1, distance2, logaxis=False,
        figure_size=(7, 5), filename=None, filetype="png", dpi=300):
        """
        Creates a plot comparing different distance metrics for the 
        specific rupture and target site combination
        """
        xdist = self._calculate_distance(distance1)       
        ydist = self._calculate_distance(distance2)       
        plt.figure(figsize=figure_size)

        if logaxis:
            plt.loglog(xdist, ydist, color='b', marker='o', linestyle='None')
        else:
            plt.plot(xdist, ydist, color='b', marker='o', linestyle='None')
        
        plt.xlabel("%s (km)" % distance1, size='medium')
        plt.ylabel("%s (km)" % distance2, size='medium')
        plt.title('Rupture: M=%6.1f, Dip=%3.0f, Ztor=%4.1f, Aspect=%5.2f'
                   % (self.magnitude, self.dip, self.ztor, self.aspect))
        _save_image(filename, filetype, dpi)
        plt.show()
Exemplo n.º 29
0
def plot_response_spectra(spectra,
                          axis_type="loglog",
                          figure_size=(8, 6),
                          filename=None,
                          filetype="png",
                          dpi=300):
    """
    Creates a plot of the suite of response spectra (Acceleration,
    Velocity, Displacement, Pseudo-Acceleration, Pseudo-Velocity) derived
    from a particular ground motion record
    """
    fig = plt.figure(figsize=figure_size)
    fig.set_tight_layout(True)
    ax = plt.subplot(2, 2, 1)
    # Acceleration
    PLOT_TYPE[axis_type](ax, spectra["Period"], spectra["Acceleration"])
    PLOT_TYPE[axis_type](ax, spectra["Period"], spectra["Pseudo-Acceleration"])
    ax.set_xlabel("Periods (s)", fontsize=12)
    ax.set_ylabel("Acceleration (cm/s/s)", fontsize=12)
    ax.set_xlim(np.min(spectra["Period"]), np.max(spectra["Period"]))
    ax.grid()
    ax.legend(("Acceleration", "PSA"), loc=0)
    ax = plt.subplot(2, 2, 2)
    # Velocity
    PLOT_TYPE[axis_type](ax, spectra["Period"], spectra["Velocity"])
    PLOT_TYPE[axis_type](ax, spectra["Period"], spectra["Pseudo-Velocity"])
    ax.set_xlabel("Periods (s)", fontsize=12)
    ax.set_ylabel("Velocity (cm/s)", fontsize=12)
    ax.set_xlim(np.min(spectra["Period"]), np.max(spectra["Period"]))
    ax.grid()
    ax.legend(("Velocity", "PSV"), loc=0)
    ax = plt.subplot(2, 2, 3)
    # Displacement
    PLOT_TYPE[axis_type](ax, spectra["Period"], spectra["Displacement"])
    ax.set_xlabel("Periods (s)", fontsize=12)
    ax.set_ylabel("Displacement (cm)", fontsize=12)
    ax.set_xlim(np.min(spectra["Period"]), np.max(spectra["Period"]))
    ax.grid()
    _save_image(filename, filetype, dpi)
    plt.show()
Exemplo n.º 30
0
    def create_plot(self):
        """
        Creates the plot
        """
        data = self.residuals.residuals[self.gmpe][self.imt]

        fig = plt.figure(figsize=self.figure_size)
        fig.set_tight_layout(True)
        if self.num_plots > 1:
            nrow = 3
            ncol = 1
        else:
            nrow = 1
            ncol = 1
        tloc = 1
        for res_type in data.keys():
            depths = self._get_depths(self.gmpe, self.imt, res_type)
            self._residual_plot(plt.subplot(nrow, ncol, tloc), depths, data, res_type)
            tloc += 1
        _save_image(self.filename, self.filetype, self.dpi)
        if self.show:
            plt.show()
def db_magnitude_distance_by_trt(db1, dist_type,
        figure_size=(7, 5), filename=None, filetype="png", dpi=300):
    """
    Plot magnitude-distance comparison by tectonic region
    """
    trts=[]
    for i in db1.records:
        trts.append(i.event.tectonic_region)
    trt_types=list(set(trts))
    selector = SMRecordSelector(db1)
    plt.figure(figsize=figure_size)
    for trt in trt_types:
        subdb = selector.select_trt_type(trt, as_db=True)
        mag, dists = get_magnitude_distances(subdb, dist_type)
        plt.semilogx(dists, mag, "o", mec='k', mew=0.5, label=trt)
    plt.xlabel(DISTANCE_LABEL[dist_type], fontsize=14)
    plt.ylabel("Magnitude", fontsize=14)
    plt.title("Magnitude vs Distance by Tectonic Region", fontsize=18)
    plt.legend(loc='lower right', numpoints=1)
    plt.grid()
    _save_image(filename, filetype, dpi)
    plt.show()
Exemplo n.º 32
0
def plot_response_spectra(spectra, axis_type="loglog", figure_size=(8, 6),
        filename=None, filetype="png", dpi=300):
    """
    Creates a plot of the suite of response spectra (Acceleration,
    Velocity, Displacement, Pseudo-Acceleration, Pseudo-Velocity) derived
    from a particular ground motion record
    """
    fig = plt.figure(figsize=figure_size)
    fig.set_tight_layout(True)
    ax = plt.subplot(2, 2, 1)
    # Acceleration
    PLOT_TYPE[axis_type](ax, spectra["Period"], spectra["Acceleration"])
    PLOT_TYPE[axis_type](ax, spectra["Period"], spectra["Pseudo-Acceleration"])
    ax.set_xlabel("Periods (s)", fontsize=12)
    ax.set_ylabel("Acceleration (cm/s/s)", fontsize=12)
    ax.set_xlim(np.min(spectra["Period"]), np.max(spectra["Period"]))
    ax.grid()
    ax.legend(("Acceleration", "PSA"), loc=0) 
    ax = plt.subplot(2, 2, 2)
    # Velocity
    PLOT_TYPE[axis_type](ax, spectra["Period"], spectra["Velocity"])
    PLOT_TYPE[axis_type](ax, spectra["Period"], spectra["Pseudo-Velocity"])
    ax.set_xlabel("Periods (s)", fontsize=12)
    ax.set_ylabel("Velocity (cm/s)", fontsize=12)
    ax.set_xlim(np.min(spectra["Period"]), np.max(spectra["Period"]))
    ax.grid()
    ax.legend(("Velocity", "PSV"), loc=0) 
    ax = plt.subplot(2, 2, 3)
    # Displacement
    PLOT_TYPE[axis_type](ax, spectra["Period"], spectra["Displacement"])
    ax.set_xlabel("Periods (s)", fontsize=12)
    ax.set_ylabel("Displacement (cm)", fontsize=12)
    ax.set_xlim(np.min(spectra["Period"]), np.max(spectra["Period"]))
    ax.grid()
    _save_image(filename, filetype, dpi)
    plt.show()