• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WISDEM / WEIS / 14248718711

03 Apr 2025 05:06PM UTC coverage: 60.46% (+5.7%) from 54.799%
14248718711

Pull #372

github

ptrbortolotti
Merge branch 'main' of https://github.com/WISDEM/WEIS into develop
Pull Request #372: Develop

544 of 600 new or added lines in 19 files covered. (90.67%)

3 existing lines in 2 files now uncovered.

8023 of 13270 relevant lines covered (60.46%)

0.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.7
/weis/visualization/appServer/share/vizFileGen.py
1
# This file generates an inputfile for the vizulaization tool.
2
# the user passes the modeling and analysis option files, the tools generated what
3
# we are currently calling the vizInputFile.yaml. This provides the viz tool
4
# with the information it needs to generate the visualizations for the specific run.
5
# The generation of the vizInputFile.yaml will eventually be offloaded to WEIS.
6

7
import os
1✔
8
import numpy as np
1✔
9
import pandas as pd
1✔
10
import argparse
1✔
11
import yaml
1✔
12
import warnings
1✔
13

14
from weis.glue_code.gc_LoadInputs     import WindTurbineOntologyPythonWEIS
1✔
15

16

17
class WEISVizInputFileGenerator:
1✔
18

19
    def __init__(self, fname_modeling_options, fname_opt_options, fname_wt_input):
1✔
20
        self.fname_modeling_options = fname_modeling_options
1✔
21
        self.fname_opt_options = fname_opt_options
1✔
22
        self.fname_wt_input = fname_wt_input
1✔
23
        self.vizInput = {}
1✔
24

25

26
    def fetchWEISinputs(self):
1✔
27
        wt_initial = WindTurbineOntologyPythonWEIS(self.fname_wt_input, self.fname_modeling_options, self.fname_opt_options)
1✔
28
        self.wt_init, self.modeling_options, self.opt_options = wt_initial.get_input_data()
1✔
29

30
    def userOptions(self):
1✔
31
        # Add the user options to the vizInput file
32
        self.vizInput['userOptions'] = {}
1✔
33
        # Run type
34
        self.vizInput['userOptions']['optimization'] = {}
1✔
35
        self.vizInput['userOptions']['optimization']['status'] = self.opt_options['driver']['optimization']['flag']
1✔
36
        
37
        if self.modeling_options['RAFT']['flag']:
1✔
38
            self.vizInput['userOptions']['optimization']['type'] = 1    # RAFT
1✔
39

40
        elif self.modeling_options['OpenFAST_Linear']['flag']:
×
41
            self.vizInput['userOptions']['optimization']['type'] = 2    # not currently supported.
×
42
            warnings.warn("Current WEIS run configuration is not supported by WEIS_Viz")
×
43

44
        elif self.modeling_options['OpenFAST']['flag']:
×
45
            self.vizInput['userOptions']['optimization']['type'] = 3    # OpenFAST, Control
×
46

47
        else:
48
            self.vizInput['userOptions']['optimization']['type'] = 0    # not currently supported.
×
49
            warnings.warn("Current WEIS run configuration is not supported by WEIS_Viz")
×
50

51
        
52
        self.vizInput['userOptions']['deisgn_of_experiments'] = self.opt_options['driver']['design_of_experiments']['flag']
1✔
53
        self.vizInput['userOptions']['inverse_design'] = False if self.opt_options['inverse_design'] == {} else True
1✔
54

55
        # SQL recorder context
56
        self.vizInput['userOptions']['sql_recorder'] = self.opt_options['recorder']['flag']
1✔
57
        self.vizInput['userOptions']['sql_recorder_file'] = self.opt_options['recorder']['file_name']
1✔
58

59
        # Outputs context
60
        self.vizInput['userOptions']['output_folder'] = os.path.join(os.path.split(self.fname_opt_options)[0], self.opt_options['general']['folder_output']) 
1✔
61
        if self.vizInput['userOptions']['output_folder'].endswith(os.sep):      # To get proper basename, it shouldn't be ended with '/'
1✔
NEW
62
            self.vizInput['userOptions']['output_folder'] = self.vizInput['userOptions']['output_folder'].rstrip(os.sep)
×
63
        self.vizInput['userOptions']['output_fileName'] = self.opt_options['general']['fname_output']
1✔
64

65
    def setDefaultUserPreferencs(self):
1✔
66

67
        # Set the default user preferences
68
        self.vizInput['userPreferences'] = {}
1✔
69
        self.vizInput['userPreferences']['openfast'] = {}
1✔
70
        self.vizInput['userPreferences']['openfast']['file_path'] = {}
1✔
71
        self.vizInput['userPreferences']['openfast']['file_path']['file1'] = 'None'
1✔
72

73
        self.vizInput['userPreferences']['openfast']['graph'] = {}
1✔
74
        self.vizInput['userPreferences']['openfast']['graph']['xaxis'] = 'Time'
1✔
75
        self.vizInput['userPreferences']['openfast']['graph']['yaxis'] = ['Wind1VelX', 'GenPwr', 'BldPitch1', 'GenSpeed', 'PtfmPitch']
