Skip to content

Commit b79b1ca

Browse files
Merge pull request #51 from TUW-GEO/dev
add remote cmap
2 parents e478cda + 83e1170 commit b79b1ca

26 files changed

+503
-412
lines changed

Diff for: .isort.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
known_third_party = eo_datascience,nbformat,pytest,setuptools,yaml

Diff for: .pre-commit-config.yaml

+61-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,72 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0 # the release, git tag, or commit you want to use
3+
rev: v4.6.0 # the release, git tag, or commit you want to use
44
hooks:
55
- id: trailing-whitespace
66
- id: check-added-large-files
77
- id: check-yaml
88
- id: detect-private-key
9+
- id: end-of-file-fixer
10+
- id: check-docstring-first
11+
- id: check-json
12+
- id: double-quote-string-fixer
13+
14+
- repo: https://github.com/psf/black
15+
rev: 23.12.1
16+
hooks:
17+
- id: black
18+
19+
- repo: https://github.com/keewis/blackdoc
20+
rev: v0.3.9
21+
hooks:
22+
- id: blackdoc
23+
24+
- repo: https://github.com/PyCQA/flake8
25+
rev: 7.0.0
26+
hooks:
27+
- id: flake8
28+
29+
- repo: https://github.com/asottile/seed-isort-config
30+
rev: v2.2.0
31+
hooks:
32+
- id: seed-isort-config
33+
34+
- repo: https://github.com/PyCQA/isort
35+
rev: 5.13.2
36+
hooks:
37+
- id: isort
38+
39+
- repo: https://github.com/pre-commit/mirrors-prettier
40+
rev: v3.1.0
41+
hooks:
42+
- id: prettier
43+
additional_dependencies: [[email protected]]
44+
45+
- repo: https://github.com/nbQA-dev/nbQA
46+
rev: 1.7.1
47+
hooks:
48+
- id: nbqa-black
49+
additional_dependencies: [black]
50+
- id: nbqa-pyupgrade
51+
additional_dependencies: [pyupgrade]
52+
exclude: foundations/quickstart.ipynb
53+
- id: nbqa-isort
54+
additional_dependencies: [isort]
55+
56+
- repo: https://github.com/s-weigand/flake8-nb
57+
rev: "v0.5.3"
58+
hooks:
59+
- id: flake8-nb
60+
61+
# - repo: local
62+
# hooks:
63+
# - id: convert-ipynb
64+
# name: Convert Jupyter notebooks
65+
# entry: make convert
66+
# language: system
67+
# pass_filenames: false
968

1069
- repo: https://github.com/kynan/nbstripout
1170
rev: 0.7.1
1271
hooks:
13-
- id: nbstripout
72+
- id: nbstripout

Diff for: Makefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ YML = $(wildcard notebooks/**/*.yml)
66
REQ := $(basename $(notdir $(YML)))
77
NB != find chapters -name "*.quarto_ipynb" -o -name "*.ipynb" -not -path \
88
"*/.jupyter_cache/*"
9+
QN != git diff --cached --name-only "***.ipynb"
910

1011
CONDA_ENV != conda info --base
1112
CONDA_ACTIVATE := source $(CONDA_ENV)/etc/profile.d/conda.sh ; \
@@ -53,6 +54,11 @@ post-render:
5354
cp ./Makefile ./notebooks/
5455
cp -r ./chapters/images ./notebooks
5556

57+
convert:
58+
$(foreach f, $(QN), \
59+
quarto convert $(f); \
60+
mv $(subst .ipynb,.qmd, $(f)) $(subst notebooks,chapters,$(subst .ipynb,.qmd,$(f))); )
61+
5662
preview: $(CONDA_ENV)/envs/eo-datascience $(CONDA_ENV_DIR) $(KERNEL_DIR)
5763
$(CONDA_ACTIVATE) eo-datascience
5864
- mkdir -p _preview/notebooks
@@ -79,4 +85,4 @@ teardown:
7985
jupyter kernelspec uninstall -y $(f); \
8086
conda deactivate; \
8187
conda remove -n $(f) --all -y ; \
82-
conda deactivate; )
88+
conda deactivate; )

