Skip to content
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
45 changes: 19 additions & 26 deletions notebooks/clear_all_notebooks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import pathlib as pl
import json
import subprocess

notebook_count = 0
# add the basenames of any notebooks we want to keep the results of
Expand All @@ -18,30 +19,22 @@
'10_modpath_particle_tracking-demo.ipynb'
]

def check_nb_for_output(notebook):
has_output = False
# run autotest on each notebook
with open(notebook) as src:
data = src.read()
data = json.loads(data)
for item in data['cells']:
for k, v in item.items():
if item['cell_type'] == 'code':
if any (item['outputs']):
has_output = True
return has_output


if __name__ == "__main__":

for [path, subdirs, files] in os.walk('.'):
for cf in files:
if cf.lower().endswith('.ipynb') and '.ipynb_checkpoint' not in path:
nb = pl.Path(path) / cf
if ('solutions' not in str(nb) and
nb.name not in skip_notebooks and
check_nb_for_output(nb) is True):
print(f"clearing {nb}")
os.system(f"jupyter nbconvert --clear-output --inplace {nb._str}")
notebook_count += 1
print(notebook_count," notebooks cleared")
nbdir = pl.Path(".")
nbs = nbdir.rglob("*.ipynb")
for nb in nbs:
if ('solutions' not in str(nb) and
nb.name not in skip_notebooks):
print("clearing", nb)
cmd = (
"jupyter",
"nbconvert",
"--ClearOutputPreprocessor.enabled=True",
"--ClearMetadataPreprocessor.enabled=True",
"--ClearMetadataPreprocessor.preserve_nb_metadata_mask={('kernelspec')}",
"--inplace",
nb,
)
proc = subprocess.run(cmd)
assert proc.returncode == 0, f"Error running command: {' '.join(cmd)}"

12 changes: 0 additions & 12 deletions notebooks/part0_python_intro/00_python_basics_review.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1379,18 +1379,6 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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.10"
}
},
"nbformat": 4,
Expand Down
16 changes: 1 addition & 15 deletions notebooks/part0_python_intro/00_skills_test_on_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@
"cell_type": "code",
"execution_count": null,
"id": "b755a4ce",
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [],
"source": [
"# finally split on \"whitespace\" resulting in a list of words\n",
Expand Down Expand Up @@ -287,18 +285,6 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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.13"
}
},
"nbformat": 4,
Expand Down
12 changes: 0 additions & 12 deletions notebooks/part0_python_intro/01_functions_scripts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -694,18 +694,6 @@
"display_name": "pyclass",
"language": "python",
"name": "python3"
},
"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.12.11"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1605,18 +1605,6 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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,
Expand Down
12 changes: 0 additions & 12 deletions notebooks/part0_python_intro/03_useful-std-library-modules.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1252,18 +1252,6 @@
"display_name": "pyclass",
"language": "python",
"name": "python3"
},
"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,
Expand Down
12 changes: 0 additions & 12 deletions notebooks/part0_python_intro/04_files_and_strings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -843,18 +843,6 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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.12.1"
}
},
"nbformat": 4,
Expand Down
29 changes: 13 additions & 16 deletions notebooks/part0_python_intro/05_numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@
"print('a[:10]: ', a[:10])\n",
"\n",
"#or print the values from position 20 to the end\n",
"print('a[90:]', a[20:])"
"print('a[20:]', a[20:])"
]
},
{
Expand Down Expand Up @@ -576,7 +576,7 @@
"metadata": {},
"outputs": [],
"source": [
"a[slice(50, None, 5)]"
"a[slice(10, None, 5)]"
]
},
{
Expand Down Expand Up @@ -643,6 +643,15 @@
"#what do you think? Do you think numpy has an identity function?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"np.eye(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -772,7 +781,7 @@
"metadata": {},
"outputs": [],
"source": [
"# are they the same shape and have all the xam\n",
"# are they the same shape and have all the same values\n",
"np.array_equal(a, b), np.array_equal(b,c)"
]
},
Expand Down Expand Up @@ -1748,21 +1757,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "pyclass",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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,
Expand Down
12 changes: 0 additions & 12 deletions notebooks/part0_python_intro/06_matplotlib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1180,18 +1180,6 @@
"display_name": "lisus_p2",
"language": "python",
"name": "python3"
},
"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.10"
}
},
"nbformat": 4,
Expand Down
6 changes: 1 addition & 5 deletions notebooks/part0_python_intro/06b_matplotlib_animation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
6 changes: 1 addition & 5 deletions notebooks/part0_python_intro/07a_Theis-exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,7 @@
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"metadata": {},
"nbformat": 4,
"nbformat_minor": 4
}
12 changes: 0 additions & 12 deletions notebooks/part0_python_intro/08_pandas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1527,18 +1527,6 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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,
Expand Down
17 changes: 2 additions & 15 deletions notebooks/part0_python_intro/09_a_Geopandas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"hoods_boundary = gp.GeoDataFrame(data={'thing':['bounding_box']},geometry=[bbox], crs=hoods.crs)\n",
"hoods_boundary"
]
Expand Down Expand Up @@ -900,7 +899,7 @@
"metadata": {},
"outputs": [],
"source": [
"trees = gp.read_file(datapath / 'Street_Trees.geojson', index_col=0)\n",
"trees = gp.read_file(datapath / 'Street_Trees.geojson')\n",
"trees.plot(column='SPECIES')"
]
},
Expand Down Expand Up @@ -1110,7 +1109,7 @@
},
{
"cell_type": "markdown",
"id": "1952cb07",
"id": "4fa8965f-9b9a-4e6e-9426-a45ce2ee1527",
"metadata": {},
"source": [
"### On your own...\n",
Expand All @@ -1132,18 +1131,6 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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,
Expand Down
12 changes: 0 additions & 12 deletions notebooks/part0_python_intro/09_b_Geopandas_ABQ.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,6 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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,
Expand Down
Loading
Loading