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


Python PyDSTool.expr2fun方法代码示例

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


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

示例1: make_measure

# 需要导入模块: import PyDSTool [as 别名]
# 或者: from PyDSTool import expr2fun [as 别名]
def make_measure(fn_name, fn_spec, **defs):
    """Dynamically create a python function for use with calculation
    context.
    """
    all_defs = defs.copy()
    q = dst.QuantSpec('_dummy_', fn_spec, treatMultiRefs=False)
    import PyDSTool.parseUtils as pu
    mapping = pu.symbolMapClass()
    assumed_modules = []
    tokens = q.parser.tokenized
    for sym in q.freeSymbols:
        # Hack, for now: if first (therefore, assumed all)
        # occurrences of symbol are in quotes, then don't convert.
        # Better solution would be to make parser create "x" as a single
        # symbol, at least with a detect quote option
        first_ix = tokens.index(sym)
        if first_ix == 0 or (first_ix > 0 and tokens[first_ix-1] not in ['"', "'"]):
            if pu.isHierarchicalName(sym):
                parts = sym.split('.')
                if parts[0] == 'sim':
                    mapping[sym] = 'con.'+sym
##                elif parts[0] == 'bombardier':
##                    # special case as this factory function is defined in that
##                    # module so that reference will fail at runtime: remove
##                    # 'bombardier' prefix
##                    rest_sym = '.'.join(parts[1:])
##                    mapping[sym] = rest_sym
##                    scope = globals()
##                    # locals override
##                    scope.update(locals())
##                    if parts[1] in scope:
##                        all_defs[parts[1]] = scope[parts[1]]
##                    else:
##                        raise ValueError("Cannot resolve scope of symbol '%s'"%sym)
                else:
                    # assume module reference
                    assumed_modules.append(parts[0])
                    # record here to ensure inclusion in dyn_dummy
                    mapping[sym] = 'self.'+sym
            else:
                mapping[sym] = 'con.workspace.'+sym
        elif first_ix > 0 and tokens[first_ix-1] in ['"', "'"]:
            # put this symbol in the mapping values to ensure not included
            # as an argument to the function
            mapping[sym] = sym
    q.mapNames(mapping)
    import types
    for module_name in assumed_modules:
        global_scope = globals()
        # test if module name in scope
        if module_name in global_scope:
            _mod = global_scope[module_name]
            if isinstance(_mod, types.ModuleType):
                all_defs[module_name] = _mod

    # dyn_dummy contains dummy mappings but declares symbols to leave
    # evaluating until runtime
    dyn_dummy = dict(zip(mapping.values(), ['']*len(mapping)))
    funq = dst.expr2fun(q, ensure_args=['con'], ensure_dynamic=dyn_dummy,
                   for_funcspec=False, fn_name=fn_name,
                   **all_defs)

    # decorate output
    funq.attr_name = fn_name
    return funq
开发者ID:mcneela,项目名称:Retina,代码行数:67,代码来源:calc_context.py

示例2: plot

# 需要导入模块: import PyDSTool [as 别名]
# 或者: from PyDSTool import expr2fun [as 别名]
# find dixed points of the model
fp_coord = pp.find_fixedpoints(dmModel, n=4, eps=1e-8)

# plot the null-clines
nulls_x, nulls_y = pp.find_nullclines(dmModel, 's1', 's2', n=3, \
										eps=1e-8, max_step=0.01, fps=fp_coord)

plot(nulls_x[:,0], nulls_x[:,1], 'b')
plot(nulls_y[:,0], nulls_y[:,1], 'g')

# compute the jacobian matrix
jac, new_fnspecs = dst.prepJacobian(dmModel.funcspec._initargs['varspecs'],
			['s1','s2'],dmModel.funcspec._initargs['fnspecs'])
scope = dst.copy(dmModel.pars)
scope.update(new_fnspecs)
jac_fn = dst.expr2fun(jac, ensure_args=['t'],**scope)

# add fixed points to the phase portrait
for i in range(0,len(fp_coord)):
	fp = pp.fixedpoint_2D(dmModel, dst.Point(fp_coord[i]),
						jac = jac_fn, eps=1e-8)
	pp.plot_PP_fps(fp)

# compute and plot projectories
traj = dmModel.compute('trajectory1')
pts = traj.sample()
plot(pts['s1'], pts['s2'], 'r-o')

xlabel('s_1')
ylabel('s_2')
title('Phase plane I1=0.035 nA, I2=0.035 nA')
开发者ID:gilsho,项目名称:bioe332assign2,代码行数:33,代码来源:pplane.py


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