Skip to content

load_builder

This module contains builder for building load models for distribution system.

Examples

>>> from shift.load_builder import (
    ConstantPowerFactorBuildingGeometryLoadBuilder)
>>> from shift.geometry import BuildingGeometry
>>> g1 = BuildingGeometry()
>>> g1.latitude = 56.567
>>> g1.longitude = 67.8889
>>> g1.area = 2
>>> g2 = BuildingGeometry()
>>> g2.latitude = 56.567
>>> g2.longitude = 67.8889
>>> g2.area = 2
>>> builder = ConstantPowerFactorBuildingGeometryLoadBuilder(g1,
    RandomPhaseAllocator(50, 0, 50, [g1,g2]),
    ProportionalBuildingAreaToConsumptionConverter(2,5,0,10),
    SimpleVoltageSetter(13.2),DefaultConnSetter(),
    1.0)
>>> b = LoadBuilderEngineer(builder)
>>> print(b.get_load())

BuildingAreaToConsumptionConverter

Bases: ABC

Interface for computing power consumption from building area.

Source code in shift\load_builder.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class BuildingAreaToConsumptionConverter(ABC):
    """Interface for computing power consumption from building area."""

    @abstractmethod
    def convert(self, area: float) -> float:
        """Abstract method for computing the power consumption.

        Args:
            area (float): Building area

        Returns:
            float: Power consumption in kW
        """
        pass

convert(area) abstractmethod

Abstract method for computing the power consumption.

Parameters:

Name Type Description Default
area float

Building area

required

Returns:

Name Type Description
float float

Power consumption in kW

Source code in shift\load_builder.py
76
77
78
79
80
81
82
83
84
85
86
@abstractmethod
def convert(self, area: float) -> float:
    """Abstract method for computing the power consumption.

    Args:
        area (float): Building area

    Returns:
        float: Power consumption in kW
    """
    pass

ConnSetter

Bases: ABC

Interface for setting the connection type for load object.

Source code in shift\load_builder.py
330
331
332
333
334
335
336
337
338
339
340
341
342
343
class ConnSetter(ABC):
    """Interface for setting the connection type for load object."""

    @abstractmethod
    def get_conn(self, load: Load) -> LoadConnection:
        """Abstract method for setting connection type for load object.

        Args:
            load (Load): Load instance

        Returns:
            LoadConnection: Connection type for the load
        """
        pass

get_conn(load) abstractmethod

Abstract method for setting connection type for load object.

Parameters:

Name Type Description Default
load Load

Load instance

required

Returns:

Name Type Description
LoadConnection LoadConnection

Connection type for the load

Source code in shift\load_builder.py
333
334
335
336
337
338
339
340
341
342
343
@abstractmethod
def get_conn(self, load: Load) -> LoadConnection:
    """Abstract method for setting connection type for load object.

    Args:
        load (Load): Load instance

    Returns:
        LoadConnection: Connection type for the load
    """
    pass

ConstantPowerFactorBuildingGeometryLoadBuilder

Bases: GeometryLoadBuilder

Concerete implementation for building constant power factor type load from geometry object.

Refer to the base class for base attributes.

Attributes:

Name Type Description
power_factor float

Power factor

area_converter BuildingAreaToConsumptionConverter

BuildingAreaToConsumptionConverter instance

Source code in shift\load_builder.py
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
class ConstantPowerFactorBuildingGeometryLoadBuilder(GeometryLoadBuilder):
    """Concerete implementation for building constant
    power factor type load from geometry object.

    Refer to the base class for base attributes.

    Attributes:
        power_factor (float): Power factor
        area_converter (BuildingAreaToConsumptionConverter):
            BuildingAreaToConsumptionConverter instance
    """

    def __init__(
        self,
        geometry: Geometry,
        phaseallocator: PhaseAllocator,
        area_converter: BuildingAreaToConsumptionConverter,
        kv_setter: VoltageSetter,
        conn_setter: ConnSetter,
        power_factor: float,
    ) -> None:
        """Constructor for
        `ConstantPowerFactorBuildingGeometryLoadBuilder` class.

        Refer to base class for base arguments.

        Args:
            area_converter (BuildingAreaToConsumptionConverter):
                BuildingAreaToConsumptionConverter instance
            power_factor (float): Power factor
        """

        super().__init__(
            geometry,
            phaseallocator,
            kv_setter,
            conn_setter,
            ConstantPowerFactorLoad(),
        )
        self.power_factor = power_factor
        self.area_converter = area_converter

    def set_power_data(self) -> None:
        """Refer to base class for more details."""
        self.load.pf = self.power_factor
        self.load.kw = self.area_converter.convert(self.geometry.area)

