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
18 changes: 9 additions & 9 deletions docs/advanced-guide/extending-muse.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import List, Optional, Text\n",
"from typing import Optional\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we have to wait for a newer version of Python until we can write Optionals as my_type | None!

"\n",
"from muse.outputs.sector import market_quantity, register_output_quantity\n",
"from xarray import DataArray, Dataset\n",
Expand Down Expand Up @@ -137,7 +137,7 @@
"\n",
"@register_output_sink(name=\"txt\")\n",
"@sink_to_file(\".txt\")\n",
"def text_dump(data: Any, filename: Text) -> None:\n",
"def text_dump(data: Any, filename: str) -> None:\n",
" from pathlib import Path\n",
"\n",
" Path(filename).write_text(f\"Hello world!\\n\\n{data}\")"
Expand Down Expand Up @@ -286,7 +286,7 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import MutableMapping, Text\n",
"from collections.abc import MutableMapping\n",
"\n",
"import pandas as pd\n",
"import xarray as xr\n",
Expand All @@ -295,13 +295,13 @@
"\n",
"@register_cached_quantity(overwrite=True)\n",
"def capacity(\n",
" cached: List[xr.DataArray],\n",
" agents: MutableMapping[Text, MutableMapping[Text, Text]],\n",
" cached: list[xr.DataArray],\n",
" agents: MutableMapping[str, MutableMapping[str, str]],\n",
") -> pd.DataFrame:\n",
" \"\"\"Consolidates the cached capacity into a single DataFrame to save.\n",
"\n",
" Args:\n",
" cached (List[xr.DataArray]): The list of cached arrays during the calculation of\n",
" cached (list[xr.DataArray]): The list of cached arrays during the calculation of\n",
" the time period with the capacity.\n",
" agents (MutableMapping[Text, MutableMapping[Text, Text]]): Agents' metadata.\n",
"\n",
Expand Down Expand Up @@ -453,8 +453,8 @@
" market: Dataset,\n",
" capacity: DataArray,\n",
" technologies: Dataset,\n",
" sum_over: Optional[List[Text]] = None,\n",
" drop: Optional[List[Text]] = None,\n",
" sum_over: Optional[list[str]] = None,\n",
" drop: Optional[list[str]] = None,\n",
" rounding: int = 4,\n",
"):\n",
" \"\"\"Current consumption.\"\"\"\n",
Expand All @@ -469,7 +469,7 @@
"\n",
"@register_output_sink(name=\"txt\", overwrite=True)\n",
"@sink_to_file(\".txt\")\n",
"def text_dump(data: Any, filename: Text, msg: Optional[Text] = \"Hello, world!\") -> None: # noqa: F811\n",
"def text_dump(data: Any, filename: str, msg: Optional[str] = \"Hello, world!\") -> None: # noqa: F811\n",
" from pathlib import Path\n",
"\n",
" Path(filename).write_text(f\"{msg}\\n\\n{data}\")"
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# -- Project information -----------------------------------------------------
from typing import List

project = "MUSE"
copyright = "2022, Sustainable Gas Institute"
Expand Down Expand Up @@ -54,7 +53,7 @@
"xarray": ("http://xarray.pydata.org/en/stable/", None),
}

bibtex_bibfiles: List[str] = []
bibtex_bibfiles: list[str] = []

