Skip to content
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

Migrate openfield methods and update versions #42

Merged
merged 101 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
3918f47
Added model creation methods
tg359 Feb 11, 2022
4ee39f7
Slowly adding methdos
tg359 Feb 11, 2022
3398a5b
Interim commit for posterity
tg359 Feb 14, 2022
f540f6b
interim - not working
tg359 Feb 16, 2022
7195981
still not working, but at least it rebased
tg359 Feb 22, 2022
55d639e
Functional, not tidy
tg359 Feb 23, 2022
d02d0c6
Adding methods to install versions from github ... in progress
tg359 Feb 23, 2022
93cfbf9
Interim commit containing methods used for setting up ladybug_tools f…
tg359 Feb 24, 2022
ca4f3ae
Tidied toolkit, removed unecessary methods, add warnings, updated pkg…
tg359 Feb 24, 2022
8441459
All working except for MRT approximation method - needs some geometry…
tg359 Feb 25, 2022
73552a6
Figuring out shelter/sun interactions
tg359 Feb 28, 2022
e11aa54
Methods functioning, detailed testing required
tg359 Mar 1, 2022
35581d8
Added spatial comfort post-processing methods
tg359 Mar 2, 2022
bc7e90f
Added ylims to utci pseudo journey plot
tg359 Mar 3, 2022
1a915df
Added ylims to utci pseudo journey plot
tg359 Mar 3, 2022
7d4277e
Added params to utci_pseudo_journey plot
jamesramsden-bh Mar 3, 2022
1161384
Modified spatial method to be faster
tg359 Mar 4, 2022
f230def
Added constant scale param to UTCI journey plot
jamesramsden-bh Mar 3, 2022
7c51804
Getting messy, needs to be tidied and made to work!
tg359 Mar 7, 2022
0d9d5b0
functional, not tidy
tg359 Mar 8, 2022
d550d74
Added EWM method for MRT decay rate following transition between unsh…
tg359 Mar 15, 2022
2ff0185
Tidied typology generation method
tg359 Mar 22, 2022
3107f69
Added initial wrapper method around openfield
tg359 Mar 24, 2022
c8e1dc8
Wrapped openfield method - functional, needs tidying
tg359 Mar 25, 2022
e8f2ba7
More changes to make this better align with BHoM workflows
tg359 Mar 25, 2022
d47987b
...
tg359 Mar 27, 2022
9d9d1af
to_json methods functional
tg359 Mar 31, 2022
77cbdcb
...
tg359 Mar 31, 2022
7615368
...
tg359 Apr 1, 2022
399bb27
working prototype typology simulation
tg359 Apr 5, 2022
1858aea
finally ready, pending review
tg359 Apr 12, 2022
c1d92f4
Fixed minor bugs to expose methods to BHoM
tg359 Apr 12, 2022
3347c14
Moved pre-run checks to "compute" to comply with BHoMBot checks
tg359 Apr 14, 2022
fae4833
potentially breaking changes
tg359 Apr 27, 2022
8582710
Functional spatial moisture matrix
tg359 Apr 29, 2022
3e52b06
Probably fuctional, but not fully tested
tg359 Apr 30, 2022
093a2b8
Probably fuctional, but not fully tested
tg359 Apr 30, 2022
3618b68
testing to make it faster
tg359 May 3, 2022
b691ad6
pre-review, post-tidying
tg359 May 5, 2022
5649f94
Post review changes and last minute additions - needs TODOs to be add…
tg359 May 9, 2022
6eade31
Addressed TODOs
tg359 May 10, 2022
06cb268
Added methods for spatial comfort summary
tg359 May 26, 2022
b264e87
Hopefully fixed issue running on other machines, and simplified exist…
tg359 Jun 6, 2022
1e4789b
Updated plot_utci_journey params and background colour
jamesramsden-bh May 31, 2022
c7eb079
fixed conflict
tg359 Jun 6, 2022
95fb0b2
Added PV TOF plot
tg359 Jun 7, 2022
63b16d3
Fixed previous results loading error
tg359 Jun 8, 2022
3735cfe
Fixed error in solar time (datetime) from epw
tg359 Jun 8, 2022
dfa5353
Fixed issue where shade BC was Ground and should have been Outdoors
tg359 Jun 8, 2022
9ebdf20
Fixed print format of UTCI matrix calculation progress
tg359 Jun 8, 2022
49623fa
Added model creation methods
tg359 Feb 11, 2022
1deb994
Slowly adding methdos
tg359 Feb 11, 2022
283a536
Interim commit for posterity
tg359 Feb 14, 2022
9fa7bdc
interim - not working
tg359 Feb 16, 2022
e53fd19
still not working, but at least it rebased
tg359 Feb 22, 2022
9987a2c
Functional, not tidy
tg359 Feb 23, 2022
fd4148f
Adding methods to install versions from github ... in progress
tg359 Feb 23, 2022
454d495
Interim commit containing methods used for setting up ladybug_tools f…
tg359 Feb 24, 2022
7fe920b
Tidied toolkit, removed unecessary methods, add warnings, updated pkg…
tg359 Feb 24, 2022
a721324
All working except for MRT approximation method - needs some geometry…
tg359 Feb 25, 2022
c5fbe85
Figuring out shelter/sun interactions
tg359 Feb 28, 2022
bfbd846
Methods functioning, detailed testing required
tg359 Mar 1, 2022
6e4a6ca
Added spatial comfort post-processing methods
tg359 Mar 2, 2022
25e48ba
Added ylims to utci pseudo journey plot
tg359 Mar 3, 2022
8574a40
Added ylims to utci pseudo journey plot
tg359 Mar 3, 2022
613938d
Added params to utci_pseudo_journey plot
jamesramsden-bh Mar 3, 2022
bf2ae1f
Modified spatial method to be faster
tg359 Mar 4, 2022
a1f5ddf
Added constant scale param to UTCI journey plot
jamesramsden-bh Mar 3, 2022
74b726a
Getting messy, needs to be tidied and made to work!
tg359 Mar 7, 2022
4fa1c5b
functional, not tidy
tg359 Mar 8, 2022
32e3f2e
Added EWM method for MRT decay rate following transition between unsh…
tg359 Mar 15, 2022
d541e3e
Tidied typology generation method
tg359 Mar 22, 2022
62988e4
Added initial wrapper method around openfield
tg359 Mar 24, 2022
f949813
Wrapped openfield method - functional, needs tidying
tg359 Mar 25, 2022
1ffd6e5
More changes to make this better align with BHoM workflows
tg359 Mar 25, 2022
67fb0b5
...
tg359 Mar 27, 2022
0990c2a
to_json methods functional
tg359 Mar 31, 2022
d147f7b
...
tg359 Mar 31, 2022
9316c29
...
tg359 Apr 1, 2022
bbb4001
working prototype typology simulation
tg359 Apr 5, 2022
d64870b
finally ready, pending review
tg359 Apr 12, 2022
eb53aa0
Fixed minor bugs to expose methods to BHoM
tg359 Apr 12, 2022
0a27d16
Moved pre-run checks to "compute" to comply with BHoMBot checks
tg359 Apr 14, 2022
ff205a7
potentially breaking changes
tg359 Apr 27, 2022
456f756
Functional spatial moisture matrix
tg359 Apr 29, 2022
c0429d5
Probably fuctional, but not fully tested
tg359 Apr 30, 2022
cf0751a
Probably fuctional, but not fully tested
tg359 Apr 30, 2022
b948cda
testing to make it faster
tg359 May 3, 2022
57e18b8
pre-review, post-tidying
tg359 May 5, 2022
64aeafb
Post review changes and last minute additions - needs TODOs to be add…
tg359 May 9, 2022
c3b14b3
Addressed TODOs
tg359 May 10, 2022
f91d664
Added methods for spatial comfort summary
tg359 May 26, 2022
9a5dbef
Hopefully fixed issue running on other machines, and simplified exist…
tg359 Jun 6, 2022
64a8bfc
Updated plot_utci_journey params and background colour
jamesramsden-bh May 31, 2022
51b2dd1
fixed conflict
tg359 Jun 6, 2022
f9e2c8e
Added PV TOF plot
tg359 Jun 7, 2022
949d269
Fixed previous results loading error
tg359 Jun 8, 2022
d799e12
Fixed error in solar time (datetime) from epw
tg359 Jun 8, 2022
b9a2ed3
Fixed issue where shade BC was Ground and should have been Outdoors
tg359 Jun 8, 2022
0cafade
Fixed post merge problems
tg359 Jun 8, 2022
b2ad787
...
tg359 Jun 8, 2022
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
100 changes: 100 additions & 0 deletions LadybugTools_Engine/Compute/ExternalComfort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, 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>.
*/

