mirror of
https://github.com/heyarne/earth-observation-for-journalism.git
synced 2026-05-06 19:13:40 +02:00
"pplt" → "plt"
This commit is contained in:
parent
5461777aea
commit
1ff1d972d5
7 changed files with 126 additions and 136 deletions
|
|
@ -460,7 +460,7 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"from sentinel_helpers import plot_all\n",
|
||||
"import matplotlib.pyplot as pplt"
|
||||
"import matplotlib.pyplot as plt"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -496,7 +496,7 @@
|
|||
" [{'color': 'none', 'edgecolor': 'blue', 'alpha': 0.1, 'figsize': (16, 9)},\n",
|
||||
" {'color': 'none', 'edgecolor': 'red'},\n",
|
||||
" {'color': 'none', 'edgecolor': 'grey'}])\n",
|
||||
"pplt.title('Area of interest, its convex hull and products returned from the API')"
|
||||
"plt.title('Area of interest, its convex hull and products returned from the API')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -3484,16 +3484,16 @@
|
|||
"source": [
|
||||
"import rasterio as r\n",
|
||||
"import rasterio.plot as rplt\n",
|
||||
"import matplotlib.pyplot as pplt\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"# preview the first downloaded image\n",
|
||||
"with r.open(sentinel_helpers.scihub_band_paths(downloaded_paths[3], ['TCI'], '20m')[0]) as true_color:\n",
|
||||
" # we do not need\n",
|
||||
" fig, (axr, axg, axb) = pplt.subplots(1,3, figsize=(21,7))\n",
|
||||
" fig, (axr, axg, axb) = plt.subplots(1,3, figsize=(21,7))\n",
|
||||
" rplt.show((true_color, 1), ax=axr, cmap='Reds', title='red channel')\n",
|
||||
" rplt.show((true_color, 2), ax=axg, cmap='Greens', title='green channel')\n",
|
||||
" rplt.show((true_color, 3), ax=axb, cmap='Blues', title='blue channel')\n",
|
||||
" pplt.show()"
|
||||
" plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -3505,9 +3505,9 @@
|
|||
"# plotting the included true-colo image\n",
|
||||
"with r.open(sentinel_helpers.scihub_band_paths(downloaded_paths[3], ['TCI'], '20m')[0]) as true_color:\n",
|
||||
" # note that in order to get the real colors, we need to reverse the bands into \"rasterio band order\"\n",
|
||||
" pplt.figure(figsize=(20,20))\n",
|
||||
" plt.figure(figsize=(20,20))\n",
|
||||
" rplt.show(true_color.read(), transform=true_color.transform)\n",
|
||||
" pplt.show()"
|
||||
" plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -3650,10 +3650,10 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fig, (ax) = pplt.subplots(1, 1, figsize=(8,16))\n",
|
||||
"fig, (ax) = plt.subplots(1, 1, figsize=(8,16))\n",
|
||||
"rplt.show(mosaic, transform=mosaic_transform, ax=ax)\n",
|
||||
"brandenburg.to_crs(target_crs).plot(ax=ax, facecolor='none', edgecolor='white')\n",
|
||||
"pplt.show()"
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -288,7 +288,7 @@
|
|||
"plot_all([gdf, footprint],\n",
|
||||
" [{'color': 'none', 'edgecolor': 'blue', 'alpha': 0.1, 'figsize': (16, 9)},\n",
|
||||
" {'color': 'none', 'edgecolor': 'red'}])\n",
|
||||
"pplt.title('Region of interest superimposed on all product tiles matching search criteria')"
|
||||
"plt.title('Region of interest superimposed on all product tiles matching search criteria')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -382,7 +382,7 @@
|
|||
"plot_all([gdf.loc[:idx], footprint],\n",
|
||||
" [{'facecolor': 'none', 'edgecolor': 'blue', 'alpha': 0.1},\n",
|
||||
" {'facecolor': 'none', 'edgecolor': 'red'}])\n",
|
||||
"pplt.title('Region of interest superimposed on selected products')"
|
||||
"plt.title('Region of interest superimposed on selected products')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -619,7 +619,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib.pyplot as pplt\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import rasterio as r\n",
|
||||
"from rasterio import plot as rplot\n",
|
||||
"from rasterio.warp import calculate_default_transform, reproject, Resampling\n",
|
||||
|
|
@ -862,7 +862,7 @@
|
|||
" _, height, width = masked.shape\n",
|
||||
" \n",
|
||||
" # show the result\n",
|
||||
" pplt.figure(figsize=(20,20))\n",
|
||||
" plt.figure(figsize=(20,20))\n",
|
||||
" rplot.show(masked,\n",
|
||||
" transform=masked_transform,\n",
|
||||
" title=f'Plot of {region_of_interest} using data between {start_date.strftime(\"%Y-%m-%d\")} and {end_date.strftime(\"%Y-%m-%d\")}')\n",
|
||||
|
|
|
|||
|
|
@ -516,7 +516,7 @@
|
|||
"source": [
|
||||
"from sentinel_helpers import scihub_cloud_mask\n",
|
||||
"import rasterio as r\n",
|
||||
"import matplotlib.pyplot as pplt\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"highres_raster_path = [band_path for band_path in highest_resolution_band_paths if resolution(band_path) == target_resolution][0]\n",
|
||||
"highres_raster_path"
|
||||
|
|
@ -583,7 +583,7 @@
|
|||
" target_shape=target_shape,\n",
|
||||
" target_transform=target_transform)\n",
|
||||
"\n",
|
||||
"pplt.imshow(raster_cloud_mask)"
|
||||
"plt.imshow(raster_cloud_mask)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -744,7 +744,7 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"# to debug the cloud / tile mask, uncomment these lines\n",
|
||||
"# pplt.imshow(tile_mask)"
|
||||
"# plt.imshow(tile_mask)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as pplt\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"from sentinel_helpers import scihub_band_paths, scihub_band_date, RasterReaderList\n",
|
||||
"import rasterio as r\n",
|
||||
"import rasterio.plot as rplt\n",
|
||||
|
|
@ -224,7 +224,7 @@
|
|||
"\n",
|
||||
"def plot_nbrs(products, geom):\n",
|
||||
" with RasterReaderList(products) as readers:\n",
|
||||
" fig, axes = pplt.subplots(nrows=1, ncols=3, figsize=(20, 20))\n",
|
||||
" fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(20, 20))\n",
|
||||
"\n",
|
||||
" # we need to reproject from WGS84 so the geometry can be correctly plotted on the map\n",
|
||||
" _geom = geom.to_crs(readers[0].crs)\n",
|
||||
|
|
@ -252,7 +252,7 @@
|
|||
" _geom.plot(ax=ax, facecolor='none', edgecolor='red')\n",
|
||||
" \n",
|
||||
" # increase horizontal whitespace between subplots\n",
|
||||
" pplt.subplots_adjust(wspace=0.32)\n",
|
||||
" plt.subplots_adjust(wspace=0.32)\n",
|
||||
" \n",
|
||||
" # add colorbar using the last image\n",
|
||||
" img = axes[-1].get_images()[0]\n",
|
||||
|
|
@ -385,7 +385,7 @@
|
|||
"dnbr_norm = BoundaryNorm(boundaries, dnbr_cmap.N, clip=True)\n",
|
||||
"\n",
|
||||
"def plot_dnbr(dnbr, dnbr_crs, dnbr_transform, geom):\n",
|
||||
" fig, (ax1, ax2) = pplt.subplots(ncols=2, figsize=(16, 8))\n",
|
||||
" fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(16, 8))\n",
|
||||
" _geom = geom.to_crs(dnbr_crs)\n",
|
||||
"\n",
|
||||
" # plot black and white image\n",
|
||||
|
|
@ -451,8 +451,8 @@
|
|||
"\n",
|
||||
"potsdam_mittelmark_extract = dnbr[0,500:800,420:810]\n",
|
||||
"\n",
|
||||
"img = pplt.imshow(potsdam_mittelmark_extract, cmap='Greys')\n",
|
||||
"pplt.colorbar(img)"
|
||||
"img = plt.imshow(potsdam_mittelmark_extract, cmap='Greys')\n",
|
||||
"plt.colorbar(img)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -622,8 +622,8 @@
|
|||
" out_shape=(window.height, window.width),\n",
|
||||
" transform=window_transform)\n",
|
||||
"\n",
|
||||
"pplt.figure(figsize=(10, 10))\n",
|
||||
"pplt.imshow(nature_reserve_mask)"
|
||||
"plt.figure(figsize=(10, 10))\n",
|
||||
"plt.imshow(nature_reserve_mask)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -635,8 +635,8 @@
|
|||
"burned_in_nature_reserve = dnbr.copy()\n",
|
||||
"burned_in_nature_reserve.mask = burned_in_nature_reserve.mask | nature_reserve_mask\n",
|
||||
"\n",
|
||||
"pplt.figure(figsize=(10, 10))\n",
|
||||
"pplt.imshow(burned_in_nature_reserve[0], cmap=dnbr_cmap, norm=dnbr_norm)"
|
||||
"plt.figure(figsize=(10, 10))\n",
|
||||
"plt.imshow(burned_in_nature_reserve[0], cmap=dnbr_cmap, norm=dnbr_norm)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -653,8 +653,8 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"burned_in_nature_reserve.mask = burned_in_nature_reserve.mask | (burned_in_nature_reserve.data < 0.1)\n",
|
||||
"pplt.figure(figsize=(10, 10))\n",
|
||||
"pplt.imshow(burned_in_nature_reserve[0], cmap=dnbr_cmap, norm=dnbr_norm)"
|
||||
"plt.figure(figsize=(10, 10))\n",
|
||||
"plt.imshow(burned_in_nature_reserve[0], cmap=dnbr_cmap, norm=dnbr_norm)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -743,7 +743,7 @@
|
|||
" tci_paths = map(lambda p: scihub_band_paths(p, ['TCI'], '60m')[0], products)\n",
|
||||
" \n",
|
||||
" with RasterReaderList(tci_paths) as readers:\n",
|
||||
" fig, axes = pplt.subplots(ncols=len(readers), figsize=(20,10))\n",
|
||||
" fig, axes = plt.subplots(ncols=len(readers), figsize=(20,10))\n",
|
||||
" _geom = geometry.to_crs(readers[0].crs)\n",
|
||||
" \n",
|
||||
" window = geometry_window(readers[0], _geom.buffer(5000))\n",
|
||||
|
|
@ -869,8 +869,8 @@
|
|||
" out_shape=(window.height, window.width),\n",
|
||||
" transform=window_transform)\n",
|
||||
"\n",
|
||||
"pplt.figure(figsize=(10, 10))\n",
|
||||
"pplt.imshow(luebtheen_military_site_mask)"
|
||||
"plt.figure(figsize=(10, 10))\n",
|
||||
"plt.imshow(luebtheen_military_site_mask)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -882,8 +882,8 @@
|
|||
"burned_in_military_site = dnbr.copy()\n",
|
||||
"burned_in_military_site.mask = burned_in_military_site.mask | luebtheen_military_site_mask\n",
|
||||
"\n",
|
||||
"pplt.figure(figsize=(10, 10))\n",
|
||||
"pplt.imshow(burned_in_military_site[0], cmap=dnbr_cmap, norm=dnbr_norm)"
|
||||
"plt.figure(figsize=(10, 10))\n",
|
||||
"plt.imshow(burned_in_military_site[0], cmap=dnbr_cmap, norm=dnbr_norm)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -895,8 +895,8 @@
|
|||
"# keep only the pixels with a burn serverity of at least 0.1\n",
|
||||
"burned_in_military_site.mask = burned_in_military_site.mask | (burned_in_military_site.data < 0.1)\n",
|
||||
"\n",
|
||||
"pplt.figure(figsize=(10, 10))\n",
|
||||
"pplt.imshow(burned_in_military_site[0], cmap=dnbr_cmap, norm=dnbr_norm)"
|
||||
"plt.figure(figsize=(10, 10))\n",
|
||||
"plt.imshow(burned_in_military_site[0], cmap=dnbr_cmap, norm=dnbr_norm)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ def scihub_band_paths(p, bands, resolution=None):
|
|||
information for the given bands. Because some bands are available in more than one
|
||||
resolution, this can be filtered by prodiding a third parameter (e.g. resolution='10m').
|
||||
|
||||
`p` can be a string or a pathlib.Path.
|
||||
`bands` can be a list of bands or a single band.
|
||||
- `p` can be a string or a pathlib.Path.
|
||||
- `bands` can be a list of bands or a single band.
|
||||
|
||||
The returned paths are formatted in the zip scheme as per Apache Commons VFS if necessary
|
||||
and can be directly opened by rasterio.
|
||||
|
|
@ -85,20 +85,16 @@ def scihub_band_paths(p, bands, resolution=None):
|
|||
# archive first
|
||||
with ZipFile(p) as f:
|
||||
files = f.namelist()
|
||||
rasters = [f for f in files if f.endswith('.jp2')]
|
||||
rasters = [Path(f'zip+file://{p.absolute()}!/{f}') for f in files if f.endswith('.jp2')]
|
||||
else:
|
||||
rasters = p.glob('**/*.jp2')
|
||||
|
||||
# take only the paths that contain one of the given bands
|
||||
rasters = [raster for band in bands for raster in rasters if band in raster]
|
||||
rasters = [raster for band in bands for raster in rasters if band in raster.name]
|
||||
|
||||
# if a resolution is given, further discard the bands we don't need
|
||||
if resolution:
|
||||
rasters = [raster for raster in rasters if resolution in raster]
|
||||
|
||||
if p.suffix == '.zip':
|
||||
# we have to reformat the paths to point inside the zip archive
|
||||
rasters = [f'zip+file://{p}!/{r}' for r in rasters]
|
||||
rasters = [raster for raster in rasters if resolution in raster.name]
|
||||
|
||||
return rasters
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue