Skip to content

Commit

Permalink
update for winter term 2024/2025
Browse files Browse the repository at this point in the history
  • Loading branch information
fneum committed Oct 15, 2024
1 parent bc6e35f commit 37add99
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 335 deletions.
7 changes: 1 addition & 6 deletions data-science-for-esm/01-workshop-python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1608,12 +1608,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
},
"vscode": {
"interpreter": {
"hash": "69786ae8c799a179d39b18fbc76c1e4e4ca1662535939a7096f8f45ee1440c35"
}
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
5 changes: 3 additions & 2 deletions data-science-for-esm/02-workshop-numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@
"metadata": {},
"source": [
"Numpy also has some utilities for helping us generate multi-dimensional arrays.\n",
"For instance, `meshgrid` creates 2D arrays out of a combination of 1D arrays."
"For instance, `meshgrid` creates 2D arrays out of a combination of 1D arrays.\n",
"It takes two arrays representing x and y values and creates two 2D grids: one for all the x coordinates and another for all the y coordinates, which can be used to evaluate functions on a complete grid covering the x-y plane."
]
},
{
Expand Down Expand Up @@ -1338,7 +1339,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
11 changes: 3 additions & 8 deletions data-science-for-esm/03-workshop-pandas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@
"metadata": {},
"outputs": [],
"source": [
"ts.resample(\"M\").mean().head()"
"ts.resample(\"ME\").mean().head()"
]
},
{
Expand All @@ -949,7 +949,7 @@
"metadata": {},
"outputs": [],
"source": [
"ts.resample(\"M\").mean().plot()"
"ts.resample(\"ME\").mean().plot()"
]
},
{
Expand Down Expand Up @@ -1559,12 +1559,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
},
"vscode": {
"interpreter": {
"hash": "69786ae8c799a179d39b18fbc76c1e4e4ca1662535939a7096f8f45ee1440c35"
}
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion data-science-for-esm/04-workshop-geopandas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
26 changes: 21 additions & 5 deletions data-science-for-esm/05-workshop-pysheds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@
"outputs": [],
"source": [
"fn = \"output_COP30.tif\"\n",
"grid = Grid.from_raster(fn)\n",
"dem = grid.read_raster(fn)"
"grid = Grid.from_raster(fn, nodata=0)\n",
"dem = grid.read_raster(fn, nodata=0)"
]
},
{
Expand Down Expand Up @@ -173,8 +173,24 @@
"metadata": {},
"outputs": [],
"source": [
"pit_filled_dem = grid.fill_pits(dem)\n",
"flooded_dem = grid.fill_depressions(pit_filled_dem)\n",
"pit_filled_dem = grid.fill_pits(dem)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"flooded_dem = grid.fill_depressions(pit_filled_dem)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"conditioned_dem = grid.resolve_flats(flooded_dem)"
]
},
Expand Down Expand Up @@ -431,7 +447,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions data-science-for-esm/06-workshop-atlite.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@
"outputs": [],
"source": [
"url = \"https://tubcloud.tu-berlin.de/s/XoDpBcweJHmYKgF/download/GEBCO_2014_2D-PT.nc\"\n",
"gebco = rasterio.open(url)"
"gebco = rasterio.open(url, driver=\"netcdf\")"
]
},
{
Expand Down Expand Up @@ -1324,7 +1324,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
106 changes: 10 additions & 96 deletions data-science-for-esm/07-workshop-networkx.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Say we want to calculate the Laplacian $L$ of this graph based on its incidence\n",
"Say we want to calculate the so-called *Laplacian* $L$ of this graph based on its incidence\n",
"matrix $K$, which is an $N\\times N$ matrix defined as $L=KK^\\top$ for an\n",
"undirected graph. The Laplacian matrix of a graph is a representation that\n",
"captures the connectivity and structure of the graph by quantifying the\n",
Expand Down Expand Up @@ -120,13 +120,6 @@
"K"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To calculate the Laplacian matrix, we form a dot product of the incidence matrix with its transpose:"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -700,92 +693,6 @@
"L"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What is the *degree matrix*?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"G.degree()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here, we need to do some work to produce a diagonal matrix from the output of `G.degree()`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"degrees = [val for node, val in G.degree()]\n",
"D = np.diag(degrees)\n",
"D"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's do a few checks using different formulas for the *Laplacian matrix*:\n",
"\n",
"$$L = KK^\\top$$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"K.dot(K.T)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"assert (K.dot(K.T) == L).all()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$L = D-A$$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"D - A"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"assert (D - A == L).all()"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1011,7 +918,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's checkout the synchronous zone of Ireland. We want to compute the **Power Transfer Distribution Factor (PTDF)** matrix for this area.\n",
"Let's checkout the synchronous zone of Ireland. We want to compute the so-called **Power Transfer Distribution Factor (PTDF)** matrix for this area.\n",
"\n",
"The **PTDF** matrix measures the sensitivity of power flows in each transmission line relative to incremental changes in nodal power injections or withdrawals throughout the electricity network. It is a matrix representation showing how changes in power injections or withdrawals at various nodes in a power grid affect the flow in each of its transmission lines. It is an alternative formulation for linearised power flow to the cycle-based approache from the lecture.\n",
"\n",
Expand Down Expand Up @@ -1653,6 +1560,13 @@
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -1677,7 +1591,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
16 changes: 15 additions & 1 deletion data-science-for-esm/08-workshop-pyomo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,20 @@
"- What parameters of the storage unit would have to be changed to reduce the objective? What's the sensitivity?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -1880,7 +1894,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 37add99

Please sign in to comment.