Skip to content

Commit f3a9663

Browse files
authored
Merge pull request #50 from simpeg/pull_request_template
Add pull request template
2 parents 9e29a71 + 7be8093 commit f3a9663

File tree

13 files changed

+572
-108
lines changed

13 files changed

+572
-108
lines changed

.github/pull_request_template.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!--
2+
Thanks for contributing a pull request to SimPEG user tutorials!
3+
Remember to use a personal fork of SimPEG user tutorials to propose changes.
4+
5+
Check out the stages of a pull request at
6+
https://docs.simpeg.xyz/content/getting_started/contributing/pull-requests.html
7+
8+
Note that we are a team of volunteers and we appreciate your
9+
patience during the review process.
10+
11+
Again, thanks for contributing!
12+
13+
Feel free to remove lines from this template that do not apply to you pull request.
14+
-->
15+
16+
#### Summary
17+
<!-- Add a summary of this Pull Request. Explain what it provides as tutorial material. -->
18+
19+
#### PR Checklist
20+
* [ ] If this is a work in progress PR, set as a Draft PR
21+
* [ ] General
22+
* [ ] Notebook is compatible with latest SimPEG release
23+
* [ ] No deprecated functions and/or input arguments are being used
24+
* [ ] Coding cells linted according to the [style guides](https://docs.simpeg.xyz/latest/content/getting_started/contributing/code-style.html).
25+
* [ ] Introduction is complete:
26+
* [ ] Title and author added to notebook
27+
* [ ] Admonitions for notebook difficulty and computational resources have been added
28+
* [ ] Keywords list has been added
29+
* [ ] Summary paragraph describing the tutorial has been added
30+
* [ ] Learning objectives have been listed
31+
* [ ] Hyperlinks to other tutorial notebooks added if necessary
32+
* [ ] For sections and subsections:
33+
* [ ] A header and short summary of what is being done
34+
* [ ] Links to API documentation added for all classes and functions that are used
35+
* [ ] Newly introduced functionality is explained, or links are provided to relevant materials
36+
* [ ] The approach taken when choosing hyperparameter values is explained. The use of ad hoc values without explanation is discouraged
37+
* [ ] All figures are legible and rendered appropriately
38+
* [ ] Marked as ready for review (if this is was a draft PR), and converted to a pull request
39+
* [ ] Tagged ``@simpeg/simpeg-developers`` when ready for review
40+
41+
42+
#### Additional information
43+
<!--Any additional information you think is important.-->
44+
45+
46+
<!--
47+
Once all tests pass and the code has been reviewed and approved, it will be merged into main
48+
-->

index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,10 @@ Requires moderate computational resources. Run-times may exceed several minutes
106106
The computational resources required to execute this notebook exceed those provided by standard laptop computers. To execute the notebook, please deploy to a cluster computing environment.
107107
```
108108

109+
Want to Add a Tutorial?
110+
-----------------------
111+
112+
Please visit the [Contributing to User Tutorials](notebooks/contributing_index.md) page to find out how you can add a tutorial.
113+
114+
115+

myst.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ project:
116116
children:
117117
- file: notebooks/12-pgi-inversion/plot_inv_1_joint_pf_pgi_full_info_tutorial.ipynb
118118
- file: notebooks/12-pgi-inversion/plot_inv_2_joint_pf_pgi_no_info_tutorial.ipynb
119+
- file: notebooks/contributing_index.md
120+
children:
121+
- file: notebooks/contributing/build_website.md
122+
- file: notebooks/contributing/formatting.md
123+
- file: notebooks/contributing/pull_request.md
119124

120125
site:
121126
template: book-theme

notebooks/03-gravity/fwd_gravity_anomaly_3d.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@
8989
"import numpy as np\n",
9090
"from scipy.interpolate import LinearNDInterpolator\n",
9191
"import matplotlib as mpl\n",
92-
"\n",
93-
"mpl.rcParams.update({\"font.size\": 14})\n",
9492
"import matplotlib.pyplot as plt\n",
9593
"import os\n",
9694
"\n",
95+
"mpl.rcParams.update({\"font.size\": 14})\n",
96+
"\n",
9797
"save_output = False # Optional"
9898
]
9999
},

notebooks/03-gravity/fwd_gravity_gradiometry_3d.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@
9292
"import numpy as np\n",
9393
"from scipy.interpolate import LinearNDInterpolator\n",
9494
"import matplotlib as mpl\n",
95+
"import matplotlib.pyplot as plt\n",
9596
"\n",
9697
"mpl.rcParams.update({\"font.size\": 14})\n",
97-
"import matplotlib.pyplot as plt\n",
9898
"\n",
9999
"save_output = False # Optional"
100100
]

notebooks/04-magnetics/fwd_magnetics_induced_3d.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@
9090
"import numpy as np\n",
9191
"from scipy.interpolate import LinearNDInterpolator\n",
9292
"import matplotlib as mpl\n",
93-
"\n",
94-
"mpl.rcParams.update({\"font.size\": 14})\n",
9593
"import matplotlib.pyplot as plt\n",
9694
"import os\n",
9795
"\n",
96+
"mpl.rcParams.update({\"font.size\": 14})\n",
97+
"\n",
9898
"save_output = False # Optional"
9999
]
100100
},

notebooks/04-magnetics/fwd_magnetics_mvi_3d.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@
9292
"from scipy.interpolate import LinearNDInterpolator\n",
9393
"from scipy.constants import mu_0\n",
9494
"import matplotlib as mpl\n",
95+
"import matplotlib.pyplot as plt\n",
9596
"\n",
9697
"mpl.rcParams.update({\"font.size\": 14})\n",
97-
"import matplotlib.pyplot as plt\n",
9898
"\n",
9999
"save_output = False # Optional"
100100
]

notebooks/07-fdem/fwd_fdem_3d.ipynb

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
"from discretize.utils import mkvc, active_from_xyz\n",
8383
"\n",
8484
"# Common Python functionality\n",
85-
"import os\n",
8685
"import numpy as np\n",
8786
"import matplotlib as mpl\n",
8887
"import matplotlib.pyplot as plt\n",
@@ -843,56 +842,6 @@
843842
"\n",
844843
"plt.show()"
845844
]
846-
},
847-
{
848-
"cell_type": "markdown",
849-
"metadata": {},
850-
"source": [
851-
"## Optional: Export Data\n",
852-
"\n",
853-
"Write the true model, data and topography\n",
854-
"\n",
855-
"\n"
856-
]
857-
},
858-
{
859-
"cell_type": "code",
860-
"execution_count": 21,
861-
"metadata": {
862-
"execution": {
863-
"iopub.execute_input": "2025-05-23T17:19:25.643898Z",
864-
"iopub.status.busy": "2025-05-23T17:19:25.643584Z",
865-
"iopub.status.idle": "2025-05-23T17:19:25.648762Z",
866-
"shell.execute_reply": "2025-05-23T17:19:25.648248Z"
867-
}
868-
},
869-
"outputs": [],
870-
"source": [
871-
"if save_file:\n",
872-
" dir_path = os.path.dirname(fdem.__file__).split(os.path.sep)[:-3]\n",
873-
" dir_path.extend([\"tutorials\", \"assets\", \"fdem\"])\n",
874-
" dir_path = os.path.sep.join(dir_path) + os.path.sep\n",
875-
"\n",
876-
" # Write topography\n",
877-
" fname = dir_path + \"fdem_topo.txt\"\n",
878-
" np.savetxt(fname, np.c_[topo_xyz], fmt=\"%.4e\")\n",
879-
"\n",
880-
" # Write data with 2% noise added\n",
881-
" fname = dir_path + \"fdem_data.obs\"\n",
882-
" bz_real = bz_real + 1e-14 * np.random.rand(len(bz_real))\n",
883-
" bz_imag = bz_imag + 1e-14 * np.random.rand(len(bz_imag))\n",
884-
" f_vec = np.kron(frequencies, np.ones(ntx))\n",
885-
" receiver_locations = np.kron(np.ones((len(frequencies), 1)), receiver_locations)\n",
886-
"\n",
887-
" np.savetxt(fname, np.c_[f_vec, receiver_locations, bz_real, bz_imag], fmt=\"%.4e\")\n",
888-
"\n",
889-
" # Plot true model\n",
890-
" output_model = plotting_map * model\n",
891-
" output_model[np.isnan(output_model)] = 1e-8\n",
892-
"\n",
893-
" fname = dir_path + \"true_model.txt\"\n",
894-
" np.savetxt(fname, output_model, fmt=\"%.4e\")"
895-
]
896845
}
897846
],
898847
"metadata": {

notebooks/08-tdem/fwd_tdem_3d.ipynb

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
"from discretize.utils import mkvc, active_from_xyz\n",
8383
"\n",
8484
"# Common Python functionality\n",
85-
"import os\n",
8685
"import numpy as np\n",
8786
"import matplotlib as mpl\n",
8887
"import matplotlib.pyplot as plt\n",
@@ -913,56 +912,6 @@
913912
"\n",
914913
"plt.show()"
915914
]
916-
},
917-
{
918-
"cell_type": "markdown",
919-
"metadata": {},
920-
"source": [
921-
"## Optional: Export Data\n",
922-
"\n",
923-
"Write the true model, data and topography\n",
924-
"\n",
925-
"\n"
926-
]
927-
},
928-
{
929-
"cell_type": "code",
930-
"execution_count": 23,
931-
"metadata": {
932-
"execution": {
933-
"iopub.execute_input": "2025-05-23T17:54:48.125857Z",
934-
"iopub.status.busy": "2025-05-23T17:54:48.125627Z",
935-
"iopub.status.idle": "2025-05-23T17:54:48.132415Z",
936-
"shell.execute_reply": "2025-05-23T17:54:48.131374Z"
937-
}
938-
},
939-
"outputs": [],
940-
"source": [
941-
"if save_file:\n",
942-
" dir_path = os.path.dirname(tdem.__file__).split(os.path.sep)[:-3]\n",
943-
" dir_path.extend([\"tutorials\", \"assets\", \"tdem\"])\n",
944-
" dir_path = os.path.sep.join(dir_path) + os.path.sep\n",
945-
"\n",
946-
" fname = dir_path + \"tdem_topo.txt\"\n",
947-
" np.savetxt(fname, np.c_[topo_xyz], fmt=\"%.4e\")\n",
948-
"\n",
949-
" # Write data with 2% noise added\n",
950-
" fname = dir_path + \"tdem_data.obs\"\n",
951-
" rng = np.random.default_rng(seed=42)\n",
952-
" noise = rng.uniform(low=0.0, high=0.02 * np.abs(dpred), size=len(dpred))\n",
953-
" dpred += noise\n",
954-
" t_vec = np.kron(np.ones(ntx), time_channels)\n",
955-
" receiver_locations = np.kron(receiver_locations, np.ones((len(time_channels), 1)))\n",
956-
"\n",
957-
" np.savetxt(fname, np.c_[receiver_locations, t_vec, dpred], fmt=\"%.4e\")\n",
958-
"\n",
959-
" # Plot true model\n",
960-
" output_model = plotting_map * model\n",
961-
" output_model[np.isnan(output_model)] = 1e-8\n",
962-
"\n",
963-
" fname = dir_path + \"true_model.txt\"\n",
964-
" np.savetxt(fname, output_model, fmt=\"%.4e\")"
965-
]
966915
}
967916
],
968917
"metadata": {
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
Building the User Tutorials Website Locally
2+
===========================================
3+
4+
Here, we provide instructions for setting up an appropriate Python environment and building the SimPEG user tutorials website locally with [MyST](https://mystmd.org/).
5+
6+
## Step 1: Cloning the GitHub Repository
7+
8+
The URL for the SimPEG user tutorials GitHub repository is: https://github.com/simpeg/user-tutorials/. If using the Git Bash shell:
9+
10+
```bash
11+
git clone https://github.com/simpeg/user-tutorials
12+
cd user-tutorials
13+
```
14+
15+
## Step 2: Setting Up a Python Environment
16+
17+
The Jupyter notebooks containing the tutorials are maintained to run properly using the [latest release of SimPEG](https://github.com/simpeg/simpeg/releases).
18+
Notebooks may not run correctly if SimPEG is being imported from an earlier release or development branch.
19+
The [mystmd][install-mystmd] and [nodejs](https://nodejs.org/api/packages.html) are also required to build the website locally.
20+
21+
We advise building a Python environment from the `environment.yml` file in the root directory of the repository.
22+
To create the `simpeg-user-tutorials` environment using conda:
23+
24+
```bash
25+
conda env create -f environment.yml
26+
```
27+
28+
Once built, you can activate using:
29+
30+
```bash
31+
conda activate simpeg-user-tutorials
32+
```
33+
34+
## Step 3: Build and Execution Commands
35+
36+
The SimPEG user tutorials are a collection of [Jupyter Notebook](https://jupyter.org/) (and [Markdown](https://www.markdownguide.org/getting-started/)) files,
37+
which [MyST][mystmd.org] builds into a website. Here, we describe the commands that contributors should be familiar with.
38+
39+
:::{important}
40+
The tutorial notebooks, including their states, are tracked by GitHub. When the SimPEG user tutorials repository was cloned, all notebooks had been run and saved. Therefore, you do not need to rerun all of the notebooks prior to building the website!
41+
:::
42+
43+
### Locally Build and Serve Website
44+
45+
The following command will build the website and serve it locally.
46+
This will allow you to preview the website and observe any changes to notebooks on the fly.
47+
To locally build and serve the website:
48+
the website:
49+
50+
```bash
51+
myst start
52+
```
53+
54+
Next, follow the instructions prompted by the command to launch the local build in your brower.
55+
56+
### Build Only
57+
58+
The following command will build the website and store the HTML files in
59+
a new `_build` folder:
60+
61+
```bash
62+
myst build --html
63+
```
64+
65+
### Clean Cached Builds
66+
67+
```bash
68+
myst clean --all
69+
```
70+
71+
### Rerunning Notebooks
72+
73+
When making alterations and rerunning notebooks, we typically do so by launching Jupyter Notebooks:
74+
75+
```bash
76+
jupyter notebook
77+
```
78+
79+
However, we can rerun a notebook and overwrite its output cells in place using `nbconvert`.
80+
To rerun a single notebook, use:
81+
82+
```bash
83+
jupyter nbconvert --to notebook --execute --inplace notebook.ipynb
84+
```
85+
86+
We may also want to rerun all notebooks in the repository.
87+
To rerun all notebooks, use:
88+
89+
```bash
90+
jupyter nbconvert --to notebook --execute --inplace notebooks/**/*.ipynb
91+
```
92+
93+
:::{danger}
94+
Rerunning all notebooks is a computationally intensive task. Some notebooks
95+
require significant amount of memory to allocate large sensitivity matrices.
96+
:::
97+
98+
> [!IMPORTANT]
99+
> If you are using bash as your shell, make sure to run `shopt -s
100+
> globstar` to enable the `globstar` feature that allows the use of `**` for
101+
> filename expansion.
102+
103+
104+
105+
106+
[install-mystmd]: https://mystmd.org/guide/quickstart
107+
[jupyter]: https://jupyter.org
108+
[mystmd.org]: https://mystmd.org
109+

0 commit comments

Comments
 (0)