Exemplo n.º 1
0
    def __init__(self,
                 data: DataInput = 'Germany',
                 start_datetime: datetime.datetime = (datetime.datetime(
                     1980, 1, 1, 0, 0, 0)),
                 interpolation_kind: Union[str, int] = 'linear',
                 **kwargs) -> None:
        try:
            from scipy.interpolate import interp1d
        except ImportError as imp_err:
            raise RuntimeError(
                'Could not import from scipy.'
                'You can install it using "pip install scipy".') from imp_err

        if data == 'Germany':
            data = OpenPowerSystemClimate('germany')

        self.data = data

        climate_dict = data.load_historical_climate_data(start_datetime)

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

        self.datetime_values_utc = np.array(climate_dict.pop('datetime'),
                                            dtype='datetime64[m]')
        self.initial_time = self.datetime_values_utc[0]
        # Check where is the end of the data
        self.last_time = self.datetime_values_utc[-1].astype(datetime.datetime)
        self.last_time = self.last_time.replace(
            tzinfo=None if start_datetime.tzinfo is None else datetime.
            timezone.utc)
        # must use real values for interp1d
        minutes = (self.datetime_values_utc - self.initial_time).astype(float)

        self.interpolators = {
            key: interp1d(minutes,
                          values,
                          kind=interpolation_kind,
                          assume_sorted=True)
            for key, values in climate_dict.items()
        }
        # creats getters correponding to the received data
        for key in climate_dict.keys():
            setattr(self, 'get_' + key, self._make_interpolated_getter(key))

        intialization_time = self.datetime_values_utc[0].astype(
            datetime.datetime)
        intialization_time = intialization_time.replace(
            tzinfo=start_datetime.tzinfo)

        # Checks that the data does not start after the start datetime
        if intialization_time > start_datetime:
            raise ValueError("Requested start_datetime in utc is : {},"
                             " but dataset {} for"
                             " country '{}', starts "
                             "only at {}".format(start_datetime, data,
                                                 data.country,
                                                 intialization_time))

        self.initialize_starting_state(intialization_time=intialization_time)
Exemplo n.º 2
0
 def test_loading_aware_datetime(self):
     data = OpenPowerSystemClimate('germany')
     start_datetime = datetime.datetime(2014,
                                        1,
                                        1,
                                        0,
                                        0,
                                        0,
                                        tzinfo=datetime.timezone.utc)
Exemplo n.º 3
0
    def __init__(self,
                 data: ClimateLoader = 'Germany',
                 start_datetime: datetime.datetime = datetime.datetime(
                     1980, 1, 1, 0, 0, 0),
                 **kwargs) -> None:
        """Create a real climate simulator.

        Args:
            data: Datset to be used. Defaults to 'Germany'.
            start_datetime: The start of the simulation.
                Defaults to datetime(1980, 1, 1, 0, 0, 0).
        """
        if data == 'Germany':
            data = OpenPowerSystemClimate('germany')

        # should get the tzinfromation as well
        climate_data = data.load_historical_climate_data(start_datetime)

        if 'step_size' in kwargs:
            raise ValueError(
                ("'step_size' cannot be specified in {}"
                 ". It uses the step size from {}."
                 "You can use {} if you want to use a specific step_size."
                 ).format(self, data.load_historical_climate_data,
                          RealInterpolatedClimate))

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

        self.irradiance_iter = iter(
            climate_data.get('irradiance')
            if climate_data.get('radiation_global') is None else climate_data.
            get('radiation_global'))

        self.temperature_iter = iter(climate_data['outside_temperature'])

        intialization_time = climate_data['datetime'][0].astype(
            datetime.datetime)
        intialization_time = intialization_time.replace(
            tzinfo=start_datetime.tzinfo)
        # Checks that the data does not start after the start datetime
        if intialization_time > start_datetime:
            raise ValueError(
                "Requested start_datetime is : {}, but dataset {} for"
                " country '{}', starts "
                "only at {}".format(start_datetime, data, data.country,
                                    intialization_time))

        self.initialize_starting_state(intialization_time)
Exemplo n.º 4
0
sys.path.insert(1, os.path.join(sys.path[0], '..'))
import datetime
from demod.simulators.base_simulators import SimLogger
from demod.datasets.GermanTOU.loader import GTOU
from demod.datasets.OpenPowerSystems.loader import OpenPowerSystemClimate

from demod.simulators.crest_simulators import Crest4StatesModel
from demod.simulators.weather_simulators import RealClimate
from demod.simulators.lighting_simulators import FisherLightingSimulator

n_households = 100
# Start of the simulation
start_datetime = datetime.datetime(2014, 3, 1, 0, 0, 0)

climate_sim = RealClimate(
    data=OpenPowerSystemClimate('Germany'),  # A climate dataset
    start_datetime=start_datetime,  # Specifiy the start of the simulaiton
    logger=SimLogger('get_irradiance'))

activity_sim = Crest4StatesModel(
    n_households,
    data=GTOU('4_States'),  # Time of use survey for germany
    start_datetime=start_datetime,  # Specifiy the start of the simulaiton
    logger=SimLogger('get_active_occupancy'))

lighting_sim = FisherLightingSimulator(
    n_households,
    # Gets the initial values from other simulators
    initial_active_occupancy=activity_sim.get_occupancy(),
    initial_irradiance=climate_sim.get_irradiance(),
    logger=SimLogger('get_power_consumption'))
Exemplo n.º 5
0
 def test_loading(self):
     data = OpenPowerSystemClimate('germany')
     data.load_historical_climate_data(datetime.datetime(2014, 1, 1))
Exemplo n.º 6
0
 def test_other_data(self):
     self.kwargs['data'] = OpenPowerSystemClimate('switzerland')
     self.run_base_tests()
     self.kwargs.pop('data')