diff --git a/.lycheeignore b/.lycheeignore new file mode 100644 index 0000000..745f0c6 --- /dev/null +++ b/.lycheeignore @@ -0,0 +1,4 @@ +# Stack Exchange blocks Lychee's automated requests with HTTP 403. +https://stackoverflow\.com/.* +https://unix\.stackexchange\.com/.* +https://apple\.stackexchange\.com/.* diff --git a/data/README.txt b/data/README.txt index b9fdf48..7ee3dfd 100644 --- a/data/README.txt +++ b/data/README.txt @@ -1 +1 @@ -This is a placeholder directory for input/output data for example analyses. +This is a placeholder directory for output data for example analyses. diff --git a/muse2_data_analysis/helpers.py b/muse2_data_analysis/helpers.py index 0f578f7..7950887 100644 --- a/muse2_data_analysis/helpers.py +++ b/muse2_data_analysis/helpers.py @@ -6,20 +6,7 @@ DATA_DIR = Path(__file__).parent.parent.absolute() / "data" EXAMPLE_NAME = "muse1_default" -_INPUT_DIR = DATA_DIR / f"{EXAMPLE_NAME}_input" -_OUTPUT_DIR = DATA_DIR / f"{EXAMPLE_NAME}_output" - - -def get_example_input_dir() -> Path: - """Get the directory for example input data. - - If the folder does not exist, we create it by extracting an example from muse2. - """ - if _INPUT_DIR.exists(): - return _INPUT_DIR - - run_muse2("example", "extract", EXAMPLE_NAME, str(_INPUT_DIR)) - return _INPUT_DIR +_OUTPUT_DIR = DATA_DIR / f"{EXAMPLE_NAME}" def get_example_output_dir() -> Path: @@ -30,9 +17,6 @@ def get_example_output_dir() -> Path: if _OUTPUT_DIR.exists(): return _OUTPUT_DIR - # Ensure INPUT_DIR exists - get_example_input_dir() - # Run the example model - run_muse2("run", str(_INPUT_DIR), "--output-dir", str(_OUTPUT_DIR)) + run_muse2("example", "run", EXAMPLE_NAME, "--output-dir", str(_OUTPUT_DIR)) return _OUTPUT_DIR diff --git a/notebooks/capacity.ipynb b/notebooks/capacity.ipynb index 8f4dcce..0f4e6cf 100644 --- a/notebooks/capacity.ipynb +++ b/notebooks/capacity.ipynb @@ -56,7 +56,7 @@ "assets = pd.read_csv(OUTPUT_DIR / \"assets.csv\")\n", "asset_capacities = pd.read_csv(OUTPUT_DIR / \"asset_capacities.csv\")\n", "\n", - "merged = asset_capacities.merge(assets, on=[\"asset_id\", \"group_id\"])\n", + "merged = asset_capacities.merge(assets, on=\"asset_id\")\n", "agg_capacities = merged.groupby([\"milestone_year\", \"agent_id\", \"process_id\"])[\n", " \"capacity\"\n", "].sum()\n", diff --git a/notebooks/prices.ipynb b/notebooks/prices.ipynb index b8d9831..8c118de 100644 --- a/notebooks/prices.ipynb +++ b/notebooks/prices.ipynb @@ -23,8 +23,8 @@ "\n", "from muse2_data_analysis.helpers import get_example_output_dir\n", "\n", - "INPUT_DIR = get_example_output_dir()\n", - "prices = pd.read_csv(INPUT_DIR / \"commodity_prices.csv\")\n", + "OUTPUT_DIR = get_example_output_dir()\n", + "prices = pd.read_csv(OUTPUT_DIR / \"commodity_prices.csv\")\n", "prices.head()" ] }, diff --git a/tests/test_helpers.py b/tests/test_helpers.py index dd4ce39..5c5d545 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -6,35 +6,6 @@ from muse2_data_analysis import helpers -@patch("muse2_data_analysis.helpers.run_muse2") -def test_get_example_input_dir_returns_existing_directory( - run_muse2_mock: Mock, tmp_path: Path -) -> None: - """Check that get_example_input_dir returns an existing input directory.""" - input_dir = tmp_path / "input" - input_dir.mkdir() - - with patch.object(helpers, "_INPUT_DIR", input_dir): - assert helpers.get_example_input_dir() == input_dir - - run_muse2_mock.assert_not_called() - - -@patch("muse2_data_analysis.helpers.run_muse2") -def test_get_example_input_dir_extracts_example_when_missing( - run_muse2_mock: Mock, tmp_path: Path -) -> None: - """Check that get_example_input_dir extracts the example when missing.""" - input_dir = tmp_path / "input" - - with patch.object(helpers, "_INPUT_DIR", input_dir): - assert helpers.get_example_input_dir() == input_dir - - run_muse2_mock.assert_called_once_with( - "example", "extract", helpers.EXAMPLE_NAME, str(input_dir) - ) - - @patch("muse2_data_analysis.helpers.run_muse2") def test_get_example_output_dir_returns_existing_directory( run_muse2_mock: Mock, tmp_path: Path @@ -50,20 +21,15 @@ def test_get_example_output_dir_returns_existing_directory( @patch("muse2_data_analysis.helpers.run_muse2") -@patch("muse2_data_analysis.helpers.get_example_input_dir") def test_get_example_output_dir_runs_example_when_missing( - get_example_input_dir_mock: Mock, run_muse2_mock: Mock, tmp_path: Path + run_muse2_mock: Mock, tmp_path: Path ) -> None: - """Check that get_example_output_dir ensures input exists and runs the model.""" - input_dir = tmp_path / "input" + """Check that get_example_output_dir runs the example when output is missing.""" output_dir = tmp_path / "output" - get_example_input_dir_mock.return_value = input_dir - with patch.object(helpers, "_INPUT_DIR", input_dir): - with patch.object(helpers, "_OUTPUT_DIR", output_dir): - assert helpers.get_example_output_dir() == output_dir + with patch.object(helpers, "_OUTPUT_DIR", output_dir): + assert helpers.get_example_output_dir() == output_dir - get_example_input_dir_mock.assert_called_once_with() run_muse2_mock.assert_called_once_with( - "run", str(input_dir), "--output-dir", str(output_dir) + "example", "run", helpers.EXAMPLE_NAME, "--output-dir", str(output_dir) )