|
| 1 | +from pathlib import Path |
| 2 | +from typing_extensions import Annotated |
| 3 | + |
| 4 | +import matplotlib.pyplot as plt |
| 5 | +import pandas as pd |
| 6 | +import panel as pn |
| 7 | +import typer |
| 8 | + |
| 9 | +import simdec as sd |
| 10 | + |
| 11 | +app = typer.Typer() |
| 12 | + |
| 13 | + |
| 14 | +@app.command() |
| 15 | +def main( |
| 16 | + data: Annotated[ |
| 17 | + Path, |
| 18 | + typer.Option( |
| 19 | + exists=True, |
| 20 | + file_okay=True, |
| 21 | + dir_okay=False, |
| 22 | + writable=False, |
| 23 | + readable=True, |
| 24 | + resolve_path=True, |
| 25 | + ), |
| 26 | + ] |
| 27 | +): |
| 28 | + data = pd.read_csv(data) |
| 29 | + output_name, *inputs_names = list(data.columns) |
| 30 | + inputs, output = data[inputs_names], data[output_name] |
| 31 | + |
| 32 | + res = sd.sensitivity_indices(inputs=inputs, output=output) |
| 33 | + si = res.si |
| 34 | + |
| 35 | + res = sd.decomposition(inputs=inputs, output=output, sensitivity_indices=si) |
| 36 | + |
| 37 | + fig, ax = plt.subplots() |
| 38 | + palette = sd.palette(states=res.states) |
| 39 | + _ = sd.visualization(bins=res.bins, palette=palette, ax=ax) |
| 40 | + |
| 41 | + # use a notebook to see the styling |
| 42 | + table, styler = sd.tableau( |
| 43 | + statistic=res.statistic, |
| 44 | + var_names=res.var_names, |
| 45 | + states=res.states, |
| 46 | + bins=res.bins, |
| 47 | + palette=palette[::-1], |
| 48 | + ) |
| 49 | + |
| 50 | + # panel app |
| 51 | + pn.extension(template="material") |
| 52 | + pn_fig = pn.pane.Matplotlib(fig, dpi=144) |
| 53 | + pn_table = pn.pane.DataFrame(styler) |
| 54 | + pn_app = pn.Column(pn_fig, pn_table) |
| 55 | + pn_app.save("app.html") |
0 commit comments