diff --git a/.gitignore b/.gitignore index cda7e3a37b6607b3b9360a049121d38774cecebe..d18ea1ce67c8cd151b3cab775b7d515c32ac9fb2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ # ignore symbolic links *.egg-info +*.eggs # ignore compiled python files *.pyc diff --git a/dataprocessing/readtools.py b/dataprocessing/readtools.py index b7d5c643e4ceade42c1a2ebbc11c699b86e45da9..1e08a9d9d50128a66000cd17436e3745f98a6a17 100644 --- a/dataprocessing/readtools.py +++ b/dataprocessing/readtools.py @@ -3,7 +3,6 @@ import pandas as pd from .timeseries import * import re - def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False): from modelicares import SimRes sim = SimRes(filename) @@ -12,6 +11,7 @@ def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False): timeseries = [] for name in sim.names(): timeseries.append(TimeSeries(name, sim(name).times(), sim(name).values())) + timeseries_names = sim.names() elif is_regex is True: # Read in variables which match with regex timeseries = [] @@ -30,7 +30,7 @@ def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False): timeseries.append(TimeSeries(name, sim(name).times(), sim(name).values())) print('Modelica results column names: ' + str(timeseries_names)) - print('Modelica results number: ' + str(len(timeseries_list))) + print('Modelica results number: ' + str(len(timeseries_names))) return timeseries diff --git a/examples/NEPLAN/read_NEPLAN.py b/examples/NEPLAN/read_NEPLAN.py new file mode 100644 index 0000000000000000000000000000000000000000..6fedcd62d432a9733d4f144d5cf1203d7e46359a --- /dev/null +++ b/examples/NEPLAN/read_NEPLAN.py @@ -0,0 +1,36 @@ +import re + +def readsim(file_name,timeseries_names=None, is_regex=False): + str_tmp = open(file_name,"r") + low = 0 + high = 0 + flag = True + dic = {} + seq = [] + value = [] + i = 0 + isfloat = re.compile(r'^[-+]?[0-9]+\.[0-9]+$') + for line in str_tmp.readlines(): + line = line.replace(",",".") + high -= high + low -= low + del value[:] + for letter in line: + if letter == " " or letter == "\n": # different data or end + if low is not high: # not NONE + if flag: # seq + seq.append(line[low:high]) + else: # value + if isfloat.match(line[low:high]): + value.append(float(line[low:high])) + else: + value.append(line[low:high]) + else: # NONE + value.append(r'#') + low = high + 1 + high += 1 + flag = False + dic[i] = dict(zip(seq, value)) + i += 1 + str_tmp.close() + return dic \ No newline at end of file diff --git a/examples/NEPLAN/read_NEPLAN_example.py b/examples/NEPLAN/read_NEPLAN_example.py new file mode 100644 index 0000000000000000000000000000000000000000..cc6c517fe310d78d5e83de6f2cb00c191c88f9a1 --- /dev/null +++ b/examples/NEPLAN/read_NEPLAN_example.py @@ -0,0 +1,15 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +import read_NEPLAN +import re + +file = r"C:\Users\jdi-bli\Desktop\Test\Slack_Rxline_PQLoad.rlf" + +# Example 1: Read in all variable +result = read_NEPLAN.readsim(file) +for i in range(6): + print(result[i]) # result as list of TimeSeries + +# Example 2: Read in specific variable +# all_bus_voltages = readsim_Neplan.readsim(file, ) +# all_comp_currents = ... \ No newline at end of file