Skip to content

Commit 040d072

Browse files
authored
Update examples + check repository health (#33)
* Add directory README and launch notebook. * Touch up text and code in notebooks * Update ruff setting * Make pretty * Use Miniforge in place of Mambaforge Mambaforge is being retired: https://conda-forge.org/news/2024/07/29/sunsetting-mambaforge/. * Drop Python 3.9, add 3.13 * Also update Python version information in metadata * Use absolute path to working directory with bmi_tester
1 parent 143800a commit 040d072

File tree

8 files changed

+74
-25
lines changed

8 files changed

+74
-25
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ jobs:
2020
strategy:
2121
matrix:
2222
os: [ubuntu-latest, macos-latest, windows-latest]
23-
python-version: ["3.10", "3.11", "3.12"]
23+
python-version: ["3.10", "3.11", "3.12", "3.13"]
2424

2525
steps:
2626
- uses: actions/checkout@v4
2727

2828
- uses: conda-incubator/setup-miniconda@v3
2929
with:
30-
miniforge-variant: Mambaforge
3130
miniforge-version: latest
3231
python-version: ${{ matrix.python-version }}
3332

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "0",
6+
"metadata": {},
7+
"source": [
8+
"# Examples: Python BMI"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "1",
14+
"metadata": {},
15+
"source": [
16+
"Here are examples of using the *Heat* model and its Python *BMI*.\n",
17+
"\n",
18+
"* [run-model.ipynb](./run-model.ipynb) and [run-model-from-bmi.ipynb](./run-model-from-bmi.ipynb): These Jupyter Notebooks show how to interact with the *Heat* model through its API and its BMI, respectively.\n",
19+
"* [heat.yaml](./heat.yaml): A configuration file used to pass parameters to the *Heat* BMI."
20+
]
21+
}
22+
],
23+
"metadata": {
24+
"kernelspec": {
25+
"display_name": "CSDMS",
26+
"language": "python",
27+
"name": "csdms"
28+
},
29+
"language_info": {
30+
"codemirror_mode": {
31+
"name": "ipython",
32+
"version": 3
33+
},
34+
"file_extension": ".py",
35+
"mimetype": "text/x-python",
36+
"name": "python",
37+
"nbconvert_exporter": "python",
38+
"pygments_lexer": "ipython3",
39+
"version": "3.11.7"
40+
}
41+
},
42+
"nbformat": 4,
43+
"nbformat_minor": 5
44+
}

examples/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Examples: Python BMI
2+
3+
Here are examples of using the *Heat* model and its Python BMI.
4+
5+
* [run-model.ipynb](./run-model.ipynb) and [run-model-from-bmi.ipynb](./run-model-from-bmi.ipynb): These Jupyter Notebooks show how to interact with the *Heat* model through its API and its BMI, respectively.
6+
* [heat.yaml](./heat.yaml): A configuration file used to pass parameters to the *Heat* BMI.

