How to use JupyterHub?
First of all, to use JupyterHub you have to be registered and signed in Creodias.
Please see: How to register to Creodias Portal?
After that, choose Tools → JupyterHub from navigation menu:
Then you can see main page of JupyterHub. It is highly recommended to create new projects in persistent directory to avoid data loss caused by e.g. by restart of your Jupyter Notebook container.
You can create a new script by choosing New and the language of your choice e.g. Python 3.
Product Query and selection
You can define search parameters and query the CREODIAS Finder engine for products that correspond to chosen parameters. Finder API is describerd here:
https://creodias.eu/eo-data-finder-api-manual
To run the script you can use "Run" button on the top or use shortcut "Ctrl + Enter".
All shortcuts are available after clicking keyboard icon, there you can also define your own shortcuts. Keep in mind that you have to save your script.
Below you can find the above code.
Query = 'Tokio%20Winter' # here you can define semantic search Cloud = '[0,5]' # here you can define cloud cover in percentage sort = 'sortParam=cloudCover&sortOrder=ascending' Coll = 'Sentinel2' # here you can choose which satellite are you interested in ResultNumber = 0 OutputFileName = 'TrueColor' URL = 'http://finder.creodias.eu/resto/api/collections/' + Coll +'/search.json?_pretty=true&q=' + Query + '&' + 'cloudCover=' + Cloud + '&' + sort import json, requests, os products = json.loads(requests.get(URL).text)['features'] for product in products: print(product['properties']['productIdentifier']) file = products[ResultNumber]['properties']['productIdentifier']
Product selection
Using selected product identifier (stored in "file" variable), you can open access bands to be later saved as a GeoTif.
import rasterio path = file + '/GRANULE' + '/' + os.listdir(file + '/GRANULE')[0] + '/IMG_DATA' if (os.path.isdir(path + '/' + sorted(os.listdir(path))[0])): path = path + '/' + sorted(os.listdir(path))[0] band2 = rasterio.open(path + '/' + sorted(os.listdir(path))[1]) #blue band3 = rasterio.open(path + '/' + sorted(os.listdir(path))[2]) #green band4 = rasterio.open(path + '/' + sorted(os.listdir(path))[3]) #red path
GeoTif creation
Now you can create a GeoTif file. Bands are stored in GeoTiff format and saved to the current directory of your Notebook.
We recommend storing the results in "persistent" directory.
from rasterio import plot import matplotlib.pyplot as plt trueColor = rasterio.open( OutputFileName + '.tiff','w',driver='Gtiff', width=band4.width, height=band4.height, count=3, crs=band4.crs, transform=band4.transform, dtype=band4.dtypes[0] ) trueColor.write(band2.read(1), 3) #blue trueColor.write(band3.read(1), 2) #green trueColor.write(band4.read(1), 1) #red trueColor.close() os.path.isfile(OutputFileName + '.tiff')
Displaying the imageNow you can display the image.
|