Exemplo n.º 1
0
 def test_examples(self):
     """Apply algorithm and check expected results."""
     example_results = dict(zip(self.df.columns, [40, 79, 41]))
     for column, expected in example_results.items():
         cycles = detect_cycles(self.df[column])
         result = cycles.sum().sum()  # sum along column sums (kind of ID)
         msg = ('Test for example ' + column +
                ' failed. Expected checksum ' + str(expected) + ', is ' +
                str(result) + '.' + str(cycles))
         eq_(result, expected, msg)
Exemplo n.º 2
0
    def test_example(self):
        """Apply algorithm and check expected results."""
        cycles = detect_cycles(self.ds)
        # using an input series with DatetimeIndex returns the timestamps
        # for start, end and minimum as well as a timedelta as duration
        t0 = datetime.strptime('2019-01-02', '%Y-%m-%d')
        t1 = datetime.strptime('2019-01-06', '%Y-%m-%d')
        t2 = datetime.strptime('2019-01-10', '%Y-%m-%d')
        tmin1 = datetime.strptime('2019-01-04', '%Y-%m-%d')
        tmin2 = datetime.strptime('2019-01-08', '%Y-%m-%d')
        expected = pd.DataFrame(
            [[t0, t1, tmin1, 1.0, t1 - t0], [t1, t2, tmin2, 1.0, t2 - t1]],
            columns=['t_start', 't_end', 't_minimum', 'doc', 'duration'])

        assert_frame_equal(cycles, expected)
Exemplo n.º 3
0
 def test_ValueError_length(self):
     """Invoke ValueErrors."""
     detect_cycles(pd.Series([0, 1, 0]))
Exemplo n.º 4
0
 def test_ValueError_no_cycle(self):
     """Invoke ValueErrors."""
     detect_cycles(pd.Series([0, 1, 2, 3, 2, 1, 0]))
Exemplo n.º 5
0
 def test_TypeError(self):
     """Invoke TypeErrors."""
     detect_cycles(self.df['nones'])
Exemplo n.º 6
0
 def test_ValueError_no_valley(self):
     """Invoke ValueErrors."""
     detect_cycles(self.df['no_valley'])
Exemplo n.º 7
0
 def test_ValueError_no_peak(self):
     """Invoke ValueErrors."""
     detect_cycles(self.df['no_peak'])
Exemplo n.º 8
0
)

# Cylces ---------------------------------------------------------
cycles = {}
cycles_h = {}
cycles_l = {}

for dir in os.listdir(path):
    df = pd.read_csv(
        os.path.join(path, dir, "output", "filling_levels.csv"),
        index_col=[0],
        parse_dates=True,
    )
    df["phs"] = df[[c for c in df.columns if "phs" in c]].sum(axis=1)
    if sum(df["battery"] != 0):
        cycles_l[dir] = detect_cycles(df["battery"])
    if sum(df["phs"] != 0):
        cycles_h[dir] = detect_cycles(df["phs"])

for v in base_scenarios:
    if v in cycles_l:
        ax = sns.jointplot(
            x=cycles_l[v]["duration"] / np.timedelta64(1, "h"),
            y=cycles_l[v]["doc"],
            marginal_kws=dict(bins=100, rug=True),
            kind="scatter",
            color="m",
            edgecolor="purple",
        )
        ax.set_axis_labels("Duration of cycle in h",
                           "Normalised depth of cycle")
Exemplo n.º 9
0
# filling levels --------------------------------------------------------------
cycles = {}
cycles_h = {}
cycles_l = {}

for dir in os.listdir(path):
    if dir in base_scenarios:
        df = pd.read_csv(
            os.path.join(path, dir, "output", "filling_levels.csv"),
            index_col=[0],
            parse_dates=True,
        )
        if not "flex" in dir:
            try:
                cycles[dir] = detect_cycles(df["DE-flex-decentral_heat-tes"])
            except:
                pass

for dir in os.listdir(path):
    df = pd.read_csv(
        os.path.join(path, dir, "output", "filling_levels.csv"),
        index_col=[0],
        parse_dates=True,
    )
    if sum(df["DE-hydrogen-storage"] != 0):
        cycles_h[dir] = detect_cycles(df["DE-hydrogen-storage"])
    if sum(df["DE-lithium-battery"] != 0):
        cycles_l[dir] = detect_cycles(df["DE-lithium-battery"])

for v in base_scenarios: