Skip to content

Commit 37bb52e

Browse files
author
Fraser Greenroyd
authored
7.1 Deployment (#176)
2 parents 8235f6f + 78c068e commit 37bb52e

80 files changed

Lines changed: 1534 additions & 279 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LadybugTools_Adapter/AdapterActions/Execute.cs

Lines changed: 170 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -34,6 +34,11 @@
3434
using System.IO;
3535
using System.Linq;
3636
using System.Text;
37+
using BH.Engine.Base;
38+
using System.Drawing;
39+
using BH.Engine.Serialiser;
40+
using BH.Engine.LadyBugTools;
41+
using System.Reflection;
3742

3843
namespace BH.Adapter.LadybugTools
3944
{
@@ -74,7 +79,6 @@ public List<object> IRunCommand(IExecuteCommand command)
7479

7580
private List<object> RunCommand(GetMaterialCommand command)
7681
{
77-
PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true);
7882
LadybugConfig config = new LadybugConfig()
7983
{
8084
JsonFile = new FileSettings()
@@ -88,7 +92,7 @@ private List<object> RunCommand(GetMaterialCommand command)
8892
{
8993
string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_material.py");
9094

91-
string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
95+
string cmdCommand = $"{m_environment.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
9296

9397
Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
9498
}
@@ -103,7 +107,6 @@ private List<object> RunCommand(GetMaterialCommand command)
103107

104108
private List<object> RunCommand(GetTypologyCommand command)
105109
{
106-
PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true);
107110
LadybugConfig config = new LadybugConfig()
108111
{
109112
JsonFile = new FileSettings()
@@ -117,7 +120,7 @@ private List<object> RunCommand(GetTypologyCommand command)
117120
{
118121
string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_typology.py");
119122

120-
string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
123+
string cmdCommand = $"{m_environment.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
121124

122125
Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
123126
}
@@ -133,15 +136,15 @@ private List<object> RunCommand(GetTypologyCommand command)
133136
private List<object> RunCommand(RunSimulationCommand command)
134137
{
135138
// validation prior to passing to Python
136-
if (command.EpwFile == null)
139+
if (command.EPWFile == null)
137140
{
138-
BH.Engine.Base.Compute.RecordError($"{nameof(command.EpwFile)} input cannot be null.");
141+
BH.Engine.Base.Compute.RecordError($"{nameof(command.EPWFile)} input cannot be null.");
139142
return null;
140143
}
141144

142-
if (!File.Exists(command.EpwFile.GetFullFileName()))
145+
if (!File.Exists(command.EPWFile.GetFullFileName()))
143146
{
144-
BH.Engine.Base.Compute.RecordError($"{command.EpwFile.GetFullFileName()} does not exist.");
147+
BH.Engine.Base.Compute.RecordError($"FIle '{command.EPWFile.GetFullFileName()}' does not exist.");
145148
return null;
146149
}
147150

@@ -170,21 +173,20 @@ private List<object> RunCommand(RunSimulationCommand command)
170173
// construct the base object and file to be passed to Python for simulation
171174
SimulationResult simulationResult = new SimulationResult()
172175
{
173-
EpwFile = Path.GetFullPath(command.EpwFile.GetFullFileName()).Replace(@"\", "/"),
176+
EpwFile = Path.GetFullPath(command.EPWFile.GetFullFileName()).Replace(@"\", "/"),
174177
GroundMaterial = command.GroundMaterial,
175178
ShadeMaterial = command.ShadeMaterial,
176-
Name = Engine.LadybugTools.Compute.SimulationID(command.EpwFile.GetFullFileName(), command.GroundMaterial, command.ShadeMaterial)
179+
Name = Engine.LadybugTools.Compute.SimulationID(command.EPWFile.GetFullFileName(), command.GroundMaterial, command.ShadeMaterial)
177180
};
178181

179182
// push object to json file
180183
Push(new List<SimulationResult>() { simulationResult }, actionConfig: config);
181184

182-
// locate the Python executable and file containing the simulation code
183-
PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true);
185+
// locate the Python file containing the simulation code
184186
string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "simulation_result.py");
185187

186188
// run the simulation
187-
string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
189+
string cmdCommand = $"{m_environment.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
188190
Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
189191

190192
// reload from Python results
@@ -232,12 +234,11 @@ private List<object> RunCommand(RunExternalComfortCommand command)
232234
// push objects to json file
233235
Push(new List<ExternalComfort>() { externalComfort }, actionConfig: config);
234236

235-
// locate the Python executable and file containing the simulation code
236-
PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true);
237+
// locate the Python file containing the simulation code
237238
string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "external_comfort.py");
238239

239240
// run the calculation
240-
string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
241+
string cmdCommand = $"{m_environment.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
241242
Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
242243

243244
// reload from Python results
@@ -250,6 +251,157 @@ private List<object> RunCommand(RunExternalComfortCommand command)
250251
return externalComfortPopulated;
251252
}
252253

254+
/**************************************************/
255+
256+
private List<object> RunCommand(HeatPlotCommand command)
257+
{
258+
if (command.EPWFile == null)
259+
{
260+
BH.Engine.Base.Compute.RecordError($"{nameof(command.EPWFile)} input cannot be null.");
261+
return null;
262+
}
263+
264+
if (!System.IO.File.Exists(command.EPWFile.GetFullFileName()))
265+
{
266+
BH.Engine.Base.Compute.RecordError($"File '{command.EPWFile}' does not exist.");
267+
return null;
268+
}
269+
270+
string epwFile = System.IO.Path.GetFullPath(command.EPWFile.GetFullFileName());
271+
272+
string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "heatmap.py");
273+
274+
//check if the colourmap is valid for user warning, but run with input anyway as the map could be defined separately.
275+
string colourMap = command.ColourMap;
276+
if (colourMap.ColourMapValidity())
277+
colourMap = colourMap.ToColourMap().FromColourMap();
278+
279+
// run the process
280+
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -cmap \"{colourMap}\" -p \"{command.OutputLocation}\"";
281+
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
282+
283+
m_executeSuccess = true;
284+
return new List<object>() { result };
285+
}
286+
287+
/**************************************************/
288+
289+
private List<object> RunCommand(WindroseCommand command)
290+
{
291+
if (command.EPWFile == null)
292+
{
293+
BH.Engine.Base.Compute.RecordError($"{nameof(command.EPWFile)} input cannot be null.");
294+
return null;
295+
}
296+
297+
if (!System.IO.File.Exists(command.EPWFile.GetFullFileName()))
298+
{
299+
BH.Engine.Base.Compute.RecordError($"File '{command.EPWFile.GetFullFileName()}' does not exist.");
300+
return null;
301+
}
302+
303+
if (command.AnalysisPeriod == null)
304+
{
305+
BH.Engine.Base.Compute.RecordError($"Please input a valid analysis period to run this command.");
306+
return null;
307+
}
308+
309+
string epwFile = System.IO.Path.GetFullPath(command.EPWFile.GetFullFileName());
310+
311+
string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "windrose.py");
312+
313+
//check if the colourmap is valid for user warning, but run with input anyway as the map could be defined separately.
314+
string colourMap = command.ColourMap;
315+
if (colourMap.ColourMapValidity())
316+
colourMap = colourMap.ToColourMap().FromColourMap();
317+
318+
// run the process
319+
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -cmap \"{colourMap}\" -bins \"{command.NumberOfDirectionBins}\" -p \"{command.OutputLocation}\"";
320+
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
321+
322+
m_executeSuccess = true;
323+
return new List<object> { result };
324+
}
325+
326+
/**************************************************/
327+
328+
private List<object> RunCommand(UTCIHeatPlotCommand command)
329+
{
330+
if (command.EPWFile == null)
331+
{
332+
BH.Engine.Base.Compute.RecordError($"{nameof(command.EPWFile)} input cannot be null.");
333+
return null;
334+
}
335+
336+
if (!System.IO.File.Exists(command.EPWFile.GetFullFileName()))
337+
{
338+
BH.Engine.Base.Compute.RecordError($"File '{command.EPWFile.GetFullFileName()}' does not exist.");
339+
return null;
340+
}
341+
342+
if (command.GroundMaterial == null)
343+
{
344+
BH.Engine.Base.Compute.RecordError($"Please input a valid ground material to run this command.");
345+
return null;
346+
}
347+
348+
if (command.ShadeMaterial == null)
349+
{
350+
BH.Engine.Base.Compute.RecordError($"Please input a valid shade material to run this command.");
351+
return null;
352+
}
353+
354+
if (command.Typology == null)
355+
{
356+
BH.Engine.Base.Compute.RecordError($"Please input a valid Typology to run this command.");
357+
}
358+
359+
if (!(command.BinColours.Count == 10 || command.BinColours.Count == 0))
360+
{
361+
BH.Engine.Base.Compute.RecordError($"When overriding bin colours 10 colours must be provided, but {command.BinColours.Count} colours were provided instead.");
362+
return null;
363+
}
364+
List<string> colours = command.BinColours.Select(x => x.ToHexCode()).ToList();
365+
366+
string hexColours = $"[\"{string.Join("\",\"", colours)}\"]";
367+
if (hexColours == "[\"\"]")
368+
hexColours = "[]";
369+
370+
Dictionary<string, string> inputObjects = new Dictionary<string, string>()
371+
{
372+
{ "ground_material", command.GroundMaterial.FromBHoM() },
373+
{ "shade_material", command.ShadeMaterial.FromBHoM() },
374+
{ "typology", command.Typology.FromBHoM() },
375+
{ "bin_colours", hexColours }
376+
};
377+
378+
string argFile = Path.GetTempFileName();
379+
File.WriteAllText(argFile, inputObjects.ToJson());
380+
381+
string epwFile = System.IO.Path.GetFullPath(command.EPWFile.GetFullFileName());
382+
383+
string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "utci_heatmap.py");
384+
385+
// run the process
386+
string cmdCommand = $"{m_environment.Executable} \"{script}\" -e \"{epwFile}\" -in \"{argFile}\" -ws \"{command.WindSpeedMultiplier}\" -sp \"{command.OutputLocation}\"";
387+
string result = "";
388+
389+
try
390+
{
391+
result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
392+
}
393+
catch (Exception ex)
394+
{
395+
BH.Engine.Base.Compute.RecordError(ex, "An error occurred while running some python.");
396+
}
397+
finally
398+
{
399+
File.Delete(argFile);
400+
}
401+
402+
return new List<object> { result.Split('\n').Last() };
403+
}
404+
253405
/**************************************************/
254406
/* Private methods - Fallback */
255407
/**************************************************/
@@ -261,3 +413,4 @@ private List<object> RunCommand(IExecuteCommand command)
261413
}
262414
}
263415
}
416+