__init__(geometry, phaseallocator, area_converter, kv_setter, conn_setter, power_factor)

Constructor for ConstantPowerFactorBuildingGeometryLoadBuilder class.

Refer to base class for base arguments.

Parameters:

Name Type Description Default
area_converter BuildingAreaToConsumptionConverter

BuildingAreaToConsumptionConverter instance

required
power_factor float

Power factor

required
Source code in shift\load_builder.py
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
def __init__(
    self,
    geometry: Geometry,
    phaseallocator: PhaseAllocator,
    area_converter: BuildingAreaToConsumptionConverter,
    kv_setter: VoltageSetter,
    conn_setter: ConnSetter,
    power_factor: float,
) -> None:
    """Constructor for
    `ConstantPowerFactorBuildingGeometryLoadBuilder` class.

    Refer to base class for base arguments.

    Args:
        area_converter (BuildingAreaToConsumptionConverter):
            BuildingAreaToConsumptionConverter instance
        power_factor (float): Power factor
    """

    super().__init__(
        geometry,
        phaseallocator,
        kv_setter,
        conn_setter,
        ConstantPowerFactorLoad(),
    )
    self.power_factor = power_factor
    self.area_converter = area_converter

set_power_data()

Refer to base class for more details.

Source code in shift\load_builder.py
482
483
484
485
def set_power_data(self) -> None:
    """Refer to base class for more details."""
    self.load.pf = self.power_factor
    self.load.kw = self.area_converter.convert(self.geometry.area)

ConstantPowerFactorSimpleLoadGeometryLoadBuilder

Bases: GeometryLoadBuilder

Concerete implementation for building constant power factor type load from simple load point geometry object.

Refer to base class for base attributes.

Attributes:

Name Type Description
power_factor float

Power factor

Source code in shift\load_builder.py
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
class ConstantPowerFactorSimpleLoadGeometryLoadBuilder(GeometryLoadBuilder):
    """Concerete implementation for building constant power
    factor type load from simple load point geometry object.

    Refer to base class for base attributes.

    Attributes:
        power_factor (float): Power factor
    """

    def __init__(
        self,
        geometry: Geometry,
        phaseallocator: PhaseAllocator,
        kv_setter: VoltageSetter,
        conn_setter: ConnSetter,
        power_factor: float,
    ) -> None:
        """Constructor for
        `ConstantPowerFactorSimpleLoadGeometryLoadBuilder` class.

        Refer to base class for base arguments.

        Args:
            power_factor (float): Power factor
        """

        super().__init__(
            geometry,
            phaseallocator,
            kv_setter,
            conn_setter,
            ConstantPowerFactorLoad(),
        )
        self.power_factor = power_factor

    def set_power_data(self) -> None:
        """Refer to base class for more details."""
        self.load.pf = self.power_factor
        self.load.kw = self.geometry.kw

__init__(geometry, phaseallocator, kv_setter, conn_setter, power_factor)

Constructor for ConstantPowerFactorSimpleLoadGeometryLoadBuilder class.

Refer to base class for base arguments.

Parameters:

Name Type Description Default
power_factor float

Power factor

required
Source code in shift\load_builder.py
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
def __init__(
    self,
    geometry: Geometry,
    phaseallocator: PhaseAllocator,
    kv_setter: VoltageSetter,
    conn_setter: ConnSetter,
    power_factor: float,
) -> None:
    """Constructor for
    `ConstantPowerFactorSimpleLoadGeometryLoadBuilder` class.

    Refer to base class for base arguments.

    Args:
        power_factor (float): Power factor
    """

    super().__init__(
        geometry,
        phaseallocator,
        kv_setter,
        conn_setter,
        ConstantPowerFactorLoad(),
    )
    self.power_factor = power_factor

set_power_data()

Refer to base class for more details.

Source code in shift\load_builder.py
524
525
526
527
def set_power_data(self) -> None:
    """Refer to base class for more details."""
    self.load.pf = self.power_factor
    self.load.kw = self.geometry.kw

DefaultConnSetter

Bases: ConnSetter

Class for handling default connection type.

Source code in shift\load_builder.py
346
347
348
349
350
351
352
353
354
355
class DefaultConnSetter(ConnSetter):
    """Class for handling default connection type."""

    def get_conn(self, load: Load) -> LoadConnection:
        """Refer to the base class for more details."""
        return (
            LoadConnection.DELTA
            if load.num_phase == NumPhase.TWO
            else LoadConnection.STAR
        )

get_conn(load)

Refer to the base class for more details.

Source code in shift\load_builder.py
349
350
351
352
353
354
355
def get_conn(self, load: Load) -> LoadConnection:
    """Refer to the base class for more details."""
    return (
        LoadConnection.DELTA
        if load.num_phase == NumPhase.TWO
        else LoadConnection.STAR
    )

GeometryLoadBuilder

Bases: LoadBuilder

Concrete implementation for converting geometry to load.

Attributes:

Name Type Description
geometry Geometry

Geometry instance

phaseallocator PhaseAllocator

PhaseAllocator instance

kv_setter VoltageSetter

VoltageSetter instance

conn_setter conn_setter

ConnSetter Instance

load Load

Load instance

Source code in shift\load_builder.py
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
class GeometryLoadBuilder(LoadBuilder):
    """Concrete implementation for converting geometry to load.

    Attributes:
        geometry (Geometry): Geometry instance
        phaseallocator (PhaseAllocator): PhaseAllocator instance
        kv_setter (VoltageSetter): VoltageSetter instance
        conn_setter (conn_setter): ConnSetter Instance
        load (Load): Load instance
    """

    def __init__(
        self,
        geometry: Geometry,
        phaseallocator: PhaseAllocator,
        kv_setter: VoltageSetter,
        conn_setter: ConnSetter,
        load: Load,
    ) -> None:
        """Constructor for GeometryLoadBuilder class.

        Args:
            geometry (Geometry): Geometry instance
            phaseallocator (PhaseAllocator): PhaseAllocator instance
            kv_setter (VoltageSetter): VoltageSetter instance
            conn_setter (conn_setter): ConnSetter Instance
            load (Load): Load instance
        """

        self.geometry = geometry
        self.load = load
        self.phase_allocator = phaseallocator
        self.kvsetter = kv_setter
        self.connsetter = conn_setter

    def set_name_and_location(self) -> None:
        """Refer to base class for more details."""
        self.load.name = (
            f"{self.geometry.longitude}_{self.geometry.latitude}_load"
        )
        self.load.latitude = self.geometry.latitude
        self.load.longitude = self.geometry.longitude

    def set_power_data(self) -> None:
        """Refer to base class for more details."""
        pass

    def set_phase_data(self) -> None:
        """Refer to base class for more details."""
        self.load.phase = self.phase_allocator.get_phase(self.geometry)
        self.load.num_phase = self.phase_allocator.get_num_phase(self.geometry)

    def set_kv_and_conn(self) -> None:
        """Refer to base class for more details."""
        self.load.kv = self.kvsetter.get_kv(self.load)
        self.load.conn_type = self.connsetter.get_conn(self.load)

__init__(geometry, phaseallocator, kv_setter, conn_setter, load)

Constructor for GeometryLoadBuilder class.

Parameters:

Name Type Description Default
geometry Geometry

Geometry instance

required
phaseallocator PhaseAllocator

PhaseAllocator instance

required
kv_setter VoltageSetter

VoltageSetter instance

required
conn_setter conn_setter

ConnSetter Instance

required
load Load

Load instance

required
Source code in shift\load_builder.py
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
def __init__(
    self,
    geometry: Geometry,
    phaseallocator: PhaseAllocator,
    kv_setter: VoltageSetter,
    conn_setter: ConnSetter,
    load: Load,
) -> None:
    """Constructor for GeometryLoadBuilder class.

    Args:
        geometry (Geometry): Geometry instance
        phaseallocator (PhaseAllocator): PhaseAllocator instance
        kv_setter (VoltageSetter): VoltageSetter instance
        conn_setter (conn_setter): ConnSetter Instance
        load (Load): Load instance
    """

    self.geometry = geometry
    self.load = load
    self.phase_allocator = phaseallocator
    self.kvsetter = kv_setter
    self.connsetter = conn_setter

set_kv_and_conn()

Refer to base class for more details.

Source code in shift\load_builder.py
434
435
436
437
def set_kv_and_conn(self) -> None:
    """Refer to base class for more details."""
    self.load.kv = self.kvsetter.get_kv(self.load)
    self.load.conn_type = self.connsetter.get_conn(self.load)

set_name_and_location()

Refer to base class for more details.

Source code in shift\load_builder.py
417
418
419
420
421
422
423
def set_name_and_location(self) -> None:
    """Refer to base class for more details."""
    self.load.name = (
        f"{self.geometry.longitude}_{self.geometry.latitude}_load"
    )
    self.load.latitude = self.geometry.latitude
    self.load.longitude = self.geometry.longitude

set_phase_data()

Refer to base class for more details.

Source code in shift\load_builder.py
429
430
431
432
def set_phase_data(self) -> None:
    """Refer to base class for more details."""
    self.load.phase = self.phase_allocator.get_phase(self.geometry)
    self.load.num_phase = self.phase_allocator.get_num_phase(self.geometry)

set_power_data()

Refer to base class for more details.

Source code in shift\load_builder.py
425
426
427
def set_power_data(self) -> None:
    """Refer to base class for more details."""
    pass

LoadBuilder

Bases: ABC

Builder interface for converting geometries to power system loads.

Source code in shift\load_builder.py
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
class LoadBuilder(ABC):
    """Builder interface for converting geometries to power system loads."""

    @abstractmethod
    def set_name_and_location(self) -> None:
        """Abstract method for setting name and location."""
        pass

    @abstractmethod
    def set_power_data(self) -> None:
        """Abstract method for setting the power consumption for load."""
        pass

    @abstractmethod
    def set_phase_data(self) -> None:
        """Abstract method for setting phase to load."""
        pass

    @abstractmethod
    def set_kv_and_conn(self) -> None:
        """Abstract methid for setting kv and connection."""
        pass

set_kv_and_conn() abstractmethod

Abstract methid for setting kv and connection.

Source code in shift\load_builder.py
376
377
378
379
@abstractmethod
def set_kv_and_conn(self) -> None:
    """Abstract methid for setting kv and connection."""
    pass

set_name_and_location() abstractmethod

Abstract method for setting name and location.

Source code in shift\load_builder.py
361
362
363
364
@abstractmethod
def set_name_and_location(self) -> None:
    """Abstract method for setting name and location."""
    pass

set_phase_data() abstractmethod

Abstract method for setting phase to load.

Source code in shift\load_builder.py
371
372
373
374
@abstractmethod
def set_phase_data(self) -> None:
    """Abstract method for setting phase to load."""
    pass

set_power_data() abstractmethod

Abstract method for setting the power consumption for load.

Source code in shift\load_builder.py
366
367
368
369
@abstractmethod
def set_power_data(self) -> None:
    """Abstract method for setting the power consumption for load."""
    pass

LoadBuilderEngineer

Director for building loads.

Attributes:

Name Type Description
builder LoadBuilder

LoadBuilder instance

Source code in shift\load_builder.py
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
class LoadBuilderEngineer:
    """Director for building loads.

    Attributes:
        builder (LoadBuilder): LoadBuilder instance
    """

    def __init__(self, builder: LoadBuilder) -> None:
        """Constructor for `LoadBuilderEngineer` class.

        Args:
            builder (LoadBuilder): LoadBuilder instance
        """
        self.builder = builder
        self.builder.set_name_and_location()
        self.builder.set_power_data()
        self.builder.set_phase_data()
        self.builder.set_kv_and_conn()

    def get_load(self) -> Load:
        """Returns a `Load` instance."""
        return self.builder.load

__init__(builder)

Constructor for LoadBuilderEngineer class.

Parameters:

Name Type Description Default
builder LoadBuilder

LoadBuilder instance

required
Source code in shift\load_builder.py
537
538
539
540
541
542
543
544
545
546
547
def __init__(self, builder: LoadBuilder) -> None:
    """Constructor for `LoadBuilderEngineer` class.

    Args:
        builder (LoadBuilder): LoadBuilder instance
    """
    self.builder = builder
    self.builder.set_name_and_location()
    self.builder.set_power_data()
    self.builder.set_phase_data()
    self.builder.set_kv_and_conn()

get_load()

Returns a Load instance.

Source code in shift\load_builder.py
549
550
551
def get_load(self) -> Load:
    """Returns a `Load` instance."""
    return self.builder.load

PhaseAllocator

Bases: ABC

Interface for allocating phase.

