Example #1
0
 def run(self, solar_area, wind_area, battery_capacity):
     power_supply = (self.wind_power_simulation * wind_area +
                     self.solar_power_simulation * solar_area)
     supply, load = power_supply.tolist(), self.Task.load_demand.tolist()
     if self.config != {}:
         model = Soc_model_variable_load(
             Battery(battery_capacity, config=self.config), supply, load)
     else:
         model = Soc_model_variable_load(Battery(battery_capacity), supply,
                                         load)
     lpsp = model.get_lost_power_supply_probability()
     return lpsp
Example #2
0
    def post_run(self, solar_area, wind_area, battery_capacity, dispatch):
        power_supply = (self.wind_power_simulation * wind_area +
                        self.solar_power_simulation * solar_area)

        post_run_len = len(dispatch)  # match length of simulation
        supply, load = power_supply[:post_run_len].tolist(
        ), dispatch['Power'].tolist()

        if self.config != {}:
            model = Soc_model_variable_load(
                Battery(battery_capacity, config=self.config), supply, load)
        else:
            model = Soc_model_variable_load(Battery(battery_capacity), supply,
                                            load)

        prop_load = (self.Task.load_demand[:post_run_len] -
                     self.Task.hotel_load[:post_run_len]).as_matrix()
        load_demand = self.Task.load_demand[:post_run_len].as_matrix()
        hotel_load = self.Task.hotel_load[:post_run_len].as_matrix()

        load_demand_history = np.vstack((load_demand, prop_load, hotel_load))
        load_demand_history_df = pd.DataFrame(
            data=load_demand_history[:post_run_len].T,
            index=self.Task.mission.df[:post_run_len].index,
            columns=['Load_demand', 'Prop_load', 'Hotel_load'],
        )

        load_demand_history_df = full_day_cut(load_demand_history_df)

        battery_history = model.get_battery_history()
        battery_history_df = pd.DataFrame(
            data=battery_history[:post_run_len].T,
            index=self.df[:post_run_len].index,
            columns=['SOC', 'Battery', 'Unmet', 'Waste', 'Supply'],
        )

        results = [
            battery_history_df,
            load_demand_history_df[:post_run_len],
            self.solar[:post_run_len] * solar_area,
            self.wind[:post_run_len] * wind_area,
        ]
        result_df = pd.concat(results, axis=1)

        return result_df
Example #3
0
    def result(self, solar_area, wind_area, battery_capacity):
        power_supply = (self.wind_power_simulation * wind_area +
                        self.solar_power_simulation * solar_area)
        supply, load = power_supply.tolist(), self.Task.load_demand.tolist()
        if self.config is not {}:
            model = Soc_model_variable_load(
                Battery(battery_capacity, config=self.config), supply, load)
        else:
            model = Soc_model_variable_load(Battery(battery_capacity), supply,
                                            load)

        prop_load = (self.Task.load_demand - self.Task.hotel_load).as_matrix()
        load_demand = self.Task.load_demand.as_matrix()
        hotel_load = self.Task.hotel_load.as_matrix()

        load_demand_history = np.vstack((load_demand, prop_load, hotel_load))
        load_demand_history_df = pd.DataFrame(
            data=load_demand_history.T,
            index=self.Task.mission.df.index,
            columns=['Load_demand', 'Prop_load', 'Hotel_load'],
        )
        load_demand_history_df = full_day_cut(load_demand_history_df)

        battery_history = model.get_battery_history()
        battery_history_df = pd.DataFrame(
            data=battery_history.T,
            index=self.df.index,
            columns=['SOC', 'Battery', 'Unmet', 'Waste', 'Supply'],
        )

        results = [
            battery_history_df,
            load_demand_history_df,
            self.solar * solar_area,
            self.wind * wind_area,
        ]
        result_df = pd.concat(results, axis=1)
        return result_df
Example #4
0
    def post_run(self, solar_area, wind_area, battery_capacity, dispatch):
        print('====== Post simulation run ======')
        power_supply = (
            self.wind_power_simulation * wind_area
            + self.solar_power_simulation * solar_area
        )

        post_run_len = len(dispatch)  # match length of simulation
        supply, load = power_supply[:post_run_len].tolist(), dispatch['Power'].tolist()

        if self.config != {}:
            battery = Battery(battery_capacity, config=self.config)
        else:
            battery = Battery(battery_capacity)

        battery.run(supply, load)
        prop_load = (self.Task.load_demand - self.Task.hotel_load).values
        load_demand = self.Task.load_demand.values
        hotel_load = self.Task.hotel_load.values
        critical_load = self.Task.critical_prop_load + self.Task.critical_hotel_load.values

        load_demand_history = np.vstack((load_demand, prop_load, hotel_load, critical_load))
        load_demand_history_df = pd.DataFrame(
            data=load_demand_history.T,
            index=self.Task.mission.df.index,
            columns=['Load_demand', 'Prop_load', 'Hotel_load', 'Critical_load'],
        )

        load_demand_history_df = full_day_cut(load_demand_history_df)

        battery_history = battery.battery_history()
        battery_history_df = pd.DataFrame(
            data=battery_history[:post_run_len].T,
            index=self.df[:post_run_len].index,
            columns=['SOC', 'Battery', 'Unmet', 'Waste', 'Supply'],
        )

        results = [
            battery_history_df,
            load_demand_history_df[:post_run_len],
            self.solar[:post_run_len] * solar_area,
            self.wind[:post_run_len] * wind_area,
        ]
        result_df = pd.concat(results, axis=1)

        return result_df
