Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
fa59017
Add comments and simplify sector.next
tsmbland Oct 2, 2024
697ff3f
Simplify agent module, more comments
tsmbland Oct 3, 2024
b47c811
Simplify retirment profile code
tsmbland Oct 3, 2024
a86e07f
Simplify merge_assets
tsmbland Oct 3, 2024
3e51311
Revert change to merge_assets
tsmbland Oct 4, 2024
941a5a6
Delete unused factory
tsmbland Oct 4, 2024
9d2cac9
More comments added to code
tsmbland Oct 4, 2024
e386da1
Revert some changes to fix tests
tsmbland Oct 4, 2024
018ca5c
Fix tests
tsmbland Oct 4, 2024
4fd2e79
Small fix to another test
tsmbland Oct 4, 2024
51a5273
Delete legacy sector
tsmbland Oct 4, 2024
1518034
Delete tests and documentation
tsmbland Oct 4, 2024
3b0cb49
Remove more redundant code
tsmbland Oct 4, 2024
3a05344
Delete new_to_old_timeslice function
tsmbland Oct 4, 2024
977647d
Remove unnecessary convert_timeslice operations
tsmbland Oct 8, 2024
647d3fe
Use global TIMESLICE variable throughout
tsmbland Oct 8, 2024
8faf468
Simplify some other parts of the code accordingly
tsmbland Oct 8, 2024
65c3e48
Draft new function with intended behaviour
tsmbland Oct 9, 2024
d9eb060
Use new function wherever possible
tsmbland Oct 10, 2024
7ebab9e
Update tests
tsmbland Oct 10, 2024
a0fe43c
Remove represent_hours function
tsmbland Oct 10, 2024
c2b94e7
Fix issue with timeslice ordering
tsmbland Oct 11, 2024
5cbc8f2
Remove remaining convert_timeslice calls
tsmbland Oct 11, 2024
81e7a6a
Simplify timeslice_op function
tsmbland Oct 11, 2024
19cf269
Delete old convert_timeslice function
tsmbland Oct 11, 2024
57c1c73
Delete unused functions
tsmbland Oct 11, 2024
e4150e3
Simplify timeslie import process
tsmbland Oct 11, 2024
dc8b8b8
Formatting
tsmbland Oct 11, 2024
0288459
Default arguments for convert_timeslice
tsmbland Oct 11, 2024
c7f67f4
Update results files
tsmbland Oct 11, 2024
9360ad1
Merge branch 'refactor' into legacy
tsmbland Oct 14, 2024
b2e8294
Merge branch 'legacy' into convert_timeslice2
tsmbland Oct 14, 2024
94ef9b7
Merge branch 'legacy' into convert_timeslice2
tsmbland Oct 14, 2024
cc9d237
Fix test
tsmbland Oct 14, 2024
acdcbf8
Merge branch 'refactor' into legacy
tsmbland Oct 14, 2024
89f8c61
Carry changes from fix_supply_issue2 branch
tsmbland Oct 16, 2024
793aacf
More benign changes
tsmbland Oct 16, 2024
22c141e
Fix incorrect convert_timeslice usage in tests
tsmbland Oct 16, 2024
a59580c
Fix timeslice import in tests
tsmbland Oct 16, 2024
993af9f
Delete unused fixture
tsmbland Oct 16, 2024
908872a
Fix market fixtures
tsmbland Oct 16, 2024
e0a8c3a
More test fixes
tsmbland Oct 16, 2024
8034807
Fix a fixture
tsmbland Oct 16, 2024
86d7dd2
Merge branch 'legacy' into convert_timeslice2
tsmbland Oct 16, 2024
1bd7c84
Move default timeslice settings to conftest
tsmbland Oct 16, 2024
c616694
Fix docstring tests
tsmbland Oct 17, 2024
d054a3b
A few more tiny changes (e.g. typing)
tsmbland Oct 17, 2024
0c84ba9
Remove inline comment
tsmbland Oct 17, 2024
65313de
Merge branch 'v1.3' into refactor
tsmbland Oct 21, 2024
4ce54e6
Merge branch 'refactor' into legacy
tsmbland Oct 21, 2024
ad3766e
Merge branch 'legacy' into convert_timeslice2
tsmbland Oct 21, 2024
a02088e
Small changes
tsmbland Oct 21, 2024
4785412
Fix constraints tests
tsmbland Oct 22, 2024
88d40b4
Fix remaining tests
tsmbland Oct 22, 2024
4fbc1ff
Create separate functions for broadcasting and distributing timeslices
tsmbland Oct 22, 2024
0258ae9
Check for existing timeslice dimension in broadcast_timeslice
tsmbland Oct 22, 2024
b0ce228
Fix test
tsmbland Oct 22, 2024
8d06e85
Merge branch 'v1.3' into refactor
tsmbland Oct 25, 2024
5c5fc45
Merge branch 'refactor' into legacy
tsmbland Oct 25, 2024
8149020
Merge branch 'legacy' into convert_timeslice2
tsmbland Oct 25, 2024
885f752
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 25, 2024
433c39c
Fix merge conflicts
tsmbland Oct 25, 2024
6975787
Merge branch 'broadcast_errors2' into refactor
tsmbland Oct 25, 2024
2e601ea
Merge branch 'v1.2.2' into refactor
tsmbland Oct 25, 2024
423fafe
Merge branch 'main' into refactor
tsmbland Oct 28, 2024
c270dfa
Merge branch 'main' into refactor
tsmbland Oct 28, 2024
b521d93
Merge branch 'refactor' into legacy
tsmbland Oct 28, 2024
fde592b
Merge branch 'legacy' into convert_timeslice2
tsmbland Oct 28, 2024
d5875f9
Fix tests
tsmbland Oct 28, 2024
46ab820
Remove timeslice arguments
tsmbland Oct 28, 2024
d5b5676
Fix tests
tsmbland Oct 28, 2024
ae3c06c
Turn off automatic broadcasting over the timeslice dimension (#530)
tsmbland Oct 30, 2024
366c37c
Drop convert_market_timeslice
tsmbland Nov 1, 2024
908be7b
Remove timeslice attribute from sectors
tsmbland Nov 4, 2024
d3604dc
Merge branch 'v1.3' into convert_timeslice2
tsmbland Nov 5, 2024
59cceb8
Delete sections from documentation
tsmbland Nov 7, 2024
59ba25c
Rename timeslice_op, add docstring
tsmbland Nov 7, 2024
bd08d1f
Merge branch 'v1.3' into convert_timeslice2
tsmbland Nov 8, 2024
e77b227
Merge branch 'v1.3' into convert_timeslice2
tsmbland Nov 11, 2024
b78c843
Docstring and better error message for patch
tsmbland Nov 11, 2024
b591866
Merge branch 'v1.3' into convert_timeslice2
tsmbland Nov 12, 2024
4a9d29d
Merge branch 'v1.3' into convert_timeslice2
tsmbland Nov 12, 2024
1c8226c
Merge branch 'v1.3' into convert_timeslice2
tsmbland Nov 12, 2024
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.2.2
current_version = 1.3.0
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ authors:
given-names: Adam

title: MUSE_OS
version: v1.2.2
version: v1.3.0
date-released: 2024-08-13
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
project = "MUSE"
copyright = "2024, Imperial College London"
author = "Imperial College London"
release = "1.2.2"
release = "1.3.0"
version = ".".join(release.split(".")[:2])

# -- General configuration ---------------------------------------------------
Expand Down
103 changes: 0 additions & 103 deletions docs/inputs/toml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,30 +236,6 @@ levels. For instance, there no ``peak`` periods during weekends. All that matter
that the relative weights (i.e. the number of hours) are consistent and sum up to a
year.

The input above defines the finest times slice in the code. In order to define rougher
timeslices we can introduce items in each levels that represent aggregates at that
level. By default, we have the following:

.. code-block:: TOML

[timeslices.aggregates]
all-day = ["night", "morning", "afternoon", "early-peak", "late-peak", "evening"]
all-week = ["weekday", "weekend"]
all-year = ["winter", "summer", "spring-autumn"]

Here, ``all-day`` aggregates the full day. However, one could potentially create
aggregates such as:

.. code-block:: TOML

[timeslices.aggregates]
daylight = ["morning", "afternoon", "early-peak", "late-peak"]
nightlife = ["evening", "night"]

It is possible to specify a timeslice level for the mca by adding an
`mca.timeslice_levels` section, using an inline table format.
See section on `Timeslices_`.

*outputs_cache*
This option behaves exactly like `outputs` for sectors and accepts the same options but
controls the output of cached quantities instead. This option is NOT available for
Expand Down Expand Up @@ -423,30 +399,6 @@ Sectors contain a number of subsections:
Path to a csv file describing the outputs of each technology involved in the sector.
See :ref:`inputs-iocomms`.

Once the finest timeslice and its aggregates are given, it is possible for each sector
to define the timeslice simply by referring to the slices it will use at each level.

.. _sector-timeslices:

*timeslice_levels*
Optional. These define the timeslices of a sector. If not specified, the finest timeslice levels will be used
(See `Timeslices`_).
It can be implemented with the following rows:

.. code-block:: TOML

[sectors.some_sector.timeslice_levels]
day = ["daylight", "nightlife"]
month = ["all-year"]

Above, ``sectors.some_sector.timeslice_levels.week`` defaults its value in the finest
timeslice. Indeed, if the subsection ``sectors.some_sector.timeslice_levels`` is not
given, then the sector will default to using the finest timeslices.

If the MCA uses a rougher
timeslice framework, the market will be expressed within it. Hence information from
sectors with a finer timeslice framework will be lost.

*subsectors*

Subsectors group together agents into separate groups servicing the demand for
Expand Down Expand Up @@ -711,58 +663,3 @@ The following attributes are accepted:

filters.region = ["USA", "ASEA"]
filters.commodity = ["algae", "fluorescent light"]


--------------
Legacy Sectors
--------------

Legacy sectors wrap sectors developed for a previous version of MUSE to the open-source
version.

Preset sectors are defined in :py:class:`~muse.sectors.PresetSector`.

The can be defined in the TOML file as follows:

.. code-block:: TOML

[global_input_files]
macrodrivers = '{path}/input/Macrodrivers.csv'
regions = '{path}/input/Regions.csv'
global_commodities = '{path}/input/MUSEGlobalCommodities.csv'

[sectors.Industry]
type = 'legacy'
priority = 'demand'
agregation_level = 'month'
excess = 0

userdata_path = '{muse_sectors}/Industry'
technodata_path = '{muse_sectors}/Industry'
timeslices_path = '{muse_sectors}/Industry/TimeslicesIndustry.csv'
output_path = '{path}/output'

For historical reasons, the three `global_input_files` above are required. The sector
itself can use the following attributes.

*type*
See the attribute in the standard mode, :ref:`type<sector-type>`. *Legacy* sectors
are those with type "legacy".

*priority*
See the attribute in the standard mode, :ref:`priority<sector-priority>`.

*agregation_level*
Information relevant to the sector's timeslice.

*excess*
Excess factor used to model early obsolescence.

*userdata_path*
Path to a directory with sector-specific data files.

*technodata_path*
Path to a technodata CSV file. See. :ref:`inputs-technodata`.

*output_path*
Path to a directory where the sector will write output files.
3 changes: 1 addition & 2 deletions src/muse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os

VERSION = "1.2.2"
VERSION = "1.3.0"


def _create_logger(color: bool = True):
Expand Down Expand Up @@ -89,7 +89,6 @@ def add_file_logger() -> None:
"read_technodictionary",
"read_technologies",
"read_timeslice_shares",
"read_csv_timeslices",
"read_settings",
"read_macro_drivers",
"read_csv_agent_parameters",
Expand Down
48 changes: 47 additions & 1 deletion src/muse/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,51 @@ def run():
muse_main(args.settings, args.model, args.copy)


def patched_broadcast_compat_data(self, other):
"""Patch for xarray.core.variable._broadcast_compat_data.

This has been introduced to disallow automatic broadcasting along the 'timeslice'
dimension.

If `self` and `other` differ in whether they have a 'timeslice' dimension (in which
case automatic broadcasting would normally be performed), an error is raised.

In this case, developers must explicitly handle broadcasting by calling either
`broadcast_timeslice` or `distribute_timeslice` (see `muse.timeslices`). The
appropriate choice of operation will depend on the context and the quantity in
question.
"""
from xarray.core.variable import Variable, _broadcast_compat_variables

if (isinstance(other, Variable)) and ("timeslice" in self.dims) != (
"timeslice" in getattr(other, "dims", [])
):
raise ValueError(
"Broadcasting along the 'timeslice' dimension is required, but automatic "
"broadcasting is disabled. Please handle it explicitly using "
"`broadcast_timeslice` or `distribute_timeslice` (see `muse.timeslices`)."
)

# The rest of the function is copied directly from
# xarray.core.variable._broadcast_compat_data
if all(hasattr(other, attr) for attr in ["dims", "data", "shape", "encoding"]):
# `other` satisfies the necessary Variable API for broadcast_variables
new_self, new_other = _broadcast_compat_variables(self, other)
self_data = new_self.data
other_data = new_other.data
dims = new_self.dims
else:
# rely on numpy broadcasting rules
self_data = self.data
other_data = other
dims = self.dims
return self_data, other_data, dims


if "__main__" == __name__:
run()
from unittest.mock import patch

with patch(
"xarray.core.variable._broadcast_compat_data", patched_broadcast_compat_data
):
run()
Loading