Source code in shift\load_builder.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
class PhaseAllocator(ABC):
    """Interface for allocating phase."""

    @abstractmethod
    def get_phase(self, geometry: Geometry) -> Phase:
        """Abstract method for getting a phase.

        Args:
            geometry (Geometry): Geometry instance for
                which phase is to be determined

        Returns:
            Phase: Phase instance for the geometry
        """
        pass

    @abstractmethod
    def get_num_phase(self, geometry: Geometry) -> NumPhase:
        """Abstract method for getting number of phase.

        Args:
            geometry (Geometry): Geometry instance for
                which num_phase is to be determined

        Returns:
            NumPhase: NumPhase instance for the geometry
        """
        pass

get_num_phase(geometry) abstractmethod

Abstract method for getting number of phase.

Parameters:

Name Type Description Default
geometry Geometry

Geometry instance for which num_phase is to be determined

required

Returns:

Name Type Description
NumPhase NumPhase

NumPhase instance for the geometry

Source code in shift\load_builder.py
179
180
181
182
183
184
185
186
187
188
189
190
@abstractmethod
def get_num_phase(self, geometry: Geometry) -> NumPhase:
    """Abstract method for getting number of phase.

    Args:
        geometry (Geometry): Geometry instance for
            which num_phase is to be determined

    Returns:
        NumPhase: NumPhase instance for the geometry
    """
    pass

get_phase(geometry) abstractmethod

Abstract method for getting a phase.

Parameters:

Name Type Description Default
geometry Geometry

Geometry instance for which phase is to be determined

required

Returns:

Name Type Description
Phase Phase

Phase instance for the geometry

Source code in shift\load_builder.py
166
167
168
169
170
171
172
173
174
175
176
177
@abstractmethod
def get_phase(self, geometry: Geometry) -> Phase:
    """Abstract method for getting a phase.

    Args:
        geometry (Geometry): Geometry instance for
            which phase is to be determined

    Returns:
        Phase: Phase instance for the geometry
    """
    pass

PiecewiseBuildingAreaToConsumptionConverter

Bases: BuildingAreaToConsumptionConverter

Class for handling computation of power consumption using piecewide linear function.

Attributes:

Name Type Description
curve List[list]

Piecewise linear function e.g. [[1,2], [3,4]]

Source code in shift\load_builder.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
class PiecewiseBuildingAreaToConsumptionConverter(
    BuildingAreaToConsumptionConverter
):
    """Class for handling computation of power consumption
    using piecewide linear function.

    Attributes:
        curve (List[list]): Piecewise linear function e.g. [[1,2], [3,4]]
    """

    def __init__(self, area_to_kw_curve: List[list]) -> None:
        """Constructor for `PiecewiseBuildingAreaToConsumptionConverter` class.

        Args:
            area_to_kw_curve (List[list]): Piecewise linear
                function e.g. [[1,2], [3,4]]
        """
        self.curve = area_to_kw_curve

    def convert(self, area: float) -> float:
        """Refer to base class for more details."""
        return get_point_from_curve(self.curve, area)

__init__(area_to_kw_curve)

Constructor for PiecewiseBuildingAreaToConsumptionConverter class.

Parameters:

Name Type Description Default
area_to_kw_curve List[list]

Piecewise linear function e.g. [[1,2], [3,4]]

required
Source code in shift\load_builder.py
 99
100
101
102
103
104
105
106
def __init__(self, area_to_kw_curve: List[list]) -> None:
    """Constructor for `PiecewiseBuildingAreaToConsumptionConverter` class.

    Args:
        area_to_kw_curve (List[list]): Piecewise linear
            function e.g. [[1,2], [3,4]]
    """
    self.curve = area_to_kw_curve

convert(area)

Refer to base class for more details.

Source code in shift\load_builder.py
108
109
110
def convert(self, area: float) -> float:
    """Refer to base class for more details."""
    return get_point_from_curve(self.curve, area)

ProportionalBuildingAreaToConsumptionConverter

Bases: BuildingAreaToConsumptionConverter

Class for handling computation of power consumption using proportional allocation method.

Attributes:

Name Type Description
min_kw float

Minimum kw to be assigned

max_kw float

Maximum kw to be assigned

max_area float

Maximum area of all the buildings

min_area float

Minimum area of all the buildings

