def plot_trunc_gr_model( aval, bval, min_mag, max_mag, dmag, catalogue=None, completeness=None, filename=None, figure_size=(8, 6), filetype='png', dpi=300, ax=None): """ Plots a Gutenberg-Richter model """ input_model = TruncatedGRMFD(min_mag, max_mag, dmag, aval, bval) if not catalogue: # Plot only the modelled recurrence annual_rates, cumulative_rates = _get_recurrence_model(input_model) if ax is None: fig, ax = plt.subplots(figsize=figure_size) else: fig = ax.get_figure() ax.semilogy(annual_rates[:, 0], annual_rates[:, 1], 'b-') ax.semilogy(annual_rates[:, 0], cumulative_rates, 'r-') ax.xlabel('Magnitude') ax.set_ylabel('Annual Rate') ax.set_legend(['Incremental Rate', 'Cumulative Rate']) _save_image(fig, filename, filetype, dpi) else: completeness = _check_completeness_table(completeness, catalogue) plot_recurrence_model( input_model, catalogue, completeness, dmag, filename=filename, figure_size=figure_size, filetype=filetype, dpi=dpi, ax=ax)
def plot_trunc_gr_model(aval, bval, min_mag, max_mag, dmag, catalogue=None, completeness=None, figure_size=None, filename=None, filetype='png', dpi=300): """ Plots a Gutenberg-Richter model """ input_model = TruncatedGRMFD(min_mag, max_mag, dmag, aval, bval) if not catalogue: # Plot only the modelled recurrence annual_rates, cumulative_rates = _get_recurrence_model(input_model) plt.semilogy(annual_rates[:, 0], annual_rates[:, 1], 'b-') plt.semilogy(annual_rates[:, 0], cumulative_rates, 'r-') plt.xlabel('Magnitude', fontsize='large') plt.ylabel('Annual Rate', fontsize='large') plt.legend(['Incremental Rate', 'Cumulative Rate']) _save_image(filename, filetype, dpi) else: completeness = _check_completeness_table(completeness, catalogue) plot_recurrence_model(input_model, catalogue, completeness, input_model.bin_width, figure_size, filename, filetype, dpi)
def plot_recurrence_models( configs, area, slip, msr, rake, shear_modulus=30.0, disp_length_ratio=1.25E-5, msr_sigma=0., filename=None, filetype='png', dpi=300): """ Plots a set of recurrence models :param list configs: List of configuration dictionaries """ plt.figure(figsize=DEFAULT_SIZE) for config in configs: model = RecurrenceBranch(area, slip, msr, rake, shear_modulus, disp_length_ratio, msr_sigma, weight=1.0) model.get_recurrence(config) occurrence = model.recurrence.occur_rates cumulative = np.array([np.sum(occurrence[iloc:]) for iloc in range(0, len(occurrence))]) if 'AndersonLuco' in config['Model_Name']: flt_label = config['Model_Name'] + ' - ' + config['Model_Type'] +\ ' Type' else: flt_label = config['Model_Name'] flt_color = np.random.uniform(0.1, 1.0, 3) plt.semilogy(model.magnitudes, cumulative, '-', label=flt_label, color=flt_color, linewidth=2.) plt.semilogy(model.magnitudes, model.recurrence.occur_rates, '--', color=flt_color, linewidth=2.) plt.xlabel('Magnitude', fontsize=14) plt.ylabel('Annual Rate', fontsize=14) plt.legend(bbox_to_anchor=(1.1, 1.0)) _save_image(filename, filetype, dpi)
def plot_trunc_gr_model(aval, bval, min_mag, max_mag, dmag, catalogue=None, completeness=None, figure_size=None, filename=None, filetype='png', dpi=300): """ Plots a Gutenberg-Richter model """ input_model = TruncatedGRMFD(min_mag, max_mag, dmag, aval, bval) if not catalogue: # Plot only the modelled recurrence annual_rates, cumulative_rates = _get_recurrence_model(input_model) plt.semilogy(annual_rates[:, 0], annual_rates[:, 1], 'b-') plt.semilogy(annual_rates[:, 0], cumulative_rates, 'r-') plt.xlabel('Magnitude', fontsize='large') plt.ylabel('Annual Rate', fontsize='large') plt.legend(['Incremental Rate', 'Cumulative Rate']) _save_image(filename, filetype, dpi) else: completeness = _check_completeness_table(completeness, catalogue) plot_recurrence_model(input_model, catalogue, completeness, input_model.bin_width, figure_size, filename, filetype, dpi)
def plot_recurrence_model(input_model, catalogue, completeness, dmag, figure_size=(10, 8), filename=None, filetype='png', dpi=300): """ Plot a calculated recurrence model over an observed catalogue, adjusted for time-varying completeness """ if figure_size is None: figure_size=(10, 8) if dmag is None: dmag = 0.1 annual_rates, cumulative_rates = _get_recurrence_model(input_model) # Get observed annual recurrence if not catalogue.end_year: catalogue.update_end_year() cent_mag, t_per, n_obs = get_completeness_counts(catalogue, completeness, dmag) obs_rates = n_obs / t_per cum_obs_rates = np.array([np.sum(obs_rates[i:]) for i in range(len(obs_rates))]) # Create plot plt.figure(figsize=figure_size) plt.semilogy(cent_mag, obs_rates, 'bo') plt.semilogy(annual_rates[:, 0], annual_rates[:, 1], 'b-') plt.semilogy(cent_mag, cum_obs_rates, 'rs') plt.semilogy(annual_rates[:, 0], cumulative_rates, 'r-') plt.grid(which='both') plt.xlabel('Magnitude', fontsize='16') plt.ylabel('Annual Rate', fontsize='16') plt.legend(['Observed Incremental Rate', 'Model Incremental Rate', 'Observed Cumulative Rate', 'Model Cumulative Rate'], fontsize=14) plt.tick_params(labelsize=12) _save_image(filename, filetype, dpi)
def plot_trunc_gr_model( aval, bval, min_mag, max_mag, dmag, catalogue=None, completeness=None, filename=None, figure_size=(8, 6), filetype='png', dpi=300, ax=None): """ Plots a Gutenberg-Richter model """ input_model = TruncatedGRMFD(min_mag, max_mag, dmag, aval, bval) if not catalogue: # Plot only the modelled recurrence annual_rates, cumulative_rates = _get_recurrence_model(input_model) if ax is None: fig, ax = plt.subplots(figsize=figure_size) else: fig = ax.get_figure() ax.semilogy(annual_rates[:, 0], annual_rates[:, 1], 'b-') ax.semilogy(annual_rates[:, 0], cumulative_rates, 'r-') ax.xlabel('Magnitude') ax.set_ylabel('Annual Rate') ax.set_legend(['Incremental Rate', 'Cumulative Rate']) _save_image(fig, filename, filetype, dpi) else: completeness = _check_completeness_table(completeness, catalogue) plot_recurrence_model( input_model, catalogue, completeness, dmag, filename=filename, figure_size=figure_size, filetype=filetype, dpi=dpi, ax=ax)
def plot_recurrence_model(input_model, catalogue, completeness, dmag, figure_size=(10, 8), filename=None, filetype='png', dpi=300): """ Plot a calculated recurrence model over an observed catalogue, adjusted for time-varying completeness """ if figure_size is None: figure_size = (10, 8) if dmag is None: dmag = 0.1 annual_rates, cumulative_rates = _get_recurrence_model(input_model) # Get observed annual recurrence if not catalogue.end_year: catalogue.update_end_year() cent_mag, t_per, n_obs = get_completeness_counts(catalogue, completeness, dmag) obs_rates = n_obs / t_per cum_obs_rates = np.array([np.sum(obs_rates[i:]) for i in range(len(obs_rates))]) # Create plot plt.figure(figsize=figure_size) plt.semilogy(cent_mag, obs_rates, 'bo') plt.semilogy(annual_rates[:, 0], annual_rates[:, 1], 'b-') plt.semilogy(cent_mag, cum_obs_rates, 'rs') plt.semilogy(annual_rates[:, 0], cumulative_rates, 'r-') plt.grid(which='both') plt.xlabel('Magnitude', fontsize='16') plt.ylabel('Annual Rate', fontsize='16') plt.legend(['Observed Incremental Rate', 'Model Incremental Rate', 'Observed Cumulative Rate', 'Model Cumulative Rate'], fontsize=14) plt.tick_params(labelsize=12) _save_image(filename, filetype, dpi)
def plot_recurrence_models(configs, area, slip, msr, rake, shear_modulus=30.0, disp_length_ratio=1.25E-5, msr_sigma=0., figure_size=(8, 6), filename=None, filetype='png', dpi=300, ax=None): """ Plots a set of recurrence models :param list configs: List of configuration dictionaries """ if ax is None: fig, ax = plt.subplots(figsize=figure_size) else: fig = ax.get_figure() for config in configs: model = RecurrenceBranch(area, slip, msr, rake, shear_modulus, disp_length_ratio, msr_sigma, weight=1.0) model.get_recurrence(config) occurrence = model.recurrence.occur_rates cumulative = np.array( [np.sum(occurrence[iloc:]) for iloc in range(0, len(occurrence))]) if 'AndersonLuco' in config['Model_Name']: flt_label = config['Model_Name'] + ' - ' + config['Model_Type'] +\ ' Type' else: flt_label = config['Model_Name'] flt_color = np.random.uniform(0.1, 1.0, 3) ax.semilogy(model.magnitudes, cumulative, '-', label=flt_label, color=flt_color, linewidth=2.) ax.semilogy(model.magnitudes, model.recurrence.occur_rates, '--', color=flt_color, linewidth=2.) ax.set_xlabel('Magnitude') ax.set_ylabel('Annual Rate') ax.legend(bbox_to_anchor=(1.1, 1.0)) _save_image(fig, filename, filetype, dpi)
def plot_cumulative_moment(year, mag, figure_size=(8, 6), filename=None, filetype='png', dpi=300, ax=None): '''Calculation of Mmax using aCumulative Moment approach, adapted from the cumulative strain energy method of Makropoulos & Burton (1983) :param year: Year of Earthquake :type year: numpy.ndarray :param mag: Magnitude of Earthquake :type mag: numpy.ndarray :keyword iplot: Include cumulative moment plot :type iplot: Boolean :return mmax: Returns Maximum Magnitude :rtype mmax: Float ''' # Calculate seismic moment m_o = 10.**(9.05 + 1.5 * mag) year_range = np.arange(np.min(year), np.max(year) + 1, 1) nyr = np.int(np.shape(year_range)[0]) morate = np.zeros(nyr, dtype=float) # Get moment release per year for loc, tyr in enumerate(year_range): idx = np.abs(year - tyr) < 1E-5 if np.sum(idx) > 0: # Some moment release in that year morate[loc] = np.sum(m_o[idx]) ave_morate = np.sum(morate) / float(nyr) # Average moment rate vector exp_morate = np.cumsum(ave_morate * np.ones(nyr)) if ax is None: fig, ax = plt.subplots(figsize=figure_size) else: fig = ax.get_figure() ax.step(year_range, np.cumsum(morate), 'b-', linewidth=2) ax.plot(year_range, exp_morate, 'r-', linewidth=2) # Get offsets upper_morate = exp_morate + (np.max(np.cumsum(morate) - exp_morate)) lower_morate = exp_morate + (np.min(np.cumsum(morate) - exp_morate)) ax.plot(year_range, upper_morate, 'r--', linewidth=1) ax.plot(year_range, lower_morate, 'r--', linewidth=1) ax.axis([np.min(year), np.max(year), 0.0, np.sum(morate)]) _save_image(fig, filename, filetype, dpi)
def plot_cumulative_moment(year, mag, figure_size=(8, 6), filename=None, filetype='png', dpi=300, ax=None): '''Calculation of Mmax using aCumulative Moment approach, adapted from the cumulative strain energy method of Makropoulos & Burton (1983) :param year: Year of Earthquake :type year: numpy.ndarray :param mag: Magnitude of Earthquake :type mag: numpy.ndarray :keyword iplot: Include cumulative moment plot :type iplot: Boolean :return mmax: Returns Maximum Magnitude :rtype mmax: Float ''' # Calculate seismic moment m_o = 10. ** (9.05 + 1.5 * mag) year_range = np.arange(np.min(year), np.max(year) + 1, 1) nyr = np.int(np.shape(year_range)[0]) morate = np.zeros(nyr, dtype=float) # Get moment release per year for loc, tyr in enumerate(year_range): idx = np.abs(year - tyr) < 1E-5 if np.sum(idx) > 0: # Some moment release in that year morate[loc] = np.sum(m_o[idx]) ave_morate = np.sum(morate) / float(nyr) # Average moment rate vector exp_morate = np.cumsum(ave_morate * np.ones(nyr)) if ax is None: fig, ax = plt.subplots(figsize=figure_size) else: fig = ax.get_figure() ax.step(year_range, np.cumsum(morate), 'b-', linewidth=2) ax.plot(year_range, exp_morate, 'r-', linewidth=2) # Get offsets upper_morate = exp_morate + (np.max(np.cumsum(morate) - exp_morate)) lower_morate = exp_morate + (np.min(np.cumsum(morate) - exp_morate)) ax.plot(year_range, upper_morate, 'r--', linewidth=1) ax.plot(year_range, lower_morate, 'r--', linewidth=1) ax.axis([np.min(year), np.max(year), 0.0, np.sum(morate)]) _save_image(fig, filename, filetype, dpi)