def main(filename): base, ext = os.path.splitext(filename) m = Model.load(filename, solver='glpk-dcopf') gen1 = NumpyArrayNodeRecorder(m, m.nodes['gen1']) pv2 = NumpyArrayNodeRecorder(m, m.nodes['pv2']) ProgressRecorder(m) CSVRecorder(m, f'{base}.csv') m.setup() stats = m.run() print(stats.to_dataframe()) df = pandas.concat({'gen1': gen1.to_dataframe(), 'pv2': pv2.to_dataframe()}, axis=1) fig, ax = plt.subplots(figsize=(8, 4)) df.plot(ax=ax) df.resample('D').mean().plot(ax=ax, color='black') ax.set_ylabel('MW') fig.savefig(f'{base}.png', dpi=300) fig, ax = plt.subplots(figsize=(8, 4)) df.resample('M').sum().plot(ax=ax) ax.set_ylabel('MWh per month') fig.savefig(f'{base}-monthly.png', dpi=300) plt.show()
def test_numpy_recorder(simple_linear_model): """ Test the NumpyArrayNodeRecorder """ model = simple_linear_model otpt = model.nodes['Output'] model.nodes['Input'].max_flow = 10.0 otpt.cost = -2.0 rec = NumpyArrayNodeRecorder(model, otpt) # test retrieval of recorder assert model.recorders['numpyarraynoderecorder.Output'] == rec # test changing name of recorder rec.name = 'timeseries.Output' assert model.recorders['timeseries.Output'] == rec with pytest.raises(KeyError): model.recorders['numpyarraynoderecorder.Output'] model.run() assert rec.data.shape == (365, 1) assert np.all((rec.data - 10.0) < 1e-12) df = rec.to_dataframe() assert df.shape == (365, 1) assert np.all((df.values - 10.0) < 1e-12)
def test_pv_generator(): m = Model.load(os.path.join(TEST_FOLDER, 'models', 'pv-generator.json'), solver='glpk-dcopf') gen1 = NumpyArrayNodeRecorder(m, m.nodes['gen1']) pv2 = NumpyArrayNodeRecorder(m, m.nodes['pv2']) m.setup() m.run() df = pandas.concat({ 'gen1': gen1.to_dataframe(), 'pv2': pv2.to_dataframe() }, axis=1) assert df.shape[0] == 745
def test_simple_battery(): m = Model.load(os.path.join(TEST_FOLDER, 'models', 'simple-battery.json'), solver='glpk-dcopf') gen1 = NumpyArrayNodeRecorder(m, m.nodes['gen1']) pv2 = NumpyArrayNodeRecorder(m, m.nodes['pv2']) battery1 = NumpyArrayStorageRecorder(m, m.nodes['battery1']) m.setup() m.run() df = pandas.concat( { 'gen1': gen1.to_dataframe(), 'pv2': pv2.to_dataframe(), 'battery1': battery1.to_dataframe() }, axis=1) assert df.shape[0] == 745