• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pysd.read_vensim函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pysd.read_vensim函数的典型用法代码示例。如果您正苦于以下问题:Python read_vensim函数的具体用法?Python read_vensim怎么用?Python read_vensim使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_no_crosstalk

    def test_no_crosstalk(self):
        """
        Need to check that if we instantiate two copies of the same model,
        changes to one copy do not influence the other copy.
        """
        # Todo: this test could be made more comprehensive
        import pysd

        model_1 = pysd.read_vensim('test-models/samples/teacup/teacup.mdl')
        model_2 = pysd.read_vensim('test-models/samples/SIR/SIR.mdl')

        model_1.components.initial_time = lambda: 10
        self.assertNotEqual(model_2.components.initial_time, 10)
开发者ID:SimonStrong,项目名称:pysd,代码行数:13,代码来源:unit_test_pysd.py


示例2: test_set_initial_condition

    def test_set_initial_condition(self):
        import pysd
        model = pysd.read_vensim(test_model)
        initial_temp = model.components.teacup_temperature()
        initial_time = model.components.time()

        new_state = {'Teacup Temperature': 500}
        new_time = np.random.rand()

        model.set_initial_condition((new_time, new_state))
        set_temp = model.components.teacup_temperature()
        set_time = model.components.time()

        self.assertNotEqual(set_temp, initial_temp)
        self.assertEqual(set_temp, 500)

        self.assertNotEqual(initial_time, new_time)
        self.assertEqual(new_time, set_time)

        model.set_initial_condition('original')
        set_temp = model.components.teacup_temperature()
        set_time = model.components.time()

        self.assertEqual(initial_temp, set_temp)
        self.assertEqual(initial_time, set_time)
开发者ID:SimonStrong,项目名称:pysd,代码行数:25,代码来源:unit_test_pysd.py


示例3: test_no_param_list_no_bounds

    def test_no_param_list_no_bounds(self):
        model = pysd.read_vensim('test-models/samples/teacup/teacup.mdl')
        n_samples = 5
        samples = pysd.testing.sample_pspace(model=model,
                                             samples=n_samples)

        self.assertSetEqual(set(samples.columns), {'Characteristic Time', 'Room Temperature'})
开发者ID:JamesPHoughton,项目名称:pysd,代码行数:7,代码来源:unit_test_testing.py


示例4: test_multiple_load

    def test_multiple_load(self):
        """
        Test that we can load and run multiple models at the same time,
        and that the models don't interact with each other. This can
        happen if we arent careful about class attributes vs instance attributes

        This test responds to issue:
        https://github.com/JamesPHoughton/pysd/issues/23

        """
        import pysd

        model_1 = pysd.read_vensim('test-models/samples/teacup/teacup.mdl')
        model_2 = pysd.read_vensim('test-models/samples/SIR/SIR.mdl')

        self.assertNotIn('teacup_temperature', dir(model_2.components))
开发者ID:SimonStrong,项目名称:pysd,代码行数:16,代码来源:unit_test_pysd.py


示例5: test_run_return_columns_pysafe_names

 def test_run_return_columns_pysafe_names(self):
     """Addresses https://github.com/JamesPHoughton/pysd/issues/26"""
     import pysd
     model = pysd.read_vensim(test_model)
     return_columns = ['room_temperature', 'teacup_temperature']
     result = model.run(return_columns=return_columns)
     self.assertEqual(set(result.columns), set(return_columns))
开发者ID:SimonStrong,项目名称:pysd,代码行数:7,代码来源:unit_test_pysd.py


示例6: test_initial_conditions_tuple_pysafe_names

 def test_initial_conditions_tuple_pysafe_names(self):
     import pysd
     model = pysd.read_vensim(test_model)
     stocks = model.run(initial_condition=(3000, {'teacup_temperature': 33}),
                        return_timestamps=list(range(3000, 3010)))
     self.assertEqual(stocks.index[0], 3000)
     self.assertEqual(stocks['Teacup Temperature'].iloc[0], 33)
开发者ID:SimonStrong,项目名称:pysd,代码行数:7,代码来源:unit_test_pysd.py


