Python生成器

Python构建器允许构建可以使用PySD Model类运行的模型。

在转换中使用一对一词典意味着功能的广度本质上是有限的。如果没有直接的Python等效物可用,PySD会提供一个函数库,例如 pulse , step 等,这些特定于动态模型行为。

除了在Vensim/XMILE和Python之间转换单个命令外,PySD还通过用强调线替换空白来重新处理组件标识符,使其具有Python安全性。转换器允许源标识符使用字母数字字符、空白或特殊字符。为了实现这一目标,创建了一个命名空间,该命名空间将变量的原始名称与Python安全名称链接起来。PySD模型类中也提供了命名空间,允许用户使用原始名称和Python安全名称。

构建模型产生的Python代码的格式为 black 库并将其写入原始模型所在的同一文件夹中。

主要建设者

模型构建器类允许将AbstractModel转换为PySD模型,将Python代码写入文件中,稍后可以使用PySD模型类加载这些文件。每个抽象级别都有自己的构建器。然而,用户只需使用AbstractModel创建模型构建器对象并调用 build_model

class pysd.builders.python.python_model_builder.ModelBuilder(abstract_model: AbstractModel)[源代码]

模型构建器允许从抽象模型构建PySD Python模型。

参数:

abstract_model (AbstractModel) -- 要构建的抽象模型。

build_model() Path[源代码]

在一个文件中构建Python模型,该文件称为原始模型,但后缀为“.py”。

返回:

path --通往新PySD模型的道路。

返回类型:

pathlib.Path

class pysd.builders.python.python_model_builder.SectionBuilder(abstract_section: AbstractSection)[源代码]

SectionBuilder允许构建PySD模型的一部分。每个部分都将是一个文件,除非模型已设置为拆分为模块。

参数:

abstract_section (AbstractSection) -- 要构建的抽象部分。

build_section() None[源代码]

如果该部分是main部分,则在称为原始模型的文件中构建Python部分;如果该部分是宏,则在称为宏名的文件中构建Python部分。

class pysd.builders.python.python_model_builder.ElementBuilder(abstract_element: AbstractElement, section: SectionBuilder)[源代码]

ElementBuilder允许构建PySD模型的元素。

参数:
  • abstract_element (AbstractElement) -- 要构建的抽象元素。

  • section (SectionBuilder) -- 定义元素的部分。需要给下标和命名空间的访问权限。

build_element() None[源代码]

构建元素。返回要包含在部分中的字符串,该部分将是修饰的函数定义和可能的对象。

class pysd.builders.python.python_model_builder.ComponentBuilder(abstract_component: AbstractComponent, element: ElementBuilder, section: SectionBuilder)[源代码]

CLARentBuilder允许构建PySD模型的组件。

参数:
  • abstract_component (AbstracComponent) -- 要构建的抽象组件。

  • element (ElementBuilder) -- 定义组件的元素。需要为合并脚注和其他组件提供访问权限。

  • section (SectionBuilder) -- 定义元素的部分。需要给下标和命名空间的访问权限。

build_component() None[源代码]

构建模型组件,解析抽象收件箱树。

get() tuple[源代码]

获取构建组件来构建元素。

返回:

  • ast_build ( BuildAST )--解析的AbstractSyntaxTree。

  • subscript_dict ( dict or list of dicts )--组件的脚注。

  • except_subscripts ( list of dicts )--要避免的下标。

表达构建者

从抽象语法树到Python的转换以两种方式发生。外部表达与其构建者一起访问,后者将分裂其论点并与各自的构建者一起访问它们。到达最低级别后,它将被转换成Python,返回一个Building AST对象,该对象将包括pPython表达、其脚注、对其他元素的调用及其算术顺序(更多信息请参阅Build AST)。将为每个访问的参数从较低级别到顶层返回Building AST,给出最终的表达。

class pysd.builders.python.python_expressions_builder.BuildAST(expression: str, calls: dict, subscripts: dict, order: int)[源代码]

Python表情持有者。