using BH.Engine.Python;
using BH.oM.Ladybug;
using BH.oM.Python;
using BH.oM.Base.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using BH.oM.Base;
using System.IO;

namespace BH.Engine.LadybugTools
{
public static partial class Compute
{
[Description("Run an External Comfort simulation and return results.")]
[Input("epw", "An EPW file.")]
[Input("groundMaterial", "A pre-defined ground material.")]
[Input("shadeMaterial", "A pre-defined shade material.")]
[Output("externalComfortResult", "An external comfort result object containing simulation results.")]
public static CustomObject ExternalComfort(string epw, ExternalComfortMaterial groundMaterial, ExternalComfortMaterial shadeMaterial)
{
PythonEnvironment pythonEnvironment = Python.Query.LoadPythonEnvironment(Query.ToolkitName());
if (!pythonEnvironment.IsInstalled())
{
BH.Engine.Base.Compute.RecordError($"Install the {Query.ToolkitName()} Python environment before running this method (using {Query.ToolkitName()}.Compute.InstallPythonEnvironment).");
return null;
}

if (!ExternalComfortPossible())
return null;

if (groundMaterial == ExternalComfortMaterial.Undefined || shadeMaterial == ExternalComfortMaterial.Undefined)
{
BH.Engine.Base.Compute.RecordError($"Please input a valid ExternalComfortMaterial.");
return null;
}

if (!File.Exists(epw))
{
BH.Engine.Base.Compute.RecordError($"The EPW file given cannot be found.");
return null;
}

string outputPath = Path.Combine(Path.GetTempPath(), $"{System.Guid.NewGuid()}.json");

string epwPath = Path.GetFullPath(epw);

string pythonScript = String.Join("\n", new List<string>()
{
"import sys",
$"sys.path.insert(0, '{pythonEnvironment.CodeDirectory()}')",
"",
"from ladybug.epw import EPW",
"from external_comfort.external_comfort import ExternalComfort, ExternalComfortResult",
"from external_comfort.material import Material",
"",
$"epw = EPW(r'{epwPath}')",
$"ec = ExternalComfort(epw, ground_material=Material.{groundMaterial}.value, shade_material=Material.{shadeMaterial}.value)",
"ecr = ExternalComfortResult(ec)",
$"ecr.to_json(r'{outputPath}')",
"print('Nothing to see here!')",
});

string output = Python.Compute.RunPythonString(pythonEnvironment, pythonScript).Trim();

string jsonString = "";
using (StreamReader r = new StreamReader(outputPath))
{
jsonString = r.ReadToEnd();
}


return Serialiser.Convert.FromJson(jsonString) as CustomObject;
}
}
}