Source code in shift\load_builder.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
class ProportionalBuildingAreaToConsumptionConverter(
    BuildingAreaToConsumptionConverter
):
    """Class for handling computation of power consumption
    using proportional allocation method.

    Attributes:
        min_kw (float): Minimum kw to be assigned
        max_kw (float): Maximum kw to be assigned
        max_area (float): Maximum area of all the buildings
        min_area (float): Minimum area of all the buildings
    """

    def __init__(
        self, min_kw: float, max_kw: float, max_area: float, min_area: float
    ) -> None:
        """Constructor for
        `ProportionalBuildingAreaToConsumptionConverter` class.

        Args:
            min_kw (float): Minimum kw to be assigned
            max_kw (float): Maximum kw to be assigned
            max_area (float): Maximum area of all the buildings
            min_area (float): Minimum area of all the buildings

        Raises:
            InvalidInputError: If min_kw is greater than or equal to max_kw
        """
        self.min_kw = min_kw
        self.max_kw = max_kw
        self.max_area = max_area
        self.min_area = min_area

        if self.min_kw >= self.max_kw:
            raise InvalidInputError(
                f"Min kW  {min_kw} is greater than or equal to Max kW {max_kw}"
            )

    def convert(self, area: float) -> float:
        """Refer to base class for more details."""
        if self.max_area != 0:
            kw = self.min_kw + (self.max_kw - self.min_kw) * (
                area - self.min_area
            ) / (self.max_area - self.min_area)
        else:
            kw = self.min_kw

        return kw

__init__(min_kw, max_kw, max_area, min_area)

Constructor for ProportionalBuildingAreaToConsumptionConverter class.

Parameters:

Name Type Description Default
min_kw float

Minimum kw to be assigned

required
max_kw float

Maximum kw to be assigned

required
max_area float

Maximum area of all the buildings

required
min_area float

Minimum area of all the buildings

required

Raises:

Type Description
InvalidInputError

If min_kw is greater than or equal to max_kw

Source code in shift\load_builder.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
def __init__(
    self, min_kw: float, max_kw: float, max_area: float, min_area: float
) -> None:
    """Constructor for
    `ProportionalBuildingAreaToConsumptionConverter` class.

    Args:
        min_kw (float): Minimum kw to be assigned
        max_kw (float): Maximum kw to be assigned
        max_area (float): Maximum area of all the buildings
        min_area (float): Minimum area of all the buildings

    Raises:
        InvalidInputError: If min_kw is greater than or equal to max_kw
    """
    self.min_kw = min_kw
    self.max_kw = max_kw
    self.max_area = max_area
    self.min_area = min_area

    if self.min_kw >= self.max_kw:
        raise InvalidInputError(
            f"Min kW  {min_kw} is greater than or equal to Max kW {max_kw}"
        )

convert(area)

Refer to base class for more details.

Source code in shift\load_builder.py
151
152
153
154
155
156
157
158
159
160
def convert(self, area: float) -> float:
    """Refer to base class for more details."""
    if self.max_area != 0:
        kw = self.min_kw + (self.max_kw - self.min_kw) * (
            area - self.min_area
        ) / (self.max_area - self.min_area)
    else:
        kw = self.min_kw

    return kw

RandomPhaseAllocator

Bases: PhaseAllocator

Allocates the phase to all geometries uniformly randomly.

Attributes:

Name Type Description
pct_single_phases float

Percentage of single phase geometries

pct_two_phases float

Percentage of two phase geometries

pct_three_phases float

Percentage of three phase geometries

geometries List[Geometry]

List of Geometry objects

geometry_to_phase dict

A dictionary holding the phase for geometries

