Skip to content

Commit bec20d8

Browse files
committed
Fix Netlify build and add two-output function to simdec_app.py
1 parent 3b581ab commit bec20d8

5 files changed

Lines changed: 44 additions & 44 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ app.html
4040
venv/
4141
.venv/
4242
.wasm-build-venv/
43+
44+
# Local Netlify folder
45+
.netlify

netlify.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,17 @@
22
command = "npm run build"
33
publish = "dist/pyodide"
44

5+
[dev]
6+
# Prevent Netlify from watching these folders for changes
7+
ignore = ["dist", ".wasm-build-venv", "panel/data"]
8+
# Force it to use a specific port to avoid EADDRINUSE
9+
port = 8888
10+
511
[build.environment]
612
PYTHON_VERSION = "3.11"
13+
14+
[[headers]]
15+
for = "/*"
16+
[headers.values]
17+
Cross-Origin-Embedder-Policy = "require-corp"
18+
Cross-Origin-Opener-Policy = "same-origin"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"description": "Static Panel WASM build wrapper",
66
"scripts": {
77
"build": "bash ./scripts/build_wasm.sh",
8-
"serve": "python3 -m http.server 8000 --directory dist/pyodide"
8+
"serve": "mkdir -p dist/pyodide && python3 -m http.server 8000 --directory dist/pyodide"
99
}
1010
}

panel/simdec_app.py

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import pandas as pd
1212
from pandas.io.formats.style import Styler
1313
import panel as pn
14-
import seaborn as sns
1514

1615
import simdec as sd
1716
from simdec.sensitivity_indices import SensitivityAnalysisResult
@@ -43,10 +42,15 @@
4342
)
4443

4544
VALID_CHARACTERS = re.compile(r"[^A-Za-z0-9_ \-.]")
46-
try:
47-
DEFAULT_STRESS_CSV = Path(__file__).resolve().parent / "data" / "stress.csv"
48-
except NameError:
45+
# try:
46+
# DEFAULT_STRESS_CSV = Path(__file__).resolve().parent / "data" / "stress.csv"
47+
# except NameError:
48+
# DEFAULT_STRESS_CSV = Path("data/stress.csv")
49+
if Path("data/stress.csv").exists():
4950
DEFAULT_STRESS_CSV = Path("data/stress.csv")
51+
else:
52+
# Fallback for if the zip was flattened or file is in the root
53+
DEFAULT_STRESS_CSV = Path("stress.csv")
5054
GENERIC_ERROR_MSG = (
5155
"Could not parse the CSV file. "
5256
"Please check that it uses commas ',' as the delimiter "
@@ -262,49 +266,18 @@ def figure_pn(
262266
ax.set(xlabel=output_name)
263267
ax.set_xlim(xlim)
264268
else:
265-
fig, axs = plt.subplots(2, 2, sharex="col", sharey="row", figsize=(8, 8))
266-
267-
axs[0][1].axison = False
268-
269-
_ = sd.visualization(
269+
fig, _ = sd.two_output_visualization(
270270
bins=res.bins,
271+
bins2=res2.bins,
271272
palette=palette,
272273
n_bins=n_bins,
273-
kind="histogram",
274-
ax=axs[0][0],
275-
)
276-
axs[0][0].set_xlim(xlim)
277-
axs[0][0].set_box_aspect(aspect=1)
278-
axs[0][0].axis("off")
279-
280-
data = pd.concat([pd.melt(res.bins), pd.melt(res2.bins)["value"]], axis=1)
281-
data.columns = ["c", "x", "y"]
282-
data = data.sample(int(r_scatter * len(data)))
283-
_ = sns.scatterplot(
284-
data, x="x", y="y", hue="c", palette=palette, ax=axs[1][0], legend=False
285-
)
286-
axs[1][0].set(xlabel=output_name)
287-
axs[1][0].set(ylabel=output_2_name)
288-
axs[1][0].set_box_aspect(aspect=1)
289-
290-
_ = sns.histplot(
291-
data,
292-
y="y",
293-
hue="c",
294-
multiple="stack",
295-
stat="probability",
296-
palette=palette,
297-
common_bins=True,
298-
common_norm=True,
299-
bins=40,
300-
legend=False,
301-
ax=axs[1][1],
274+
output_name=output_name,
275+
output_name2=output_2_name,
276+
xlim=xlim,
277+
ylim=ylim,
278+
r_scatter=r_scatter,
302279
)
303-
axs[1][1].set_ylim(ylim)
304-
axs[1][1].set_box_aspect(aspect=1)
305-
axs[1][1].axis("off")
306280

307-
fig.subplots_adjust(wspace=-0.015, hspace=0)
308281
return fig
309282

310283

scripts/build_wasm.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ set -x
55

66
# Setup paths and environment
77
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
8+
OUT_DIR="${ROOT_DIR}/dist/pyodide"
9+
10+
# Wipe old build before starting
11+
if [ -d "${OUT_DIR}" ]; then
12+
echo "Cleaning old build..."
13+
rm -rf "${OUT_DIR}"
14+
fi
15+
816
cd "${ROOT_DIR}"
917

1018
# Determine which Python interpreter to use
@@ -51,7 +59,6 @@ WHEEL_FILENAME=$(basename "${SIMDEC_WHEEL_PATH}")
5159
OUT_DIR="${ROOT_DIR}/dist/pyodide"
5260
mkdir -p "${OUT_DIR}/_static"
5361
mkdir -p "${OUT_DIR}/data"
54-
mkdir -p "${OUT_DIR}/panel/data"
5562

5663
# Copy the wheel into the output directory so it's accessible via HTTP
5764
cp "${SIMDEC_WHEEL_PATH}" "${OUT_DIR}/"
@@ -89,6 +96,9 @@ if [[ ! -f "data/stress.csv" ]]; then
8996
fi
9097
fi
9198

99+
# Copy stress.csv to output directory
100+
cp "data/stress.csv" "${OUT_DIR}/data/"
101+
92102
# Run conversion
93103
"${PYTHON_BIN}" -m panel convert \
94104
simdec_app.py \
@@ -98,6 +108,8 @@ fi
98108
--requirements "${WHEEL_FILENAME}" numpy pandas matplotlib seaborn scipy SALib \
99109
--resources data/stress.csv
100110

111+
cp "./${WHEEL_FILENAME}" "${OUT_DIR}/"
112+
101113
# Clean up the copied wheel
102114
rm "${WHEEL_FILENAME}"
103115

0 commit comments

Comments
 (0)