Skip to content

Commit 40b2b03

Browse files
committed
Add some helper functions for notebooks
1 parent 46a64fc commit 40b2b03

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

data/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!README.txt
3+
!.gitignore

data/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a placeholder directory for input/output data for example analyses.

muse2_data_analysis/helpers.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Helper functions for notebooks."""
2+
3+
from pathlib import Path
4+
5+
from . import run_muse2
6+
7+
DATA_DIR = Path(__file__).parent.parent.absolute() / "data"
8+
EXAMPLE_NAME = "muse1_default"
9+
_INPUT_DIR = DATA_DIR / f"{EXAMPLE_NAME}_input"
10+
_OUTPUT_DIR = DATA_DIR / f"{EXAMPLE_NAME}_output"
11+
12+
13+
def get_example_input_dir() -> Path:
14+
"""Get the directory for example input data.
15+
16+
If the folder does not exist, we create it by extracting an example from muse2.
17+
"""
18+
if _INPUT_DIR.exists():
19+
return _INPUT_DIR
20+
21+
run_muse2("example", "extract", EXAMPLE_NAME, str(_INPUT_DIR))
22+
return _INPUT_DIR
23+
24+
25+
def get_example_output_dir() -> Path:
26+
"""Get the directory for example output data.
27+
28+
If the folder does not exist, we create it by running an example model with muse2.
29+
"""
30+
if _OUTPUT_DIR.exists():
31+
return _OUTPUT_DIR
32+
33+
# Ensure INPUT_DIR exists
34+
get_example_input_dir()
35+
36+
# Run the example model
37+
run_muse2("run", str(_INPUT_DIR), "--output-dir", str(_OUTPUT_DIR))
38+
return _OUTPUT_DIR

0 commit comments

Comments
 (0)