Source code in shift\load_builder.py
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
class RandomPhaseAllocator(PhaseAllocator):
    """Allocates the phase to all geometries uniformly randomly.

    Attributes:
        pct_single_phases (float): Percentage of single phase geometries
        pct_two_phases (float): Percentage of two phase geometries
        pct_three_phases (float): Percentage of three phase geometries
        geometries (List[Geometry]): List of Geometry objects
        geometry_to_phase (dict): A dictionary holding the phase for geometries
    """

    def __init__(
        self,
        pct_single_phases: float,
        pct_two_phases: float,
        pct_three_phases: float,
        geometries: List[Geometry],
    ) -> None:
        """Constructor for `RandomPhaseAllocator` class.

        Args:
            pct_single_phases (float): Percentage of single phase geometries
            pct_two_phases (float): Percentage of two phase geometries
            pct_three_phases (float): Percentage of three phase geometries
            geometries (List[Geometry]): List of Geometry objects

        Raises:
            PercentageSumNotHundred: If the sume of percentages is not 100
        """

        self.pct_single_phases = pct_single_phases
        self.pct_two_phases = pct_two_phases
        self.pct_three_phases = pct_three_phases
        self.geometries = geometries

        if pct_single_phases + pct_two_phases + pct_three_phases != 100:
            raise PercentageSumNotHundred(
                pct_single_phases + pct_two_phases + pct_three_phases
            )

        random.shuffle(self.geometries)

        three_phase_geometries = self.geometries[
            : int(len(self.geometries) * self.pct_three_phases / 100)
        ]
        self.geometry_to_phase = {g: Phase.ABCN for g in three_phase_geometries}
        self.geometry_to_numphase = {
            g: NumPhase.THREE for g in three_phase_geometries
        }

        single_phases = [Phase.AN, Phase.BN, Phase.CN]
        two_phases = [Phase.AB, Phase.BC, Phase.CA]

        two_phase_geometries = self.geometries[
            int(len(self.geometries) * self.pct_three_phases / 100) : int(
                len(self.geometries) * self.pct_two_phases / 100
            )
        ]
        self.geometry_to_phase.update(
            {g: random.choice(two_phases) for g in two_phase_geometries}
        )
        self.geometry_to_numphase.update(
            {g: NumPhase.TWO for g in two_phase_geometries}
        )

        single_phase_geometries = [
            g for g in self.geometries if g not in self.geometry_to_phase
        ]
        self.geometry_to_phase.update(
            {g: random.choice(single_phases) for g in single_phase_geometries}
        )
        self.geometry_to_numphase.update(
            {g: NumPhase.SINGLE for g in single_phase_geometries}
        )

    def get_phase(self, geometry: Geometry) -> Phase:
        """Refer to the base class for more details."""
        return self.geometry_to_phase[geometry]

    def get_num_phase(self, geometry: Geometry) -> NumPhase:
        """Refer to the base class for more details."""
        return self.geometry_to_numphase[geometry]

__init__(pct_single_phases, pct_two_phases, pct_three_phases, geometries)

Constructor for RandomPhaseAllocator class.

Parameters:

Name Type Description Default
pct_single_phases float

Percentage of single phase geometries

required
pct_two_phases float

Percentage of two phase geometries

required
pct_three_phases float

Percentage of three phase geometries

required
geometries List[Geometry]

List of Geometry objects

required

Raises:

Type Description
PercentageSumNotHundred

If the sume of percentages is not 100

Source code in shift\load_builder.py
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
def __init__(
    self,
    pct_single_phases: float,
    pct_two_phases: float,
    pct_three_phases: float,
    geometries: List[Geometry],
) -> None:
    """Constructor for `RandomPhaseAllocator` class.

    Args:
        pct_single_phases (float): Percentage of single phase geometries
        pct_two_phases (float): Percentage of two phase geometries
        pct_three_phases (float): Percentage of three phase geometries
        geometries (List[Geometry]): List of Geometry objects

    Raises:
        PercentageSumNotHundred: If the sume of percentages is not 100
    """

    self.pct_single_phases = pct_single_phases
    self.pct_two_phases = pct_two_phases
    self.pct_three_phases = pct_three_phases
    self.geometries = geometries

    if pct_single_phases + pct_two_phases + pct_three_phases != 100:
        raise PercentageSumNotHundred(
            pct_single_phases + pct_two_phases + pct_three_phases
        )

    random.shuffle(self.geometries)

    three_phase_geometries = self.geometries[
        : int(len(self.geometries) * self.pct_three_phases / 100)
    ]
    self.geometry_to_phase = {g: Phase.ABCN for g in three_phase_geometries}
    self.geometry_to_numphase = {
        g: NumPhase.THREE for g in three_phase_geometries
    }

    single_phases = [Phase.AN, Phase.BN, Phase.CN]
    two_phases = [Phase.AB, Phase.BC, Phase.CA]

    two_phase_geometries = self.geometries[
        int(len(self.geometries) * self.pct_three_phases / 100) : int(
            len(self.geometries) * self.pct_two_phases / 100
        )
    ]
    self.geometry_to_phase.update(
        {g: random.choice(two_phases) for g in two_phase_geometries}
    )
    self.geometry_to_numphase.update(
        {g: NumPhase.TWO for g in two_phase_geometries}
    )

    single_phase_geometries = [
        g for g in self.geometries if g not in self.geometry_to_phase
    ]
    self.geometry_to_phase.update(
        {g: random.choice(single_phases) for g in single_phase_geometries}
    )
    self.geometry_to_numphase.update(
        {g: NumPhase.SINGLE for g in single_phase_geometries}
    )

