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

WISDEM / WEIS / 10425728291

16 Aug 2024 08:16PM UTC coverage: 79.079%. Remained the same
10425728291

Pull #307

github

web-flow
Merge cf74152f4 into 1767dafbb
Pull Request #307: Debug arg parsing error while launching the app & Contribute Initial Documentation

21602 of 27317 relevant lines covered (79.08%)

0.79 hits per line

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

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

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

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

11
import openmdao.api as om
×
12

13
from weis.visualization.utils import *
×
14

15

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

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

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

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

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

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

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

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
        )
84
        dataOM = map_dataOM_vars[method][0]
×
85
        vars = map_dataOM_vars[method][1]
×
86
        tfeas, varfeas = get_feasible_iterations(dataOM, vars, feas_tol=feas_tol)
×
87

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

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
            )
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
            )
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
            )
147
            if has_ref_vals:
×
148
                cval = key_val_map[key]
×
149
                if cval[0] is not None:
×
150
                    axes[idx_ax, 0].plot([0, len(dataOM[key])], [cval[0], cval[0]], "b:", label="_lower bound_")
×
151
                if cval[1] is not None:
×
152
                    axes[idx_ax, 0].plot([0, len(dataOM[key])], [cval[1], cval[1]], "r:", label="_upper bound_")
×
153
            axes[idx_ax, 0].set_title(key)
×
154

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

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