本文整理汇总了Python中pysd.read_vensim函数的典型用法代码示例。如果您正苦于以下问题:Python read_vensim函数的具体用法?Python read_vensim怎么用?Python read_vensim使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_vensim函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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'})
示例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))
示例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))
示例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)
示例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)
示例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
示例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
示例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])
示例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))
示例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)
示例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)
示例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])
示例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)