66 changes: 66 additions & 0 deletions LadybugTools_Engine/Compute/ExternalComfortPossible.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, 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>.
*/

using BH.oM.Base.Attributes;
using System.Collections.Generic;
using System.IO;
using System.ComponentModel;

namespace BH.Engine.LadybugTools
{
public static partial class Compute
{
[Description("Determine whether the External Comfort process is possible.")]
[Output("bool", "True if External Comfort simulation is possible.")]
public static bool ExternalComfortPossible()
{
string username = System.Environment.UserName;

string ladybugToolsFolder = $"C:/Users/{username}/ladybug_tools";
string defaultSimulationFolder = $"C:/Users/{username}/simulation";

string openstudioPath = System.IO.Path.Combine(ladybugToolsFolder, "openstudio/bin");
string energyplusPath = System.IO.Path.Combine(ladybugToolsFolder, "openstudio/EnergyPlus");
string honeybeeOpenstudioGemPath = System.IO.Path.Combine(ladybugToolsFolder, "resources/measures/honeybee_openstudio_gem/lib");
string radiancePath = System.IO.Path.Combine(ladybugToolsFolder, "radiance");

foreach (string path in new List<string>() {
ladybugToolsFolder,
defaultSimulationFolder,
openstudioPath,
energyplusPath,
honeybeeOpenstudioGemPath,
radiancePath,
})
{
if (!Directory.Exists(path))
{
BH.Engine.Base.Compute.RecordError($"Install Ladybug Tools using the instructions found https://www.food4rhino.com/en/app/ladybug-tools in order to be able to run this method.");
return false;
}
}

return true;
}
}
}

110 changes: 110 additions & 0 deletions LadybugTools_Engine/Compute/ExternalComfortTypology.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, 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>.
*/

using BH.Engine.Python;
using BH.oM.Ladybug;
using BH.oM.Python;
using BH.oM.Base.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using BH.oM.Base;
using System.IO;

