Exemple #1
0
def test_Q_model_plotting(tmpdir):
    """
    Tests the plotting of the Q Model.
    """
    reset_matplotlib()

    tmpdir = str(tmpdir)

    Q_discrete.plot(WEIGHTS, RELAXATION_TIMES, f_min=1.0 / 100.0,
                    f_max=1.0 / 10.0)
    images_are_identical("discrete_Q_model", tmpdir)
Exemple #2
0
def test_Q_model_plotting(tmpdir):
    """
    Tests the plotting of the Q Model.
    """
    reset_matplotlib()

    tmpdir = str(tmpdir)

    Q_discrete.plot(WEIGHTS, RELAXATION_TIMES, f_min=1.0 / 100.0,
                    f_max=1.0 / 10.0)
    images_are_identical("discrete_Q_model", tmpdir)
def test_Q_model_plotting(tmpdir):
    """
    Tests the plotting of the Q Model.
    """
    reset_matplotlib()

    tmpdir = str(tmpdir)

    weights = [2.50960201, 2.31899515, 0.19681762]
    relaxation_times = [1.73160984, 14.41562154, 16.70330157]
    Q_discrete.plot(weights, relaxation_times, f_min=1.0 / 100.0,
                    f_max=1.0 / 10.0)
    images_are_identical("discrete_Q_model", tmpdir)
Exemple #4
0
def _get_default_solver_settings(solver, min_period, max_period):
    """
    Helper function returning etree representation of a solver's default
    settings.
    """
    known_solvers = ["ses3d_4_1", "ses3d_2_0", "specfem3d_cartesian"]
    if solver.lower() == "ses3d_4_1":
        from lasif.tools import Q_discrete
        from lasif.utils import generate_ses3d_4_1_template

        # Generate the relaxation weights for SES3D.
        w_p, tau_p = Q_discrete.calculate_Q_model(
            N=3,
            # These are suitable for the default frequency range.
            f_min=1.0 / max_period,
            f_max=1.0 / min_period,
            iterations=10000,
            initial_temperature=0.1,
            cooling_factor=0.9998)

        return generate_ses3d_4_1_template(w_p, tau_p)
    elif solver.lower() == "ses3d_2_0":
        from lasif.utils import generate_ses3d_2_0_template
        return generate_ses3d_2_0_template()
    elif solver.lower() == "specfem3d_cartesian":
        from lasif.utils import generate_specfem3d_cartesian_template
        return generate_specfem3d_cartesian_template()
    else:
        msg = "Solver '%s' not known. Known solvers: %s" % (
            solver, ",".join(known_solvers))
        raise LASIFException(msg)
Exemple #5
0
def test_weights_and_relaxation_times():
    """
    Regression test for the weights and relaxation times.
    """
    # Set the seed to get reproducible results.
    np.random.seed(12345)

    # These are the D_p and tau_p, respectively.
    weights, relaxation_times, = Q_discrete.calculate_Q_model(
        N=3,
        f_min=1.0 / 100.0,
        f_max=1.0 / 10.0,
        iterations=10000,
        initial_temperature=0.1,
        cooling_factor=0.9998)

    np.testing.assert_array_almost_equal(weights, WEIGHTS)

    np.testing.assert_array_almost_equal(relaxation_times, RELAXATION_TIMES)
Exemple #6
0
def test_weights_and_relaxation_times():
    """
    Regression test for the weights and relaxation times.
    """
    # Set the seed to get reproducible results.
    np.random.seed(12345)

    # These are the D_p and tau_p, respectively.
    weights, relaxation_times, = Q_discrete.calculate_Q_model(
        N=3,
        f_min=1.0 / 100.0,
        f_max=1.0 / 10.0,
        iterations=10000,
        initial_temperature=0.1,
        cooling_factor=0.9998)

    np.testing.assert_array_almost_equal(weights, WEIGHTS)

    np.testing.assert_array_almost_equal(relaxation_times, RELAXATION_TIMES)
def test_weights_and_relaxation_times():
    """
    Regression test for the weights and relaxation times.
    """
    # Set the seed to get reproducible results.
    random.seed(12345)

    # These are the D_p and tau_p, respectively.
    weights, relaxation_times, = Q_discrete.calculate_Q_model(
        N=3,
        f_min=1.0 / 100.0,
        f_max=1.0 / 10.0,
        iterations=10000,
        initial_temperature=0.1,
        cooling_factor=0.9998)

    np.testing.assert_array_almost_equal(
        weights, np.array([2.50960201, 2.31899515, 0.19681762]))
    np.testing.assert_array_almost_equal(
        relaxation_times, np.array([1.73160984, 14.41562154, 16.70330157]))
Exemple #8
0
def lasif_calculate_constant_q_model(parser, args):
    """
    Calculate a constant Q model useable by SES3D.
    """
    from lasif.tools import Q_discrete

    parser.add_argument("min_period", type=float,
                        help="minimum period for the constant frequency band")
    parser.add_argument("max_period", type=float,
                        help="maximum period for the constant frequency band")
    args = parser.parse_args(args)

    weights, relaxation_times, = Q_discrete.calculate_Q_model(
        N=3,
        f_min=1.0 / args.max_period,
        f_max=1.0 / args.min_period,
        iterations=10000,
        initial_temperature=0.1,
        cooling_factor=0.9998)
    print "Weights: %s" % ", ".join([str(i) for i in weights])
    print "Relaxation Times: %s" % ", ".join([str(i) for i in weights])
Exemple #9
0
def _get_default_solver_settings(solver, min_period, max_period, quiet=False):
    """
    Helper function returning etree representation of a solver's default
    settings.

    :param quiet: Do not print anything if set to `True`.
    """
    known_solvers = [
        "ses3d_4_1", "ses3d_2_0", "specfem3d_cartesian", "specfem3d_globe_cem"
    ]
    if solver.lower() == "ses3d_4_1":
        from lasif.tools import Q_discrete
        from lasif.utils import generate_ses3d_4_1_template

        # Generate the relaxation weights for SES3D.
        w_p, tau_p = Q_discrete.calculate_Q_model(
            N=3,
            # These are suitable for the default frequency range.
            f_min=1.0 / max_period,
            f_max=1.0 / min_period,
            iterations=10000,
            initial_temperature=0.1,
            cooling_factor=0.9998,
            quiet=quiet)

        return generate_ses3d_4_1_template(w_p, tau_p)
    elif solver.lower() == "ses3d_2_0":
        from lasif.utils import generate_ses3d_2_0_template
        return generate_ses3d_2_0_template()
    elif solver.lower() == "specfem3d_cartesian":
        from lasif.utils import generate_specfem3d_cartesian_template
        return generate_specfem3d_cartesian_template()
    elif solver.lower() == "specfem3d_globe_cem":
        from lasif.utils import generate_specfem3d_globe_cem_template
        return generate_specfem3d_globe_cem_template()
    else:
        msg = "Solver '%s' not known. Known solvers: %s" % (
            solver, ",".join(known_solvers))
        raise LASIFError(msg)