Skip to content

Commit

Permalink
env.yml update for visualization tool (#278)
Browse files Browse the repository at this point in the history
* env.yml update for visualization tool

* Add visualization utilities

* corrected accidental git deletion

* Revert "corrected accidental git deletion"

This reverts commit d32c4b3.

---------

Co-authored-by: dzalkind <dzalkind@nrel.gov>
Co-authored-by: Cory Frontin <cory.frontin@nrel.gov>
  • Loading branch information
3 people committed Jun 12, 2024
1 parent 86724c1 commit e43a159
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ channels:
- defaults

dependencies:
- dash
- dill
- jsonmerge
- mat4py
Expand All @@ -15,6 +16,8 @@ dependencies:
- smt
- wisdem
- pip:
- dash-bootstrap-components
- dash-mantine-components
- dearpygui
- marmot-agents
# Needs to be done outside of environment file:
Expand Down
Empty file added weis/visualization/__init__.py
Empty file.
84 changes: 84 additions & 0 deletions weis/visualization/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
'''
Various functions for help visualizing WEIS outputs
'''
from weis.aeroelasticse.FileTools import load_yaml
import pandas as pd
import numpy as np
import openmdao.api as om


try:
import ruamel_yaml as ry
except Exception:
try:
import ruamel.yaml as ry
except Exception:
raise ImportError('No module named ruamel.yaml or ruamel_yaml')

def read_cm(cm_file):
"""
Function originally from:
https://github.com/WISDEM/WEIS/blob/main/examples/16_postprocessing/rev_DLCs_WEIS.ipynb
Parameters
__________
cm_file : The file path for case matrix
Returns
_______
cm : The dataframe of case matrix
dlc_inds : The indices dictionary indicating where corresponding dlc is used for each run
"""
cm_dict = load_yaml(cm_file, package=1)
cnames = []
for c in list(cm_dict.keys()):
if isinstance(c, ry.comments.CommentedKeySeq):
cnames.append(tuple(c))
else:
cnames.append(c)
cm = pd.DataFrame(cm_dict, columns=cnames)

return cm

def parse_contents(data):
"""
Function from:
https://github.com/WISDEM/WEIS/blob/main/examples/09_design_of_experiments/postprocess_results.py
"""
collected_data = {}
for key in data.keys():
if key not in collected_data.keys():
collected_data[key] = []

for key_idx, _ in enumerate(data[key]):
if isinstance(data[key][key_idx], int):
collected_data[key].append(np.array(data[key][key_idx]))
elif len(data[key][key_idx]) == 1:
try:
collected_data[key].append(np.array(data[key][key_idx][0]))
except:
collected_data[key].append(np.array(data[key][key_idx]))
else:
collected_data[key].append(np.array(data[key][key_idx]))

df = pd.DataFrame.from_dict(collected_data)

return df


def load_OMsql(log):
"""
Function from :
https://github.com/WISDEM/WEIS/blob/main/examples/09_design_of_experiments/postprocess_results.py
"""
# logging.info("loading ", log)
cr = om.CaseReader(log)
rec_data = {}
cases = cr.get_cases('driver')
for case in cases:
for key in case.outputs.keys():
if key not in rec_data:
rec_data[key] = []
rec_data[key].append(case[key])

return rec_data

0 comments on commit e43a159

Please sign in to comment.