当前位置: 首页>>代码示例>>Python>>正文


Python PISM.optionsReal方法代码示例

本文整理汇总了Python中PISM.optionsReal方法的典型用法代码示例。如果您正苦于以下问题:Python PISM.optionsReal方法的具体用法?Python PISM.optionsReal怎么用?Python PISM.optionsReal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PISM的用法示例。


在下文中一共展示了PISM.optionsReal方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: options_test

# 需要导入模块: import PISM [as 别名]
# 或者: from PISM import optionsReal [as 别名]
def options_test():
    "Test command-line option handling"
    ctx = PISM.Context()

    o = PISM.PETSc.Options()

    M = PISM.optionsInt("-M", "description", default=100)
    M = PISM.optionsInt("-M", "description", default=None)

    S = PISM.optionsString("-S", "description", default="string")
    S = PISM.optionsString("-S", "description", default=None)

    R = PISM.optionsReal("-R", "description", default=1.5)
    R = PISM.optionsReal("-R", "description", default=None)

    o.setValue("-B", "on")
    B = PISM.optionsFlag("-B", "description", default=False)
    B = PISM.optionsFlag("B", "description", default=False)
    B = PISM.optionsFlag("-B", "description", default=None)

    o.setValue("-no_C", "on")
    C = PISM.optionsFlag("C", "description", default=None)

    D = PISM.optionsFlag("D", "description", default=None)
    D = PISM.optionsFlag("D", "description", default=True)

    o.setValue("-no_D", "on")
    o.setValue("-D", "on")
    try:
        # should throw RuntimeError
        D = PISM.optionsFlag("D", "description", default=None)
        return False
    except RuntimeError:
        pass

    o.setValue("-IA", "1,2,3")
    IA = PISM.optionsIntArray("-IA", "description", default=[1, 2])
    IA = PISM.optionsIntArray("-IA", "description", default=None)
    IA2 = PISM.optionsIntArray("-IA2", "description", default=None)
    IA2 = PISM.optionsIntArray("-IA2", "description", default=[1, 2])

    o.setValue("-RA", "1,2,3")
    RA = PISM.optionsRealArray("-RA", "description", default=[2, 3])
    RA = PISM.optionsRealArray("-RA", "description", default=None)
    RA2 = PISM.optionsRealArray("-RA2", "description", default=[2, 3])
    RA2 = PISM.optionsRealArray("-RA2", "description", default=None)

    o.setValue("-SA", "1,2,3")
    SA = PISM.optionsStringArray("-SA", "description", default="one,two")
    SA = PISM.optionsStringArray("-SA", "description", default=None)
    SA2 = PISM.optionsStringArray("-SA2", "description", default="two,three")
    SA2 = PISM.optionsStringArray("-SA2", "description", default=None)

    M = PISM.optionsList("-L", "description", choices="one,two", default="one")
    M = PISM.optionsList("-L", "description", choices="one,two", default=None)
开发者ID:crodehacke,项目名称:PISMcr,代码行数:57,代码来源:nosetests.py

示例2: __init__