参数:
  • expression (str) -- Python表达。

  • calls (dict) -- 对依赖项字典的其他变量的调用。

  • subscripts (dict) -- 该表达的脚注。

  • order (int) -- 表达的算术顺序。算术顺序取决于最后一次算术运算。如果该表达是数字、对函数的调用或位于括号之间;其顺序为0。如果该表达是两项的指数,其阶数将为1。如果该表达是产品或部门,其顺序将是2。如果该表达是和或减法,其顺序将是3。如果该表达是逻辑比较,其顺序将是4。

reshape(subscripts: SubscriptManager, final_subscripts: dict, final_element: bool = False) None[源代码]

将对象重塑为所需的脚注。如果它不为0,它会修改该公式并降低阶数。

参数:
  • subscripts (SubscriptManager) -- 该部分的脚注。

  • final_subscripts (dict) -- 所需的最终脚注。

  • final_element (bool (optional)) -- 如果为True,则将使用最终的脚注重新塑造数组,以具有耻辱形状。否则,长度为1的维度将包含在位置中,以允许与其他数组进行算术运算。默认为假。

lower_order(new_order: int) None[源代码]

降低顺序以保持算术运算的正确顺序。如果请求的顺序小于当前顺序,则将括号添加到公式中以将其顺序降低为0。

参数:

new_order (int) -- 表达所需的新顺序。如果为0,则假设该公式将作为函数的参数传递,因此不会执行任何操作。如果需要order 0,则new_order可以使用负值。

class pysd.builders.python.python_expressions_builder.StructureBuilder(value: object, component: object)[源代码]

抽象树结构的主要构建器。所有的构建器都是该类的子类,这允许它们继承方法。

static join_calls(arguments: dict) dict[源代码]

合并参数的调用。

参数:

arguments (dict) -- 论点词典。键应该带有从0开始的有序整数字符串。

返回:

calls --合并的呼叫词典。

返回类型:

dict

reorder(arguments: dict, force: bool = None) dict[源代码]

重新排序参数的脚注以使它们匹配。

参数:
  • arguments (dict) -- 论点词典。键应该带有从0开始的有序整数字符串。

  • force ('component', 'equal', or None (optional)) -- 如果force是“组件”,它将强制参数具有组件定义的脚注。如果力是“相等的”,它将迫使所有参数具有相同的脚注,包括浮动。如果力为“无”,则它只会修改阵列的形状,添加长度1维,以允许不同形状的阵列之间的操作。默认为无。

返回:

final_subscripts --重新排序所有元素后的final_substrates。

返回类型:

dict

get_final_subscripts(arguments: dict) dict[源代码]

获取参数组合的最终脚注。

参数:

arguments (dict) -- 论点词典。键应该带有从0开始的有序整数字符串。

返回:

final_subscripts --组合所有元素的最终__后缀。

返回类型:

dict

update_object_subscripts(name: str, component_final_subs: dict) None[源代码]

更新对象订阅。对于那些使用“add”方法同时加载多个组件并且使用混合定义的对象来说需要。

参数:
  • name (str) -- 对象字典中来自元素的对象的名称。

  • component_final_subs (dict) -- 组件的脚注,但以元素脚注范围作为键。当组件用最终脚注范围的子范围定义时,这可能与组件脚注不同。

class pysd.builders.python.python_expressions_builder.OperationBuilder(operation: ArithmeticStructure | LogicStructure, component: object)[源代码]

算术和逻辑运算的生成器。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.GameBuilder(game_str: GameStructure, component: object)[源代码]

GAME表情的生成器。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.CallBuilder(call_str: CallStructure, component: object)[源代码]

用于调用函数、宏和查找的生成器。

build_not_implemented(arguments: dict) BuildAST[源代码]

为未实现的函数调用构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

build_incomplete_call(arguments: dict) BuildAST[源代码]

为不完整的函数调用构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

build_macro_call(arguments: dict) BuildAST[源代码]

构建宏调用的方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

build_lookups_call(arguments: dict) BuildAST[源代码]

生成查找调用的方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

build_function_call(arguments: dict) BuildAST[源代码]

为函数调用构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.AllocateAvailableBuilder(allocate_str: AllocateAvailableStructure, component: object)[源代码]

