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

Update examples + check repository health #33

Merged
merged 9 commits into from
Oct 18, 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
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-version: latest
python-version: ${{ matrix.python-version }}

Expand Down
44 changes: 44 additions & 0 deletions examples/README-bmi-example-python.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"# Examples: Python BMI"
]
},
{
"cell_type": "markdown",
"id": "1",
"metadata": {},
"source": [
"Here are examples of using the *Heat* model and its Python *BMI*.\n",
"\n",
"* [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",
"* [heat.yaml](./heat.yaml): A configuration file used to pass parameters to the *Heat* BMI."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "CSDMS",
"language": "python",
"name": "csdms"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
6 changes: 6 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Examples: Python BMI

Here are examples of using the *Heat* model and its Python BMI.

* [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.
* [heat.yaml](./heat.yaml): A configuration file used to pass parameters to the *Heat* BMI.
20 changes: 10 additions & 10 deletions examples/run-model-from-bmi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Run the `Heat` model through its BMI"
"# Run the *Heat* model through its BMI"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`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."
"*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."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Start by importing `os`, `numpy` and the `Heat` BMI:"
"Start by importing *numpy* and the *Heat* BMI:"
]
},
{
Expand All @@ -27,7 +27,6 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import numpy as np\n",
"\n",
"from heat import BmiHeat"
Expand Down Expand Up @@ -62,14 +61,14 @@
"metadata": {},
"outputs": [],
"source": [
"print(x.get_component_name())"
"x.get_component_name()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Start the `Heat` model through its BMI using a configuration file:"
"Start the *Heat* model through its BMI using a configuration file:"
]
},
{
Expand All @@ -78,7 +77,7 @@
"metadata": {},
"outputs": [],
"source": [
"cat heat.yaml"
"!cat heat.yaml"
]
},
{
Expand Down Expand Up @@ -193,8 +192,9 @@
"outputs": [],
"source": [
"temperature = np.zeros(shape)\n",
"temperature[3, 4] = 100.0\n",
"x.set_value(\"plate_surface__temperature\", temperature)"
"temperature[tuple(shape//2)] = 100.0\n",
"temperature_flat = temperature.flatten()\n",
"x.set_value(\"plate_surface__temperature\", temperature_flat)"
]
},
{
Expand Down Expand Up @@ -268,7 +268,7 @@
"metadata": {},
"outputs": [],
"source": [
"distant_time = 2.0\n",
"distant_time = 10 * x.get_time_step()\n",
"while x.get_current_time() < distant_time:\n",
" x.update()"
]
Expand Down
18 changes: 9 additions & 9 deletions examples/run-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Run the `Heat` model"
"# Run the *Heat* model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`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."
"*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."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Start by importing `numpy` and `Heat`:"
"Start by importing *numpy* and *Heat*:"
]
},
{
Expand All @@ -35,7 +35,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Create an instance of the model, setting `shape` and `alpha` parameters:"
"Create an instance of the model, setting the `shape` and `alpha` parameters:"
]
},
{
Expand Down Expand Up @@ -71,7 +71,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"What does the initial temperature field look like?"
"Zero out the initial temperature field:"
]
},
{
Expand All @@ -97,7 +97,7 @@
"metadata": {},
"outputs": [],
"source": [
"m.temperature[3, 4] = 100.0\n",
"m.temperature[n_rows//2, n_cols//2] = 100.0\n",
"print(m.temperature)"
]
},
Expand Down Expand Up @@ -153,7 +153,7 @@
"metadata": {},
"outputs": [],
"source": [
"distant_time = 2.0\n",
"distant_time = 10 * m.time_step\n",
"while m.time < distant_time:\n",
" m.advance_in_time()"
]
Expand All @@ -162,7 +162,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"View the new state of the temperature field (with help from `np.set_printoptions`):"
"View the new state of the temperature field (with help from *np.set_printoptions*):"
]
},
{
Expand All @@ -179,7 +179,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that temperature is set to zero at the boundaries."
"Note that temperature is set to zero at the boundaries, so it's not conserved on the plate:"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions heat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Model the diffusion of heat over a 2D plate."""

from ._version import __version__
from .bmi_heat import BmiHeat
from .heat import Heat, solve_2d
Expand Down
1 change: 0 additions & 1 deletion heat/bmi_heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class BmiHeat(Bmi):

"""Solve the heat equation for a 2D plate."""

_name = "The 2D Heat Equation"
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering :: Physics",
]
requires-python = ">=3.9"
requires-python = ">=3.10"
dependencies = [
"numpy",
"scipy",
Expand Down Expand Up @@ -93,7 +93,7 @@ line_length = 88

[tool.ruff]
line-length = 88
ignore = [
lint.ignore = [
"E203",
"E501",
]
Expand Down
Loading