# -- GraphViz configuration ----------------------------------
graphviz_output_format = "svg"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial-code/3-add-region/visualise-new-region.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
")\n",
"\n",
"for name, sector in mca_capacity.groupby(\"sector\"):\n",
" print(\"{} sector:\".format(name))\n",
" print(f\"{name} sector:\")\n",
" g = sns.FacetGrid(data=sector, col=\"region\")\n",
" g.map(sns.lineplot, \"year\", \"capacity\", \"technology\")\n",
" g.add_legend()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"limits = [20, 20, 60]\n",
"sec_list = list(mca_capacity.groupby(\"sector\").groups.keys())\n",
"for name, sector in mca_capacity.groupby(\"sector\"):\n",
" print(\"{} sector:\".format(name))\n",
" print(f\"{name} sector:\")\n",
" fig, ax = plt.subplots(1, 2)\n",
" sns.lineplot(\n",
" data=sector[sector.region == \"R1\"],\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
")\n",
"\n",
"for name, sector in mca_capacity.groupby(\"sector\"):\n",
" print(\"{} sector:\".format(name))\n",
" print(f\"{name} sector:\")\n",
"\n",
" fig, ax = plt.subplots(1, 2)\n",
" sns.lineplot(\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"limits = [20, 70, 60]\n",
"sec_list = list(mca_capacity.groupby(\"sector\").groups.keys())\n",
"for name, sector in mca_capacity.groupby(\"sector\"):\n",
" print(\"{} sector:\".format(name))\n",
" print(f\"{name} sector:\")\n",
" fig, ax = plt.subplots(1, 2)\n",
" sns.lineplot(\n",
" data=sector[sector.region == \"R1\"],\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"outputs": [],
"source": [
"for name, sector in mca_capacity.groupby(\"sector\"):\n",
" print(\"{} sector:\".format(name))\n",
" print(f\"{name} sector:\")\n",
" sns.lineplot(\n",
" data=sector[sector.region == \"R1\"], x=\"year\", y=\"capacity\", hue=\"technology\"\n",
" )\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, Text
from typing import Optional

import xarray as xr
from muse.outputs.sector import market_quantity, register_output_quantity
Expand All @@ -9,8 +9,8 @@ def supply_timeslice(
market: xr.Dataset,
capacity: xr.DataArray,
technologies: xr.Dataset,
sum_over: Optional[List[Text]] = None,
drop: Optional[List[Text]] = None,
sum_over: Optional[list[str]] = None,
drop: Optional[list[str]] = None,
rounding: int = 4,
) -> xr.DataArray:
"""Current supply."""
Expand All @@ -29,8 +29,8 @@ def consumption_timeslice(
market: xr.Dataset,
capacity: xr.DataArray,
technologies: xr.Dataset,
sum_over: Optional[List[Text]] = None,
drop: Optional[List[Text]] = None,
sum_over: Optional[list[str]] = None,
drop: Optional[list[str]] = None,
rounding: int = 4,
) -> xr.DataArray:
"""Current consumption."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, Text
from typing import Optional

import xarray as xr
from muse.outputs.sector import market_quantity, register_output_quantity
Expand All @@ -9,8 +9,8 @@ def supply_timeslice(
market: xr.Dataset,
capacity: xr.DataArray,
technologies: xr.Dataset,
sum_over: Optional[List[Text]] = None,
drop: Optional[List[Text]] = None,
sum_over: Optional[list[str]] = None,
drop: Optional[list[str]] = None,
rounding: int = 4,
) -> xr.DataArray:
"""Current supply."""
Expand All @@ -29,8 +29,8 @@ def consumption_timeslice(
market: xr.Dataset,
capacity: xr.DataArray,
technologies: xr.Dataset,
sum_over: Optional[List[Text]] = None,
drop: Optional[List[Text]] = None,
sum_over: Optional[list[str]] = None,
drop: Optional[list[str]] = None,
rounding: int = 4,
) -> xr.DataArray:
"""Current consumption."""
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,16 @@ files = ["src/**/*.py", "tests/**/*.py"]
module = ["setup"]
ignore_errors = true

[tool.ruff]
target-version = "py39"

[tool.ruff.lint]
select = [
"D", # pydocstyle
"E", # pycodestyle
"F", # Pyflakes
"I", # isort
"UP", # Pyupgrade
"RUF" # Ruff's own checks
]
ignore = [
Expand Down
19 changes: 10 additions & 9 deletions src/muse/agents/agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Holds all building agents."""

from abc import ABC, abstractmethod
from typing import Callable, Optional, Sequence, Text, Union
from collections.abc import Sequence
from typing import Callable, Optional, Union

import xarray as xr

Expand All @@ -14,11 +15,11 @@ class AbstractAgent(ABC):

def __init__(
self,
name: Text = "Agent",
region: Text = "",
name: str = "Agent",
region: str = "",
assets: Optional[xr.Dataset] = None,
interpolation: Text = "linear",
category: Optional[Text] = None,
interpolation: str = "linear",
category: Optional[str] = None,
quantity: Optional[float] = 1,
):
"""Creates a standard MUSE agent.
Expand Down Expand Up @@ -102,10 +103,10 @@ class Agent(AbstractAgent):

def __init__(
self,
name: Text = "Agent",
region: Text = "USA",
name: str = "Agent",
region: str = "USA",
assets: Optional[xr.Dataset] = None,
interpolation: Text = "linear",
interpolation: str = "linear",
search_rules: Optional[Callable] = None,
objectives: Optional[Callable] = None,
decision: Optional[Callable] = None,
Expand All @@ -115,7 +116,7 @@ def __init__(
housekeeping: Optional[Callable] = None,
merge_transform: Optional[Callable] = None,
demand_threshhold: Optional[float] = None,
category: Optional[Text] = None,
category: Optional[str] = None,
asset_threshhold: float = 1e-4,
quantity: Optional[float] = 1,
spend_limit: int = 0,
Expand Down
Loading