namespace BH.Engine.LadybugTools
{
public static partial class Compute
{
[Description("Run an External Comfort simulation and return results.")]
[Input("epw", "An EPW file.")]
[Input("groundMaterial", "A pre-defined ground material.")]
[Input("shadeMaterial", "A pre-defined shade material.")]
[Input("typology", "A pre-defined external comfort typology.")]
[Output("typologyResult", "A typology result object containing simulation results and typology specific comfort metrics.")]
public static CustomObject ExternalComfortTypology(string epw, ExternalComfortMaterial groundMaterial, ExternalComfortMaterial shadeMaterial, BH.oM.Ladybug.ExternalComfortTypology typology)
{
PythonEnvironment pythonEnvironment = Python.Query.LoadPythonEnvironment(Query.ToolkitName());
if (!pythonEnvironment.IsInstalled())
{
BH.Engine.Base.Compute.RecordError($"Install the {Query.ToolkitName()} Python environment before running this method (using {Query.ToolkitName()}.Compute.InstallPythonEnvironment).");
return null;
}

if (!ExternalComfortPossible())
return null;

if (groundMaterial == ExternalComfortMaterial.Undefined || shadeMaterial == ExternalComfortMaterial.Undefined)
{
BH.Engine.Base.Compute.RecordError($"Please input a valid ExternalComfortMaterial.");
return null;
}

if (typology == BH.oM.Ladybug.ExternalComfortTypology.Undefined)
{
BH.Engine.Base.Compute.RecordError($"Please input a valid ExternalComfortTypology.");
return null;
}

if (!File.Exists(epw))
{
BH.Engine.Base.Compute.RecordError($"The EPW file given cannot be found.");
return null;
}

string epwPath = Path.GetFullPath(epw);

string outputPath = Path.Combine(Path.GetTempPath(), $"{System.Guid.NewGuid()}.json");

string pythonScript = String.Join("\n", new List<string>()
{
"import sys",
$"sys.path.insert(0, '{pythonEnvironment.CodeDirectory()}')",
"",
"from ladybug.epw import EPW",
"from external_comfort.external_comfort import ExternalComfort, ExternalComfortResult",
"from external_comfort.material import Material",
"from external_comfort.typology import Typologies, TypologyResult",
"",
$"epw = EPW(r'{epwPath}')",
$"ec = ExternalComfort(epw, ground_material=Material.{groundMaterial}.value, shade_material=Material.{shadeMaterial}.value)",
"ecr = ExternalComfortResult(ec)",
$"typ = Typologies.{typology}.value",
"typr = TypologyResult(typ, ecr)",
$"typr.to_json(r'{outputPath}')",
"print('Nothing to see here!')",
});

string output = Python.Compute.RunPythonString(pythonEnvironment, pythonScript).Trim();

string jsonString = "";
using (StreamReader r = new StreamReader(outputPath))
{
jsonString = r.ReadToEnd();
}


return Serialiser.Convert.FromJson(jsonString) as CustomObject;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
*/

using System.ComponentModel;
using System.IO;

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

namespace BH.Engine.LadybugTools
{
Expand All @@ -37,6 +36,20 @@ public static partial class Compute
[Output("pythonEnvironment", "The LadybugTools_Toolkit Python environment.")]
public static PythonEnvironment InstallLadybugToolsPythonEnvironment(bool run = false, bool force = false)
{
string ladybugToolsDirectory = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile), "ladybug_tools");

if (!Directory.Exists(ladybugToolsDirectory))
BH.Engine.Base.Compute.RecordWarning($"It looks like ladybug_tools are not installed on this machine. Code functionality for Radiance and EnergyPlus simulation will not work without a full installation. Follow instructions https://github.com/ladybug-tools/lbt-grasshopper/wiki/1.1-Windows-Installation-Steps#optional-steps to install it for the latest version of ladybug_tools.");

if (!Directory.Exists(Path.Combine(ladybugToolsDirectory, "openstudio")))
BH.Engine.Base.Compute.RecordWarning($"Openstudio is not installed in {Path.Combine(ladybugToolsDirectory, "openstudio")} and any commands used that call to it will not work. Follow instructions https://github.com/ladybug-tools/lbt-grasshopper/wiki/1.1-Windows-Installation-Steps#optional-steps to install it for the latest version of ladybug_tools.");

if (!Directory.Exists(Path.Combine(ladybugToolsDirectory, "radiance")))
BH.Engine.Base.Compute.RecordWarning($"Radiance is not installed in {Path.Combine(ladybugToolsDirectory, "radiance")} and any commands used that call to it will not work. Follow instructions https://github.com/ladybug-tools/lbt-grasshopper/wiki/1.1-Windows-Installation-Steps#optional-steps to install it for the latest version of ladybug_tools.");

if (!Directory.Exists(Path.Combine(ladybugToolsDirectory, "resources", "measures", "honeybee_openstudio_gem")))
BH.Engine.Base.Compute.RecordWarning($"honeybee-openstudio-gem measures are not available in {Path.Combine(ladybugToolsDirectory, "resources", "measures", "honeybee_openstudio_gem")} and any commands used that call to them will not work. Follow instructions https://github.com/ladybug-tools/lbt-grasshopper/wiki/1.1-Windows-Installation-Steps to install this for the latest version of ladybug_tools.");

// The following checks for beta 5.1 only. These json files to be added to the installer for later versions.
if (!File.Exists(@"C:\ProgramData\BHoM\Settings\Python\LadybugTools_Toolkit.json"))
Base.Compute.RecordError("LadybugTools_Toolkit.json does not exist. Visit the following page for more information: https://github.com/BHoM/LadybugTools_Toolkit/wiki/Beta-version-5.1---Installation-instructions");
Expand Down
Loading