Skip to content

Add multitude of features to the toolkit #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 89 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
36d7d26
added chunks method
tg359 Dec 5, 2022
bc51f79
added shade benefit categorisation
tg359 Dec 6, 2022
5f98075
updated spatial methods
tg359 Dec 6, 2022
41cf5c2
minor bugfixes
tg359 Dec 7, 2022
2b4b6fb
added wind handlers
tg359 Dec 8, 2022
38afc0f
updated beneficial mitigation measures method
tg359 Dec 9, 2022
a8b9b4e
yet more tweaks
tg359 Dec 20, 2022
fe0e1f8
added seasonality methods
tg359 Dec 21, 2022
f5b23df
fixed string sanitiser to remove HB invalid characters
tg359 Dec 22, 2022
cccbe4a
added temporary typical day method
tg359 Dec 22, 2022
554f0ba
added psychrometric chart
tg359 Jan 6, 2023
97485b3
updated data collection description text
tg359 Jan 6, 2023
a7b009d
updated psychrochart to include polygons
tg359 Jan 9, 2023
c6e1a30
added windhist plot type
tg359 Jan 10, 2023
7daadf5
pre-update version commit
tg359 Jan 15, 2023
6f9f073
added time_comfortable range method
tg359 Jan 16, 2023
8d4f25b
new shelter geometry added
tg359 Jan 20, 2023
5278381
alt_az methods added
tg359 Jan 23, 2023
a875321
added new shelter method - sans testing methods
tg359 Jan 26, 2023
b360426
added shelter tests and updated c# corresponding methods
tg359 Jan 27, 2023
fb6ac01
Merge branch 'develop' of https://github.com/BHoM/LadybugTools_Toolki…
tg359 Jan 27, 2023
649aecb
updated seasonality
tg359 Jan 30, 2023
127737e
fixed majority of linting issues
tg359 Jan 30, 2023
e9c4b05
fixed MRT calculation method
tg359 Jan 31, 2023
3c336bc
Updated UTCI feasibility method
tg359 Feb 1, 2023
77ea30f
added LBT materials from JSON
tg359 Feb 1, 2023
a043d07
updated test materials in pytest file/s
tg359 Feb 3, 2023
48ae35d
fixed tests
tg359 Feb 3, 2023
c14d619
minor modifications to enable faster project dev
tg359 Feb 3, 2023
89a4923
added wind-matrix plot method
tg359 Feb 6, 2023
e569b26
many many project changes
tg359 Feb 7, 2023
3cc9eab
tweaks to improve methods
tg359 Feb 10, 2023
6f87096
updates
tg359 Feb 13, 2023
a5c2706
removed prototypes
tg359 Feb 14, 2023
a5b7359
removed vscode build
tg359 Feb 14, 2023
fdd865e
...
tg359 Feb 14, 2023
1fed912
Remove the now ignored directory
tg359 Feb 14, 2023
088ade6
Remove the now ignored build file
tg359 Feb 14, 2023
7cf93b7
updated gitignore
tg359 Feb 14, 2023
f8ef839
made C# components work again
tg359 Feb 14, 2023
4b75b34
Delete LadybugTools_Engine/Python/src/ladybugtools_toolkit/prototypes…
tg359 Feb 14, 2023
0fd2dda
Changed FromJson to FromJsonArray
jamesramsden-bh Feb 14, 2023
faaecee
Simplified Materials.cs
jamesramsden-bh Feb 14, 2023
b07b7cd
Also tidied Typologies
jamesramsden-bh Feb 14, 2023
cd97f57
Materials and Typologies use new PythonEnvironment method for speed
jamesramsden-bh Feb 14, 2023
5698d71
updated methods to account for upstream Python_Tk changes
tg359 Feb 15, 2023
f247e64
Appled VirtualEnv
jamesramsden-bh Feb 15, 2023
aacfbfa
Fixed bug, changed 'lowest' to 'min'
jamesramsden-bh Feb 15, 2023
c331401
updated Spatial methods to fix minor inconvenient bugs causing sims t…
tg359 Feb 20, 2023
0e4ce2f
updated gitignore
tg359 Feb 21, 2023
6fdaf58
added EPW translation to different height methods, and minor bug fixe…
tg359 Feb 22, 2023
36e94d4
Added simplified mean month/time UTCI table generator
tg359 Feb 23, 2023
f94a937
BHoMified the Shelter object, plus lots of minor review changes
jamesramsden-bh Feb 28, 2023
a748275
Renamed back to GetMaterial and GetTypology
jamesramsden-bh Feb 28, 2023
d146cab
Renamed GetMaterial properly this time
jamesramsden-bh Feb 28, 2023
bb212cc
Fixed compliance issues
jamesramsden-bh Feb 28, 2023
2f32c7d
Null handling added
jamesramsden-bh Mar 1, 2023
729feca
Null handling added, that BHoMBot might like better.
jamesramsden-bh Mar 1, 2023
fc614cc
Null handling added, again trying to please the bot
jamesramsden-bh Mar 2, 2023
40d2467
Apply suggestions from code review
jamesramsden-bh Mar 3, 2023
2368836
Update LadybugTools_Engine/Query/GetMaterial.cs
jamesramsden-bh Mar 3, 2023
c0a6089
Update LadybugTools_Engine/Query/GetTypology.cs
jamesramsden-bh Mar 3, 2023
3834413
enabled passing of arrays to wind_speed_multiplier for ExternalComfor…
tg359 Mar 6, 2023
9741155
Merge branch 'LBT_Toolkit-#XX-ProjectChanges' of https://github.com/B…
tg359 Mar 6, 2023
07656cc
updated based on proposed changes to Python_Tk
tg359 Mar 6, 2023
8322db6
reverted commit and recovered lost functionality
tg359 Mar 22, 2023
7fde6ba
reverted commit and recovered lost functionality
tg359 Mar 22, 2023
d825bce
...
tg359 May 15, 2023
16fecb5
additional fixes
tg359 May 16, 2023
c360ae2
added wind tests
tg359 May 16, 2023
cbda94f
added wind tests
tg359 May 16, 2023
82ed7b0
updated requirements.txt
tg359 May 16, 2023
502a1bc
sdfvl;ioanfgs
tg359 May 18, 2023
d7619ff
added sql test file
tg359 May 18, 2023
6479e96
Updated opnemeteo scraper autoconversion
tg359 May 19, 2023
a37641f
Added missing koeppen method and initial lbgeometry method
tg359 May 19, 2023
c85ba7b
updated spatial_comfort test for alternative sky_view results locations
tg359 May 22, 2023
bc46e9b
minor modifications to external comfort post-processing methods
tg359 Jun 2, 2023
e665048
minor dtype fix for wind following test failure
tg359 Jun 2, 2023
4232bc5
BHoM>Python methods functional
tg359 Jun 2, 2023
2d03b68
fixed another annoying JSON formatting issue
tg359 Jun 3, 2023
721189f
minor formatting changes
tg359 Jun 5, 2023
ed62a3a
Merge branch 'develop' of https://github.com/BHoM/LadybugTools_Toolki…
tg359 Jun 7, 2023
997469a
reverted encoding attempts
tg359 Jun 7, 2023
b2ca7c7
Removed unused import
tg359 Jun 7, 2023
916e58e
Update project compliance
BHoMBot Jun 7, 2023
f93ebf1
Added Versioning_62
jamesramsden-bh Jun 8, 2023
636faf6
Renamed ILBTMaterial
jamesramsden-bh Jun 8, 2023
49e7051
Removed Versioning_62 for changes in Versioning_Toolkit
jamesramsden-bh Jun 8, 2023
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,8 @@ cython_debug/
# Testing files
*.ipynb
.dev/
prototypes/
build.ps1

# unignored files
!example.sql
46 changes: 25 additions & 21 deletions LadybugTools_Engine/Compute/EPWtoCSV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
*
* 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>.
*
*
* 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>.
*/

using BH.Engine.Python;
using BH.oM.Python;
using BH.oM.Base.Attributes;

using System;
using System.Collections.Generic;
using System.ComponentModel;

Expand All @@ -33,8 +33,10 @@ public static partial class Compute
{
[Description("Convert an EPW file into a CSV and return the path to that CSV.")]
[Input("epwFile", "An EPW file.")]
[Input("includeAdditional", "Add sun position and psychrometric properties to the resultant CSV.")]
[Output("csv", "The generated CSV file.")]
public static string EPWtoCSV(string epwFile)
[PreviousVersion("6.2", "BH.Engine.LadybugTools.Compute.EPWtoCSV(System.String)")]
public static string EPWtoCSV(string epwFile, bool includeAdditional = false)
{
if (epwFile == null)
{
Expand All @@ -48,21 +50,23 @@ public static string EPWtoCSV(string epwFile)
return null;
}

BH.oM.Python.PythonEnvironment env = Compute.InstallPythonEnv_LBT(true);
PythonEnvironment env = Python.Query.VirtualEnv(Query.ToolkitName());
string additionalProperties = includeAdditional ? "True" : "False";

string pythonScript = String.Join("\n", new List<string>()
string pythonScript = string.Join("\n", new List<string>()
{
"import traceback",
"from pathlib import Path",
"from ladybug.epw import EPW",
"from ladybugtools_toolkit.ladybug_extension.epw import to_dataframe",
"",
$"epw_path = Path(r'{epwFile}')",
"csv_path = epw_path.with_suffix('.csv')",
"try:",
" to_dataframe(EPW(epw_path.as_posix())).to_csv(csv_path.as_posix())",
" from ladybugtools_toolkit.ladybug_extension.epw import epw_to_dataframe",
$" epw_to_dataframe(EPW(epw_path.as_posix()), include_additional={additionalProperties}).to_csv(csv_path.as_posix())",
" print(csv_path)",
"except Exception as exc:",
" print(exc)",
" print(traceback.format_exc())",
});

return env.RunPythonString(pythonScript).Trim();
Expand Down
37 changes: 18 additions & 19 deletions LadybugTools_Engine/Compute/EPWtoCustomObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
*
* 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>.
*
*
* 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>.
*/

using BH.Engine.Python;
Expand All @@ -26,14 +26,12 @@
using BH.oM.Base.Attributes;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;

namespace BH.Engine.LadybugTools
{
public static partial class Compute
{
[Description("Convert an EPW file into a time-indexed CSV version.")]
[Description("Convert an EPW file into a custom BHoM object.")]
[Input("epwFile", "An EPW file.")]
[Output("object", "A BHoM object wrapping a Ladybug EPW object.")]
public static CustomObject EPWtoCustomObject(string epwFile)
Expand All @@ -50,10 +48,11 @@ public static CustomObject EPWtoCustomObject(string epwFile)
return null;
}

BH.oM.Python.PythonEnvironment env = Compute.InstallPythonEnv_LBT(true);
PythonEnvironment env = Python.Query.VirtualEnv(Query.ToolkitName());

string pythonScript = string.Join("\n", new List<string>()
{
"import traceback",
"import json",
"from pathlib import Path",
"from ladybug.epw import EPW",
Expand All @@ -62,7 +61,7 @@ public static CustomObject EPWtoCustomObject(string epwFile)
"try:",
" print(json.dumps(EPW(epw_path.as_posix()).to_dict()))",
"except Exception as exc:",
" print(exc)",
" print(traceback.format_exc())",
});

string output = env.RunPythonString(pythonScript).Trim();
Expand Down
50 changes: 29 additions & 21 deletions LadybugTools_Engine/Compute/ExternalComfort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
*
* 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>.
*
*
* 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>.
*/

using BH.Engine.Python;
Expand All @@ -27,11 +27,9 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using BH.oM.Base;
using System.IO;
using BH.oM.LadybugTools;
using BH.Engine.Serialiser;
using Rhino.DocObjects;
using BH.Engine.Geometry;

namespace BH.Engine.LadybugTools
{
Expand All @@ -40,7 +38,7 @@ public static partial class Compute
[Description("Run an External Comfort simulation and return results.")]
[Input("simulationResult", "A simulation result object.")]
[Input("typology", "An ExternalComfortTypology.")]
[Output("externalComfortResult", "An external comfort result object containing simulation results.")]
[Output("externalComfort", "An external comfort result object containing simulation results.")]
public static ExternalComfort ExternalComfort(SimulationResult simulationResult, Typology typology)
{
if (simulationResult == null)
Expand All @@ -55,6 +53,15 @@ public static ExternalComfort ExternalComfort(SimulationResult simulationResult,
return null;
}

foreach (Shelter shelter in typology.Shelters)
{
if (!BH.Engine.Geometry.Create.Polyline(shelter.Vertices).IsPlanar())
{
BH.Engine.Base.Compute.RecordError("A shelter in this Typology is not planar.");
return null;
}
}

// construct the base object
ExternalComfort externalComfort = new ExternalComfort()
{
Expand All @@ -64,16 +71,17 @@ public static ExternalComfort ExternalComfort(SimulationResult simulationResult,

// send to Python to simulate/load
string externalComfortJsonStr = System.Text.RegularExpressions.Regex.Unescape(externalComfort.ToJson());
BH.oM.Python.PythonEnvironment env = Compute.InstallPythonEnv_LBT(true);
PythonEnvironment env = Python.Query.VirtualEnv(Query.ToolkitName());
string pythonScript = string.Join("\n", new List<string>()
{
"import json",
"import traceback",
"try:",
" import json",
" from ladybugtools_toolkit.external_comfort.external_comfort import ExternalComfort",
$" external_comfort = ExternalComfort.from_json('{externalComfortJsonStr}')",
" print(external_comfort.to_json())",
"except Exception as exc:",
" print(json.dumps({'error': str(exc)}))",
" print(traceback.format_exc())",
});

string output = env.RunPythonString(pythonScript).Trim().Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).Last();
Expand Down
6 changes: 4 additions & 2 deletions LadybugTools_Engine/Compute/GEMtoHBJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

using BH.Engine.Python;
using BH.oM.Python;
using BH.oM.Base.Attributes;

using System;
Expand Down Expand Up @@ -48,14 +49,15 @@ public static string GEMtoHBJSON(string gem)
return null;
}

BH.oM.Python.PythonEnvironment env = Compute.InstallPythonEnv_LBT(true);
PythonEnvironment env = Python.Query.VirtualEnv(Query.ToolkitName());

string gemFile = System.IO.Path.GetFullPath(gem);
string outputDirectory = System.IO.Path.GetDirectoryName(gem);
string fileName = System.IO.Path.GetFileNameWithoutExtension(gem);

string pythonScript = String.Join("\n", new List<string>()
{
"import traceback",
"from honeybee.model import Model",
"from honeybee_ies.reader import model_from_ies",
"",
Expand All @@ -64,7 +66,7 @@ public static string GEMtoHBJSON(string gem)
$" hbjson_file = model.to_hbjson(folder=r\"{outputDirectory}\", name=\"{fileName}\")",
" print(hbjson_file)",
"except Exception as exc:",
" print(exc)",
" print(traceback.format_exc())",
});

return env.RunPythonString(pythonScript).Trim();
Expand Down
6 changes: 4 additions & 2 deletions LadybugTools_Engine/Compute/HBJSONtoGEM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

using BH.Engine.Python;
using BH.oM.Python;
using BH.oM.Base.Attributes;

using System;
Expand Down Expand Up @@ -48,14 +49,15 @@ public static string HBJSONtoGEM(string hbjson)
return null;
}

BH.oM.Python.PythonEnvironment env = Compute.InstallPythonEnv_LBT(true);
PythonEnvironment env = Python.Query.VirtualEnv(Query.ToolkitName());

string hbjsonFile = System.IO.Path.GetFullPath(hbjson);
string outputDirectory = System.IO.Path.GetDirectoryName(hbjsonFile);
string fileName = System.IO.Path.GetFileNameWithoutExtension(hbjsonFile);

string pythonScript = String.Join("\n", new List<string>()
{
"import traceback",
"from honeybee.model import Model",
"from pathlib import Path",
"",
Expand All @@ -64,7 +66,7 @@ public static string HBJSONtoGEM(string hbjson)
$" gem_file = model.to_gem(r\"{outputDirectory}\", name=\"{fileName}\")",
" print(gem_file)",
"except Exception as exc:",
" print(exc)",
" print(traceback.format_exc())",
});

return env.RunPythonString(pythonScript).Trim();
Expand Down
31 changes: 27 additions & 4 deletions LadybugTools_Engine/Compute/InstallPythonEnv_LBT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,46 @@
using BH.oM.Base.Attributes;
using BH.oM.Python;
using System.ComponentModel;
using System.Collections.Generic;
using System.IO;

namespace BH.Engine.LadybugTools
{
public static partial class Compute
{
[Description("Create the BHoM Python envrionment for LadybugTools_Toolkit. This creates a replica of what is found in the Pollination installed python environment, for extension using BHoM.")]
[Description("Create the BHoM Python environment for LadybugTools_Toolkit. This creates a replica of what is found in the Pollination installed python environment, for extension using BHoM.")]
[Input("run", "Run the installation process.")]
[Output("env", "The LadybugTools_Toolkit Python Environment, with BHoM code accessible.")]
public static PythonEnvironment InstallPythonEnv_LBT(bool run = false)
{
return BH.Engine.Python.Compute.InstallReferencedVirtualenv(
string referencedExecutable = @"C:\Program Files\ladybug_tools\python\python.exe";

PythonEnvironment referencedEnvironment = Python.Compute.InstallReferencedVirtualenv(
name: Query.ToolkitName(),
executable: @"C:\Program Files\ladybug_tools\python\python.exe",
localPackage: Path.Combine(Engine.Python.Query.CodeDirectory(), Query.ToolkitName()),
executable: referencedExecutable,
localPackage: Path.Combine(Python.Query.CodeDirectory(), Query.ToolkitName()),
run: run
);

// reload environment to establish the new executable path
PythonEnvironment localEnvironment = Python.Query.VirtualEnv(Query.ToolkitName());

// check here to ensure that referenced executable is using same version as local BHoM environment executable
List<string> packagesToCheck = new List<string>() { "lbt-ladybug", "lbt-dragonfly", "lbt-honeybee", "lbt-recipes" };
foreach ( string package in packagesToCheck )
{
string installed = Python.Compute.RunCommandStdout($"{Python.Modify.AddQuotesIfRequired(localEnvironment.Executable)} -m pip freeze | FindStr {package}");
string referenced = Python.Compute.RunCommandStdout($"{Python.Modify.AddQuotesIfRequired(referencedEnvironment.Executable)} -m pip freeze | FindStr {package}");
if (installed != referenced)
{
Base.Compute.RecordWarning($"BHoM environment {package} does not match referenced package version ({installed} != {referenced}). " +
$"This can be caused by the BHoM version and installed version becoming out of sync. " +
$"Try deleting the {Python.Query.VirtualEnvDirectory("LadybugTools_Toolkit")} directory and re-running the " +
$"{System.Reflection.MethodBase.GetCurrentMethod().Name} method again to fix this.");
}
}

return localEnvironment;
}
}
}
Expand Down
Loading