allocate_active函数的生成器。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.AllocateByPriorityBuilder(allocate_str: AllocateByPriorityStructure, component: object)[源代码]

allocate_by_priority函数的生成器。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.ExtLookupBuilder(getlookup_str: GetLookupsStructure, component: object)[源代码]

Builder for External Lookups.

build(arguments: dict) BuildAST | None[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --构建的对象,除非该组件已使用“add”方法添加到现有对象中。

返回类型:

BuildAST or None

class pysd.builders.python.python_expressions_builder.ExtDataBuilder(getdata_str: GetDataStructure, component: object)[源代码]

外部数据的生成器。

build(arguments: dict) BuildAST | None[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --构建的对象,除非该组件已使用“add”方法添加到现有对象中。

返回类型:

BuildAST or None

class pysd.builders.python.python_expressions_builder.ExtConstantBuilder(getconstant_str: GetConstantsStructure, component: object)[源代码]

外部常数的生成器。

build(arguments: dict) BuildAST | None[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --构建的对象,除非该组件已使用“add”方法添加到现有对象中。

返回类型:

BuildAST or None

class pysd.builders.python.python_expressions_builder.TabDataBuilder(data_str: DataStructure, component: object)[源代码]

空数据运算式的生成器。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.InitialBuilder(initial_str: InitialStructure, component: object)[源代码]

缩写的生成器。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.IntegBuilder(integ_str: IntegStructure, component: object)[源代码]

整合/股票的构建者。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.DelayBuilder(dtype: str, delay_str: DelayStructure | DelayNStructure, component: object)[源代码]

定期延误的构建者。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.DelayFixedBuilder(delay_str: DelayFixedStructure, component: object)[源代码]

延迟已修复的构建者。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.SmoothBuilder(smooth_str: SmoothStructure | SmoothNStructure, component: object)[源代码]

光滑的建造者。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.TrendBuilder(trend_str: TrendStructure, component: object)[源代码]

趋势的构建者。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.ForecastBuilder(forecast_str: ForecastStructure, component: object)[源代码]

预测的构建者。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.SampleIfTrueBuilder(sampleiftrue_str: SampleIfTrueStructure, component: object)[源代码]

如果为True,则示例的生成器。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.LookupsBuilder(lookups_str: LookupsStructure, component: object)[源代码]

定期查找的生成器。

build(arguments: dict) BuildAST | None[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --构建的对象,除非该组件已使用“add”方法添加到现有对象中。

返回类型:

BuildAST or None

class pysd.builders.python.python_expressions_builder.InlineLookupsBuilder(inlinelookups_str: InlineLookupsStructure, component: object)[源代码]

用于内联查找的生成器。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.ReferenceBuilder(reference_str: ReferenceStructure, component: object)[源代码]

用于引用其他变量的生成器。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.NumericBuilder(value: object, component: object)[源代码]

数字和nan值的生成器。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

class pysd.builders.python.python_expressions_builder.ArrayBuilder(value: object, component: object)[源代码]

数组的生成器。

build(arguments: dict) BuildAST[源代码]

构建方法。

参数:

arguments (dict) -- 构建论点的字典。

返回:

built_ast --建筑物。

返回类型:

BuildAST

pysd.builders.python.python_expressions_builder.merge_dependencies(*dependencies: dict, inplace: bool = False) dict[源代码]

合并元素的两个依赖项。

参数:
  • dependencies (dict) -- 要合并的依赖项字典。

  • inplace (bool (optional)) -- 如果为True,最终的依赖关系dict将在第一个依赖关系参数中更新,并对其进行变异。默认值为False。

返回:

current --最终的依赖关系决定。

返回类型:

dict

pysd.builders.python.python_expressions_builder.visit_loc(current_subs: dict, original_subs: dict, keep_shape: bool = False) tuple[源代码]

比较原始下标和当前下标,并根据需要返回子索引信息。

参数:
  • current_subs (dict) -- 变量中使用的下标的字典。

  • original_subs (dict) -- 变量原始脚注的字典。

  • keep_shape (bool (optional)) -- 如果True将保留原始元素的维度数并仅返回loc。默认为假。

返回:

  • loc ( list of str or None )--各维度的订阅列表。如果所有内容都已满(“:”),则没有被删除,这意味着不需要数组索引。

  • rename ( dict )--要重命名的维度的字典。

  • final_subs ( dict )--变量最后一个后缀的字典。

  • reset_coords ( bool )--布尔值,指示是否需要重新设置坐标。

  • to_float ( bool )--布尔值,指示变量是否应转换为浮点数。

class pysd.builders.python.python_expressions_builder.ASTVisitor(component: object)[源代码]

ASTVisitor允许访问组件的抽象Synatx树,返回Python对象并生成必要的对象。

参数:

component (ComponentBuilder) -- 要构建的组件构建器。

visit() None | BuildAST[源代码]

访问组件的抽象收件箱树。

返回:

visit_out --访问AST产生的Building AST对象。如果已使用“add”方法将组件内容添加到现有对象,则它将返回无。

返回类型:

BuildAST or None

支持的表达示例

运营商

支持的一元运算符

抽象语法

Python转换

逻辑结构( ['negative'] ,(A,))

-A

A

A

逻辑结构( [':NOT:'] ,(A,))

numpy.not(A)

支持的二进制运算符

抽象语法

Python转换

算术结构( ['^'] ,(A,B))

A**B

算术结构( ['*'] ,(A,B))

A*B

算术结构( ['/'] ,(A,B))

A/B

呼叫结构(“模”,(A,B))

pysd.functions.模(A,B)

算术结构( ['+'] ,(A,B))

A+B

算术结构( ['-'] ,(A,B))

A-B

逻辑结构( ['='] ,(A,B))

A == B

逻辑结构( ['<>'] ,(A,B))

A!= B

逻辑结构( ['<'] ,(A,B))

A < B

逻辑结构( ['>'] ,(A,B))

A > B

逻辑结构( ['>='] ,(A,B))

A >= B

逻辑结构( ['<='] ,(A,B))

A <= B

逻辑结构( [':AND:'] ,(A,B))

numpy。和(A,B)

逻辑结构( [':OR:'] ,(A,B))

numpy。或(A,B)

功能

支持的基本功能

抽象语法

Python转换

Python评论

CallStructure('abs', (A,))

numpy.abs(A)

呼叫结构(' min ',(A,B))

numpy.minimum(A,B)

呼叫结构(' max ',(A,B))

numpy. max(A,B)

呼叫结构(' vmin_xmile ',(A,))

pysd.functions.vmin(A)

呼叫结构(' vmax_xmile ',(A,))

pysd.functions.vmax(A)

呼叫结构(' SQRT ',(A,))

numpy.sqrt

CallStructure('exp',(A,))

numpy. BEP(A)

呼叫结构(' In ',(A,))

numpy.log(A)

呼叫结构(' pi ',(,))

numpy.py

呼叫结构(' sin ',(A,))

numpy.sin(A)

呼叫结构(' cos ',(A,))

numpy.cos(A)

CallStructure('tan',(A,))

numpy.tan(A)

呼叫结构(' arcsin ',(A,))

numpy.arcsin(A)

CallStructure('arccos',(A,))

numpy.arccos(A)

呼叫结构(“arctan”,(A,))

numpy.arctan(A)

呼叫结构(' invert_matrix ',(A,))

pysd.functions.invert_matrix(A)

CallStructure('elmcount',(A,))

len(A)

CallArchitecture(' int ',(A,))

pysd.functions.integer(A)

呼叫结构(“量子”,(A,B))

pysd.函数.量子(A,B)

呼叫结构(“模”,(A,B))

pysd.functions.模(A,B)

呼叫结构(' if_then_else ',(A,B))

pysd.functions.if_then_else(A,lambda:B,lambda:C)

呼叫结构(' if_then_else ',(A,B))

pysd.functions.if_then_else(A,lambda:B,lambda:C)

呼叫结构(' xidz ',(A,B,X))

pysd.functions.xidz(A,B,X)

呼叫结构(' zidz ',(A,B))

pysd.functions.zidz(A,B)

呼叫结构(' vmin ',(A,))

pysd.functions.vmin(A, ['dim!'] )

CallStructure('vmax',(A,))

pysd.functions.vmax(A, ['dim!'] )

呼叫结构(' sum ',(A,))

pysd.functions.sum(A, ['dim!'] )

呼叫结构(' prod ',(A,))

pysd.functions.prod(A, ['dim!'] )

呼叫结构('脉冲',(开始,宽度))

pysd.functions.pulse(start,width=width)

呼叫结构(' Xpulse ',(开始,幅度))

pysd.functions.pulse(开始,幅度=幅度)

CallStructure('Xpulse_train',(start,interval,magnitude))

pysd.functions.pulse(开始,重复_时间=间隔,幅度=幅度)

CallStructure('pulse_train',(start,tbetween,width,end))

pysd.functions.pulse(start,repeat_time=tbetween,root = root,end=end)

呼叫结构(' ramp ',(slope,start_time,end_time))

pysd.functions.ramp(时间、slope、start_time、end_time)

呼叫结构(' ramp ',(slope,start_time))

pysd.functions.ramp(时间、slope、start_time)

CallStructure('step',(height,step_time))

pysd.functions.Step(时间、高度、Step_time)

CallStructure('get_time_value',(relativeto,offset,measure))

pysd.functions.get_time_value(时间、相对于、补偿、测量)

CallArchitecture(' vector_select ',(sel_数组,BEP_数组,miss_val,n_action,e_action))

pysd.functions.vector_select(sel_数组,BEP_数组, ['dim!'] 、miss_val、n_action、e_action)

呼叫结构(' vector_rank ',(vec,Direction))

vector_rank(vec,direction)

呼叫结构(' vector_reorder ',(vec,svec))

vector_reorder(vec,svec)

呼叫结构(' vector_sort_order ',(vec,Direction))

vector_sort_order(vec,direction)

游戏结构(A)

A

AllocateDeliverable Architecture(请求、pp、avenue)

分配_可用(请求、PP、可用)

并非包括所有优先级配置文件。

AllocateByPriorityArchitecture(请求、优先级、大小、宽度、供应)

分配_by_优先级(请求、优先级、宽度、供应)

初始结构(值)

pysd.statefuls.Initial

SampleIfTrueArchitecture(条件、输入、初始值)

pysd.有权势.SampleIfTrue(.)

呼叫结构(' random_0_1 ',())

NP.random. unique(0,1,size=final_shape)

CallArchitecture(' random_uniform ',(m,x,s))

np.random.uniform(m,x,size=final_shape)

呼叫结构(' random_normal ',(m,x,h,r,s))

stats.truncnorm.rvs((m-h)/r,(x-h)/r,loc=h,scale=r,size=final_shape)

呼叫结构(' random_exponential ',(m,x,h,r,s))

stats.truncexpon.rvs((x-NP. max(m,h)/r,loc=NP. max(m,h),scale=r,size=final_shape)

支持的延迟功能

抽象语法

Python转换

延迟结构(输入,延迟_时间,初始值,1)

pysd。有权势的人。延迟(.)

延迟结构(输入,delay_time,输入,1)

pysd。有权势的人。延迟(.)

延迟结构(输入,延迟_时间,初始值,3)

pysd。有权势的人。延迟(.)

延迟结构(输入,delay_time,输入,3)

pysd。有权势的人。延迟(.)

DelayNStructure(输入,delay_time,initial_Value,n)

pysd.statefuls.DelayN(.)

DelayNArchitecture(输入,delay_time,输入,n)

pysd.statefuls.DelayN(.)

DelayFixed(输入、delay_time、initial_Value)

pysd。有状态。延迟修复(.)

DelayFixed(输入,delay_time,输入)

pysd。有状态。延迟修复(.)

SmoothFrame(输入,smth_time,initial_value,1)

pysd。有权势。顺利(.)

SmothArchitecture(输入,smth_time,输入,1)

pysd。有权势。顺利(.)

SmoothFrame(输入,smth_time,initial_value,3)

pysd。有权势。顺利(.)

SmoothStructure(input,smth_time,input,3)

pysd。有权势。顺利(.)

SmothNStructure(输入,smth_time,initional_Value,n)

pysd.有状态.SmoothN(.)

SmothNStructure(输入,smth_time,输入,n)

pysd.有状态.SmoothN(.)

预测结构(输入、平均时间、地平线、初始趋势)

pysd。有权势的人。预测(.)

预测结构(输入,平均_时间,地平线,0)

pysd。有权势的人。预测(.)

TrendStructure(input, average_time, initial_trend)

pysd。有权势的人。趋势(.)

趋势结构(输入,平均_时间,0)

pysd。有权势的人。趋势(.)

支持的get函数

抽象语法

Python转换

GetDataStructure('file','tab','time_row_or_col','cell')

pysd. externative.ExtData(.)

GetDataStructure('file','tab','time_row_or_col','cell')

pysd. externative.ExtData(.)

GetLookupsArchitecture('文件',' x_row_or_col ',',cell ')

pysd.external.ExtLookup(...)

GetLookupsArchitecture('文件',' x_row_or_col ',',cell ')

pysd.external.ExtLookup(...)

GetConstantsStructure('file','tab','cell')

pysd. externative.ExtConstant(.)

GetConstantsStructure('file','tab','cell')

pysd. externative.ExtConstant(.)

名字空间管理器

class pysd.builders.python.namespace.NamespaceManager(parameters: List[str] = [])[源代码]

命名空间管理器对象允许在命名空间中包含新元素并在命名空间中搜索元素。当包含新元素时,使用Python安全名称来编写等式。

参数:

parameters (list (optional)) -- 在宏中用作参数的参数列表。通过德福克特,这是一个空列表。

add_to_namespace(string: str) None[源代码]

向命名空间添加新字符串。

参数:

string (str) -- 要添加到命名空间的字符串。

返回类型:

None

make_python_identifier(string: str, prefix: str = None, add_to_namespace: bool = False) str[源代码]

获取任意字符串并创建有效的Python标识符。

如果创建的Python标识符已经在命名空间中,但输入字符串不在(即,两个相似的字符串解析为相同的Python标识符),或者如果标识符是reserved_words列表中的保留字,或者是Python默认保留字,则添加_1,或者如果_1在命名空间中,则添加_2等。

参数:
  • string (str) -- 要转换为有效Python标识符的文本。

  • prefix (str or None (optional)) -- 如果给定,它将被用作输出字符串的开头。默认为无。

  • add_to_namespace (bool (optional)) -- 如果为True,它会将传递的字符串添加到命名空间和cleanSpace。默认为假。

返回:

identifier --基于输入字符串的有效Python标识符。

返回类型:

str

示例

>>> make_python_identifier('Capital')
'capital'
>>> make_python_identifier('multiple words')
'multiple_words'
>>> make_python_identifier('multiple     spaces')
'multiple_spaces'

当名称是Python关键字时,添加“_1”以区分它> make_python_identifier(' for ')' for_1 '

删除开头和结尾的空白> make_pony_identifier(“whiteSpace”)“whiteSpace”

直接删除大多数特殊字符:> make_python_identifier(' H @t tra!ck ')' ht_trck '

添加有效字符串到前导数字> make_python_identifier('123abc')'nvs_123abc'

已在命名空间中> make_python_identifier(' Var $')#namency = ð ' Var ':'

命名空间冲突> make_pony_identifier(' Var @')#namency =' Var $':' var '}' var_1 '

>>> make_python_identifier('Var$')  # namespace={'Var@': 'var',
...                                              'Var%':'var_1'}
'var_2'

引用

标识符必须遵循此处概述的惯例:

https://docs.python.org/2/reference/lexical_analysis.html#identifiers

get_original_name(identifier)[源代码]

搜索变量Python标识符的原始名称。

参数:
  • identifier (str) -- 它应该是命名空间中的一个值。

  • Rerturns

  • --------

  • original_name (str) -- 变量的原始名称。

字幕经理

class pysd.builders.python.subscripts.SubscriptManager(abstract_subscripts: List[AbstractSubscriptRange], _root: Path)[源代码]

SubwrittManager对象允许保存小节中包含的脚注、搜索元素或键并简化它们。

参数:
  • abstrac_subscripts (list) -- 来自AbstractModel的AbstractSubwrittRanges列表。

  • _root (pathlib.Path) -- 模型文件的路径。需要从Excel文件中读取脚注范围。

make_coord_dict(subs: List[str]) dict[源代码]

这用于协助查找特定元素。

参数:

subs (list of strings) -- 坐标,可以是维度的名称,也可以是维度内的位置。

返回:

coordinates --访问我们感兴趣的xArray数量所需的坐标。

返回类型:

dict

示例

>>> sm = SubscriptManager([], Path(''))
>>> sm._subscripts = {
...     'Dim1': ['A', 'B', 'C'],
...     'Dim2': ['A', 'B', 'C', 'D']}
>>> sm.make_coord_dict(['Dim1', 'D'])
{'Dim1': ['A', 'B', 'C'], 'Dim2': ['D']}
>>> sm.make_coord_dict(['A'])
{'Dim1': ['A']}
>>> sm.make_coord_dict(['A', 'B'])
{'Dim1': ['A'], 'Dim2': ['B']}
>>> sm.make_coord_dict(['A', 'Dim1'])
{'Dim2': ['A'], 'Dim1': ['A', 'B', 'C']}
make_merge_list(subs_list: List[List[str]], element: str = '') List[str][源代码]

这用于在构建xrmerge时提供帮助。合并后,从一系列订阅列表中返回最终的订阅列表。合并具有来自不同定义的脚注的变量时是必要的。

参数:
  • subs_list (list of lists of strings) -- 坐标,可以是维度的名称,也可以是维度内的位置。

  • element (str (optional)) -- 元素名称(如果给出)将打印出任何错误或警告消息。默认为“”。

返回:

dims --合并后的最终脚注。

返回类型:

list

示例

>>> sm = SubscriptManager([], Path(''))
>>> sm._subscripts = {"upper": ["A", "B"], "all": ["A", "B", "C"]}
>>> sm.make_merge_list([['A'], ['B']])
['upper']
>>> sm.make_merge_list([['A'], ['B'], ['C']])
['all']
>>> sm.make_merge_list([['upper'], ['C']])
['all']
>>> sm.make_merge_list([['A'], ['C']])
['all']
simplify_subscript_input(coords: dict, merge_subs: List[str] = None) tuple[源代码]

简化了后缀输入,以避免在可以使用_subscpt_dict时打印坐标列表。使模型代码更加简单。

参数:
  • coords (dict) -- 要写入模型文件的坐标。

  • merge_subs (list of strings or None (optional)) -- 与其他对象合并后Python数组的最终脚注范围列表。如果无,则merge_subs将从坐标中取出。默认为无。

返回:

final_subs, coords --在模型文件中生成coord指令的最终脚注和方程。

返回类型:

dict, str

示例

>>> sm = SubscriptManager([], Path(''))
>>> sm._subscripts = {
...     "dim": ["A", "B", "C"],
...     "dim2": ["A", "B", "C", "D"]}
>>> sm.simplify_subscript_input({"dim": ["A", "B", "C"]})
({"dim": ["A", "B", "C"]}, "{'dim': _subscript_dict['dim']}"
>>> sm.simplify_subscript_input({"dim": ["A", "B", "C"]}, ["dim2"])
({"dim2": ["A", "B", "C"]}, "{'dim2': _subscript_dict['dim']}"
>>> sm.simplify_subscript_input({"dim": ["A", "B"]})
({"dim": ["A", "B"]}, "{'dim': ['A', 'B']}"

进口经理

class pysd.builders.python.imports.ImportsManager[源代码]

类保存导入的模块信息以进行智能导入

add(module: str, function: str | None = None) None[源代码]

从模块中添加一个函数。

参数:
  • module (str) -- 模块名称。

  • function (str or None) -- 函数名称。如果无模块将设置为真。

get_header(outfile: str) str[源代码]

返回要在模型文件中打印的导入信息

参数:

outfile (str) -- 要在标题中打印的输出文件的名称。

返回:

text --转换后的模型文件的头。

返回类型:

str