示例#1
0
 def test_load_activity_probability_profiles(self, version=None):
     from demod.datasets.CREST.loader import Crest
     data = Crest() if version is None else Crest(version)
     for n_res in [1, 2, 3, 4, 5, 6]:
         for day_type in [[1, 2, 3, 4, 5], [6, 7]]:
             subgroup = {'n_residents': n_res, 'weekday': day_type}
             app_dict = data.load_activity_probability_profiles(subgroup)
示例#2
0
 def test_ownership(self, version=None):
     from demod.datasets.CREST.loader import Crest
     data = Crest() if version is None else Crest(version)
     ownership_dict = data.load_appliance_ownership_dict()
     from demod.utils.appliances import get_ownership_from_dict
     values = get_ownership_from_dict(
         {'type': ['chest_freezer', 'tv', 'tv', 'tv']}, ownership_dict)
     self.assertTrue(np.all(values == np.array([0.163, 0.977, 0.58, 0.18])))
示例#3
0
 def test_load_tpm(self, version=None):
     from demod.datasets.CREST.loader import Crest
     data = Crest() if version is None else Crest(version)
     for n_res in [1, 2, 3, 4, 5, 6]:
         for day_type in [[1, 2, 3, 4, 5], [6, 7]]:
             subgroup = {'n_residents': n_res, 'weekday': day_type}
             tpm, labels, start_pdf = data.load_tpm(subgroup)
             n_states = int((n_res + 1)**2)
             self.assertEqual(tpm.shape, (144, n_states, n_states))
             self.assertEqual(len(labels), n_states)
             self.assertEqual(len(start_pdf), n_states)
示例#4
0
    def __init__(self,
                 data: DataInput = "CREST",
                 start_datetime: datetime.datetime = datetime.datetime(
                     2014, 1, 1, 0, 0, 0),
                 initial_clearness: float = 0.99,
                 **kwargs) -> None:
        """Initialize a climate simulator.

        Args:
            data: Data to be used. Defaults to "CREST".
            start_datetime: The start of the simulaiton.
                Defaults to datetime.datetime( 2014, 1, 1, 0, 0, 0 ).
            initial_clearness: Clearness at the start of the simulation.
                Can be from 0 to 1. Defaults to 0.99.
        """

        super().__init__(start_datetime=start_datetime, **kwargs)
        # remove some kwargs for irradiance
        kwargs.pop("logger", None)
        self.irradiance_sim = CrestIrradianceSimulator(
            data,
            start_datetime=start_datetime,
            initial_clearness=initial_clearness,
            **kwargs)

        if data == "CREST":
            data = Crest()

        # Set the cloud cooling rate
        self.cloud_cooling_rate = 0.1 / 60.0

        arma_dic = data.load_temperatures_arma()
        self.arma_dic = arma_dic

        self.initialize_starting_state()
示例#5
0
    def test_other_datasets(self):

        self.kwargs['data'] = Crest()

        BaseSimulatorChildrenTests.run_base_tests(self)

        self.test_same_time_init_start_in_test()
        self.test_instantiation_with_default_datetime()
        self.test_instantiation_with_other_datetime()
        self.test_step_updates_time()
        self.test_initialization_time()
        self.test_initialization_time_over_day()
        # self.test_non_default_step_size()

        self.kwargs.pop('data')
示例#6
0
    def __init__(self,
                 data: DataInput = "CREST",
                 initial_clearness: float = 0.99,
                 start_datetime=datetime.datetime(2014, 1, 1, 0, 0, 0),
                 **kwargs) -> None:
        """Initialize the Crest climate simulator.

        Args:
            data: the data to be used
            initial_clearness: the clearness at the start of the simulation
                It will not be used during the initialization
            start_datetime: the start of the simuulation
        """
        if data == "CREST":
            data = Crest()

        geo_dict = data.load_geographic_data()

        self.longitude = geo_dict["longitude"]
        self.latitude = geo_dict["latitude"]
        self.meridian = geo_dict["meridian"]

        # summer time is the french version of daylight saving time, sry
        self._use_summer_time = geo_dict["use_daylight_saving_time"]

        clearness_tpm, clearness_values, step_size = data.load_clearness_tpms()
        self.clearness_cdf = np.cumsum(clearness_tpm, axis=1)
        self.clearness_values = clearness_values

        check_valid_cdf(self.clearness_cdf)

        if 'step_size' in kwargs:

            if step_size != kwargs['step_size']:
                raise ValueError("'step_size' = {} was specified in {}'"
                                 ". It uses the step_size = {} from {} "
                                 " which are not the same.".format(
                                     kwargs['step_size'], self, step_size,
                                     data.load_clearness_tpms))

            kwargs = kwargs.copy()
            kwargs.pop('step_size')

        super().__init__(step_size=step_size,
                         start_datetime=start_datetime,
                         **kwargs)

        self.initialize_starting_state(initial_clearness)
