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

WISDEM / WEIS / 9938786759

15 Jul 2024 11:46AM UTC coverage: 79.516% (+8.6%) from 70.904%
9938786759

push

github

web-flow
Merge pull request #289 from WISDEM/develop

Release with improved installation

163 of 521 new or added lines in 17 files covered. (31.29%)

707 existing lines in 19 files now uncovered.

21602 of 27167 relevant lines covered (79.52%)

0.8 hits per line

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

0.0
/weis/visualization/opt_plotting.py
NEW
1
import glob
×
2

NEW
3
import glob
×
NEW
4
import json
×
NEW
5
import multiprocessing as mp
×
6

NEW
7
import pandas as pd
×
NEW
8
import numpy as np
×
NEW
9
import matplotlib.pyplot as plt
×
10

NEW
11
import openmdao.api as om
×
12

NEW
13
from weis.visualization.utils import *
×
14

15

NEW
16
def plot_conv(
×
17
    keyset_in,
18
    map_dataOM_vars,
19
    use_casewise_feasibility=False,
20
    feas_tol=1e-5,
21
    figax=None,
22
    alpha=None,
23
):
24
    """
25
    plot a set of keys
26

27
    args:
28
        keyset_in: list[str]
29
            list of keys to plot the convergence data for
30
        map_dataOM_vars: dict[str -> dict]
31
            map from a case of interest by name to an OM data dict to plot
32
        use_casewise_feasibility: bool
33
            if plotting a constraint should we plot feasibility w.r.t. that constraint (vs. all)
34

35
    returns:
36
        fig : plt.Figure
37
        ax : plt.Axes
38
    """
39

NEW
40
    if len(keyset_in) == 0:
×
NEW
41
        return
×
42

NEW
43
    markerstyle = "x"
×
NEW
44
    markersize = 5
×
NEW
45
    linestyle = "-"
×
46

NEW
47
    fig, axes = plt.subplots(
×
48
        len(keyset_in),
49
        1,
50
        sharex=True,
51
        figsize=(6, 0.60 * 4 * len(keyset_in)),
52
        squeeze=False,
53
        dpi=150,
54
    )
55

NEW
56
    has_ref_vals = type(keyset_in) == dict
×
57

NEW
58
    if has_ref_vals:
×
NEW
59
        key_val_map = keyset_in
×
NEW
60
        keyset = keyset_in.keys()
×
61
    else:
NEW
62
        keyset = keyset_in
×
63

NEW
64
    pt_imethod = []
×
NEW
65
    for imethod, method in enumerate(map_dataOM_vars.keys()):
×
NEW
66
        if imethod == 0:
×
NEW
67
            markerstyle = "o"
×
NEW
68
        elif imethod == 1:
×
NEW
69
            markerstyle = "p"
×
NEW
70
        elif imethod == 2:
×
NEW
71
            markerstyle = "s"
×
72
        else:
NEW
73
            markerstyle = "P"
×
74

NEW
75
        pt0 = axes[0, 0].plot(
×
76
            [],
77
            [],
78
            markerstyle + linestyle,
79
            label=method,
80
            markersize=markersize,
81
            # color=(0.5,0.5,0.5),
82
            alpha=alpha,
83
        )
NEW
84
        dataOM = map_dataOM_vars[method][0]
×
NEW
85
        vars = map_dataOM_vars[method][1]
×
NEW
86
        tfeas, varfeas = get_feasible_iterations(dataOM, vars, feas_tol=feas_tol)
×
87

NEW
88
        for idx_ax, key in enumerate(keyset):
×
NEW
89
            if key in ["rank", "iter",]: continue
×
NEW
90
            if use_casewise_feasibility and key in varfeas.keys():
×
NEW
91
                feas_val = varfeas[key]
×
92
            else:
NEW
93
                feas_val = tfeas  # use total feasibility
×
94

NEW
95
            axes[idx_ax, 0].plot(
×
96
                np.squeeze(dataOM[key]),
97
                linestyle,
98
                label="".join(["_", method, "_"]),
99
                color=pt0[-1].get_color(),
100
                markersize=markersize,
101
                alpha=alpha,
102
            )
NEW
103
            axes[idx_ax, 0].plot(
×
104
                np.ma.array(
105
                    dataOM[key],
106
                    mask=~(
107
                        feas_val * np.ones(
108
                            (
109
                                1,
110
                                np.array(dataOM[key]).shape[1]
111
                                if len(np.array(dataOM[key]).shape) > 1
112
                                else 1
113
                            ),
114
                            dtype=bool,
115
                        )
116
                    )
117
                ),
118
                markerstyle,
119
                label="".join(["_", method, "_"]),
120
                color=pt0[-1].get_color(),
121
                alpha=alpha,
122
                fillstyle="full",
123
                markersize=markersize,
124
            )
NEW
125
            axes[idx_ax, 0].plot(
×
126
                np.ma.array(
127
                    dataOM[key],
128
                    mask=(
129
                        feas_val * np.ones(
130
                            (
131
                                1,
132
                                np.array(dataOM[key]).shape[1]
133
                                if len(np.array(dataOM[key]).shape) > 1
134
                                else 1
135
                            ),
136
                            dtype=bool,
137
                        )
138
                    )
139
                ),
140
                markerstyle,
141
                label="".join(["_", method, "_"]),
142
                color=pt0[-1].get_color(),
143
                alpha=alpha,
144
                fillstyle="none",
145
                markersize=markersize,
146
            )
NEW
147
            if has_ref_vals:
×
NEW
148
                cval = key_val_map[key]
×
NEW
149
                if cval[0] is not None:
×
NEW
150
                    axes[idx_ax, 0].plot([0, len(dataOM[key])], [cval[0], cval[0]], "b:", label="_lower bound_")
×
NEW
151
                if cval[1] is not None:
×
NEW
152
                    axes[idx_ax, 0].plot([0, len(dataOM[key])], [cval[1], cval[1]], "r:", label="_upper bound_")
×
NEW
153
            axes[idx_ax, 0].set_title(key)
×
154

NEW
155
    if has_ref_vals:
×
NEW
156
        axes[0, 0].plot([], [], "b:", label="lower bound")
×
NEW
157
        axes[0, 0].plot([], [], "r:", label="upper bound")
×
NEW
158
    axes[0, 0].legend()
×
NEW
159
    fig.tight_layout()
×
160

NEW
161
    return fig, axes
×
162

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

© 2025 Coveralls, Inc