Skip to content

Commit fed1392

Browse files
authored
Merge pull request #177 from mnfienen/pathrefactor
refactor pathlib import to be just Path (not pl.Path) and clear noteb…
2 parents 4a15127 + 659d59b commit fed1392

25 files changed

Lines changed: 83 additions & 255 deletions

notebooks/clear_all_notebooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
import pathlib as pl
2+
from pathlib import Path
33
import json
44
import subprocess
55

@@ -20,7 +20,7 @@
2020
]
2121

2222
if __name__ == "__main__":
23-
nbdir = pl.Path(".")
23+
nbdir = Path(".")
2424
nbs = nbdir.rglob("*.ipynb")
2525
for nb in nbs:
2626
if ('solutions' not in str(nb) and

notebooks/part0_python_intro/01_functions_scripts.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@
691691
],
692692
"metadata": {
693693
"kernelspec": {
694-
"display_name": "pyclass",
694+
"display_name": "Python 3 (ipykernel)",
695695
"language": "python",
696696
"name": "python3"
697697
}

notebooks/part0_python_intro/03_useful-std-library-modules.ipynb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,21 +1254,9 @@
12541254
],
12551255
"metadata": {
12561256
"kernelspec": {
1257-
"display_name": "pyclass",
1257+
"display_name": "Python 3 (ipykernel)",
12581258
"language": "python",
12591259
"name": "python3"
1260-
},
1261-
"language_info": {
1262-
"codemirror_mode": {
1263-
"name": "ipython",
1264-
"version": 3
1265-
},
1266-
"file_extension": ".py",
1267-
"mimetype": "text/x-python",
1268-
"name": "python",
1269-
"nbconvert_exporter": "python",
1270-
"pygments_lexer": "ipython3",
1271-
"version": "3.11.11"
12721260
}
12731261
},
12741262
"nbformat": 4,

notebooks/part0_python_intro/04_files_and_strings.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
"outputs": [],
2323
"source": [
2424
"import sys\n",
25-
"import pathlib as pl\n",
25+
"from pathlib import Path\n",
2626
"import numpy as np\n",
2727
"import matplotlib.pyplot as plt\n",
2828
"\n",
2929
"# set up the path to our data\n",
30-
"pthnb = pl.Path('data') / 'fileio'\n",
30+
"pthnb = Path('data') / 'fileio'\n",
3131
"assert pthnb.is_dir()"
3232
]
3333
},
@@ -259,7 +259,7 @@
259259
"# the current working directory; now we use pathlib\n",
260260
"# os.getcwd()\n",
261261
"\n",
262-
"cwd = pl.Path.cwd()\n",
262+
"cwd = Path.cwd()\n",
263263
"print(cwd)"
264264
]
265265
},
@@ -816,7 +816,7 @@
816816
"metadata": {},
817817
"source": [
818818
"### Class Activity 4\n",
819-
"Let's use the `file_filter` function to remove the comment lines from `'FileWithComments.txt'` and create `'FileWithOutComments.txt'`. Use one of the approaches discussed above to open, read, and print data in both files after calling the `file_filter` function. Remember to use the pl.Path() approach to access the file in the `pthnb` directory. \n",
819+
"Let's use the `file_filter` function to remove the comment lines from `'FileWithComments.txt'` and create `'FileWithOutComments.txt'`. Use one of the approaches discussed above to open, read, and print data in both files after calling the `file_filter` function. Remember to use the Path() approach to access the file in the `pthnb` directory. \n",
820820
"\n",
821821
"Use the blank code block below to complete this activity."
822822
]

notebooks/part0_python_intro/06_matplotlib.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"source": [
2222
"from IPython.display import clear_output, display\n",
2323
"\n",
24-
"import pathlib as pl\n",
24+
"from pathlib import Path\n",
2525
"\n",
26-
"output_path = pl.Path(\"./data/matplotlib\")\n",
26+
"output_path = Path(\"./data/matplotlib\")\n",
2727
"output_path.mkdir(exist_ok=True, parents=True)"
2828
]
2929
},
@@ -1151,7 +1151,7 @@
11511151
"metadata": {},
11521152
"outputs": [],
11531153
"source": [
1154-
"path = pl.Path(f\"{output_path}/multipage_pdf.pdf\")\n",
1154+
"path = Path(f\"{output_path}/multipage_pdf.pdf\")\n",
11551155
"y = np.sin(x * np.pi)\n",
11561156
"\n",
11571157
"with PdfPages(path) as pdf:\n",
@@ -1177,7 +1177,7 @@
11771177
],
11781178
"metadata": {
11791179
"kernelspec": {
1180-
"display_name": "lisus_p2",
1180+
"display_name": "Python 3 (ipykernel)",
11811181
"language": "python",
11821182
"name": "python3"
11831183
}

notebooks/part0_python_intro/06b_matplotlib_animation.ipynb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@
9494
"source": []
9595
}
9696
],
97-
"metadata": {},
97+
"metadata": {
98+
"kernelspec": {
99+
"display_name": "Python 3 (ipykernel)",
100+
"language": "python",
101+
"name": "python3"
102+
}
103+
},
98104
"nbformat": 4,
99-
"nbformat_minor": 2
105+
"nbformat_minor": 4
100106
}

