Skip to content

Commit 10141b8

Browse files
Quarto output
1 parent 49dd52d commit 10141b8

11 files changed

+355
-236
lines changed

notebooks/courses/microwave-remote-sensing/01_in_class_exercise.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"metadata": {},
2121
"outputs": [],
2222
"source": [
23-
"import pystac_client\n",
2423
"import folium\n",
24+
"import pystac_client\n",
2525
"from odc import stac as odc_stac"
2626
]
2727
},

notebooks/courses/microwave-remote-sensing/02_in_class_exercise.ipynb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
"metadata": {},
2727
"outputs": [],
2828
"source": [
29+
"import matplotlib.pyplot as plt\n",
2930
"import numpy as np\n",
30-
"import pystac_client\n",
3131
"import odc.stac\n",
32-
"import matplotlib.pyplot as plt\n",
33-
"import xarray as xr\n",
34-
"import rioxarray # noqa: F401"
32+
"import pystac_client\n",
33+
"import rioxarray # noqa: F401\n",
34+
"import xarray as xr"
3535
]
3636
},
3737
{
@@ -286,8 +286,10 @@
286286
"val1_lin, val2_lin = db2lin(val1_db), db2lin(val2_db)\n",
287287
"sum_lin = val1_lin + val2_lin\n",
288288
"print(\"\\nLinear Addition:\")\n",
289-
"print(f\"\"\"Linear values: \\t\\t{val1_lin: <5}, {val2_lin: <5.2f} [lin]\n",
290-
" \\t\\t\\t(converted from dB)\"\"\")\n",
289+
"print(\n",
290+
" f\"\"\"Linear values: \\t\\t{val1_lin: <5}, {val2_lin: <5.2f} [lin]\n",
291+
" \\t\\t\\t(converted from dB)\"\"\"\n",
292+
")\n",
291293
"print(f\"Linear sum: \\t\\t{val1_lin} + {val2_lin: .2f} = {sum_lin: .2f} [lin]\")\n",
292294
"print(f\"\\t\\t\\t= {lin2db(sum_lin): .2f} [dB]\")"
293295
]

notebooks/courses/microwave-remote-sensing/03_in_class_exercise.ipynb

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
"metadata": {},
2020
"outputs": [],
2121
"source": [
22-
"import numpy as np\n",
23-
"import xarray as xr\n",
22+
"import hvplot.xarray # noqa: F401\n",
2423
"import intake\n",
25-
"import rioxarray # noqa: F401\n",
26-
"import matplotlib.pyplot as plt # noqa: F401\n",
27-
"import hvplot.xarray # noqa: F401"
24+
"import matplotlib.pyplot as plt # noqa: F401\n",
25+
"import numpy as np\n",
26+
"import rioxarray # noqa: F401\n",
27+
"import xarray as xr"
2828
]
2929
},
3030
{
@@ -73,9 +73,15 @@
7373
"metadata": {},
7474
"outputs": [],
7575
"source": [
76-
"gtc_dc.hvplot.image(x=\"x\", y=\"y\", robust=True, data_aspect=1, cmap=\"Greys_r\",\n",
77-
" groupby=\"band\", rasterize=True).\\\n",
78-
" opts(frame_height=600, framewise=False, aspect=\"equal\")"
76+
"gtc_dc.hvplot.image(\n",
77+
" x=\"x\",\n",
78+
" y=\"y\",\n",
79+
" robust=True,\n",
80+
" data_aspect=1,\n",
81+
" cmap=\"Greys_r\",\n",
82+
" groupby=\"band\",\n",
83+
" rasterize=True,\n",
84+
").opts(frame_height=600, framewise=False, aspect=\"equal\")"
7985
]
8086
},
8187
{
@@ -154,9 +160,15 @@
154160
"outputs": [],
155161
"source": [
156162
"coef_dc = cat.coef.read().compute()\n",
157-
"coef_dc.hvplot.image(x=\"x\", y=\"y\", robust=True, data_aspect=1, cmap=\"Greys_r\",\n",
158-
" groupby=\"band\", rasterize=True).\\\n",
159-
" opts(frame_height=600, framewise=False, aspect=\"equal\")"
163+
"coef_dc.hvplot.image(\n",
164+
" x=\"x\",\n",
165+
" y=\"y\",\n",
166+
" robust=True,\n",
167+
" data_aspect=1,\n",
168+
" cmap=\"Greys_r\",\n",
169+
" groupby=\"band\",\n",
170+
" rasterize=True,\n",
171+
").opts(frame_height=600, framewise=False, aspect=\"equal\")"
160172
]
161173
},
162174
{
@@ -181,21 +193,26 @@
181193
"outputs": [],
182194
"source": [
183195
"# linear scale\n",
184-
"sig0_db = (coef_dc.sel(band=\"sig0_gtc\") / 10)\n",
196+
"sig0_db = coef_dc.sel(band=\"sig0_gtc\") / 10\n",
185197
"sig0_lin = 10 ** (coef_dc.sel(band=\"sig0_gtc\") / 10)\n",
186198
"# conversion to gamma\n",
187199
"gam0_lin = sig0_lin / np.cos(np.radians(coef_dc.sel(band=\"incidence_angle\")))\n",
188200
"# dB scale\n",
189201
"gam0_db = 10 * np.log(gam0_lin)\n",
190202
"# add to existing cube\n",
191203
"coef_dc = xr.concat(\n",
192-
" [coef_dc.sel(band=\"sig0_gtc\"), gam0_db.expand_dims(band=[\"gam0_gtc\"])],\n",
193-
" dim=\"band\"\n",
194-
" )\n",
204+
" [coef_dc.sel(band=\"sig0_gtc\"), gam0_db.expand_dims(band=[\"gam0_gtc\"])], dim=\"band\"\n",
205+
")\n",
195206
"\n",
196-
"coef_dc.hvplot.image(x=\"x\", y=\"y\", robust=False, data_aspect=1, cmap=\"Greys_r\",\n",
197-
" groupby=\"band\", rasterize=True).\\\n",
198-
" opts(frame_height=600, framewise=False, aspect=\"equal\")"
207+
"coef_dc.hvplot.image(\n",
208+
" x=\"x\",\n",
209+
" y=\"y\",\n",
210+
" robust=False,\n",
211+
" data_aspect=1,\n",
212+
" cmap=\"Greys_r\",\n",
213+
" groupby=\"band\",\n",
214+
" rasterize=True,\n",
215+
").opts(frame_height=600, framewise=False, aspect=\"equal\")"
199216
]
200217
},
201218
{
@@ -224,9 +241,15 @@
224241
"# add to existing cube\n",
225242
"rtc_dc = xr.concat([coef_dc, rtc_dc], dim=\"band\")\n",
226243
"\n",
227-
"rtc_dc.hvplot.image(x=\"x\", y=\"y\", robust=True, data_aspect=1, cmap=\"Greys_r\",\n",
228-
" groupby=\"band\", rasterize=True).\\\n",
229-
" opts(frame_height=600, framewise=False, aspect=\"equal\")"
244+
"rtc_dc.hvplot.image(\n",
245+
" x=\"x\",\n",
246+
" y=\"y\",\n",
247+
" robust=True,\n",
248+
" data_aspect=1,\n",
249+
" cmap=\"Greys_r\",\n",
250+
" groupby=\"band\",\n",
251+
" rasterize=True,\n",
252+
").opts(frame_height=600, framewise=False, aspect=\"equal\")"
230253
]
231254
},
232255
{

notebooks/courses/microwave-remote-sensing/04_in_class_exercise.ipynb

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,19 @@
4545
"metadata": {},
4646
"outputs": [],
4747
"source": [
48+
"from functools import partial\n",
49+
"from pathlib import Path\n",
50+
"\n",
51+
"import folium\n",
52+
"import hvplot.xarray # noqa: F401\n",
4853
"import numpy as np\n",
4954
"import pandas as pd\n",
50-
"import xarray as xr\n",
5155
"import rioxarray # noqa: F401\n",
52-
"import hvplot.xarray # noqa: F401\n",
53-
"import folium\n",
56+
"import xarray as xr\n",
5457
"from huggingface_hub import snapshot_download\n",
55-
"from shapely.geometry import mapping, box\n",
56-
"from shapely import affinity\n",
5758
"from rasterio.enums import Resampling\n",
58-
"from pathlib import Path\n",
59-
"from functools import partial"
59+
"from shapely import affinity\n",
60+
"from shapely.geometry import box, mapping"
6061
]
6162
},
6263
{
@@ -105,9 +106,8 @@
105106
" (data_path / \"sentinel-1\").glob(\"**/*.tif\"),\n",
106107
" engine=\"rasterio\",\n",
107108
" combine=\"nested\",\n",
108-
" concat_dim=\"band\"\n",
109-
" ).\\\n",
110-
" rio.transform_bounds(\"EPSG:4326\")\n",
109+
" concat_dim=\"band\",\n",
110+
").rio.transform_bounds(\"EPSG:4326\")\n",
111111
"\n",
112112
"bbox = box(*bbox)\n",
113113
"\n",
@@ -239,7 +239,7 @@
239239
"\n",
240240
" print(\n",
241241
" f\"{name} Raster: \\n----------------\\n\"\n",
242-
" f\"resolution: {raster.rio.resolution()} {raster.rio.crs.units_factor}\\n\" #noqa\n",
242+
" f\"resolution: {raster.rio.resolution()} {raster.rio.crs.units_factor}\\n\" # noqa\n",
243243
" f\"bounds: {raster.rio.bounds()}\\n\"\n",
244244
" f\"CRS: {raster.rio.crs}\\n\"\n",
245245
" )\n",
@@ -324,8 +324,8 @@
324324
" engine=\"rasterio\",\n",
325325
" combine=\"nested\",\n",
326326
" chunks=-1,\n",
327-
" preprocess=partial_\n",
328-
" )"
327+
" preprocess=partial_,\n",
328+
")"
329329
]
330330
},
331331
{
@@ -367,7 +367,7 @@
367367
"alos_ds_lin = alos_ds_lin.rio.reproject_match(\n",
368368
" s1_ds,\n",
369369
" resampling=Resampling.bilinear,\n",
370-
" )\n",
370+
")\n",
371371
"alos_ds = 10 * np.log10(alos_ds_lin)"
372372
]
373373
},
@@ -386,10 +386,12 @@
386386
"metadata": {},
387387
"outputs": [],
388388
"source": [
389-
"alos_ds = alos_ds.assign_coords({\n",
390-
" \"x\": s1_ds.x.data,\n",
391-
" \"y\": s1_ds.y.data,\n",
392-
"})"
389+
"alos_ds = alos_ds.assign_coords(\n",
390+
" {\n",
391+
" \"x\": s1_ds.x.data,\n",
392+
" \"y\": s1_ds.y.data,\n",
393+
" }\n",
394+
")"
393395
]
394396
},
395397
{
@@ -448,8 +450,7 @@
448450
"metadata": {},
449451
"outputs": [],
450452
"source": [
451-
"fused_da = fused_da.\\\n",
452-
" resample(time=\"ME\", skipna=True).median().compute()"
453+
"fused_da = fused_da.resample(time=\"ME\", skipna=True).median().compute()"
453454
]
454455
},
455456
{
@@ -467,9 +468,9 @@
467468
"metadata": {},
468469
"outputs": [],
469470
"source": [
470-
"fused_da.\\\n",
471-
" hvplot.image(robust=True, data_aspect=1, cmap=\"Greys_r\", rasterize=True).\\\n",
472-
" opts(frame_height=600, aspect=\"equal\")"
471+
"fused_da.hvplot.image(robust=True, data_aspect=1, cmap=\"Greys_r\", rasterize=True).opts(\n",
472+
" frame_height=600, aspect=\"equal\"\n",
473+
")"
473474
]
474475
},
475476
{

notebooks/courses/microwave-remote-sensing/05_in_class_exercise.ipynb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
"metadata": {},
2828
"outputs": [],
2929
"source": [
30-
"import numpy as np\n",
30+
"import holoviews as hv\n",
31+
"import hvplot.xarray # noqa: F401\n",
3132
"import intake\n",
3233
"import matplotlib.pyplot as plt\n",
33-
"import hvplot.xarray # noqa: F401\n",
34-
"import holoviews as hv"
34+
"import numpy as np"
3535
]
3636
},
3737
{
@@ -141,17 +141,21 @@
141141
"source": [
142142
"hv.output(widget_location=\"bottom\")\n",
143143
"\n",
144-
"t1 = fused_ds.gam0.\\\n",
145-
" isel(time=2).\\\n",
146-
" hvplot.image(robust=True, data_aspect=1, cmap=\"Greys_r\",\n",
147-
" rasterize=True, clim=(-25, 0)).\\\n",
148-
" opts(frame_height=400, aspect=\"equal\")\n",
144+
"t1 = (\n",
145+
" fused_ds.gam0.isel(time=2)\n",
146+
" .hvplot.image(\n",
147+
" robust=True, data_aspect=1, cmap=\"Greys_r\", rasterize=True, clim=(-25, 0)\n",
148+
" )\n",
149+
" .opts(frame_height=400, aspect=\"equal\")\n",
150+
")\n",
149151
"\n",
150-
"t2 = fused_ds.gam0.\\\n",
151-
" isel(time=-1).\\\n",
152-
" hvplot.image(robust=True, data_aspect=1, cmap=\"Greys_r\",\n",
153-
" rasterize=True, clim=(-25, 0)).\\\n",
154-
" opts(frame_height=400, aspect=\"equal\")\n",
152+
"t2 = (\n",
153+
" fused_ds.gam0.isel(time=-1)\n",
154+
" .hvplot.image(\n",
155+
" robust=True, data_aspect=1, cmap=\"Greys_r\", rasterize=True, clim=(-25, 0)\n",
156+
" )\n",
157+
" .opts(frame_height=400, aspect=\"equal\")\n",
158+
")\n",
155159
"\n",
156160
"t1 + t2"
157161
]
@@ -173,9 +177,9 @@
173177
"metadata": {},
174178
"outputs": [],
175179
"source": [
176-
"LAI_image = LAI_mean.hvplot.\\\n",
177-
" image(rasterize=True, cmap=\"viridis\", clim=(0, 6)).\\\n",
178-
" opts(title=\"Mean LAI (Selectable)\", frame_height=400, aspect=\"equal\")\n",
180+
"LAI_image = LAI_mean.hvplot.image(rasterize=True, cmap=\"viridis\", clim=(0, 6)).opts(\n",
181+
" title=\"Mean LAI (Selectable)\", frame_height=400, aspect=\"equal\"\n",
182+
")\n",
179183
"\n",
180184
"\n",
181185
"def get_timeseries(x, y):\n",

notebooks/courses/microwave-remote-sensing/06_in_class_exercise.ipynb

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@
2020
"metadata": {},
2121
"outputs": [],
2222
"source": [
23-
"import numpy as np\n",
24-
"import xarray as xr\n",
25-
"import rioxarray # noqa: F401\n",
26-
"import intake\n",
2723
"import json\n",
28-
"import matplotlib.pyplot as plt\n",
29-
"import matplotlib.patches as mpatches\n",
30-
"from matplotlib.colors import ListedColormap, BoundaryNorm\n",
24+
"\n",
3125
"import holoviews as hv\n",
26+
"import intake\n",
27+
"import matplotlib.patches as mpatches\n",
28+
"import matplotlib.pyplot as plt\n",
29+
"import numpy as np\n",
30+
"import rioxarray # noqa: F401\n",
31+
"import xarray as xr\n",
3232
"from holoviews.streams import RangeXY\n",
33+
"from matplotlib.colors import BoundaryNorm, ListedColormap\n",
3334
"\n",
3435
"hv.extension(\"bokeh\")"
3536
]
@@ -117,8 +118,7 @@
117118
" color_mapping_data = json.load(f)\n",
118119
"\n",
119120
"# Get mapping\n",
120-
"color_mapping = {item[\"value\"]: item for item in\n",
121-
" color_mapping_data[\"land_cover\"]}\n",
121+
"color_mapping = {item[\"value\"]: item for item in color_mapping_data[\"land_cover\"]}\n",
122122
"\n",
123123
"# Create cmap and norm for plotting\n",
124124
"colors = [info[\"color\"] for info in color_mapping.values()]\n",
@@ -143,21 +143,19 @@
143143
"outputs": [],
144144
"source": [
145145
"# Get landcover codes present in the image\n",
146-
"present_landcover_codes = np.unique(cor_da.values[~np.isnan(cor_da.values)].\n",
147-
" astype(int))\n",
146+
"present_landcover_codes = np.unique(cor_da.values[~np.isnan(cor_da.values)].astype(int))\n",
148147
"\n",
149148
"# Get colors + text for legend\n",
150149
"handles = [\n",
151-
" mpatches.Patch(\n",
152-
" color=info[\"color\"], label=(f'{info[\"value\"]} - ' + (info[\"label\"]))\n",
153-
" )\n",
150+
" mpatches.Patch(color=info[\"color\"], label=(f'{info[\"value\"]} - ' + (info[\"label\"])))\n",
154151
" for info in color_mapping.values()\n",
155152
" if info[\"value\"] in present_landcover_codes\n",
156153
"]\n",
157154
"\n",
158155
"# Create the plot\n",
159-
"cor_da.plot(figsize=(10, 10), cmap=cmap, norm=norm, add_colorbar=False).\\\n",
160-
" axes.set_aspect(\"equal\")\n",
156+
"cor_da.plot(figsize=(10, 10), cmap=cmap, norm=norm, add_colorbar=False).axes.set_aspect(\n",
157+
" \"equal\"\n",
158+
")\n",
161159
"\n",
162160
"plt.legend(\n",
163161
" handles=handles,\n",

0 commit comments

Comments
 (0)