# 需要导入模块: import PISM [as 别名]
# 或者: from PISM import optionsReal [as 别名]
    def __init__(self, ssarun, method):
        """
        :param ssarun: The :class:`PISM.ssa.SSARun` defining the forward problem. See :class:`PISM.inv_ssa.SSAForwardRunFromInputFile`.
        :param method: String describing the actual ``siple`` algorithm to use. One of ``sd``, ``nlcg`` or ``ign``."""
        InvSSASolver.__init__(self, ssarun, method)

        self.target_misfit = PISM.optionsReal("-inv_target_misfit", "m/year; desired root misfit for inversions", default=None)

        monitor_adjoint = PISM.optionsFlag("-inv_monitor_adjoint", "Track accuracy of the adjoint during computation", default=False)
        morozov_scale_factor = PISM.optionsFlag("-inv_morozov_scale", "Scale factor (>=1) for Morozov discrepancy principle", default=1.0)
        ls_verbose = PISM.optionsFlag("-inv_ls_verbose", "Turn on a verbose linesearch.", default=False)
        ign_theta = PISM.optionsReal("-ign_theta", "theta parameter for IGN algorithm", default=0.5)
        max_it = PISM.optionsInt("-inv_max_it", "maximum iteration count", default=1000)

        if self.target_misfit is None:
            raise RuntimeError("Missing required option -inv_target_misfit")

        velocity_scale = ssarun.grid.ctx().config().get_double("inv_ssa_velocity_scale", "m/year")
        self.target_misfit /= velocity_scale

        self.forward_problem = SSAForwardProblem(ssarun)

        # Determine the inversion algorithm, and set up its arguments.
        if self.method == "ign":
            Solver = InvertSSAIGN
        else:
            Solver = InvertSSANLCG

        self.u_i = None
        self.zeta_i = None

        params = Solver.defaultParameters()
        params.ITER_MAX = max_it
        if self.method == "sd":
            params.steepest_descent = True
            params.ITER_MAX = 10000
        elif self.method == "ign":
            params.linearsolver.ITER_MAX = 10000
            params.linearsolver.verbose = True
        if ls_verbose:
            params.linesearch.verbose = True
        params.verbose = True
        params.thetaMax = ign_theta
        params.mu = morozov_scale_factor

        params.deriv_eps = 0.

        self.siple_solver = Solver(self.forward_problem, params=params)

        if monitor_adjoint:
            self.addIterationListener(MonitorAdjoint())
            if self.method == 'ign':
                self.addLinearIterationListener(MonitorAdjointLin())
开发者ID:crodehacke,项目名称:PISMcr,代码行数:55,代码来源:ssa_siple.py

示例3: run