LadybugTools_Adapter/AdapterActions/Pull.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -70,3 +70,4 @@ public override IEnumerable<object> Pull(IRequest request, PullType pullType = P
7070
}
7171
}
7272
}
73+

LadybugTools_Adapter/AdapterActions/Push.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -68,3 +68,4 @@ public override List<object> Push(IEnumerable<object> objects, string tag = "",
6868
}
6969
}
7070
}
71+

LadybugTools_Adapter/CRUD/CreateLadybug.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -51,3 +51,4 @@ public static void CreateLadybug(List<ILadybugTools> objects, LadybugConfig conf
5151
}
5252
}
5353
}
54+

LadybugTools_Adapter/CRUD/Read.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -41,3 +41,4 @@ protected override IEnumerable<IBHoMObject> IRead(Type type, IList indices = nul
4141
}
4242
}
4343
}
44+

LadybugTools_Adapter/Convert/Collections/EPW.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -102,3 +102,4 @@ public static string FromEPW(BH.oM.LadybugTools.EPW epw)
102102
}
103103
}
104104
}
105+

LadybugTools_Adapter/Convert/Collections/HourlyContinuousCollection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -80,3 +80,4 @@ public static string FromHourlyContinuousCollection(BH.oM.LadybugTools.HourlyCon
8080
}
8181
}
8282
}
83+

LadybugTools_Adapter/Convert/Constructions/EnergyMaterial.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -150,3 +150,4 @@ public static Dictionary<string, object> FromEnergyMaterial(BH.oM.LadybugTools.E
150150
}
151151
}
152152
}
153+

LadybugTools_Adapter/Convert/Constructions/EnergyMaterialVegetation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -219,3 +219,4 @@ public static Dictionary<string, object> FromEnergyMaterialVegetation(BH.oM.Lady
219219
}
220220
}
221221
}
222+

LadybugTools_Adapter/Convert/FromBHoM.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -109,3 +109,4 @@ private static Dictionary<string, object> Jsonify(this ILadybugTools obj)
109109
}
110110
}
111111
}
112+

0 commit comments

Comments
 (0)