Skip to content

colors ¤

default_colors module-attribute ¤

default_colors = Colors(
    {
        "GASOLINE": "#808080",
        "BIO_DIESEL": "#6B8E23",
        "DIESEL": "#D3D3D3",
        "URANIUM": "#66ff33",
        "NG": "#FFD700",
        "SNG": "#FFE100",
        "LFO": "#8B008B",
        "COAL": "#A0522D",
        "HYDRO": "#00CED1",
        "WASTE": "#FA8072",
        "SOLAR": "#FFFF00",
        "GEOTHERMAL": "#FF0000",
        "H2": "#FF00FF",
        "RES_WIND": "#FFA500",
        "HEAT_HT": "#DC143C",
        "ELECTRICITY": "#00BFFF",
        "EUD_ELECTRICITY": "#00BFFF",
        "ETHANOL": "#E1DA00",
        "AMMONIA": "#C3DA00",
        "METHANOL": "#A5DA00",
        "DME": "#87DA00",
        "CO2": "#545454",
        "WOOD": "#CD853F",
        "WET_BIOMASS": "#b37b44",
        "PLANT": "#d4904e",
        "HEAT": "#B51F1F",
        "MOB": "#FF69B4",
        "Electricity": "#00BFFF",
        "Mobility": "#8B0000",
        "Electric Infrastructure": "#000000",
        "Gas Infrastructure": "#B22222",
        "Wind": "#0000FF",
        "WIND": "#0000FF",
        "PV": "#FFD700",
        "Geothermal": "#D3B9DA",
        "Hydro River & Dam": "#008080",
        "Industry": "#006400",
        "Low Temperature Heat": "#FFA500",
        "Hydro Storage": "#00CED1",
        "Storage": "#ADD8E6",
        "Electrolysis": "#66CDAA",
        "Carbon Capture": "#A52A2A",
    }
)

Default colors used in plots.

fallback_color module-attribute ¤

fallback_color = Color('#000000')

Fallback colors in plots.

Color ¤

Color(color: str)

Utility class to represent colors.

Source code in src/energyscope/colors.py
13
14
def __init__(self, color: str):
    self.__color = color

cast staticmethod ¤

cast(color: Union[Color, str])

Cast Color or str to Color.

Parameters:

  • color (Color or str) –

    The color to cast

Returns:

  • The argument itself if it is an instance of Color, a new instance of Color otherwise

Source code in src/energyscope/colors.py
16
17
18
19
20
21
22
23
24
25
26
27
28
@staticmethod
def cast(color: Union['Color', str]):
    """
    Cast Color or str to Color.

    Args:
        color (Color or str): The color to cast

    Returns:
        The argument itself if it is an instance of Color, a new instance of Color otherwise
    """

    return color if isinstance(color, Color) else Color(color)

rgba ¤

rgba(alpha: float = None)

Provides the RGBA representation of a color, using the given alpha value when provided.

Parameters:

  • alpha (float, default: None ) –

    The alpha transparency value (0.0 to 1.0).

Returns:

  • str

    The RGBA color string in the format "rgba(r, g, b, a)".

Source code in src/energyscope/colors.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def rgba(self, alpha: float = None):
    """
    Provides the RGBA representation of a color, using the given `alpha` value when provided.

    Args:
        alpha (float, optional): The alpha transparency value (0.0 to 1.0).

    Returns:
        str: The RGBA color string in the format "rgba(r, g, b, a)".
    """

    color = self.__color.lstrip('#')
    r, g, b = int(color[0:2], 16), int(color[2:4], 16), int(color[4:6], 16)
    a = alpha if alpha is not None else int(color[6:8], 16) if len(color) == 8 else 1.0
    return f"rgba({r}, {g}, {b}, {a:.2f})"

Colors ¤

Colors(
    colors: dict[str, Union[Color, str]] = None,
    fallback: Union[Color, str] = fallback_color,
)

Utility class to represent a dict of Colors with fallback mechanism.

Colors can be accessed as in a regular dict.
If the key is not found, will try to fall back removing the text after the last underscore until it finds a match.
If no match can be found, energyscope.colors.fallback_color will be used.

colors['RES_WIND_ONSHORE'] will
  1. look for the key 'RES_WIND_ONSHORE' and return the corresponding value if exists
  2. if 'RES_WIND_ONSHORE' is not found, look for 'RES_WIND' and return the corresponding value if exists
  3. if 'RES_WIND' is not found, look for 'RES' and return the corresponding value if exists
  4. if 'RES' is not found, return energyscope.colors.fallback_color

Examples:

Examples should be written in doctest format, and should illustrate how to use the function.

>>> colors = Colors({"ELECTRICITY_LV": "#0000FF", "ELECTRICITY": "#FF0000"})
>>> print(colors["ELECTRICITY_LV"])
>>> print(colors["ELECTRICITY_OTHER"]) # will fall back to the color of "ELECTRICITY"
>>> print(colors["UNKNOWN"]) # will fall back to `fallback_color`
#0000FF
#FF0000
#000000
Source code in src/energyscope/colors.py
 94
 95
 96
 97
 98
 99
100
101
def __init__(self,
             colors: dict[str, Union[Color, str]] = None,
             fallback: Union[Color, str] = fallback_color):
    if colors:
        self.__colors = {k: Color.cast(c) for k, c in colors.items()}
    else:
        __colors = default_colors
    self.__fallback = Color.cast(fallback)

cast staticmethod ¤

cast(colors: Union[Self, dict])

Cast Colors or dict to Colors.

Parameters:

Returns:

  • The argument itself if it is an instance of Colors, a new instance of Colors otherwise

Source code in src/energyscope/colors.py
119
120
121
122
123
124
125
126
127
128
129
130
131
@staticmethod
def cast(colors: Union['Self', dict]):
    """
    Cast Colors or dict to Colors.

    Args:
        colors (Colors or dict): The colors to cast

    Returns:
        The argument itself if it is an instance of Colors, a new instance of Colors otherwise
    """

    return colors if isinstance(colors, Colors) else Colors(colors)

from_csv staticmethod ¤

from_csv(filepath: Union[str, Path]) -> Colors

Creates a Colors object from a CSV file.

Parameters:

  • filepath (str or Path) –

    the path to the CSV file
    The CSV file must contain the following columns: Name and Color.
    All the others columns will be ignored.

Returns:

  • Colors

    the Colors object

Source code in src/energyscope/colors.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@staticmethod
def from_csv(filepath: Union[str, Path]) -> 'Colors':
    """
    Creates a Colors object from a CSV file.

    Args:
        filepath (str or Path): the path to the CSV file  
            The CSV file must contain the following columns: Name and Color.  
            All the others columns will be ignored.

    Returns:
        the Colors object 
    """
    df = pd.read_csv(filepath, usecols=['Name', 'Color'])
    return Colors({row['Name']: row['Color'] for _, row in df.iterrows()})