# 需要导入模块: import PISM [as 别名]
# 或者: from PISM import optionsReal [as 别名]
def run():
    context = PISM.Context()
    config = context.config
    com = context.com
    PISM.set_abort_on_sigint(True)

    WIDE_STENCIL = int(config.get_double("grid_max_stencil_width"))

    usage = \
        """  pismi.py [-i IN.nc [-o OUT.nc]]/[-a INOUT.nc] [-inv_data inv_data.nc] [-inv_forward model] 
                [-inv_design design_var] [-inv_method meth] 
    where:
    -i            IN.nc       is input file in NetCDF format: contains PISM-written model state
    -o            OUT.nc      is output file in NetCDF format to be overwritten
    -a            INOUT.nc    is input/output file in NetCDF format to be appended to
    -inv_data     inv_data.nc is data file containing extra inversion data (e.g. observed surface velocities)
    -inv_forward  model       forward model: only 'ssa' supported
    -inv_design   design_var  design variable name; one of 'tauc'/'hardav' for SSA inversions
    -inv_method   meth        algorithm for inversion [sd,nlcg,ign,tikhonov_lmvm]

    notes:
      * only one of -i/-a is allowed; both specify the input file
      * only one of -o/-a is allowed; both specify the output file
      * if -o is used, only the variables involved in inversion are written to the output file.
      * if -a is used, the varaibles involved in inversion are appended to the given file. No
        original variables in the file are changed.
   """

    append_mode = False
    PISM.setVerbosityLevel(1)

    input_filename = PISM.optionsString("-i", "input file")
    append_filename = PISM.optionsString("-a", "append file", default=None)
    output_filename = PISM.optionsString("-o", "output file", default=None)

    if (input_filename is None) and (append_filename is None):
        PISM.verbPrintf(1, com, "\nError: No input file specified. Use one of -i [file.nc] or -a [file.nc].\n")
        sys.exit(0)

    if (input_filename is not None) and (append_filename is not None):
        PISM.verbPrintf(1, com, "\nError: Only one of -i/-a is allowed.\n")
        sys.exit(0)

    if (output_filename is not None) and (append_filename is not None):
        PISM.verbPrintf(1, com, "\nError: Only one of -a/-o is allowed.\n")
        sys.edit(0)

    if append_filename is not None:
        input_filename = append_filename
        output_filename = append_filename
        append_mode = True

    inv_data_filename = PISM.optionsString("-inv_data", "inverse data file", default=input_filename)
    verbosity = PISM.optionsInt("-verbose", "verbosity level", default=2)

    do_plotting = PISM.optionsFlag("-inv_plot", "perform visualization during the computation", default=False)
    do_final_plot = PISM.optionsFlag("-inv_final_plot", "perform visualization at the end of the computation", default=False)
    Vmax = PISM.optionsReal("-inv_plot_vmax", "maximum velocity for plotting residuals", default=30)

    design_var = PISM.optionsList("-inv_ssa",
                                  "design variable for inversion",
                                  "tauc,hardav", "tauc")
    do_pause = PISM.optionsFlag("-inv_pause", "pause each iteration", default=False)

    do_restart = PISM.optionsFlag("-inv_restart", "Restart a stopped computation.", default=False)
    use_design_prior = PISM.optionsFlag("-inv_use_design_prior", "Use prior from inverse data file as initial guess.", default=True)

    prep_module = PISM.optionsString("-inv_prep_module", "Python module used to do final setup of inverse solver", default=None)

    is_regional = PISM.optionsFlag("-regional", "Compute SIA/SSA using regional model semantics", default=False)

    using_zeta_fixed_mask = PISM.optionsFlag("-inv_use_zeta_fixed_mask",
                                             "Enforce locations where the parameterized design variable should be fixed. (Automatically determined if not provided)", default=True)

    inv_method = config.get_string("inv_ssa_method")

    if output_filename is None:
        output_filename = "pismi_" + os.path.basename(input_filename)

    saving_inv_data = (inv_data_filename != output_filename)

    PISM.setVerbosityLevel(verbosity)
    forward_run = SSAForwardRun(input_filename, inv_data_filename, design_var)
    forward_run.setup()
    design_param = forward_run.designVariableParameterization()
    solver = PISM.invert.ssa.createInvSSASolver(forward_run)

    modeldata = forward_run.modeldata
    vecs = modeldata.vecs
    grid = modeldata.grid

    # Determine the prior guess for tauc/hardav. This can be one of
    # a) tauc/hardav from the input file (default)
    # b) tauc/hardav_prior from the inv_datafile if -inv_use_design_prior is set
    design_prior = createDesignVec(grid, design_var, '%s_prior' % design_var)
    long_name = design_prior.metadata().get_string("long_name")
    units = design_prior.metadata().get_string("units")
    design_prior.set_attrs("", "best prior estimate for %s (used for inversion)" % long_name, units, "")
    if PISM.util.fileHasVariable(inv_data_filename, "%s_prior" % design_var) and use_design_prior:
        PISM.logging.logMessage("  Reading '%s_prior' from inverse data file %s.\n" % (design_var, inv_data_filename))
#.........这里部分代码省略.........
开发者ID:crodehacke,项目名称:PISMcr,代码行数:103,代码来源:pismi.py

示例4: add

# 需要导入模块: import PISM [as 别名]
# 或者: from PISM import optionsReal [as 别名]
    PISM.show_usage_check_req_opts(com, sys.argv[0], ["-i"], usage)

    config = context.config
    if not PISM.OptionString("-ssa_method", "").is_set():
        config.set_string("ssa_method", "fem")

    input_file_name = PISM.optionsString("-i",
                                         "file to bootstrap from")

    output_file_name = PISM.optionsString("-o",
                                          "output file",
                                          default="make_synth_ssa.nc")

    design_prior_scale = PISM.optionsReal("-design_prior_scale",
                                          "initial guess for design variable to be this factor of the true value",
                                          default=design_prior_scale)

    design_prior_const = PISM.optionsReal("-design_prior_const",
                                          "initial guess for design variable to be this constant",
                                          default=design_prior_const)

    noise = PISM.optionsReal("-rms_noise",
                             "pointwise rms noise to add (in m/a)",
                             default=None)

    misfit_weight_type = PISM.optionsList("-misfit_type",
                                          "Choice of misfit weight function",
                                          "grounded,fast",
                                          "grounded")
开发者ID:crodehacke,项目名称:PISMcr,代码行数:31,代码来源:make_synth_ssa.py