class TestOccupancyApplianceSimulatorCrestData(TestOccupancyApplianceSimulator
                                               ):
    """Version of test subgroup appliances, but uses CREST data.

    Was required as compatibility breaks due to different default start
    time.

    Args:
        TimeAwareSimulatorChildrenTests: [description]
        unittest: [description]
    """
    sim = OccupancyApplianceSimulator
    kwargs = {
        'data': Crest(),
        'real_profiles_algo':
        'only_switched_on'  # Crest has only switched on profiles
    }
    # Time aware parameters
    default_start_datetime = datetime.datetime(2014, 1, 1, 0, 0, 0)
    default_initialization_time = datetime.time(0, 0, 0)
    default_step_size = datetime.timedelta(minutes=1)
    random_time = datetime.datetime(2008, 4, 5, 13, 42, 26)
    random_step_size = datetime.timedelta(hours=2,
                                          minutes=42,
                                          seconds=35,
                                          milliseconds=221)

    def test_step_timestep(self):
        # needs to set the start of the simulation first
        self.kwargs['start_datetime'] = self.default_start_datetime
        super().test_step_timestep()
        self.kwargs.pop('start_datetime')

    def test_instantiation_with_default_datetime(self):
        # needs to set the start of the simulation first
        self.kwargs['start_datetime'] = self.default_start_datetime
        super().test_instantiation_with_default_datetime()
        self.kwargs.pop('start_datetime')
示例#8
0
 def test_crest_dataset(self):
     data = Crest()
     bulb_config = data.load_bulbs_config()
     self.assertEqual(bulb_config.shape, (100, 38))
     light_dic = data.load_crest_lighting()
示例#9
0
import os
import sys

sys.path.insert(1, os.path.join(sys.path[0], '..'))

from demod.simulators.load_simulators import LoadSimulator
# Import the DatasetLoader
from demod.datasets.CREST.loader import Crest

from demod.simulators.base_simulators import SimLogger

sim = LoadSimulator(n_households=100, data=Crest())

sim = LoadSimulator(n_households=1,
                    data=Crest(),
                    logger=SimLogger('current_time', 'get_power_demand',
                                     'get_temperatures'))

for i in range(24 * 60):
    sim.step()

# Plots all the logged data one by one
sim.logger.plot()
# plots all the data in column
sim.logger.plot_column()
# Gets array of the data, can be used for your own purpose
elec_cons = sim.logger.get('get_power_demand')
示例#10
0
 def test_other_loaders(self, version=None):
     from demod.datasets.CREST.loader import Crest
     data = Crest() if version is None else Crest(version)
     data.load_crest_lighting()
     data.load_bulbs_config()
示例#11
0
 def test_washing_machines_loads(self, version=None):
     from demod.datasets.CREST.loader import Crest
     data = Crest() if version is None else Crest(version)
     real_load_dict = data.load_real_profiles_dict('switchedON')
示例#12
0
 def test_population(self, version=None):
     from demod.datasets.CREST.loader import Crest
     data = Crest() if version is None else Crest(version)
     data.load_population_subgroups('resident_number')
示例#13
0
    def test_load_appliances_dict(self, version=None):
        from demod.datasets.CREST.loader import Crest
        data = Crest() if version is None else Crest(version)

        app_dict = data.load_appliance_dict()
示例#14
0
 def test_same_step_size_as_data(self):
     data = Crest()
     _, _, step_size = data.load_clearness_tpms()
     sim = self.sim(step_size=step_size)
     sim.step()