Add jupyter-book config
5977
true-color-image/01 Brandenburg Cover Research.ipynb
Normal file
7695
true-color-image/01 Brandenburg Mosaic.ipynb
Normal file
838
true-color-image/02 Indices.ipynb
Normal file
2936
true-color-image/output/2020-05-26.svg
Normal file
|
After Width: | Height: | Size: 74 KiB |
2809
true-color-image/output/2020-05-28.svg
Normal file
|
After Width: | Height: | Size: 70 KiB |
2925
true-color-image/output/2020-05-29.svg
Normal file
|
After Width: | Height: | Size: 73 KiB |
3176
true-color-image/output/2020-05-30.svg
Normal file
|
After Width: | Height: | Size: 78 KiB |
2923
true-color-image/output/2020-05-31.svg
Normal file
|
After Width: | Height: | Size: 73 KiB |
2581
true-color-image/output/2020-06-02.svg
Normal file
|
After Width: | Height: | Size: 65 KiB |
2882
true-color-image/output/2020-06-03.svg
Normal file
|
After Width: | Height: | Size: 72 KiB |
2699
true-color-image/output/2020-06-12.svg
Normal file
|
After Width: | Height: | Size: 67 KiB |
3167
true-color-image/output/2020-06-13.svg
Normal file
|
After Width: | Height: | Size: 78 KiB |
2889
true-color-image/output/2020-06-16.svg
Normal file
|
After Width: | Height: | Size: 73 KiB |
2907
true-color-image/output/2020-06-17.svg
Normal file
|
After Width: | Height: | Size: 73 KiB |
2867
true-color-image/output/2020-06-22.svg
Normal file
|
After Width: | Height: | Size: 72 KiB |
3215
true-color-image/output/2020-06-23.svg
Normal file
|
After Width: | Height: | Size: 80 KiB |
2829
true-color-image/output/2020-06-25.svg
Normal file
|
After Width: | Height: | Size: 71 KiB |
2866
true-color-image/output/2020-06-27.svg
Normal file
|
After Width: | Height: | Size: 72 KiB |
3126
true-color-image/output/2020-06-30.svg
Normal file
|
After Width: | Height: | Size: 78 KiB |
3385
true-color-image/output/2020-07-04.svg
Normal file
|
After Width: | Height: | Size: 84 KiB |
3581
true-color-image/output/2020-07-12.svg
Normal file
|
After Width: | Height: | Size: 88 KiB |
3215
true-color-image/output/2020-07-13.svg
Normal file
|
After Width: | Height: | Size: 80 KiB |
3385
true-color-image/output/2020-07-15.svg
Normal file
|
After Width: | Height: | Size: 84 KiB |
3244
true-color-image/output/2020-07-18.svg
Normal file
|
After Width: | Height: | Size: 80 KiB |
71
true-color-image/sentinel_helpers.py
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import glob
|
||||
import urllib.parse
|
||||
from pathlib import Path
|
||||
import zipfile
|
||||
|
||||
import geopandas as gp
|
||||
import rasterio as r
|
||||
|
||||
from rasterio.warp import calculate_default_transform, reproject, Resampling
|
||||
|
||||
def band_paths(p, bands, resolution=None):
|
||||
'''
|
||||
Given a zip file or folder at `p`, returns the paths inside p to the raster files containing
|
||||
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').
|
||||
|
||||
The returned paths are formatted in the zip scheme as per Apache Commons VFS if necessary
|
||||
and can be directly opened by rasterio.
|
||||
'''
|
||||
if p.endswith('.zip'):
|
||||
with zipfile.ZipFile(p) as f:
|
||||
files = f.namelist()
|
||||
rasters = [f for f in files if f.endswith('.jp2')]
|
||||
else:
|
||||
rasters = glob.glob(Path(p) / '**/*.jp2')
|
||||
rasters = [r for r in rasters for b in bands if b in r]
|
||||
if resolution:
|
||||
rasters = [r for r in rasters if resolution in r]
|
||||
|
||||
rasters = ['zip+file://' + p + '!/' + r for r in rasters]
|
||||
return rasters
|
||||
|
||||
|
||||
def rgb_paths(zip_file, resolution='10m'):
|
||||
return band_paths(zip_file, ['B02', 'B03', 'B04'], resolution)
|
||||
|
||||
|
||||
def search_osm(place):
|
||||
'''
|
||||
Returns a GeoDataFrame with results from OpenStreetMap Nominatim for the given search string.
|
||||
This allows us to fetch detailed geometries for virtually any place on earth.
|
||||
'''
|
||||
urlescaped_place = urllib.parse.quote(place)
|
||||
search_url = 'https://nominatim.openstreetmap.org/search/?q={}&format=geojson&polygon_geojson=1'.format(urlescaped_place)
|
||||
return gp.read_file(search_url)
|
||||
|
||||
|
||||
def reproject_raster_image(src, dst, target_crs):
|
||||
'''
|
||||
Reprojects `src` into `dst`, given a coordinate reference system `target_crs`.
|
||||
'''
|
||||
transform, width, height = calculate_default_transform(
|
||||
src.crs, target_crs, src.width, src.height, *src.bounds)
|
||||
|
||||
kwargs = src.meta.copy()
|
||||
kwargs.update({
|
||||
'crs': target_crs,
|
||||
'transform': transform,
|
||||
'width': width,
|
||||
'height': height
|
||||
})
|
||||
|
||||
for i in range(1, src.count + 1):
|
||||
reproject(
|
||||
source=r.band(src, i),
|
||||
destination=r.band(dst, i),
|
||||
src_transform=src.transform,
|
||||
src_crs=src.crs,
|
||||
dst_transform=transform,
|
||||
dst_crs=target_crs,
|
||||
resampling=Resampling.nearest)
|
||||