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

Return metadata for underlying collections when generating plots #220

Merged
merged 31 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0bfb45c
save point for many files, added method for getting meta data from wi…
Tom-Kingstone Jul 8, 2024
01b8a20
added data collection metadata method
Tom-Kingstone Jul 9, 2024
c201cca
serialisation/deserialisation now works for heatmaps
Tom-Kingstone Jul 10, 2024
639bc9b
fixed prevailing direction issue by ignoring calm hours, and implemen…
Tom-Kingstone Jul 10, 2024
04b5ed5
fixed incorrect namespace
Tom-Kingstone Jul 10, 2024
3ca05b2
updated to return plotinfo for diurnal and sunpath
Tom-Kingstone Jul 10, 2024
f9f152b
fixed incorrect sunpath method name
Tom-Kingstone Jul 10, 2024
642d734
added bhom analytics to metadata methods
Tom-Kingstone Jul 10, 2024
0ebabfc
Resolve copyright compliance
BHoMBot Jul 10, 2024
42fa73b
fixed versioning
Tom-Kingstone Jul 10, 2024
20d4f21
fix versioning better
Tom-Kingstone Jul 10, 2024
f018a37
versioning
Tom-Kingstone Jul 10, 2024
7dec726
try versioning again
Tom-Kingstone Jul 10, 2024
f1bb964
versioning morer
Tom-Kingstone Jul 10, 2024
d4a6a00
Update LadybugTools_Engine/Convert/HexCode.cs
FraserGreenroyd Jul 10, 2024
e7a4b1b
Update LadybugTools_Engine/Convert/HexCode.cs
FraserGreenroyd Jul 10, 2024
f301bd8
Update LadybugTools_Engine/Convert/HexCode.cs
FraserGreenroyd Jul 10, 2024
f93ef1d
Update LadybugTools_Engine/Convert/HexCode.cs
FraserGreenroyd Jul 10, 2024
d4780d3
Update LadybugTools_Engine/Convert/HexCode.cs
FraserGreenroyd Jul 10, 2024
f46d01b
final try on versioning before going over to versioning toolkit
Tom-Kingstone Jul 11, 2024
ec77fdb
added noautoconstructor to UTCIData, and updated docstrings for added…
Tom-Kingstone Jul 15, 2024
19ae9c6
moved collection_metadata to bhom/wrapped, and added method that gets…
Tom-Kingstone Jul 17, 2024
0c19bcb
moved wind metadata to bhom/wrapped and added method that gets the pr…
Tom-Kingstone Jul 17, 2024
ca70a3d
moved metadata for all other plots to bhom/wrapped and changed sunpat…
Tom-Kingstone Jul 17, 2024
57a8d50
moved metadata methods to separate folder
Tom-Kingstone Jul 23, 2024
1febd75
fix for #228 and update import paths
Tom-Kingstone Jul 29, 2024
7935a99
added python output to error message
Tom-Kingstone Jul 30, 2024
9804f9f
added method separators and fallback for ToSimulationData
Tom-Kingstone Jul 31, 2024
bdf7545
added descriptions to ISimulationData objects.
Tom-Kingstone Jul 31, 2024
7df2c7b
fixes from review
Tom-Kingstone Jul 31, 2024
8cbd052
Additional changes
jamesramsden-bh Aug 1, 2024
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
102 changes: 81 additions & 21 deletions LadybugTools_Adapter/AdapterActions/Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
using BH.Engine.Base;
using System.Drawing;
using BH.Engine.Serialiser;
using BH.Engine.LadyBugTools;
using System.Reflection;

namespace BH.Adapter.LadybugTools
Expand Down Expand Up @@ -312,12 +311,25 @@ private List<object> RunCommand(HeatPlotCommand command, ActionConfig actionConf
if (colourMap.ColourMapValidity())
colourMap = colourMap.ToColourMap().FromColourMap();

string returnFile = Path.GetTempFileName();

// run the process
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -cmap \"{colourMap}\" -p \"{command.OutputLocation}\"";
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -cmap \"{colourMap}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);

if (!File.Exists(result))
{
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
File.Delete(returnFile);
return new List<object>();
}

CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
File.Delete(returnFile);
PlotInformation info = Convert.ToPlotInformation(obj, new CollectionData());

m_executeSuccess = true;
return new List<object>() { result };
return new List<object>() { info };
}