Example #5
0
    def run(self, solar_area, wind_area, battery_capacity):
        power_supply = (
            self.wind_power_simulation * wind_area
            + self.solar_power_simulation * solar_area
        )

        if self.config != {}:
            battery = Battery(battery_capacity, config=self.config)
            safe_factor = self.config['optimization']['safe_factor']
        else:
            battery = Battery(battery_capacity)
            safe_factor = 0

        supply, load = power_supply.tolist(), (self.Task.load_demand*(1+safe_factor)).tolist()
        battery.run(supply, load)
        lpsp = battery.lost_power_supply_probability()
        return lpsp
Example #6
0
from D3HRE.core.battery_models import Soc_model_variable_load, Battery, Battery_managed

from tests.test_env import *

b1 = Battery(10)
model = Soc_model_variable_load(b1, [1, 2, 3], [1, 2, 3])
model2 = Soc_model_variable_load(Battery(10), [1, 1, 1], [10, 10, 10])


def test_lpsp_calc():
    assert model.get_lost_power_supply_probability() == 0
    assert model2.get_lost_power_supply_probability() == 1


# w and w/o config
B = 10

managed_battery = Battery_managed(B)
managed_battery_with_config = Battery_managed(B, config=config)


def test_parameter_setting():
    # Battery capacity should match
    assert managed_battery.capacity == B
    assert managed_battery_with_config.capacity == B

    # Test parameter setting in managed battery object
    assert managed_battery.DOD == 1
    assert managed_battery.init_charge == 1

    assert managed_battery_with_config.DOD == config['simulation']['battery'][
Example #7
0
    def run(self, solar_area, wind_area, battery_capacity, validation=False):

        if self.config != {}:
            battery = Battery(battery_capacity, config=self.config)
            safe_factor = self.config['optimization']['safe_factor']
            coupling_ratio = self.config['simulation']['coupling']
        else:
            battery = Battery(battery_capacity)
            safe_factor = 0
            coupling_ratio = 0.05

        # Get unit area wind power generation
        wind_raw_unit, wind_correction_unit = self.wind_power_simulation
        wind_raw = wind_raw_unit * wind_area
        wind_correction = wind_correction_unit * wind_area

        # Correct wind power generation
        prop_load = self.Task.prop_load + wind_correction
        prop_load[prop_load < 0] = 0  # disable the wind driven generator mode

        power_generation = (wind_raw + self.solar_power_simulation * solar_area) * (1 - coupling_ratio)
        # Consider the coupling between wind and solar power generation
        demand_load = prop_load + self.Task.hotel_load

        generation = power_generation.tolist()
        load = (demand_load * (1 + safe_factor)).tolist()

        battery.run(generation, load)

        if validation:

            battery_history = battery.battery_history()
            battery_history_df = pd.DataFrame(
                data=battery_history.T,
                index=self.Task.mission.df.index,
                columns=['SOC', 'Battery', 'Unmet', 'Waste', 'Supply'],
            )
            try:
                load_demand_history = np.vstack((demand_load, prop_load, self.Task.hotel_load.values,
                                             (self.Task.critical_hotel_load +
                                              prop_load * self.Task.robot.critical_prop_load_ratio).values))
            except AttributeError:
                load_demand_history = np.vstack((demand_load, prop_load, self.Task.hotel_load.values,
                                             (self.Task.critical_hotel_load +
                                              self.Task.critical_prop_load).values))
            load_demand_history_df = pd.DataFrame(
                data=load_demand_history.T,
                index=self.Task.mission.df.index,
                columns=['Load_demand', 'Prop_load', 'Hotel_load', 'Critical_load'],
            )

            generation_history_df = pd.DataFrame(
                data=generation,
                index=self.Task.mission.df.index,
                columns=['Generation']
            )
            results = [self.resource_df,
                       self.solar * solar_area,
                       self.wind * wind_area,
                       generation_history_df,
                       load_demand_history_df,
                       battery_history_df]
            self.history = pd.concat(results, axis=1)
            return self.history

        lost_power_supply_probability = battery.lost_power_supply_probability()
        return lost_power_supply_probability