notebooks/part0_python_intro/07a_Theis-exercise.ipynb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,13 @@
179179
"source": []
180180
}
181181
],
182-
"metadata": {},
182+
"metadata": {
183+
"kernelspec": {
184+
"display_name": "Python 3 (ipykernel)",
185+
"language": "python",
186+
"name": "python3"
187+
}
188+
},
183189
"nbformat": 4,
184190
"nbformat_minor": 4
185191
}

notebooks/part0_python_intro/09_b_Geopandas_ABQ.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"outputs": [],
1717
"source": [
1818
"import geopandas as gp\n",
19-
"import pathlib as pl\n",
19+
"from pathlib import Path\n",
2020
"import fiona\n",
2121
"fiona.drvsupport.supported_drivers['libkml'] = 'rw' # enable KML support which is disabled by default\n",
2222
"fiona.drvsupport.supported_drivers['LIBKML'] = 'rw' # enable KML support which is disabled by default\n"
@@ -39,7 +39,7 @@
3939
"metadata": {},
4040
"outputs": [],
4141
"source": [
42-
"datapath = pl.Path('./data/geopandas/abq/')"
42+
"datapath = Path('./data/geopandas/abq/')"
4343
]
4444
},
4545
{

notebooks/part0_python_intro/10a_Rasterio_intro.ipynb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"import rasterio\n",
2424
"from rasterio.plot import show\n",
2525
"import matplotlib.pyplot as plt\n",
26-
"import pathlib as pl"
26+
"from pathlib import Path"
2727
]
2828
},
2929
{
@@ -33,7 +33,7 @@
3333
"metadata": {},
3434
"outputs": [],
3535
"source": [
36-
"data_path = pl.Path(\"data/rasterio\") # set path to raster data folder"
36+
"data_path = Path(\"data/rasterio\") # set path to raster data folder"
3737
]
3838
},
3939
{
@@ -815,18 +815,6 @@
815815
"display_name": "Python 3 (ipykernel)",
816816
"language": "python",
817817
"name": "python3"
818-
},
819-
"language_info": {
820-
"codemirror_mode": {
821-
"name": "ipython",
822-
"version": 3
823-
},
824-
"file_extension": ".py",
825-
"mimetype": "text/x-python",
826-
"name": "python",
827-
"nbconvert_exporter": "python",
828-
"pygments_lexer": "ipython3",
829-
"version": "3.12.2"
830818
}
831819
},
832820
"nbformat": 4,

notebooks/part0_python_intro/10b_Rasterio_advanced.ipynb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"from rasterio import features\n",
5151
"import matplotlib.pyplot as plt\n",
5252
"from matplotlib.colors import LightSource\n",
53-
"import pathlib as pl\n",
53+
"from pathlib import Path\n",
5454
"\n",
5555
"# for elevation hillshade if we want to use it\n",
5656
"ls = LightSource(azdeg=315, altdeg=45)"
@@ -73,7 +73,7 @@
7373
"metadata": {},
7474
"outputs": [],
7575
"source": [
76-
"data_path = pl.Path(\"data/rasterio\")\n",
76+
"data_path = Path(\"data/rasterio\")\n",
7777
"\n",
7878
"dem_file_1970 = data_path / \"19700901_ned1_2003_adj_warp.tif\"\n",
7979
"dem_file_2008 = data_path / \"20080901_rainierlidar_30m-adj.tif\"\n",
@@ -983,18 +983,6 @@
983983
"display_name": "Python 3 (ipykernel)",
984984
"language": "python",
985985
"name": "python3"
986-
},
987-
"language_info": {
988-
"codemirror_mode": {
989-
"name": "ipython",
990-
"version": 3
991-
},
992-
"file_extension": ".py",
993-
"mimetype": "text/x-python",
994-
"name": "python",
995-
"nbconvert_exporter": "python",
996-
"pygments_lexer": "ipython3",
997-
"version": "3.12.2"
998986
}
999987
},
1000988
"nbformat": 4,

0 commit comments

Comments
 (0)