Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #69

Merged
merged 2 commits into from
Dec 19, 2024
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.10.0
hooks:
- id: black
args: [--line-length=100]
language_version: python3.12
- repo: https://github.com/mwouts/jupytext
rev: v1.16.4
rev: v1.16.5
hooks:
- id: jupytext
args: [--sync]
Expand Down
8 changes: 6 additions & 2 deletions examples/example1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"flow_definitions = [\n",
Expand All @@ -128,7 +130,9 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"lines_to_next_cell": 2
},
"source": [
"## 4. Define the MFA System equations\n",
"We define a class with our system equations in the compute method. Afterwards we create an instance of this class, using the input data defined above. The class (system equations) can then easily be reused with different input data.\n",
Expand Down
3 changes: 2 additions & 1 deletion examples/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.16.4
# jupytext_version: 1.16.5
# kernelspec:
# display_name: .venv
# language: python
Expand Down Expand Up @@ -112,6 +112,7 @@
#
# We just need to define the compute method with our system equations, as all the other things we need are inherited from the MFASystem class.


# %%
class SimpleMFA(MFASystem):
def compute(self):
Expand Down
16 changes: 12 additions & 4 deletions examples/example2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@
"cell_type": "code",
"execution_count": 20,
"id": "1ea15908-23c4-424b-832d-d5507fd13021",
"metadata": {},
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"stock_definitions = [\n",
Expand All @@ -185,7 +187,9 @@
{
"cell_type": "markdown",
"id": "f382cce6",
"metadata": {},
"metadata": {
"lines_to_next_cell": 2
},
"source": [
"\n",
"We just need to define the compute method with our system equations, as all the other things we need are inherited from the MFASystem class. The flow names are generated from the processes each flow connects, in this case with the naming function `process_names_with_arrow`, which is passed to the flow initialization below."
Expand All @@ -195,7 +199,9 @@
"cell_type": "code",
"execution_count": 21,
"id": "fef3eb3c-7f88-41b0-86a2-d23bccc0783a",
"metadata": {},
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"class SimpleMFA(MFASystem):\n",
Expand Down Expand Up @@ -233,7 +239,9 @@
{
"cell_type": "markdown",
"id": "ea62e42a-4ece-4d6b-91cb-998553bb7e84",
"metadata": {},
"metadata": {
"lines_to_next_cell": 2
},
"source": [
"## 3. Load data and initialise flows and stocks\n",
"Now that we have defined the MFA system and know what data we need, we can load the data.\n",
Expand Down
4 changes: 3 additions & 1 deletion examples/example2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.16.4
# jupytext_version: 1.16.5
# kernelspec:
# display_name: .venv
# language: python
Expand Down Expand Up @@ -149,6 +149,7 @@
#
# We just need to define the compute method with our system equations, as all the other things we need are inherited from the MFASystem class. The flow names are generated from the processes each flow connects, in this case with the naming function `process_names_with_arrow`, which is passed to the flow initialization below.


# %%
class SimpleMFA(MFASystem):
def compute(self):
Expand Down Expand Up @@ -189,6 +190,7 @@ def compute(self):
#
# The methods `read_dimensions` and `read_parameters` are already defined in the parent DataReader class, and loop over the methods `read_dimension` and `read_parameter_values` that we specify for our usecase here.


# %%
class CustomDataReader(DataReader):
def __init__(self, path_to_time_parameters, path_to_element_parameters):
Expand Down
2 changes: 1 addition & 1 deletion examples/example3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.16.4
# jupytext_version: 1.16.5
# kernelspec:
# display_name: .venv
# language: python
Expand Down
20 changes: 11 additions & 9 deletions examples/example5.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@
"cell_type": "code",
"execution_count": 4,
"id": "5314d22c-a522-43db-be20-54fdbed58fab",
"metadata": {
"lines_to_next_cell": 1
},
"metadata": {},
"outputs": [],
"source": [
"flow_definitions = [\n",
Expand All @@ -157,7 +155,9 @@
"cell_type": "code",
"execution_count": 5,
"id": "5985b315-d592-4cce-8bcb-1b1aef0eeb5b",
"metadata": {},
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"class VehicleMFA(MFASystem):\n",
Expand Down Expand Up @@ -211,7 +211,9 @@
{
"cell_type": "markdown",
"id": "48f46cc9-4637-41cb-980d-37b9930a4a86",
"metadata": {},
"metadata": {
"lines_to_next_cell": 2
},
"source": [
"## 3. Define our data reader\n",
"Now that we have defined the MFA system and know what data we need, we can load the data.\n",
Expand Down Expand Up @@ -324,9 +326,7 @@
"cell_type": "code",
"execution_count": 8,
"id": "55906a64-8b14-4015-aa5f-4383d019c1cd",
"metadata": {
"lines_to_next_cell": 1
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -436,7 +436,9 @@
{
"cell_type": "markdown",
"id": "4f90be3d-6663-4e6f-a10b-11f88404b44d",
"metadata": {},
"metadata": {
"lines_to_next_cell": 2
},
"source": [
"## 5. Improve the model\n",
"\n",
Expand Down
5 changes: 4 additions & 1 deletion examples/example5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.16.4
# jupytext_version: 1.16.5
# kernelspec:
# display_name: .venv
# language: python
Expand Down Expand Up @@ -120,6 +120,7 @@
)
]


# %%
class VehicleMFA(MFASystem):
"""We just need to define the compute method with our system equations,
Expand Down Expand Up @@ -174,6 +175,7 @@ def compute_flows(self):
# Now that we have defined the MFA system and know what data we need, we can load the data.
# To do the data loading, we define a DataReader class. Such a class can be reused with different datasets of the same format by passing attributes, e.g. the directory where the data is stored, in the init function. In this example, we will also build upon this data reader in a following step.


# %%
class CustomDataReader(DataReader):
"""The methods `read_dimensions` and `read_parameters` are already defined in the parent
Expand Down Expand Up @@ -270,6 +272,7 @@ def vehicle_new_registration(self, data, dims):
#
# To make these changes in the model dimensions and parameters, we build on the `CustomDataReader` class defined above, extending the time dimension to earlier years, as well as extending the data for the `vehicle_new_registration` parameter, which is our only time-dependent parameter.


# %%
class AnotherCustomDataReader(CustomDataReader):
@property
Expand Down
3 changes: 2 additions & 1 deletion sodym/named_dim_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class NamedDimArray(PydanticBaseModel):
foo[keys] = bar or foo = bar[keys]. For details on the allowed values of 'keys', see the docstring of the
SubArrayHandler class.

The dimensions of a NamedDimArray stored as a :py:class:`sodym.dimensions.DimensionSet` object in the 'dims' attribute."""
The dimensions of a NamedDimArray stored as a :py:class:`sodym.dimensions.DimensionSet` object in the 'dims' attribute.
"""

model_config = ConfigDict(arbitrary_types_allowed=True, protected_namespaces=())

Expand Down