Diff for: chapters/courses/microwave-remote-sensing/02_in_class_exercise.qmd

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import pystac_client
2323
import odc.stac
2424
import matplotlib.pyplot as plt
2525
import xarray as xr
26-
import rioxarray # noqa
26+
import rioxarray # noqa: F401
2727
```
2828

2929
## Exploring the Data
@@ -288,4 +288,3 @@ data_2_save.rio.to_raster(
288288
loaded_data = xr.open_dataset("sig0_mean_mosaic_july.tif", engine="rasterio")
289289
loaded_data
290290
```
291-

Diff for: chapters/courses/microwave-remote-sensing/03_in_class_exercise.qmd

+3-8
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ In this notebook, we will introduce some of the steps involved in the processing
1414
import numpy as np
1515
import xarray as xr
1616
import intake
17-
18-
import rioxarray #noqa
19-
import matplotlib.pyplot as plt # noqa
20-
import hvplot.xarray # noqa
21-
22-
from pathlib import Path
23-
from functools import partial
17+
import rioxarray # noqa: F401
18+
import matplotlib.pyplot as plt # noqa: F401
19+
import hvplot.xarray # noqa: F401
2420
```
2521

2622
## Loading Backscatter Data
@@ -156,4 +152,3 @@ rtc_dc.hvplot.image(x="x", y="y", robust=True, data_aspect=1, cmap="Greys_r",
156152
*Figure 7: $\sigma^0_E$, $\gamma^0_E$, and $\gamma^0_T$ can be selected on the right-hand side of the graphic.*
157153

158154
When comparing $\gamma^0_E$ and $\gamma^0_T$ in the plot we can clearly see the impact of the radiometric correction in the mountainous areas. This correction is necessary, because for slopes facing towards the sensor, a larger ground area contributes to the backscatter value of a slant range resolution cell, than for slopes lying in the opposite direction. This results in significant brightness changes, where foreshortening areas appear brighter and lengthening areas darker. $\gamma^0_T$ adjusts the backscatter to represent what it would be if the terrain was flat, thus reducing these effects. This significantly reduces the impact of the terrain on the backscatter values, allowing for more accurate comparisons across different terrain types and locations. The correction is done by using a DEM to determine the local illuminated area at each radar position. The above illustrated approach is also referred to as terrain flattening because in the resulting image, mountains appear flat. As $\gamma^0_T$ is corrected for geometric and radiometric distortions, it is also referred to as Normalized Radar Backscatter (NRB) and is the current standard for Analysis-Ready-Backscatter (ARD).
159-

Diff for: chapters/courses/microwave-remote-sensing/04_in_class_exercise.qmd

+2-5
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@ In this notebook we will study two different SAR products. SAR data from the Adv
4040
import numpy as np
4141
import pandas as pd
4242
import xarray as xr
43-
import rioxarray # noqa
44-
import hvplot.xarray # noqa
43+
import rioxarray # noqa: F401
44+
import hvplot.xarray # noqa: F401
4545
import folium
46-
4746
from huggingface_hub import snapshot_download
4847
from shapely.geometry import mapping, box
4948
from shapely import affinity
5049
from rasterio.enums import Resampling
51-
5250
from pathlib import Path
5351
from functools import partial
5452
```
@@ -299,4 +297,3 @@ fused_da.\
299297
```
300298

301299
*Figure 3: Stacked array with ALOS-2 L-band and Sentinel-1 C-band $\gamma^0_T (dB)$.*
302-

Diff for: chapters/courses/microwave-remote-sensing/05_in_class_exercise.qmd

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ In this notebook, we aim to demonstrate how C-band (4–8 GHz, wavelengths of ap
2020

2121
```{python}
2222
import numpy as np
23-
import xarray as xr
2423
import intake
25-
2624
import matplotlib.pyplot as plt
27-
import hvplot.xarray # noqa
25+
import hvplot.xarray # noqa: F401
2826
import holoviews as hv
2927
```
3028

@@ -154,4 +152,3 @@ LAI_image + time_series
154152
Can you see some patterns when analyzing the different wavelengths and polarizations?
155153

156154
Remember again that we deal with a logarithmic scale. A measurement of 10 dB is 10 times brighter than the intensity measured at 0 dB, and 100 times brighter at 20 dB. The most notable difference is that the offset between cross- and co-polarised signals becomes larger at low LAI and lower at higher LAI. This might indicate the effect of volume scattering in forested areas where co- and cross-polarization render backscattering values more equal. You will study the differences among cross- and co-polarized backscattering in more detail in the homework exercise.
157-

Diff for: chapters/courses/microwave-remote-sensing/06_in_class_exercise.qmd

+2-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ In this notebook, we will investigate the varying backscatter values associated
1414
```{python}
1515
import numpy as np
1616
import xarray as xr
17-
import rioxarray # noqa
18-
17+
import rioxarray # noqa: F401
1918
import intake
2019
import json
21-
22-
from functools import partial
23-
from pathlib import Path
24-
2520
import matplotlib.pyplot as plt
2621
import matplotlib.patches as mpatches
2722
from matplotlib.colors import ListedColormap, BoundaryNorm
@@ -62,7 +57,7 @@ For the different land cover types we use the official color encoding which can
6257