get_num_phase(geometry)

Refer to the base class for more details.

Source code in shift\load_builder.py
272
273
274
def get_num_phase(self, geometry: Geometry) -> NumPhase:
    """Refer to the base class for more details."""
    return self.geometry_to_numphase[geometry]

get_phase(geometry)

Refer to the base class for more details.

Source code in shift\load_builder.py
268
269
270
def get_phase(self, geometry: Geometry) -> Phase:
    """Refer to the base class for more details."""
    return self.geometry_to_phase[geometry]

SimpleVoltageSetter

Simple voltage setter for setting kv for loads.

Attributes:

Name Type Description
line_to_line_voltage float

Line to line voltage in kV

voltage_dict dict

NumPhase to voltage mapper

Source code in shift\load_builder.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
class SimpleVoltageSetter:
    """Simple voltage setter for setting kv for loads.

    Attributes:
        line_to_line_voltage (float): Line to line voltage in kV
        voltage_dict (dict): NumPhase to voltage mapper
    """

    def __init__(self, line_to_line_voltage: float) -> None:
        """Constructor for `SimpleVoltageSetter` class.

        Args:
            line_to_line_voltage (float): Line to line voltage in kV

        Raises:
            NegativeKVError: If the `line_to_line_voltage` is negative
            ZeroKVError: if the `line_to_line_voltage` is 0
        """

        self.line_to_line_voltage = line_to_line_voltage
        if self.line_to_line_voltage < 0:
            raise NegativeKVError(self.line_to_line_voltage)

        if self.line_to_line_voltage == 0:
            raise ZeroKVError()

        self.voltage_dict = {
            NumPhase.SINGLE: round(self.line_to_line_voltage / math.sqrt(3), 3),
            NumPhase.TWO: self.line_to_line_voltage,
            NumPhase.THREE: self.line_to_line_voltage,
        }

    def get_kv(self, load: Load) -> float:
        """Refer to the base class for more details."""
        return self.voltage_dict[load.num_phase]

__init__(line_to_line_voltage)

Constructor for SimpleVoltageSetter class.

Parameters:

Name Type Description Default
line_to_line_voltage float

Line to line voltage in kV

required

Raises:

Type Description
NegativeKVError

If the line_to_line_voltage is negative

ZeroKVError

if the line_to_line_voltage is 0

Source code in shift\load_builder.py
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
def __init__(self, line_to_line_voltage: float) -> None:
    """Constructor for `SimpleVoltageSetter` class.

    Args:
        line_to_line_voltage (float): Line to line voltage in kV

    Raises:
        NegativeKVError: If the `line_to_line_voltage` is negative
        ZeroKVError: if the `line_to_line_voltage` is 0
    """

    self.line_to_line_voltage = line_to_line_voltage
    if self.line_to_line_voltage < 0:
        raise NegativeKVError(self.line_to_line_voltage)

    if self.line_to_line_voltage == 0:
        raise ZeroKVError()

    self.voltage_dict = {
        NumPhase.SINGLE: round(self.line_to_line_voltage / math.sqrt(3), 3),
        NumPhase.TWO: self.line_to_line_voltage,
        NumPhase.THREE: self.line_to_line_voltage,
    }

get_kv(load)

Refer to the base class for more details.

Source code in shift\load_builder.py
325
326
327
def get_kv(self, load: Load) -> float:
    """Refer to the base class for more details."""
    return self.voltage_dict[load.num_phase]

VoltageSetter

Bases: ABC

Interface for setting voltage for loads.

Source code in shift\load_builder.py
277
278
279
280
281
282
283
284
285
286
287
288
289
290
class VoltageSetter(ABC):
    """Interface for setting voltage for loads."""

    @abstractmethod
    def get_kv(self, load: Load) -> float:
        """Abstract method for getting voltage level for load object.

        Args:
            load (Load): Load instance

        Returns:
            float: Voltage in kV for load object
        """
        pass

get_kv(load) abstractmethod

Abstract method for getting voltage level for load object.

Parameters:

Name Type Description Default
load Load

Load instance

required

Returns:

Name Type Description
float float

Voltage in kV for load object

Source code in shift\load_builder.py
280
281
282
283
284
285
286
287
288
289
290
@abstractmethod
def get_kv(self, load: Load) -> float:
    """Abstract method for getting voltage level for load object.

    Args:
        load (Load): Load instance

    Returns:
        float: Voltage in kV for load object
    """
    pass