示例7: test_set_initial_condition_origin_short

    def test_set_initial_condition_origin_short(self):
        import pysd
        model = pysd.read_vensim(test_model)
        initial_temp = model.components.teacup_temperature()
        initial_time = model.components.time()

        new_state = {'Teacup Temperature': 500}
        new_time = 10

        model.set_initial_condition((new_time, new_state))
        set_temp = model.components.teacup_temperature()
        set_time = model.components.time()

        self.assertNotEqual(set_temp, initial_temp, "Test definition is wrong, please change configuration")
        self.assertEqual(set_temp, 500)

        self.assertNotEqual(initial_time, new_time, "Test definition is wrong, please change configuration")
        self.assertEqual(new_time, set_time)

        model.set_initial_condition('o')
        set_temp = model.components.teacup_temperature()
        set_time = model.components.time()

        self.assertEqual(initial_temp, set_temp)
        self.assertEqual(initial_time, set_time)
开发者ID:JamesPHoughton,项目名称:pysd,代码行数:25,代码来源:unit_test_pysd.py


示例8: runner

def runner(model_file):
    directory = os.path.dirname(model_file)

    # load model
    if model_file.endswith('.mdl'):
        model = pysd.read_vensim(model_file)
    elif model_file.endswith(".xmile"):
        model = pysd.read_xmile(model_file)
    else:
        raise AttributeError('Modelfile should be *.mdl or *.xmile')

    # load canonical output
    try:
        encoding = detect_encoding(directory + '/output.csv')
        canon = pd.read_csv(directory + '/output.csv', encoding=encoding, index_col='Time')
    except IOError:
        try:
            encoding = detect_encoding(directory + '/output.tab')
            canon = pd.read_table(directory + '/output.tab', encoding=encoding, index_col='Time')
        except IOError:
            raise IOError('Canonical output file not found')

    # run model
    output = model.run(return_columns=canon.columns)

    return output, canon
开发者ID:JamesPHoughton,项目名称:pysd,代码行数:26,代码来源:test_utils.py


示例9: test_run

 def test_run(self):
     import pysd
     model = pysd.read_vensim(test_model)
     stocks = model.run()
     self.assertTrue(isinstance(stocks, pd.DataFrame))  # return a dataframe
     self.assertTrue('Teacup Temperature' in stocks.columns.values)  # contains correct column
     self.assertGreater(len(stocks), 3)  # has multiple rows
     self.assertTrue(stocks.notnull().all().all())  # there are no null values in the set
开发者ID:SimonStrong,项目名称:pysd,代码行数:8,代码来源:unit_test_pysd.py


示例10: test_initial_conditions_current

 def test_initial_conditions_current(self):
     import pysd
     model = pysd.read_vensim(test_model)
     stocks1 = model.run(return_timestamps=list(range(0, 31)))
     stocks2 = model.run(initial_condition='current',
                         return_timestamps=list(range(30, 45)))
     self.assertEqual(stocks1['Teacup Temperature'].iloc[-1],
                      stocks2['Teacup Temperature'].iloc[0])
开发者ID:SimonStrong,项目名称:pysd,代码行数:8,代码来源:unit_test_pysd.py


示例11: test_run_return_columns_original_names

 def test_run_return_columns_original_names(self):
     """Addresses https://github.com/JamesPHoughton/pysd/issues/26
     - Also checks that columns are returned in the correct order"""
     import pysd
     model = pysd.read_vensim(test_model)
     return_columns = ['Room Temperature', 'Teacup Temperature']
     result = model.run(return_columns=return_columns)
     self.assertEqual(set(result.columns), set(return_columns))
开发者ID:SimonStrong,项目名称:pysd,代码行数:8,代码来源:unit_test_pysd.py


示例12: test_initial_conditions_tuple_original_names

 def test_initial_conditions_tuple_original_names(self):
     """ Responds to https://github.com/JamesPHoughton/pysd/issues/77"""
     import pysd
     model = pysd.read_vensim(test_model)
     stocks = model.run(initial_condition=(3000, {'Teacup Temperature': 33}),
                        return_timestamps=list(range(3000, 3010)))
     self.assertEqual(stocks.index[0], 3000)
     self.assertEqual(stocks['Teacup Temperature'].iloc[0], 33)
开发者ID:SimonStrong,项目名称:pysd,代码行数:8,代码来源:unit_test_pysd.py


示例13: test_set_component_with_real_name

    def test_set_component_with_real_name(self):
        import pysd
        model = pysd.read_vensim(test_model)
        model.set_components({'Room Temperature': 20})
        self.assertEqual(model.components.room_temperature(), 20)

        model.run(params={'Room Temperature': 70})
        self.assertEqual(model.components.room_temperature(), 70)
开发者ID:SimonStrong,项目名称:pysd,代码行数:8,代码来源:unit_test_pysd.py


示例14: test_replace_element

 def test_replace_element(self):
     import pysd
     model = pysd.read_vensim(test_model)
     stocks1 = model.run()
     model.components.characteristic_time = lambda: 3
     stocks2 = model.run()
     self.assertGreater(stocks1['Teacup Temperature'].loc[10],
                        stocks2['Teacup Temperature'].loc[10])
开发者ID:SimonStrong,项目名称:pysd,代码行数:8,代码来源:unit_test_pysd.py


示例15: test_reset_state

 def test_reset_state(self):
     import pysd
     import warnings
     model = pysd.read_vensim(test_model)
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter("always")
         model.reset_state()
     self.assertEqual(len(w), 1)
开发者ID:SimonStrong,项目名称:pysd,代码行数:8,代码来源:unit_test_pysd.py


示例16: test_set_constant_parameter

    def test_set_constant_parameter(self):
        """ In response to: re: https://github.com/JamesPHoughton/pysd/issues/5"""
        import pysd
        model = pysd.read_vensim(test_model)
        model.set_components({'room_temperature': 20})
        self.assertEqual(model.components.room_temperature(), 20)

        model.run(params={'room_temperature': 70})
        self.assertEqual(model.components.room_temperature(), 70)
开发者ID:SimonStrong,项目名称:pysd,代码行数:9,代码来源:unit_test_pysd.py


示例17: test_set_components_with_function

    def test_set_components_with_function(self):
        def test_func():
            return 5

        import pysd
        model = pysd.read_vensim(test_model)
        model.set_components({'Room Temperature': test_func})
        res = model.run(return_columns=['Room Temperature'])
        self.assertEqual(test_func(), res['Room Temperature'].iloc[0])
开发者ID:SimonStrong,项目名称:pysd,代码行数:9,代码来源:unit_test_pysd.py


示例18: test_run_return_timestamps_past_final_time

 def test_run_return_timestamps_past_final_time(self):
     """ If the user enters a timestamp that is longer than the euler
     timeseries that is defined by the normal model file, should
     extend the euler series to the largest timestamp"""
     import pysd
     model = pysd.read_vensim(test_model)
     return_timestamps = list(range(0, 100, 10))
     stocks = model.run(return_timestamps=return_timestamps)
     self.assertSequenceEqual(return_timestamps, list(stocks.index))
开发者ID:SimonStrong,项目名称:pysd,代码行数:9,代码来源:unit_test_pysd.py


示例19: test__integrate

 def test__integrate(self):
     import pysd
     # Todo: think through a stronger test here...
     model = pysd.read_vensim(test_model)
     res = model._integrate(time_steps=list(range(5)),
                            capture_elements=['teacup_temperature'],
                            return_timestamps=list(range(0, 5, 2)))
     self.assertIsInstance(res, list)
     self.assertIsInstance(res[0], dict)
开发者ID:SimonStrong,项目名称:pysd,代码行数:9,代码来源:unit_test_pysd.py


示例20: test_run_return_timestamps

    def test_run_return_timestamps(self):
        """Addresses https://github.com/JamesPHoughton/pysd/issues/17"""
        import pysd
        model = pysd.read_vensim(test_model)
        timestamps = np.random.rand(5).cumsum()
        stocks = model.run(return_timestamps=timestamps)
        self.assertTrue((stocks.index.values == timestamps).all())

        stocks = model.run(return_timestamps=5)
        self.assertEqual(stocks.index[0], 5)
开发者ID:SimonStrong,项目名称:pysd,代码行数:10,代码来源:unit_test_pysd.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python status.OperStatus类代码示例发布时间:2022-05-27
下一篇:
Python converter.scsi_ba_to_int函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap