Skip to content

Commit 7369670

Browse files
authored
8.2 Deployment (#182)
2 parents 6d0d1fc + 86aa757 commit 7369670

File tree

7 files changed

+266
-94
lines changed

7 files changed

+266
-94
lines changed

Python_Engine/Compute/VirtualEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static PythonEnvironment VirtualEnvironment(this PythonVersion version, s
108108
StartInfo = new ProcessStartInfo()
109109
{
110110
FileName = targetExecutable,
111-
Arguments = $"-m ipykernel install --name={name}",
111+
Arguments = $"-m ipykernel install --name={name} --user", //--user adds the kernel to %appdata%/jupyter/kernels, rather than to the virtualenv/share/jupyter/kernels
112112
RedirectStandardError = true,
113113
UseShellExecute = false,
114114
}

Python_Engine/Python/pyproject.toml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[project]
2+
name = "python_toolkit"
3+
readme = "README.md"
4+
dynamic = ["version", "description"]
5+
authors = [
6+
{ name = "BHoM", email = "[email protected]" }
7+
]
8+
dependencies = [
9+
"case-converter",
10+
"jupyterlab",
11+
"matplotlib",
12+
"numpy",
13+
"pandas",
14+
"plotly",
15+
"pytest>=8.3.5",
16+
"pytest-cov>=6.0.0",
17+
"pytest-order",
18+
"virtualenv",
19+
]
20+
21+
[urls]
22+
source = "https://github.com/BHoM/Python_Toolkit"
23+
24+
[build-system]
25+
requires = ["setuptools", "pywin32"]
26+
build-backend = "setuptools.build_meta"
27+
28+
[dependency-groups]
29+
dev = [
30+
"black",
31+
"ipykernel>=6.29.5",
32+
"pylint>=3.3.5",
33+
"pytest>=8.3.5",
34+
"pytest-cov>=6.0.0",
35+
"pytest-order",
36+
"sphinx>=8.1.3",
37+
"sphinx-bootstrap-theme>=0.8.1",
38+
"sphinxcontrib-fulltoc>=1.2.0",
39+
"sphinxcontrib-napoleon>=0.7",
40+
]
41+
42+
[tool.setuptools]
43+
package-dir = {"" = "src"}
44+
45+
[tool.setuptools.packages.find]
46+
where = ["src"]
47+
exclude = ["tests"]
48+
49+
[tool.pytest.ini_options]
50+
pythonpath = "src"

Python_Engine/Python/requirements.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

Python_Engine/Python/setup.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,10 @@ def _bhom_version() -> str:
1616

1717
here = Path(__file__).parent.resolve()
1818
long_description = (here / "README.md").read_text(encoding="utf-8")
19-
requirements = [
20-
i.strip()
21-
for i in (here / "requirements.txt").read_text(encoding="utf-8-sig").splitlines()
22-
]
2319

2420
setuptools.setup(
25-
name=TOOLKIT_NAME.lower(),
26-
author="BHoM",
27-
author_email="[email protected]",
2821
description=f"A Python library that contains minimal code intended to be used by the {TOOLKIT_NAME} Python environment for BHoM workflows.",
2922
long_description=long_description,
3023
long_description_content_type="text/markdown",
31-
url=f"https://github.com/BHoM/{TOOLKIT_NAME}",
32-
package_dir={"": "src"},
33-
packages=setuptools.find_packages(where="src", exclude=['tests']),
34-
install_requires=requirements,
3524
version=BHOM_VERSION,
3625
)
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import plotly.graph_objects as go
2+
import pandas as pd
3+
from matplotlib.colors import Colormap
4+
import decimal as d
5+
from typing import List, Dict
6+
import math
7+
8+
from ..bhom.analytics import bhom_analytics
9+
10+
def set_dimensions(df: pd.DataFrame, tick_mark_count: int, dp:int) -> List[Dict[str, any]]:
11+
12+
"""Set the dimensions for a parallel coordinate plot, based on column datatypes and unique values.
13+
14+
Args:
15+
df (pd.DataFrame):
16+
The pandas DataFrame to plot.
17+
tick_mark_count (int):
18+
The number of tick marks to show on the parallel coordinate plot.
19+
dp (int):
20+
The number of decimal places to show on the tick marks.
21+
22+
Returns:
23+
list[dict[str, any]]:
24+
A list of dimensions to plot.
25+
"""
26+
27+
df_copy = df.copy()
28+
dimensions = []
29+
30+
for column in df_copy.columns:
31+
32+
dim = {}
33+
dim['label'] = str(column)
34+
35+
if df_copy[column].dtype == "object":
36+
#for catagorical data types, convert to numerical, with text as tick marks
37+
df_copy[column] = df_copy[column].astype("category").cat.codes
38+
39+
dim['values'] = df_copy[column]
40+
dim['tickvals'] = df_copy[column].unique()
41+
dim['ticktext'] = df[column].unique()
42+
43+
dimensions.append(dim)
44+
continue
45+
46+
dim['values'] = df_copy[column]
47+
48+
if df_copy[column].nunique() < tick_mark_count:
49+
50+
dim['range'] = [df_copy[column].min(), df_copy[column].max()]
51+
dim['tickvals'] = dim['ticktext'] = df_copy[column].unique()
52+
53+
dimensions.append(dim)
54+
55+
else:
56+
# reduce the number of tick marks if the column has a large number of unique values
57+
dim['range'] = [df_copy[column].min(), df_copy[column].max()]
58+
59+
if (dim['range'][1] - dim['range'][0] +1) < tick_mark_count:
60+
tick_mark_count = math.ceil(dim['range'][1] - dim['range'][0]) + 1
61+
62+
dim['tickvals'] = [df_copy[column].min() + i * (df_copy[column].max() - df_copy[column].min()) / (tick_mark_count - 1) for i in range(tick_mark_count)]
63+
dim['ticktext'] = [round(i ,dp) for i in dim['tickvals']]
64+
65+
dimensions.append(dim)
66+
67+
return dimensions
68+
69+
@bhom_analytics()
70+
def parallel_coordinate_plot(
71+
72+
df: pd.DataFrame = pd.DataFrame(),
73+
variables_to_show: list = None,
74+
decimal_places: int = 0,
75+
tick_mark_count: int = 11,
76+
colour_key: str = None,
77+
cmap: Colormap = "viridis",
78+
dimensions: List[dict] = None,
79+
plot_title: str = "",
80+
plot_bgcolour: str = 'black',
81+
paper_bgcolour: str = 'black',
82+
font_colour: str = 'white',
83+
**kwargs,
84+
) -> go.Figure:
85+
"""Create a parallel coordinate plot of a pandas DataFrame.
86+
87+
Args:
88+
df (pd.DataFrame):
89+
The pandas DataFrame to plot.
90+
variables_to_show (list, optional):
91+
The variables to show on the parallel coordinate plot. Must be a subset of df.columns.
92+
decimal_places (int, optional):
93+
The number of decimal places to show on the tick marks. Defaults to 0.
94+
tick_mark_count (int, optional):
95+
The number of tick marks to show on the parallel coordinate plot. Defaults to 11.
96+
colour_key (str, optional):
97+
The column to use as the colour key. Defaults to None.
98+
cmap (Colormap or str, optional):
99+
The colormap to use for the colour key. Can be a matplotlib Colormap or a string representing a Plotly colorscale. Defaults to "viridis".
100+
dimensions (list[dict], optional):
101+
A list of dimensions to plot. If None, dimensions will be automatically generated based on the DataFrame. Defaults to None.
102+
plot_title (str, optional):
103+
The title of the plot. Defaults to an empty string.
104+
plot_bgcolour (str, optional):
105+
The background color of the plot. Defaults to 'black'.
106+
paper_bgcolour (str, optional):
107+
The background color of the paper. Defaults to 'black'.
108+
font_colour (str, optional):
109+
The color of the font used in the plot. Defaults to 'white'.
110+
**kwargs:
111+
Additional keyword arguments to pass to go.Parcoords().
112+
113+
Returns:
114+
go.Figure:
115+
The populated go.Figure object.
116+
"""
117+
118+
if variables_to_show is not None:
119+
df = df[variables_to_show]
120+
121+
if dimensions is None:
122+
dimensions = set_dimensions(df, tick_mark_count, decimal_places)
123+
124+
if colour_key is None and not df.empty:
125+
colour_key = df.columns[-1]
126+
127+
line = dict(color=df[colour_key], colorscale=cmap)
128+
129+
fig = go.Figure(
130+
data=go.Parcoords(
131+
line = line,
132+
dimensions = dimensions,
133+
**kwargs
134+
)
135+
)
136+
137+
fig.update_layout(
138+
title = plot_title,
139+
plot_bgcolor = plot_bgcolour,
140+
paper_bgcolor = paper_bgcolour,
141+
font_color = font_colour
142+
)
143+
144+
return fig

Python_Engine/Python_Engine.csproj

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<TargetFramework>netstandard2.0</TargetFramework>
4-
<AssemblyVersion>8.0.0.0</AssemblyVersion>
5-
<Description>https://github.com/BHoM/Python_Toolkit</Description>
6-
<Version>6.0.0</Version>
7-
<Authors>BHoM</Authors>
8-
<Copyright>Copyright © https://github.com/BHoM</Copyright>
9-
<RootNamespace>BH.Engine.Python</RootNamespace>
10-
<FileVersion>8.1.0.0</FileVersion>
11-
<OutputPath>..\Build\</OutputPath>
12-
</PropertyGroup>
13-
<ItemGroup>
14-
<ProjectReference Include="..\Python_oM\Python_oM.csproj" />
15-
</ItemGroup>
16-
<ItemGroup>
17-
<Reference Include="BHoM">
18-
<SpecificVersion>False</SpecificVersion>
19-
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM.dll</HintPath>
20-
<Private>False</Private>
21-
</Reference>
22-
<Reference Include="BHoM_Engine">
23-
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM_Engine.dll</HintPath>
24-
<Private>False</Private>
25-
<SpecificVersion>False</SpecificVersion>
26-
</Reference>
27-
<Reference Include="Reflection_Engine">
28-
<SpecificVersion>False</SpecificVersion>
29-
<HintPath>$(ProgramData)\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
30-
<Private>False</Private>
31-
</Reference>
32-
<Reference Include="Serialiser_Engine">
33-
<SpecificVersion>False</SpecificVersion>
34-
<HintPath>$(ProgramData)\BHoM\Assemblies\Serialiser_Engine.dll</HintPath>
35-
<Private>False</Private>
36-
</Reference>
37-
</ItemGroup>
38-
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
39-
<Exec Command="xcopy $(TargetDir)$(TargetFileName) $(ProgramData)\BHoM\Assemblies /Y" />
40-
</Target>
41-
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
42-
<Exec Command="if not exist $(ProgramData)\BHoM\Extensions\PythonEnvironments mkdir $(ProgramData)\BHoM\Extensions\PythonEnvironments&#xD;&#xA;if not exist $(ProgramData)\BHoM\Extensions\PythonCode mkdir $(ProgramData)\BHoM\Extensions\PythonCode&#xD;&#xA; &#xD;&#xA;if exist $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName) rmdir $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName) /S /Q&#xD;&#xA;mkdir $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName)&#xD;&#xA; &#xD;&#xA;robocopy $(ProjectDir)Python $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName) /mir /xf &quot;*.pyc&quot; &quot;*.ipynb&quot; /xd &quot;__*__&quot; &quot;.*&quot; &gt; output.log&#xD;&#xA;del output.log" />
43-
</Target>
44-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.0</TargetFramework>
4+
<AssemblyVersion>8.0.0.0</AssemblyVersion>
5+
<Description>https://github.com/BHoM/Python_Toolkit</Description>
6+
<Version>6.0.0</Version>
7+
<Authors>BHoM</Authors>
8+
<Copyright>Copyright © https://github.com/BHoM</Copyright>
9+
<RootNamespace>BH.Engine.Python</RootNamespace>
10+
<FileVersion>8.2.0.0</FileVersion>
11+
<OutputPath>..\Build\</OutputPath>
12+
</PropertyGroup>
13+
<ItemGroup>
14+
<ProjectReference Include="..\Python_oM\Python_oM.csproj" />
15+
</ItemGroup>
16+
<ItemGroup>
17+
<Reference Include="BHoM">
18+
<SpecificVersion>False</SpecificVersion>
19+
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM.dll</HintPath>
20+
<Private>False</Private>
21+
</Reference>
22+
<Reference Include="BHoM_Engine">
23+
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM_Engine.dll</HintPath>
24+
<Private>False</Private>
25+
<SpecificVersion>False</SpecificVersion>
26+
</Reference>
27+
<Reference Include="Reflection_Engine">
28+
<SpecificVersion>False</SpecificVersion>
29+
<HintPath>$(ProgramData)\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
30+
<Private>False</Private>
31+
</Reference>
32+
<Reference Include="Serialiser_Engine">
33+
<SpecificVersion>False</SpecificVersion>
34+
<HintPath>$(ProgramData)\BHoM\Assemblies\Serialiser_Engine.dll</HintPath>
35+
<Private>False</Private>
36+
</Reference>
37+
</ItemGroup>
38+
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
39+
<Exec Command="xcopy $(TargetDir)$(TargetFileName) $(ProgramData)\BHoM\Assemblies /Y" />
40+
</Target>
41+
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
42+
<Exec Command="if not exist $(ProgramData)\BHoM\Extensions\PythonEnvironments mkdir $(ProgramData)\BHoM\Extensions\PythonEnvironments&#xD;&#xA;if not exist $(ProgramData)\BHoM\Extensions\PythonCode mkdir $(ProgramData)\BHoM\Extensions\PythonCode&#xD;&#xA; &#xD;&#xA;if exist $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName) rmdir $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName) /S /Q&#xD;&#xA;mkdir $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName)&#xD;&#xA; &#xD;&#xA;robocopy $(ProjectDir)Python $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName) /mir /xf &quot;*.pyc&quot; &quot;*.ipynb&quot; /xd &quot;__*__&quot; &quot;.*&quot; &gt; output.log&#xD;&#xA;del output.log" />
43+
</Target>
44+
</Project>

Python_oM/Python_oM.csproj

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<AssemblyVersion>8.0.0.0</AssemblyVersion>
6-
<Description>https://github.com/BHoM/Python_Toolkit</Description>
7-
<Version>6.0.0</Version>
8-
<Authors>BHoM</Authors>
9-
<Copyright>Copyright © https://github.com/BHoM</Copyright>
10-
<RootNamespace>BH.oM.Python</RootNamespace>
11-
<FileVersion>8.1.0.0</FileVersion>
12-
<OutputPath>..\Build\</OutputPath>
13-
</PropertyGroup>
14-
15-
<ItemGroup>
16-
<Reference Include="BHoM">
17-
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM.dll</HintPath>
18-
<SpecificVersion>False</SpecificVersion>
19-
<Private>False</Private>
20-
</Reference>
21-
</ItemGroup>
22-
23-
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
24-
<Exec Command="xcopy $(TargetDir)$(TargetFileName) $(ProgramData)\BHoM\Assemblies /Y" />
25-
</Target>
26-
27-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<AssemblyVersion>8.0.0.0</AssemblyVersion>
6+
<Description>https://github.com/BHoM/Python_Toolkit</Description>
7+
<Version>6.0.0</Version>
8+
<Authors>BHoM</Authors>
9+
<Copyright>Copyright © https://github.com/BHoM</Copyright>
10+
<RootNamespace>BH.oM.Python</RootNamespace>
11+
<FileVersion>8.2.0.0</FileVersion>
12+
<OutputPath>..\Build\</OutputPath>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<Reference Include="BHoM">
17+
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM.dll</HintPath>
18+
<SpecificVersion>False</SpecificVersion>
19+
<Private>False</Private>
20+
</Reference>
21+
</ItemGroup>
22+
23+
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
24+
<Exec Command="xcopy $(TargetDir)$(TargetFileName) $(ProgramData)\BHoM\Assemblies /Y" />
25+
</Target>
26+
27+
</Project>

0 commit comments

Comments
 (0)