Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
import json
#
# This file is part of the Buildings and Habitats object Model (BHoM)
# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
#
# Each contributor holds copyright over their respective contributions.
# The project versioning (Git) records all such contribution source information.
#
#
# The BHoM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3.0 of the License, or
# (at your option) any later version.
#
# The BHoM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
#

import json
from typing import Any, Callable, Union, Dict
from functools import wraps
from ..bhom_object import CONSOLE_LOGGER, BHoMJSONDecoder, BHoMJSONEncoder, BHoMObject, IObject
Expand All @@ -14,6 +36,8 @@ def bhom_callable(self, identifier: str, argument_types:Dict[str, type] = {}, en
when __input_json__ is set, this will cause the method to always output BHoM style json (using the encoder_cls provided to this decorator)

Args:
identifier (str): The unique name C# uses to call the method through run_wrapped.

argument_types (dict[str, type]): this is a dictionary that is used to map the argument names to types (specifically BHoMObject types) to subclasses of BHoMObjects.
For example, if you have a class that is a subclass of BHoMObject, the default serialiser will only deserialise json to a BHoMObject.
To go the extra step to get your class, you must provide the type in this dictionary to allow the wrapper to convert the BHoMObject type to your desired type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
"""Container widget for embedding matplotlib figures or image content."""
#
# This file is part of the Buildings and Habitats object Model (BHoM)
# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
#
# Each contributor holds copyright over their respective contributions.
# The project versioning (Git) records all such contribution source information.
#
#
# The BHoM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3.0 of the License, or
# (at your option) any later version.
#
# The BHoM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
#

"""Container widget for embedding matplotlib figures or image content."""

import tkinter as tk
from tkinter import ttk
Expand Down Expand Up @@ -131,7 +153,7 @@ def embed_image(self, image: tk.PhotoImage) -> None:
"""Embed a Tk image in the figure container.

Args:
image: Tk PhotoImage object to embed
image: Tk PhotoImage object to embed.
"""
self._close_held_figure()
self._clear_children()
Expand All @@ -144,7 +166,7 @@ def embed_image_file(self, file_path: str) -> None:
"""Load and embed an image file, scaled to fit the container.

Args:
file_path: Path to image file
file_path: Path to image file.
"""
self.image_file = file_path
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
#
# This file is part of the Buildings and Habitats object Model (BHoM)
# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
#
# Each contributor holds copyright over their respective contributions.
# The project versioning (Git) records all such contribution source information.
#
#
# The BHoM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3.0 of the License, or
# (at your option) any later version.
#
# The BHoM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
#

"""Scrollable listbox with a search filter that keeps selections while items are filtered out."""

from __future__ import annotations
Expand Down Expand Up @@ -51,6 +73,9 @@ def fuzzy_scorer(query: str, text: str, min_score: float = 75) -> Optional[float
text: The item being tested.
min_score: Similarity (0-100) an item needs to be shown. To use a different value, bind it with
`functools.partial(fuzzy_scorer, min_score=...)` and pass that as `scorer`.

Returns:
The match score (0-100), or None if it is below `min_score`.
"""
compute, bhom_scorer = _load_bhom_search()
query = _NON_ALNUM.sub(" ", query.lower()).strip()
Expand All @@ -70,6 +95,10 @@ def default_scorer(query: str, text: str, min_score: float = 75) -> Optional[flo
query: The text typed into the filter.
text: The item being tested.
min_score: Similarity (0-100) a fuzzy match needs to be shown.

Returns:
A score (higher is better) if the item matches, or None to hide it. Items containing the query score
200, above any fuzzy score (0-100).
"""
words = _NON_ALNUM.sub(" ", query.lower()).split()
if not words:
Expand Down
26 changes: 24 additions & 2 deletions Python_Engine/Python/src/python_toolkit/helpers/decay_rate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
import re
#
# This file is part of the Buildings and Habitats object Model (BHoM)
# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
#
# Each contributor holds copyright over their respective contributions.
# The project versioning (Git) records all such contribution source information.
#
#
# The BHoM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3.0 of the License, or
# (at your option) any later version.
#
# The BHoM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
#

import re
from enum import Enum, auto

import numpy as np
Expand Down Expand Up @@ -61,7 +83,7 @@ def decay_rate_smoother(

Args:
series (pd.Series):
The series to modify
The series to modify.
difference_threshold (float, optional):
The difference between current/previous values which class as a "transition".
Defaults to -10.
Expand Down
26 changes: 24 additions & 2 deletions Python_Engine/Python/src/python_toolkit/helpers/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
import re
#
# This file is part of the Buildings and Habitats object Model (BHoM)
# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
#
# Each contributor holds copyright over their respective contributions.
# The project versioning (Git) records all such contribution source information.
#
#
# The BHoM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3.0 of the License, or
# (at your option) any later version.
#
# The BHoM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
#

import re
from datetime import timedelta
from typing import Any

Expand Down Expand Up @@ -55,7 +77,7 @@ def decay_rate_smoother(

Args:
series (pd.Series):
The series to modify
The series to modify.
difference_threshold (float, optional):
The difference between current/previous values which class as a "transition".
Defaults to -10.
Expand Down
30 changes: 26 additions & 4 deletions Python_Engine/Python/src/python_toolkit/plot/cmap_sample.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
#
# This file is part of the Buildings and Habitats object Model (BHoM)
# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
#
# Each contributor holds copyright over their respective contributions.
# The project versioning (Git) records all such contribution source information.
#
#
# The BHoM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3.0 of the License, or
# (at your option) any later version.
#
# The BHoM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
#

from matplotlib import pyplot as plt
from matplotlib.colors import Colormap, Normalize
from matplotlib.figure import Figure
Expand All @@ -17,12 +39,12 @@ def cmap_sample_plot(
Generate a sample plot for a given colormap.

Args:
cmap: Either a colormap string (e.g., 'viridis') or a custom Colormap object
bounds: Optional tuple of (vmin, vmax) for normalization. If None, uses (0, 1)
figsize: Figure size as (width, height). If None, defaults to (9, 1)
cmap: Either a colormap string (e.g., 'viridis') or a custom Colormap object.
bounds: Optional tuple of (vmin, vmax) for normalization. If None, uses (0, 1).
figsize: Figure size as (width, height). If None, defaults to (9, 1).
bins: Number of discrete bins for the gradient. Defaults to 256.
Returns:
Matplotlib Figure object
Matplotlib Figure object.
"""

figsize = figsize or (9, 1)
Expand Down
26 changes: 24 additions & 2 deletions Python_Engine/Python/src/python_toolkit/plot/spatial_heatmap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
"""Methods for plotting spatial heatmaps."""
#
# This file is part of the Buildings and Habitats object Model (BHoM)
# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
#
# Each contributor holds copyright over their respective contributions.
# The project versioning (Git) records all such contribution source information.
#
#
# The BHoM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3.0 of the License, or
# (at your option) any later version.
#
# The BHoM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
#

"""Methods for plotting spatial heatmaps."""

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -69,7 +91,7 @@ def spatial_heatmap(
clabels (bool, optional):
A flag to show contour labels. Defaults to False.
style_context (string, optional):
The matplotlib style to use. Defaults to python_toolkit.bhom
The matplotlib style to use. Defaults to python_toolkit.bhom.

Returns:
Figure: A matplotlib Figure object.
Expand Down
26 changes: 25 additions & 1 deletion Python_Engine/Python/src/python_toolkit/plot/utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
"""Text and colour utility methods for plotting"""
#
# This file is part of the Buildings and Habitats object Model (BHoM)
# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
#
# Each contributor holds copyright over their respective contributions.
# The project versioning (Git) records all such contribution source information.
#
#
# The BHoM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3.0 of the License, or
# (at your option) any later version.
#
# The BHoM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
#

"""Text and colour utility methods for plotting"""

import base64
import colorsys
Expand Down Expand Up @@ -369,6 +391,8 @@ def figure_to_base64(figure: plt.Figure, html: bool = False, transparent: bool =
A matplotlib figure object.
html (bool, optional):
Set to True to include the HTML preamble for a base64 encoded image. Default is False.
transparent (bool, optional):
Set to True to save the figure with a transparent background. Default is True.

Returns:
str:
Expand Down
Loading