diff --git a/pyproject.toml b/pyproject.toml index fee7f94..13a3cbb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pytrnsys_process" -version = "0.0.27" +version = "0.0.28" authors = [ { name="Alex Hobé", email="alex.hobe@ost.ch" }, { name="Sebastian Swoboda", email="sebastian@swoboda.ch" }, diff --git a/pytrnsys_process/plot/plotters.py b/pytrnsys_process/plot/plotters.py index 0f666a2..87b3fee 100644 --- a/pytrnsys_process/plot/plotters.py +++ b/pytrnsys_process/plot/plotters.py @@ -124,7 +124,7 @@ def _do_plot( cmap = self.get_cmap(kwargs) if cmap: - cm = _plt.cm.get_cmap(cmap) + cm = _plt.get_cmap(cmap) colors = cm(_np.linspace(0, 1, len(columns))) else: colors = [None] * len(columns) diff --git a/pytrnsys_process/process/process_sim.py b/pytrnsys_process/process/process_sim.py index 2842e8f..fc67849 100644 --- a/pytrnsys_process/process/process_sim.py +++ b/pytrnsys_process/process/process_sim.py @@ -186,9 +186,16 @@ def _process_file( file_type == conf.FileType.TIMESTEP and conf.global_settings.reader.read_step_files ): - simulation_data_collector.step.append( - _read_file(file_path, conf.FileType.TIMESTEP) - ) + # There are two ways to have a step file: + # - using type 25 + # - using type 46 + # The user can copy and paste both, and they would like to use '_step.prt'. + # Here we try both, as a temporary solution, till the file reading is fully refactored. + try: + step_df = _read_file(file_path, conf.FileType.TIMESTEP) + except KeyError: + step_df = _read_file(file_path, conf.FileType.HYDRAULIC) + simulation_data_collector.step.append(step_df) elif ( file_type == conf.FileType.HYDRAULIC and conf.global_settings.reader.read_step_files diff --git a/tests/pytrnsys_process/data/process-sim/sim-2/temp/ENERGY_BALANCE_MO_HP_60_incorrect.Prt b/tests/pytrnsys_process/data/process-sim/sim-2/temp/ENERGY_BALANCE_MO_HP_60_incorrect.Prt new file mode 100644 index 0000000..a6195af --- /dev/null +++ b/tests/pytrnsys_process/data/process-sim/sim-2/temp/ENERGY_BALANCE_MO_HP_60_incorrect.Prt @@ -0,0 +1,40 @@ + Label not available Label not available Label not available Label not available +Period TIME QSnk60PauxEvap_kW QSnk60PelAuxComp_kW QSnk60PauxCondSwitch_kW +November +0.8016000000000000E+004 +0.2161358340750096E+005 +0.5776788628296898E+004 +0.2739037203579770E+005 +December +0.8760000000000000E+004 +0.2838888210807185E+005 +0.8140286109162899E+004 +0.3652916821723460E+005 +January +0.9504000000000000E+004 +0.3099081794071290E+005 +0.9306178154672469E+004 +0.4029699609538541E+005 +February +0.1017600000000000E+005 +0.2580109312781669E+005 +0.7868013262659784E+004 +0.3366910639047660E+005 +March +0.1092000000000000E+005 +0.2120961830858527E+005 +0.6169001827384862E+004 +0.2737862013597025E+005 +April +0.1164000000000000E+005 +0.1486670395882630E+005 +0.3978451920217696E+004 +0.1884515587904413E+005 +May +0.1238400000000000E+005 +0.7628377358636680E+004 +0.1915581261331994E+004 +0.9543958619968678E+004 +June +0.1310400000000000E+005 +0.2731920242477886E+004 +0.6593262316230313E+003 +0.3391246474100910E+004 +July +0.1384800000000000E+005 +0.1063312304434059E+004 +0.2777601024093779E+003 +0.1341072406843437E+004 +August +0.1459200000000000E+005 +0.2057131024277858E+004 +0.4836754477946225E+003 +0.2540806472072484E+004 +September +0.1531200000000000E+005 +0.4886254979749180E+004 +0.1108116448792786E+004 +0.5994371428541986E+004 +October +0.1605600000000000E+005 +0.1312982789194613E+005 +0.3133620291843777E+004 +0.1626344818378989E+005 +November +0.1677600000000000E+005 +0.2141597363167885E+005 +0.5715598281347823E+004 +0.2713157191302666E+005 +December +0.1752000000000000E+005 +0.2837193267579600E+005 +0.8142118404336021E+004 +0.3651405108013218E+005 + + Maximum Instantaneous Values + Label not available Label not available Label not available Label not available +Maximum Value +0.1752000000000000E+005 +0.1301301130104686E+003 +0.3577578501555571E+002 +0.1567056145561912E+003 +Time of Maximum +0.1752000000000000E+005 +0.1453096666666667E+005 +0.1429330000000000E+005 +0.1453096666666667E+005 + + Minimum Instantaneous Values + Label not available Label not available Label not available Label not available +Minimum Value +0.7300033333333334E+004 +0.0000000000000000E+000 +0.0000000000000000E+000 +0.0000000000000000E+000 +Time of Minimum +0.7300033333333334E+004 +0.1752000000000000E+005 +0.1752000000000000E+005 +0.1752000000000000E+005 + + Maximum Integrated Values + Label not available Label not available Label not available Label not available +Maximum Value +0.1752000000000000E+005 +0.3099081794071290E+005 +0.9306178154672469E+004 +0.4029699609538541E+005 +Time of Maximum +0.1752000000000000E+005 +0.9504000000000000E+004 +0.9504000000000000E+004 +0.9504000000000000E+004 + + Minimum Integrated Values + Label not available Label not available Label not available Label not available +Minimum Value +0.8016000000000000E+004 +0.1063312304434059E+004 +0.2777601024093779E+003 +0.1341072406843437E+004 +Time of Minimum +0.8016000000000000E+004 +0.1384800000000000E+005 +0.1384800000000000E+005 +0.1384800000000000E+005 + + Sum (note: sums are set to zero for inputs that were not integrated.) + Label not available Label not available Label not available Label not available +Total +0.0000000000000000E+000 +0.2241554289605119E+006 +0.6267451637187461E+005 +0.2868299453323836E+006 diff --git a/tests/pytrnsys_process/data/process-sim/sim-2/temp/HPCtrlPrinter_step.Prt b/tests/pytrnsys_process/data/process-sim/sim-2/temp/HPCtrlPrinter_step.Prt new file mode 100644 index 0000000..97d9920 --- /dev/null +++ b/tests/pytrnsys_process/data/process-sim/sim-2/temp/HPCtrlPrinter_step.Prt @@ -0,0 +1,6 @@ + TIME HPCtrl PriceCtrl ElPrice HotWatCtrl HotWatProportion + +0.0000000000000000E+00 +0.0000000000000000E+00 +1.0000000000000000E+00 +2.0997000000000000E+01 +2.0000000000000000E+00 +9.9999837206454878E-01 + +1.6666666666666666E-01 +1.0000000000000000E+00 +1.0000000000000000E+00 +1.5273000000000000E+01 +2.0000000000000000E+00 +9.9999837206454878E-01 + +3.3333333333333331E-01 +1.0000000000000000E+00 +1.0000000000000000E+00 +1.5273000000000000E+01 +2.0000000000000000E+00 +9.9999837206454878E-01 + +5.0000000000000000E-01 +1.0000000000000000E+00 +1.0000000000000000E+00 +1.5273000000000000E+01 +2.0000000000000000E+00 +9.9999837206454878E-01 + +6.6666666666666663E-01 +1.0000000000000000E+00 +1.0000000000000000E+00 +1.5273000000000000E+01 +2.0000000000000000E+00 +9.9999837206454878E-01 diff --git a/tests/pytrnsys_process/test_process_sim.py b/tests/pytrnsys_process/test_process_sim.py index fa333b4..f79fee5 100644 --- a/tests/pytrnsys_process/test_process_sim.py +++ b/tests/pytrnsys_process/test_process_sim.py @@ -1,3 +1,5 @@ +import logging as _logging + import pandas as _pd import pytest as _pt @@ -5,24 +7,34 @@ from pytrnsys_process import util from pytrnsys_process.process import process_sim as ps -PATH_TO_RESULTS = const.DATA_FOLDER / "process-sim/sim-1" +PATH_TO_RESULTS = const.DATA_FOLDER / "process-sim" / "sim-1" +PATH_TO_RESULTS_2 = const.DATA_FOLDER / "process-sim" / "sim-2" class TestProcessSim: - - def test_process_sim_prt(self, monkeypatch): + @staticmethod + def run_process_sim_with_caplog(files, results_path, caplog): + caplog.clear() + with caplog.at_level(_logging.INFO): + return ps.process_sim(files, results_path) + + def test_process_sim_prt(self, monkeypatch, caplog): + # The following monkeypatch is needed, as otherwise these tests do not + # incorporate the changed setting properly. monkeypatch.setattr( "pytrnsys_process.config.global_settings.reader.read_step_files", True, ) sim_files = util.get_files([PATH_TO_RESULTS], get_mfr_and_t=True) - simulation = ps.process_sim(sim_files, PATH_TO_RESULTS) - with _pt.raises(Exception) as exc_info: - assert ( - "don-not-process.xlsx: No columns to parse from file" - in str(exc_info.value) - ) + simulation = self.run_process_sim_with_caplog( + sim_files, PATH_TO_RESULTS, caplog + ) + + assert ( + "don-not-process.xlsx: No columns to parse from file" + in caplog.text + ) self.do_assert(simulation) assert simulation.scalar.shape == (1, 10) @@ -57,7 +69,23 @@ def test_process_sim_ignore_deck(self, monkeypatch): simulation = ps.process_sim(sim_files, PATH_TO_RESULTS) assert simulation.scalar.shape == (0, 0) - def do_assert(self, simulation): + def test_process_sim_type_25_step(self, monkeypatch, caplog): + monkeypatch.setattr( + "pytrnsys_process.config.global_settings.reader.read_step_files", + True, + ) + sim_files = util.get_files( + [PATH_TO_RESULTS_2], get_mfr_and_t=False, read_deck_files=False + ) + simulation = self.run_process_sim_with_caplog( + sim_files, PATH_TO_RESULTS_2, caplog + ) + assert "KeyError: 'Month'" in caplog.text + + assert simulation.step.shape == (5, 5) + + @staticmethod + def do_assert(simulation): assert simulation.hourly.shape == (3, 18) assert simulation.monthly.shape == (14, 11) assert simulation.step.shape == (5, 142)