examples/run-model-from-bmi.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Run the `Heat` model through its BMI"
7+
"# Run the *Heat* model through its BMI"
88
]
99
},
1010
{
1111
"cell_type": "markdown",
1212
"metadata": {},
1313
"source": [
14-
"`Heat` models the diffusion of temperature on a uniform rectangular plate with Dirichlet boundary conditions. View the source code for the [model](https://github.com/csdms/bmi-example-python/blob/master/heat/heat.py) and its [BMI](https://github.com/csdms/bmi-example-python/blob/master/heat/bmi_heat.py) on GitHub."
14+
"*Heat* models the diffusion of temperature on a uniform rectangular plate with Dirichlet boundary conditions. View the source code for the [model](https://github.com/csdms/bmi-example-python/blob/master/heat/heat.py) and its [BMI](https://github.com/csdms/bmi-example-python/blob/master/heat/bmi_heat.py) on GitHub."
1515
]
1616
},
1717
{
1818
"cell_type": "markdown",
1919
"metadata": {},
2020
"source": [
21-
"Start by importing `os`, `numpy` and the `Heat` BMI:"
21+
"Start by importing *numpy* and the *Heat* BMI:"
2222
]
2323
},
2424
{
@@ -27,7 +27,6 @@
2727
"metadata": {},
2828
"outputs": [],
2929
"source": [
30-
"import os\n",
3130
"import numpy as np\n",
3231
"\n",
3332
"from heat import BmiHeat"
@@ -62,14 +61,14 @@
6261
"metadata": {},
6362
"outputs": [],
6463
"source": [
65-
"print(x.get_component_name())"
64+
"x.get_component_name()"
6665
]
6766
},
6867
{
6968
"cell_type": "markdown",
7069
"metadata": {},
7170
"source": [
72-
"Start the `Heat` model through its BMI using a configuration file:"
71+
"Start the *Heat* model through its BMI using a configuration file:"
7372
]
7473
},
7574
{
@@ -78,7 +77,7 @@
7877
"metadata": {},
7978
"outputs": [],
8079
"source": [
81-
"cat heat.yaml"
80+
"!cat heat.yaml"
8281
]
8382
},
8483
{
@@ -193,8 +192,9 @@
193192
"outputs": [],
194193
"source": [
195194
"temperature = np.zeros(shape)\n",
196-
"temperature[3, 4] = 100.0\n",
197-
"x.set_value(\"plate_surface__temperature\", temperature)"
195+
"temperature[tuple(shape//2)] = 100.0\n",
196+
"temperature_flat = temperature.flatten()\n",
197+
"x.set_value(\"plate_surface__temperature\", temperature_flat)"
198198
]
199199
},
200200
{
@@ -268,7 +268,7 @@
268268
"metadata": {},
269269
"outputs": [],
270270
"source": [
271-
"distant_time = 2.0\n",
271+
"distant_time = 10 * x.get_time_step()\n",
272272
"while x.get_current_time() < distant_time:\n",
273273
" x.update()"
274274
]

examples/run-model.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Run the `Heat` model"
7+
"# Run the *Heat* model"
88
]
99
},
1010
{
1111
"cell_type": "markdown",
1212
"metadata": {},
1313
"source": [
14-
"`Heat` models the diffusion of temperature on a uniform rectangular plate with Dirichlet boundary conditions. View the [source code](https://github.com/csdms/bmi-example-python/blob/master/heat/heat.py) for the model on GitHub."
14+
"*Heat* models the diffusion of temperature on a uniform rectangular plate with Dirichlet boundary conditions. View the [source code](https://github.com/csdms/bmi-example-python/blob/master/heat/heat.py) for the model on GitHub."
1515
]
1616
},
1717
{
1818
"cell_type": "markdown",
1919
"metadata": {},
2020
"source": [
21-
"Start by importing `numpy` and `Heat`:"
21+
"Start by importing *numpy* and *Heat*:"
2222
]
2323
},
2424
{
@@ -35,7 +35,7 @@
3535
"cell_type": "markdown",
3636
"metadata": {},
3737
"source": [
38-
"Create an instance of the model, setting `shape` and `alpha` parameters:"
38+
"Create an instance of the model, setting the `shape` and `alpha` parameters:"
3939
]
4040
},
4141
{
@@ -71,7 +71,7 @@
7171
"cell_type": "markdown",
7272
"metadata": {},
7373
"source": [
74-
"What does the initial temperature field look like?"
74+
"Zero out the initial temperature field:"
7575
]
7676
},
7777
{
@@ -97,7 +97,7 @@
9797
"metadata": {},
9898
"outputs": [],
9999
"source": [
100-
"m.temperature[3, 4] = 100.0\n",
100+
"m.temperature[n_rows//2, n_cols//2] = 100.0\n",
101101
"print(m.temperature)"
102102
]
103103
},
@@ -153,7 +153,7 @@
153153
"metadata": {},
154154
"outputs": [],
155155
"source": [
156-
"distant_time = 2.0\n",
156+
"distant_time = 10 * m.time_step\n",
157157
"while m.time < distant_time:\n",
158158
" m.advance_in_time()"
159159
]
@@ -162,7 +162,7 @@
162162
"cell_type": "markdown",
163163
"metadata": {},
164164
"source": [
165-
"View the new state of the temperature field (with help from `np.set_printoptions`):"
165+
"View the new state of the temperature field (with help from *np.set_printoptions*):"
166166
]
167167
},
168168
{
@@ -179,7 +179,7 @@
179179
"cell_type": "markdown",
180180
"metadata": {},
181181
"source": [
182-
"Note that temperature is set to zero at the boundaries."
182+
"Note that temperature is set to zero at the boundaries, so it's not conserved on the plate:"
183183
]
184184
},
185185
{

heat/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Model the diffusion of heat over a 2D plate."""
2+
23
from ._version import __version__
34
from .bmi_heat import BmiHeat
45
from .heat import Heat, solve_2d

heat/bmi_heat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
class BmiHeat(Bmi):
11-
1211
"""Solve the heat equation for a 2D plate."""
1312

1413
_name = "The 2D Heat Equation"

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ classifiers = [
2626
"License :: OSI Approved :: MIT License",
2727
"Operating System :: OS Independent",
2828
"Programming Language :: Python :: 3",
29-
"Programming Language :: Python :: 3.9",
3029
"Programming Language :: Python :: 3.10",
3130
"Programming Language :: Python :: 3.11",
3231
"Programming Language :: Python :: 3.12",
32+
"Programming Language :: Python :: 3.13",
3333
"Programming Language :: Python :: Implementation :: CPython",
3434
"Topic :: Scientific/Engineering :: Physics",
3535
]
36-
requires-python = ">=3.9"
36+
requires-python = ">=3.10"
3737
dependencies = [
3838
"numpy",
3939
"scipy",
@@ -93,7 +93,7 @@ line_length = 88
9393

9494
[tool.ruff]
9595
line-length = 88
96-
ignore = [
96+
lint.ignore = [
9797
"E203",
9898
"E501",
9999
]

0 commit comments

Comments
 (0)