/**************************************************/
Expand Down Expand Up @@ -351,12 +363,25 @@ private List<object> RunCommand(WindroseCommand command, ActionConfig actionConf
if (colourMap.ColourMapValidity())
colourMap = colourMap.ToColourMap().FromColourMap();

string returnFile = Path.GetTempFileName();

// run the process
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -cmap \"{colourMap}\" -bins \"{command.NumberOfDirectionBins}\" -p \"{command.OutputLocation}\"";
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -cmap \"{colourMap}\" -bins \"{command.NumberOfDirectionBins}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);

if (!File.Exists(result))
{
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
File.Delete(returnFile);
return new List<object>();
}

CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
File.Delete(returnFile);
PlotInformation info = Convert.ToPlotInformation(obj, new WindroseData());

m_executeSuccess = true;
return new List<object> { result };
return new List<object> { info };
}

/**************************************************/
Expand Down Expand Up @@ -397,6 +422,7 @@ private List<object> RunCommand(UTCIHeatPlotCommand command, ActionConfig action
BH.Engine.Base.Compute.RecordError($"When overriding bin colours 10 colours must be provided, but {command.BinColours.Count} colours were provided instead.");
return null;
}

List<string> colours = command.BinColours.Select(x => x.ToHexCode()).ToList();

string hexColours = $"[\"{string.Join("\",\"", colours)}\"]";
Expand All @@ -418,25 +444,29 @@ private List<object> RunCommand(UTCIHeatPlotCommand command, ActionConfig action

string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "utci_heatmap.py");

string returnFile = Path.GetTempFileName();

// run the process
string cmdCommand = $"{m_environment.Executable} \"{script}\" -e \"{epwFile}\" -in \"{argFile}\" -ws \"{command.WindSpeedMultiplier}\" -sp \"{command.OutputLocation}\"";
string result = "";
string cmdCommand = $"{m_environment.Executable} \"{script}\" -e \"{epwFile}\" -in \"{argFile}\" -ws \"{command.WindSpeedMultiplier}\" -r \"{returnFile.Replace('\\', '/')}\" -sp \"{command.OutputLocation}\"";
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);

try
{
result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
}
catch (Exception ex)
{
BH.Engine.Base.Compute.RecordError(ex, "An error occurred while running some python.");
}
finally
string resultFile = result.Split('\n').Last();

if (!File.Exists(resultFile))
{
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
File.Delete(returnFile);
File.Delete(argFile);
return new List<object>();
}

CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
File.Delete(returnFile);
File.Delete(argFile);
PlotInformation info = Convert.ToPlotInformation(obj, new UTCIData());

m_executeSuccess = true;
return new List<object> { result.Split('\n').Last() };
return new List<object> { info };
}

/**************************************************/
Expand Down Expand Up @@ -473,12 +503,27 @@ private List<object> RunCommand(DiurnalPlotCommand command, ActionConfig actionC

string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "diurnal.py");

string returnFile = Path.GetTempFileName();

// run the process
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -c \"{command.Colour.ToHexCode()}\" -t \"{command.Title}\" -ap \"{command.Period.ToString().ToLower()}\" -p \"{command.OutputLocation}\"";
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -c \"{command.Colour.ToHexCode()}\" -t \"{command.Title}\" -ap \"{command.Period.ToString().ToLower()}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);

string resultFile = result.Split('\n').Last();

if (!File.Exists(resultFile))
{
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
File.Delete(returnFile);
return new List<object>();
}

CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
File.Delete(returnFile);
PlotInformation info = Convert.ToPlotInformation(obj, new CollectionData());

m_executeSuccess = true;
return new List<object>() { result.Split('\n').Last() };
return new List<object>() { info };
}

/**************************************************/
Expand Down Expand Up @@ -513,12 +558,27 @@ private List<object> RunCommand(SunPathPlotCommand command, ActionConfig actionC

string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "sunpath.py");

string returnFile = Path.GetTempFileName();

//run the process
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -s {command.SunSize} -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -p \"{command.OutputLocation}\"";
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -s {command.SunSize} -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
string result = Engine.Python.Compute.RunCommandStdout(cmdCommand, hideWindows: true);

string resultFile = result.Split('\n').Last();

if (!File.Exists(resultFile))
{
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
File.Delete(returnFile);
return new List<object>();
}

CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
File.Delete(returnFile);
PlotInformation info = Convert.ToPlotInformation(obj, new SunPathData());

m_executeSuccess = true;
return new List<object>() { result.Split('\n').Last() };
return new List<object>() { info };
}

/**************************************************/
Expand Down
Loading