6358
```{python}
6459
# Load encoding
65-
with open("../../images/cmaps/06_color_mapping.json", "r") as f:
60+
with cat.corine_cmap.read()[0] as f:
6661
color_mapping_data = json.load(f)
6762
6863
# Get mapping
@@ -220,4 +215,3 @@ hist_opts = hv.opts.Histogram(width=350, height=555)
220215
221216
dmap.opts(image_opts, hist_opts)
222217
```
223-

Diff for: chapters/courses/microwave-remote-sensing/07_in_class_exercise.qmd

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ Speckle is defined as a kind of noise that affects all radar images. Given the m
1818

1919
```{python}
2020
import numpy as np
21-
import xarray as xr
2221
import intake
2322
import json
24-
from pathlib import Path
2523
import matplotlib.pyplot as plt
2624
import holoviews as hv
2725
from holoviews.streams import RangeXY
@@ -139,7 +137,7 @@ We also create the same dashboard for backscatter of different landcover types o
139137

140138
```{python}
141139
# Load encoding
142-
with open("../../images/cmaps/06_color_mapping.json", "r") as f:
140+
with cat.corine_cmap.read()[0] as f:
143141
color_mapping_data = json.load(f)
144142
145143
# Get mapping
@@ -354,4 +352,3 @@ plot_variability(fused_ds, filter_fun_temporal=temporal_filter)
354352
*Figure 4: Lake Neusiedl $\sigma^0_E$ with a temporal filter applied.*
355353

356354
Let´s observe the histograms of the two plots. Especially in the region around the lake, it is clear that the distribution is now less dispersed and more centered around a central value.
357-

Diff for: chapters/courses/microwave-remote-sensing/08_in_class_exercise.qmd

-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ This notebook will outline the process of working with interferograms and the st
1919

2020

2121
```{python}
22-
import xarray as xr
23-
import numpy as np
2422
import matplotlib.pyplot as plt
2523
import hvplot.xarray # noqa: F401
2624
import seaborn as sns
2725
import holoviews as hv
2826
import folium
2927
import base64
3028
import intake
31-
from pathlib import Path
3229
from io import BytesIO
3330
3431
hv.extension("bokeh")
@@ -285,4 +282,3 @@ folium.LayerControl().add_to(m)
285282
286283
m
287284
```
288-

