Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions src/muse/data/example/default_timeslice/output.py

This file was deleted.

4 changes: 0 additions & 4 deletions src/muse/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,6 @@ def _copy_default_timeslice(path: Path):
example_data_dir() / "default_timeslice" / "settings.toml",
path / "settings.toml",
)
copyfile(
example_data_dir() / "default_timeslice" / "output.py",
path / "output.py",
)


def _copy_multiple_agents(path: Path):
Expand Down
27 changes: 0 additions & 27 deletions src/muse/readers/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,33 +875,6 @@ def read_trade(
return result.rename(src_region="region")


def read_finite_resources(path: Union[str, Path]) -> xr.DataArray:
"""Reads finite resources from csv file.

The CSV file is made up of columns "Region", "Year", as well
as three timeslice columns ("Month", "Day", "Hour"). All three sets of columns are
optional. The timeslice set should contain a full set of timeslices, if present.
Other columns correspond to commodities.
"""
from muse.timeslices import TIMESLICE

data = pd.read_csv(path)
data.columns = [c.lower() for c in data.columns]
ts_levels = TIMESLICE.get_index("timeslice").names

if set(data.columns).issuperset(ts_levels):
timeslice = pd.MultiIndex.from_arrays(
[data[u] for u in ts_levels], names=ts_levels
)
timeslice = pd.DataFrame(timeslice, columns=["timeslice"])
data = pd.concat((data, timeslice), axis=1)
data.drop(columns=ts_levels, inplace=True)
indices = list({"year", "region", "timeslice"}.intersection(data.columns))
data.set_index(indices, inplace=True)

return xr.Dataset.from_dataframe(data).to_array(dim="commodity")


def check_utilization_and_minimum_service_factors(data, filename):
if "utilization_factor" not in data.columns:
raise ValueError(
Expand Down
40 changes: 0 additions & 40 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ def logger():
return logger


@fixture()
def sectors_dir(tmpdir):
"""Copies sectors directory to new dir.

This gives some assurance the machinery for specifying sectors data actually works.
"""
from shutil import copytree

from muse.defaults import DEFAULT_SECTORS_DIRECTORY

copytree(DEFAULT_SECTORS_DIRECTORY, tmpdir.join("sectors_data_dir"))
return tmpdir.join("sectors_data_dir")


def compare_df(
expected: DataFrame,
actual: DataFrame,
Expand Down Expand Up @@ -376,17 +362,6 @@ def retro_agent(agent_args, technologies, stock) -> Agent:
return create_agent(agent_args, technologies, stock.capacity, "retrofit")


@fixture
def objective(retro_agent, coords) -> DataArray:
from numpy.random import choice, rand

asset = retro_agent.assets.technology.rename(technology="asset")
techs = [i for i in coords["technology"] if choice((True, False))]
data = rand(len(asset), len(techs))
coords = {"asset": asset, "technology": techs}
return DataArray(data, coords=coords, dims=("asset", "technology"))


@fixture
def stock(coords, technologies) -> Dataset:
return _stock(coords, technologies)
Expand Down Expand Up @@ -447,21 +422,6 @@ def _stock(
return result


@fixture
def assets(coords, technologies) -> Dataset:
"""Stock with repeat technologies."""
from xarray import concat

return concat(
(
_stock(coords, technologies),
_stock(coords, technologies),
_stock(coords, technologies),
),
dim="technology",
)


@fixture
def search_space(retro_agent, technologies):
"""Example search space, as would be computed by an agent."""
Expand Down
31 changes: 1 addition & 30 deletions tests/test_investments.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
from pytest import fixture, mark


@fixture
def capacity_expansion():
from numpy import arange
from numpy.random import rand
from xarray import Dataset

from muse.investments import CapacityAddition

data = Dataset()
data["asset"] = "asset", arange(5, 10)
data["replacement"] = "replacement", arange(0, 6)
data["ranks"] = data.asset + data.replacement // 2
data["ranks"] = data.ranks.rank("replacement").astype(int)
data["deltas"] = (
("asset", "replacement"),
rand(data.asset.size, data.replacement.size),
)
data["deltas"] *= rand(*data.deltas.shape) > 0.25

return CapacityAddition(data.ranks, data.deltas)


def add_var(coordinates, *dims, factor=100.0):
from numpy.random import rand

shape = tuple(len(coordinates[u]) for u in dims)
return dims, (rand(*shape) * factor).astype(type(factor))
from pytest import mark


def test_cliff_retirement_known_profile():
Expand Down
27 changes: 0 additions & 27 deletions tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,6 @@ def streetcred(*args, **kwargs):
)


@fixture
def limits_path(tmp_path):
from textwrap import dedent

path = tmp_path / "limits.csv"
path.write_text(
dedent(
"""
Year,Month,Day,Hour,Region,Gas
2020,all-year,all-week,night,R1,5
2020,all-year,all-week,morning,R1,5
2020,all-year,all-week,afternoon,R1,5
2020,all-year,all-week,early-peak,R1,5
2020,all-year,all-week,late-peak,R1,5
2020,all-year,all-week,evening,R1,5
2050,all-year,all-week,night,R1,8
2050,all-year,all-week,morning,R1,8
2050,all-year,all-week,afternoon,R1,8
2050,all-year,all-week,early-peak,R1,8
2050,all-year,all-week,late-peak,R1,8
2050,all-year,all-week,evening,R1,8
"""
)
)
return path


@mark.usefixtures("streetcred")
def test_save_with_dir(tmpdir):
from pandas import read_csv
Expand Down
23 changes: 0 additions & 23 deletions tests/test_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,6 @@
from pytest import approx, fixture


@fixture
def demand(
technologies: xr.Dataset, capacity: xr.DataArray, market: xr.DataArray
) -> xr.DataArray:
from collections.abc import Hashable, Mapping
from typing import Any

region = xr.DataArray(list(set(capacity.region.values)), dims="region")
coords: Mapping[Hashable, Any] = {
"commodity": technologies.commodity,
"year": capacity.year,
"region": region,
"timeslice": market.timeslice,
}
data = np.random.randint(0, 5, tuple(len(u) for u in coords.values()))
return xr.DataArray(data, coords=coords, dims=tuple(coords.keys()))


@fixture
def production(
technologies: xr.Dataset, capacity: xr.DataArray, timeslice
Expand All @@ -39,11 +21,6 @@ def production(
return broadcast_timeslice(capacity) * distribute_timeslice(comms)


def make_array(array):
data = np.random.randint(1, 5, len(array))
return xr.DataArray(data, dims=array.dims, coords=array.coords)


def test_supply_enduse(technologies, capacity, timeslice):
"""End-use part of supply."""
from muse.commodities import is_enduse
Expand Down
30 changes: 0 additions & 30 deletions tests/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ def user_data_files(settings: dict) -> None:
new_file.write_text("Some data")


@fixture
def sectors_files(settings: dict):
"""Creates the files related to the sector."""
for data in settings["sectors"].values():
for path in data.values():
if not isinstance(path, (Path, str)):
continue
path = Path(path)
if path.suffix != ".csv":
continue

path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("Some data")


@fixture
def plugins(settings: dict, tmp_path) -> Path:
"""Creates the files related to the custom modules."""
Expand All @@ -48,21 +33,6 @@ def plugins(settings: dict, tmp_path) -> Path:
return plugin


@fixture
def input_file(settings: dict, tmpdir, plugins, user_data_files, sectors_files) -> Path:
"""Creates a whole set of MUSE input files in a temporary directory.

This fixture creates a temporal directory with all the folders and files required
for a successful run of the read_settings function.
"""
# Finally we create the settings file
input_file = tmpdir.join("settings.toml")
with open(input_file, "w") as f:
toml.dump(settings, f)

return input_file


def test_add_known_parameters(settings: dict):
"""Test the add_known_parameters function.

Expand Down