示例5: createTikhonovFunctionals

# 需要导入模块: import PISM [as 别名]
# 或者: from PISM import optionsReal [as 别名]
def createTikhonovFunctionals(ssarun):
    """Returns a tuple ``(designFunctional,stateFunctional)`` of :cpp:class:`IP_Functional`'s
    for Tikhonov-based inversions.  The specific functionals are constructed on the basis of
    command-line parameters ``inv_state_func`` and ``inv_design_func``.

    :param ssarun: The instance of :class:`PISM.ssa.SSARun` that encapsulates the forward problem,
                   typically a :class:`SSATaucForwardRunFromFile`.
  """
    vecs = ssarun.modeldata.vecs
    grid = ssarun.grid

    useGroundedIceOnly = PISM.OptionBool("-inv_ssa_grounded_ice_tauc",
                                         "Computed norms for tau_c only on elements with all grounded ice.")

    misfit_type = grid.ctx().config().get_string("inv_state_func")
    if misfit_type == "meansquare":
        stateFunctional = createMeanSquareMisfitFunctional(grid, vecs)
    elif misfit_type == "log_ratio":
        vel_ssa_observed = vecs.vel_ssa_observed
        scale = grid.ctx().config().get_double("inv_log_ratio_scale")
        velocity_eps = grid.ctx().config().get_double("inv_ssa_velocity_eps", "m/second")
        misfit_weight = None
        if vecs.has('vel_misfit_weight'):
            misfit_weight = vecs.vel_misfit_weight
        stateFunctional = PISM.IPLogRatioFunctional(grid, vel_ssa_observed, velocity_eps, misfit_weight)
        stateFunctional.normalize(scale)
    elif misfit_type == "log_relative":
        vel_ssa_observed = vecs.vel_ssa_observed
        velocity_scale = grid.ctx().config().get_double("inv_ssa_velocity_scale", "m/second")
        velocity_eps = grid.ctx().config().get_double("inv_ssa_velocity_eps", "m/second")
        misfit_weight = None
        if vecs.has('vel_misfit_weight'):
            misfit_weight = vecs.vel_misfit_weight
        stateFunctional = PISM.IPLogRelativeFunctional(grid, vel_ssa_observed, velocity_eps, misfit_weight)
        stateFunctional.normalize(velocity_scale)
    else:
        raise RuntimeError("Unknown inv_state_func '%s'; unable to construct solver.", misfit_type)

    design_functional = grid.ctx().config().get_string("inv_design_func")
    if design_functional == "sobolevH1":
        designFunctional = createHilbertDesignFunctional(grid, vecs, useGroundedIceOnly)
    elif design_functional == "tv":
        area = 4 * grid.Lx() * grid.Ly()
        velocity_scale = grid.ctx().config().get_double("inv_ssa_velocity_scale", "m/second")
        length_scale = grid.ctx().config().get_double("inv_ssa_length_scale")
        lebesgue_exponent = grid.ctx().config().get_double("inv_ssa_tv_exponent")
        cTV = 1 / area
        cTV *= (length_scale) ** (lebesgue_exponent)

        zeta_fixed_mask = None
        if vecs.has('zeta_fixed_mask'):
            zeta_fixed_mask = vecs.zeta_fixed_mask

        strain_rate_eps = PISM.optionsReal("-inv_ssa_tv_eps",
                                           "regularization constant for 'total variation' functional", default=None)
        if strain_rate_eps is None:
            schoofLen = grid.ctx().config().get_double("Schoof_regularizing_length", "m")
            strain_rate_eps = 1 / schoofLen

        designFunctional = PISM.IPTotalVariationFunctional2S(grid, cTV, lebesgue_exponent, strain_rate_eps, zeta_fixed_mask)
    else:
        raise Exception("Unknown inv_design_func '%s'; unable to construct solver." % design_functional)

    return (designFunctional, stateFunctional)
开发者ID:crodehacke,项目名称:PISMcr,代码行数:66,代码来源:ssa.py


注:本文中的PISM.optionsReal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。