diff --git a/src/muse/data/example/default_timeslice/output.py b/src/muse/data/example/default_timeslice/output.py deleted file mode 100644 index 68225919d..000000000 --- a/src/muse/data/example/default_timeslice/output.py +++ /dev/null @@ -1,45 +0,0 @@ -from typing import Optional - -import xarray as xr - -from muse.outputs.sector import market_quantity, register_output_quantity - - -@register_output_quantity -def supply_timeslice( - market: xr.Dataset, - capacity: xr.DataArray, - technologies: xr.Dataset, - sum_over: Optional[list[str]] = None, - drop: Optional[list[str]] = None, - rounding: int = 4, -) -> xr.DataArray: - """Current supply.""" - market = market.reset_index("timeslice") - result = ( - market_quantity(market.supply, sum_over=sum_over, drop=drop) - .rename("supply") - .to_dataframe() - .round(rounding) - ) - return result[result.supply != 0] - - -@register_output_quantity -def consumption_timeslice( - market: xr.Dataset, - capacity: xr.DataArray, - technologies: xr.Dataset, - sum_over: Optional[list[str]] = None, - drop: Optional[list[str]] = None, - rounding: int = 4, -) -> xr.DataArray: - """Current consumption.""" - market = market.reset_index("timeslice") - result = ( - market_quantity(market.consumption, sum_over=sum_over, drop=drop) - .rename("consumption") - .to_dataframe() - .round(rounding) - ) - return result[result.consumption != 0] diff --git a/src/muse/examples.py b/src/muse/examples.py index df6293d6f..fb81e0647 100644 --- a/src/muse/examples.py +++ b/src/muse/examples.py @@ -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): diff --git a/src/muse/readers/csv.py b/src/muse/readers/csv.py index 4eea66108..600715b7b 100644 --- a/src/muse/readers/csv.py +++ b/src/muse/readers/csv.py @@ -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( diff --git a/tests/conftest.py b/tests/conftest.py index f7d52adb8..3c223b50a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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, @@ -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) @@ -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.""" diff --git a/tests/test_investments.py b/tests/test_investments.py index 38f49a261..d22909a8e 100644 --- a/tests/test_investments.py +++ b/tests/test_investments.py @@ -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(): diff --git a/tests/test_outputs.py b/tests/test_outputs.py index dd4fa5d51..db011e150 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -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 diff --git a/tests/test_quantities.py b/tests/test_quantities.py index 8e1238342..9f89f16b4 100644 --- a/tests/test_quantities.py +++ b/tests/test_quantities.py @@ -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 @@ -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 diff --git a/tests/test_readers.py b/tests/test_readers.py index 87589d1dc..084d37b14 100644 --- a/tests/test_readers.py +++ b/tests/test_readers.py @@ -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.""" @@ -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.