Diff for: chapters/courses/microwave-remote-sensing/09_in_class_exercise.qmd

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import numpy as np
2727
import matplotlib.pyplot as plt
2828
import matplotlib.patches as patches
2929
import xarray as xr
30-
from pathlib import Path
3130
import cmcrameri as cmc # noqa: F401
3231
import snaphu
3332
import seaborn as sns
@@ -427,4 +426,3 @@ In the following animation, we can capture the 3D displacement caused by the Rid
427426

428427
![](../../images/ridgecrest.gif)
429428
*Credits: NASA*
430-

Diff for: chapters/images/cmaps/06_color_mapping.json

-50
This file was deleted.

Diff for: chapters/tutorials/floodmapping.qmd

+12-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import numpy as np
2424
import xarray as xr
2525
import numpy as np
2626
import datetime
27-
import rioxarray
27+
import rioxarray # noqa: F401
2828
import pandas as pd
2929
3030
import hvplot.pandas
@@ -93,8 +93,9 @@ def post_process_eodc_cube(dc, items, bands):
9393
9494
9595
def post_process_eodc_cube_(dc, items, band):
96-
scale = items[0].assets[band].extra_fields.get("raster:bands")[0]["scale"]
97-
nodata = items[0].assets[band].extra_fields.get("raster:bands")[0]["nodata"]
96+
fields = items[0].assets[band].extra_fields
97+
scale = fields.get("raster:bands")[0]["scale"]
98+
nodata = fields.get("raster:bands")[0]["nodata"]
9899
return dc.where(dc != nodata) / scale
99100
100101
@@ -312,7 +313,9 @@ likelihood_pdi = hvplot.bind(
312313
).interactive()
313314
314315
view_likelihoods = (
315-
likelihood_pdi.hvplot("sigma", "water_likelihood", ylabel="likelihoods").dmap()
316+
likelihood_pdi.hvplot(
317+
"sigma", "water_likelihood",
318+
ylabel="likelihoods").dmap()
316319
* likelihood_pdi.hvplot("sigma", "land_likelihood").dmap()
317320
* likelihood_pdi.hvplot("observed", "land_likelihood").dmap()
318321
).opts(frame_height=200, frame_width=300)
@@ -349,7 +352,9 @@ def calc_posteriors(sigma, x=None, y=None):
349352
land_likelihood = calc_land_likelihood(sigma=sigma, x=x, y=y)
350353
water_likelihood = calc_water_likelihood(sigma=sigma, x=x, y=y)
351354
evidence = (water_likelihood * 0.5) + (land_likelihood * 0.5)
352-
return (water_likelihood * 0.5) / evidence, (land_likelihood * 0.5) / evidence
355+
water_posterior = (water_likelihood * 0.5) / evidence
356+
land_posterior = (land_likelihood * 0.5) / evidence
357+
return water_posterior, land_posterior
353358
```
354359

355360
We can plot the posterior probabilities of flooding and non-flooding again and compare these to pixel's measured $\sigma^0$. For reference we model the flood and non-flood posteriors (`model_posteriors`) over a range of $\sigma^0$ values. **Hover** on a pixel to calculate the posterior probability.
@@ -446,8 +451,8 @@ colorbar_opts = {
446451
"ticker": FixedTicker(ticks=[0, 1]),
447452
}
448453
flood_view = flood_dc.decision.hvplot.image(
449-
x="x", y="y", rasterize=True, geo=True, cmap=["rgba(0, 0, 1, 0.1)", "darkred"]
454+
x="x", y="y", rasterize=True, geo=True,
455+
cmap=["rgba(0, 0, 1, 0.1)", "darkred"]
450456
).opts(frame_height=400, colorbar_opts={**colorbar_opts})
451457
mrs_view.get(0) * flood_view
452458
```
453-

0 commit comments

Comments
 (0)