1✔
76

77
        self.vizInput['userPreferences']['optimization'] = {}
1✔
78
        self.vizInput['userPreferences']['optimization']['convergence'] = {}
1✔
79
        self.vizInput['userPreferences']['optimization']['convergence']['channels'] = ['floating.jointdv_0', 'floating.jointdv_1', 'floating.memgrp1.outer_diameter_in', 'raft.Max_PtfmPitch', 'floatingse.system_structural_mass']
1✔
80
        
81
        # Only for OpenFAST Optimization type
82
        if self.vizInput['userOptions']['optimization']['type'] == 3:
1✔
83
            self.vizInput['userPreferences']['optimization']['dlc'] = {}
×
84
            self.vizInput['userPreferences']['optimization']['dlc']['xaxis'] = 'Wind1VelX'
×
85
            self.vizInput['userPreferences']['optimization']['dlc']['xaxis_stat'] = 'mean'
×
86
            self.vizInput['userPreferences']['optimization']['dlc']['yaxis'] = ['Wind1VelY', 'GenSpeed', 'PtfmPitch']
×
87
            self.vizInput['userPreferences']['optimization']['dlc']['yaxis_stat'] = 'max'
×
88
            self.vizInput['userPreferences']['optimization']['timeseries'] = {}
×
89
            self.vizInput['userPreferences']['optimization']['timeseries']['channels'] = ['Wind1VelX', 'GenPwr', 'BldPitch1', 'GenSpeed', 'PtfmPitch']
×
90

91
        self.vizInput['userPreferences']['wisdem'] = {}
1✔
92
        self.vizInput['userPreferences']['wisdem']['blade'] = {}
1✔
93
        self.vizInput['userPreferences']['wisdem']['blade']['shape_yaxis'] = ['rotorse.rc.chord_m', 'rotorse.re.pitch_axis', 'rotorse.theta_deg']
1✔
94
        self.vizInput['userPreferences']['wisdem']['blade']['struct_yaxis'] = ['rotorse.rhoA_kg/m']
1✔
95
        self.vizInput['userPreferences']['wisdem']['blade']['struct_yaxis_log'] = ['rotorse.EA_N', 'rotorse.EIxx_N*m**2', 'rotorse.EIyy_N*m**2', 'rotorse.GJ_N*m**2']
1✔
96
        self.vizInput['userPreferences']['wisdem']['blade']['xaxis'] = 'rotorse.rc.s'
1✔
97
        self.vizInput['userPreferences']['wisdem']['output_path'] = self.vizInput['userOptions']['output_folder']
1✔
98

99
    def getOutputDirStructure(self):
1✔
100
        self.vizInput['outputDirStructure'] = path_to_dict(self.vizInput['userOptions']['output_folder'],d = {'dirs':{},'files':[]})
1✔
101

102
    def writeVizInputFile(self, fname_output):
1✔
103
        with open(fname_output, 'w') as f:
1✔
104
            yaml.dump(self.vizInput, f, default_flow_style=False)
1✔
105

106

107
def path_to_dict(path, d):
1✔
108

109
    name = os.path.basename(path)
1✔
110

111
    if os.path.isdir(path):
1✔
112
        if name not in d['dirs']:
1✔
113
            d['dirs'][name] = {'dirs':{},'files':[]}
1✔
114
        for x in os.listdir(path):
1✔
115
            path_to_dict(os.path.join(path,x), d['dirs'][name])
1✔
116
    else:
117
        d['files'].append(name)
1✔
118
    
119
    return d
1✔
120

121
def main():
1✔
122

123
    parser = argparse.ArgumentParser(description='WEIS Visualization App')
1✔
124
    parser.add_argument('--modeling_options', 
1✔
125
                        type=str, 
126
                        default='modeling_options.yaml', 
127
                        help='Modeling options file'
128
                        )
129
    
130
    parser.add_argument('--analysis_options', 
1✔
131
                        type=str, 
132
                        default='analysis_options.yaml', 
133
                        help='Analysis options file'
134
                        )
135
    
136
    parser.add_argument('--wt_input', 
1✔
137
                        type=str, 
138
                        default='wt_input.yaml', 
139
                        help='Wind turbine input file'
140
                        )
141
    
142
    parser.add_argument('--output', 
1✔
143
                        type=str, 
144
                        default='vizInputFile.yaml', 
145
                        help='Output file name'
146
                        )
147

148
    args = parser.parse_args()
1✔
149

150
    # Generate the viz input file
151
    viz = WEISVizInputFileGenerator(args.modeling_options, args.analysis_options, args.wt_input)
1✔
152
    viz.fetchWEISinputs()
1✔
153

154
    # Process the user options of importance to the visualization tool
155
    viz.userOptions()
1✔
156

157
    # Set the default user preferences
158
    viz.setDefaultUserPreferencs()
1✔
159

160
    # Get the output directory structure
161
    viz.getOutputDirStructure()
1✔
162

163
    # Write the viz input file
164
    viz.writeVizInputFile(args.output)
1✔
165

166

167
if __name__ == "__main__":
1✔
168
    main()
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc