better-wfp-00003 data pipeline results (Sentinel-2 reflectances and vegetation indices): loading from pickle file and exploiting¶
This Notebook shows how to: * reload better-wfp-00003 data pipeline results previously stored in a pickle file * Create a new dataframe with data values cropped over the area of interest * Plot an RGB * Create a geotiff
Import needed modules¶
In [1]:
import pandas as pd
from geopandas import GeoDataFrame
import gdal
import numpy as np
from shapely.geometry import Point
from shapely.geometry import Polygon
import matplotlib
import matplotlib.pyplot as plt
from PIL import Image
%matplotlib inline
from shapely.wkt import loads
from shapely.geometry import box
from urlparse import urlparse
import requests
Read picke data file¶
In [2]:
pickle_filename = 'better-wfp-00003_Jun-Sep_2017_Afghanistan.pkl'
In [3]:
results = GeoDataFrame(pd.read_pickle(pickle_filename))
In [4]:
results.head(100)
Out[4]:
enclosure | enddate | identifier | self | startdate | title | wkt | |
---|---|---|---|---|---|---|---|
0 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | 2412362a3137482a3b8b692ff621761f97b40577 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | Reproducibility notebook used for generating S... | POLYGON((67.9974286897346 35.6884876797069,67.... |
1 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | 2e66b787b9be5fe0bfe39592a28d4662debc22d4 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | Reproducibility notebook used for generating S... | POLYGON((67.989865566835 36.0488297143412,67.9... |
2 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | 4a9471ba1e80fc8a60aa29ba1557f4ced5cf38f3 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.989865566835 36.0488297143412,67.9... |
3 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | 52506c40158ff7486ccfc71423748d34d5bbcc17 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((68.1160119769251 35.690459964115,68.1... |
4 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | 5711d6b38f923d4de2524b179cc8fd09a2cfbadb | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((68.1159808017597 36.0515787124833,68.... |
5 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | 79c4e4cf290243bfe08bc9a4c4f21b4ad3eb1639 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.9974286897346 35.6884876797069,67.... |
6 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | c7cb7db8e5ee781ff1eb527a56baae2b5a8bf7bf | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | Reproducibility notebook used for generating S... | POLYGON((68.1159808017597 36.0515787124833,68.... |
7 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | db646dd896b5f92cd8b59b13c7c2a11d924841a8 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | Reproducibility notebook used for generating S... | POLYGON((68.1160119769251 35.690459964115,68.1... |
8 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | 16de0dad6fa7512cfc89af473142baddca03ae11 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | S2A_MSIL2A_20170922T061631_N0205_R034_T42SVF_2... | POLYGON((68.1159808018 36.0515787125,68.115980... |
9 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | 7683005022868530d38eef49c0f16d6d4217fc73 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | S2A_MSIL2A_20170922T061631_N0205_R034_T42SUE_2... | POLYGON((67.9974286897 35.6884876797,67.997428... |
10 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | c422d249e83339cca003e3cfcafadddac0d7e8f7 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | S2A_MSIL2A_20170922T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... |
11 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | dae488c87a5a42d835ec9f8306df84d1072c0a53 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | S2A_MSIL2A_20170922T061631_N0205_R034_T42SVE_2... | POLYGON((68.1160119769 35.6904599641,68.116011... |
12 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | 192b1b71373a470afd60f11e2a5cb2b3c1441f87 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.989865566835 36.0488297143412,67.9... |
13 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | 70706cb23f81b922075a9311fc650d14c13e5b0d | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | Reproducibility notebook used for generating S... | POLYGON((68.1160119769251 35.690459964115,68.1... |
14 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | 7c0af606e15975e8e08a299ff025b7737def3786 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.9974286897346 35.6884876797069,67.... |
15 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | f156b13b6a868a7bd07532f717f142221a7cf25b | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | Reproducibility notebook used for generating S... | POLYGON((67.989865566835 36.0488297143412,67.9... |
16 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | fe63c937fb92d3e2464557fd8cb565d5f681251c | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((68.1160119769251 35.690459964115,68.1... |
17 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | ffe633ed75dc5e981a8615a4e50b3808523b844c | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | Reproducibility notebook used for generating S... | POLYGON((67.9974286897346 35.6884876797069,67.... |
18 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | 09c70577ef6af4c7f8a5083280ca8234990f2710 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... |
19 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | bca16ed49337c47daf332ab2141ef921026c3237 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SVE_2... | POLYGON((68.1160119769 35.6904599641,68.116011... |
20 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | 0c94bed326d42e33214d3df90cf612366695e264 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((68.1159808017597 36.0515787124833,68.... |
21 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | 1ffd3740bf150a1a1d7430e0d3ba1987b75a218b | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | Reproducibility notebook used for generating S... | POLYGON((68.1159808017597 36.0515787124833,68.... |
22 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | 4d0f83b6073d28ccba5b51f94b004c2ff0494038 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SVF_2... | POLYGON((68.1159808018 36.0515787125,68.115980... |
23 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | f7db2620131adb305e95eecc813548235c3e2838 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SUE_2... | POLYGON((67.9974286897 35.6884876797,67.997428... |
24 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-02 06:16:31.026 | 057d7c04fc5a57143f7e2c2f69c819813d2a65ed | https://catalog.terradue.com//better-wfp-00003... | 2017-09-02 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.9974286897346 35.6884876797069,67.... |
25 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-02 06:16:31.026 | 18d99d9c3d4a193e28374117d4adfde6912bd8f7 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-02 06:16:31.026 | Reproducibility notebook used for generating S... | POLYGON((68.1159808017597 36.0515787124833,68.... |
26 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-02 06:16:31.026 | ca63a3b448ec602cd14d19ce887391c29da8df70 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-02 06:16:31.026 | Reproducibility notebook used for generating S... | POLYGON((67.989865566835 36.0488297143412,67.9... |
27 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-02 06:16:31.026 | cbf4b2a3063e396cc5c741712c2754719fdee6f3 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-02 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.989865566835 36.0488297143412,67.9... |
28 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-02 06:16:31.026 | dc90927cf8609603d53a748f3b45f34464fa241e | https://catalog.terradue.com//better-wfp-00003... | 2017-09-02 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((68.1159808017597 36.0515787124833,68.... |
29 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-02 06:16:31.026 | ee4ac565ee4d211d72ad3fb17b61b3ea4a6f1432 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-02 06:16:31.026 | Reproducibility notebook used for generating S... | POLYGON((67.9974286897346 35.6884876797069,67.... |
... | ... | ... | ... | ... | ... | ... | ... |
70 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-24 06:16:31.026 | c11db799ff134efebb79e700ddad21d7dd10c027 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-24 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.9974286897346 35.6884876797069,67.... |
71 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-24 06:16:31.026 | c49975dbaec85dc206a9cf54fd402b0b6d6be661 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-24 06:16:31.026 | Reproducibility notebook used for generating S... | POLYGON((67.9974286897346 35.6884876797069,67.... |
72 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-24 06:16:31.026 | d3fe21d94ee015d37ea4fa43f63f8df32dd74ff8 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-24 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((68.1160119769251 35.690459964115,68.1... |
73 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-24 06:16:31.026 | ea613d7e3ed2713b960494b036aae8808ab99ac0 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-24 06:16:31.026 | Reproducibility notebook used for generating S... | POLYGON((68.1160119769251 35.690459964115,68.1... |
74 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-24 06:16:31.026 | 0f2deda35d9683aae156936cecf28b60726ec4e1 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-24 06:16:31.026 | S2A_MSIL2A_20170724T061631_N0205_R034_T42SVE_2... | POLYGON((68.1160119769 35.6904599641,68.116011... |
75 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-24 06:16:31.026 | 16c947ba2950a3623426b10f5095225f1bff8d6c | https://catalog.terradue.com//better-wfp-00003... | 2017-07-24 06:16:31.026 | S2A_MSIL2A_20170724T061631_N0205_R034_T42SUE_2... | POLYGON((67.9974286897 35.6884876797,67.997428... |
76 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-24 06:16:31.026 | 3682a24ba9a9a70cda1b3726a4edd5832966ed22 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-24 06:16:31.026 | S2A_MSIL2A_20170724T061631_N0205_R034_T42SVF_2... | POLYGON((68.1159808018 36.0515787125,68.115980... |
77 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-24 06:16:31.026 | e8b7dce754154844380ebb49ed7ca1e4a5e0e995 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-24 06:16:31.026 | S2A_MSIL2A_20170724T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... |
78 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | 59b1aa75b38c0f5d5bd6b2c0ecb1bc4367d902a4 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | Reproducibility stage-in notebook for Sentinel... | POLYGON((68.1159808017597 36.0515787124833,68.... |
79 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | bb60e8dcb7a825fcf97b1d4e52a4e772e201bde2 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | Reproducibility notebook used for generating S... | POLYGON((68.1159808017597 36.0515787124833,68.... |
80 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | 20ffcebfd0ee8ed9d172e35424afd09f72079af3 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.9974286897346 35.6884876797069,67.... |
81 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | 52329bb6101640ab86ec31b6d6541aa33bf2c3e3 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.989865566835 36.0488297143412,67.9... |
82 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | 830566193a2221a6bbb40b9fe98eb8ad0cc028fd | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | Reproducibility stage-in notebook for Sentinel... | POLYGON((68.1160119769251 35.690459964115,68.1... |
83 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | 83528ae6316e7f174b10416174539d270c1fb1f7 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | Reproducibility notebook used for generating S... | POLYGON((68.1160119769251 35.690459964115,68.1... |
84 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | a8c51f57648cbc96740ce12a88915a0d2b9cce77 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | Reproducibility notebook used for generating S... | POLYGON((67.989865566835 36.0488297143412,67.9... |
85 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | bc91b23371029695bd0aea1826fef1533d6e4f5c | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | Reproducibility notebook used for generating S... | POLYGON((67.9974286897346 35.6884876797069,67.... |
86 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | 2b4542c94be5339a0dbb08d5b80ee4e9862163d9 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | S2B_MSIL2A_20170716T060629_N0205_R134_T42SUE_2... | POLYGON((67.9974286897 35.6884876797,67.997428... |
87 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | 7c9a47f3aaed7342f02d7393c153b9797d0d4d7e | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | S2B_MSIL2A_20170716T060629_N0205_R134_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... |
88 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | 8339c693cd170d0510ce2b2a0aa6113b05f0d502 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | S2B_MSIL2A_20170716T060629_N0205_R134_T42SVE_2... | POLYGON((68.1160119769 35.6904599641,68.116011... |
89 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-16 06:06:29.027 | a461e4dea755e97b753c41bfc606575b36f03768 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-16 06:06:29.027 | S2B_MSIL2A_20170716T060629_N0205_R134_T42SVF_2... | POLYGON((68.1159808018 36.0515787125,68.115980... |
90 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-11 06:06:31.026 | 4b9ee5a5da3824841c5870877fe43ba35081f645 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-11 06:06:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.989865566835 36.0488297143412,67.9... |
91 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-11 06:06:31.026 | e3f4c3d3b75f939a4c7c9d38f1d5cad66f2fa8da | https://catalog.terradue.com//better-wfp-00003... | 2017-07-11 06:06:31.026 | Reproducibility notebook used for generating S... | POLYGON((67.989865566835 36.0488297143412,67.9... |
92 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-11 06:06:31.026 | 433a06683ddeb1f5f067ff46ed61525fc9015398 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-11 06:06:31.026 | S2A_MSIL2A_20170711T060631_N0205_R134_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... |
93 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-04 06:16:31.026 | 258c744cea1d3eaeb957629e434fa3e60ce064db | https://catalog.terradue.com//better-wfp-00003... | 2017-07-04 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.9974286897346 35.6884876797069,67.... |
94 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-04 06:16:31.026 | 63f45d94a7f8ab7422a7a3a2e553bf57c5e854db | https://catalog.terradue.com//better-wfp-00003... | 2017-07-04 06:16:31.026 | Reproducibility notebook used for generating S... | POLYGON((68.1159808017597 36.0515787124833,68.... |
95 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-04 06:16:31.026 | 89794d00dc2637cb8f2054ff8a0ca0aed27d591a | https://catalog.terradue.com//better-wfp-00003... | 2017-07-04 06:16:31.026 | Reproducibility notebook used for generating S... | POLYGON((67.9974286897346 35.6884876797069,67.... |
96 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-04 06:16:31.026 | 9828863eb9302b3e7008ebea4d1ec5fc7ed883b7 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-04 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((67.989865566835 36.0488297143412,67.9... |
97 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-04 06:16:31.026 | cd0bb783e89121b7439c11a49a150ad590c3e381 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-04 06:16:31.026 | Reproducibility stage-in notebook for Sentinel... | POLYGON((68.1159808017597 36.0515787124833,68.... |
98 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-04 06:16:31.026 | a974d295387bb056bae5edc140fb7002e8a9e234 | https://catalog.terradue.com//better-wfp-00003... | 2017-07-04 06:16:31.026 | S2A_MSIL2A_20170704T061631_N0205_R034_T42SUE_2... | POLYGON((67.9974286897 35.6884876797,67.997428... |
99 | https://store.terradue.com/better-wfp-00003/_r... | 2017-07-04 06:16:31.026 | e569a4b2999a84b3802f674d857b9982469c338e | https://catalog.terradue.com//better-wfp-00003... | 2017-07-04 06:16:31.026 | S2A_MSIL2A_20170704T061631_N0205_R034_T42SVF_2... | POLYGON((68.1159808018 36.0515787125,68.115980... |
100 rows × 7 columns
Credentials for ellip platform access¶
- Provide here your ellip username and api key for platform access
In [5]:
import getpass
user = getpass.getpass("Enter your username:")
api_key = getpass.getpass("Enter the API key:")
Define filter parameters¶
Time of interest¶
In [6]:
mydates = ['2017-09-22 06:16:31.026', '2017-09-09 06:06:31.026','2017-09-02 06:16:31.026']
Area of interest¶
- The user can choose to define an AOI selecting a Point and a buffer size used to build a squared polygon around that point
In [7]:
point_of_interest = Point(67.890, 36.085)
In [8]:
buffer_size = 0.07
In [9]:
aoi_wkt1 = box(*point_of_interest.buffer(buffer_size).bounds)
In [11]:
aoi_wkt1.wkt
Out[11]:
'POLYGON ((67.95999999999999 36.015, 67.95999999999999 36.155, 67.82000000000001 36.155, 67.82000000000001 36.015, 67.95999999999999 36.015))'
- Or define a Polygon (in this case this is exactly the Afghanistan reference AOI) from a WKT geometry
In [12]:
geom = 'MULTIPOLYGON (((6.4788 14.5973, 7.5577 14.5973, 7.5577 13.6328, 6.4788 13.6328, 6.4788 14.5973)), ((67.7116 37.9032, 68.791 37.9032, 68.791 36.9211, 67.7116 36.9211, 67.7116 37.9032)), ((-10.3668 15.3471, -9.351800000000001 15.3471, -9.351800000000001 14.3406, -10.3668 14.3406, -10.3668 15.3471)), ((67.62430000000001 36.7228, 68.116 36.7228, 68.116 35.6923, 67.62430000000001 35.6923, 67.62430000000001 36.7228)))'
aoi_wkt2 = loads(geom)[3]
In [13]:
aoi_wkt2.wkt
Out[13]:
'POLYGON ((67.62430000000001 36.7228, 68.116 36.7228, 68.116 35.6923, 67.62430000000001 35.6923, 67.62430000000001 36.7228))'
Create a new dataframe with data values¶
- Get the subframe data values related to selected tiles and bands, and create a new GeoDataFrame having the original metadata stack with the specific bands data extended info (data values, size, and geo projection and transformation).
Define auxiliary methods to create new dataframe¶
- The first method gets tile reference, bands list, cropping flag, AOI cropping area and returns the related n bands data array with related geospatial infos
- If crop = False the original bands extent is returned
In [14]:
def get_bands_as_array(url,band_indices,bands_name,crop,bbox):
output = '/vsimem/clip.tif'
bands=[]
ds = gdal.Open('/vsigzip//vsicurl/%s' % url)
bands_count = ds.RasterCount
if bands_count < len(band_indices):
raise('ERROR: Selected bands are more than the data ones')
if crop == True:
ulx, uly, lrx, lry = bbox[0], bbox[3], bbox[2], bbox[1]
ds = gdal.Translate(output, ds, bandList=band_indices, projWin = [ulx, uly, lrx, lry], projWinSRS = 'EPSG:4326')
print 'data cropping : DONE'
else:
ds = gdal.Translate(output, ds, bandList=band_indices)
ds = None
ds = gdal.Open(output)
w = ds.GetRasterBand(1).XSize
h = ds.GetRasterBand(1).YSize
geo_transform = ds.GetGeoTransform()
projection = ds.GetProjection()
for i in range(len(band_indices)):
data = ds.GetRasterBand(i+1).ReadAsArray(0, 0, w, h).astype(np.float)
data[data==-9999] = np.nan
bands.append(data)
band = None
data = None
print 'bands %s values got' %band_indices
ds = None
return bands,geo_transform,projection,w,h
- The second one selects the data to be managed (only the actual result related to the selected tile) and returns a new GeoDataFrame containing the requested bands extended info with the original metadata set
In [15]:
def get_GDF_with_datavalues(row, user, api_key, bands_list='all', crop=False, bbox=None):
bands_name = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'B9', 'B11', 'B12','ndvi','ndwi','mndwi','ndbi','quality_cloud_confidence','quality_snow_confidence','quality_scene_classification','opaque_clouds_10m']
band_indices = range(1,len(bands_name)+1)
if bands_list is not 'all':
band_indices = [bands_name.index(x)+1 for x in bands_list ]
# get data values: everything but the mask tif result
if ('.gz' in row['title']):
print 'Getting bands %s for %s' %(band_indices, row['title'])
parsed_url = urlparse(row['enclosure'])
url = '%s://%s:%s@%s/api%s' % (list(parsed_url)[0], user, api_key, list(parsed_url)[1], list(parsed_url)[2])
bands,geo_transform,projection,w,h = get_bands_as_array(url,band_indices,bands_name,crop,bbox)
extended_info = list()
for i,bi in enumerate(band_indices):
extended_info.append(dict(row))
extended_info[i]['band'] = bands_name[bi-1]
extended_info[i]['data'] = bands[i]
extended_info[i]['geo_transform'] = geo_transform
extended_info[i]['projection'] = projection
extended_info[i]['xsize'] = w
extended_info[i]['ysize'] = h
print 'Getting data values for %s : DONE' %row['title']
return extended_info
- Define the reference tiles
In [16]:
ref_tiles = ['T42SUE', 'T42SVE', 'T42SUF', 'T42SVF']
- Select from metadataframe a subframe of Vegetation Index results related to more tiles in the same date:
In [17]:
mydate_results = results[(results['startdate'] == mydates[1]) &
((results.apply(lambda row: ref_tiles[0] in row['title'] and '.gz' in row['title'], axis=1)) |
(results.apply(lambda row: ref_tiles[1] in row['title'] and '.gz' in row['title'], axis=1)) |
(results.apply(lambda row: ref_tiles[2] in row['title'] and '.gz' in row['title'], axis=1)) |
(results.apply(lambda row: ref_tiles[3] in row['title'] and '.gz' in row['title'], axis=1)))]
mydate_results.head()
Out[17]:
enclosure | enddate | identifier | self | startdate | title | wkt | |
---|---|---|---|---|---|---|---|
18 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | 09c70577ef6af4c7f8a5083280ca8234990f2710 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... |
19 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | bca16ed49337c47daf332ab2141ef921026c3237 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SVE_2... | POLYGON((68.1160119769 35.6904599641,68.116011... |
22 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | 4d0f83b6073d28ccba5b51f94b004c2ff0494038 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SVF_2... | POLYGON((68.1159808018 36.0515787125,68.115980... |
23 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | f7db2620131adb305e95eecc813548235c3e2838 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SUE_2... | POLYGON((67.9974286897 35.6884876797,67.997428... |
- Create a new GeoDataFrame with the selected metadata plus the data values of the selected bands (set ‘all’ in order to select all the bands) cropped over the aoi_wkt2 area
In [18]:
myGDF = GeoDataFrame()
aoi_wkt = aoi_wkt1
for row in mydate_results.iterrows():
myGDF = myGDF.append(get_GDF_with_datavalues(row[1], user, api_key, ['ndvi','ndwi'], True, bbox=aoi_wkt.bounds), ignore_index=True)
#myGDF = myGDF.append(get_GDF_with_datavalues(row[1], user, api_key, 'all', True, bbox=aoi_wkt.bounds), ignore_index=True)
Getting bands [13, 14] for S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_20170909T061506_VI_BOA.gz
data cropping : DONE
bands [13, 14] values got
Getting data values for S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_20170909T061506_VI_BOA.gz : DONE
Getting bands [13, 14] for S2A_MSIL2A_20170909T060631_N0205_R134_T42SVE_20170909T061506_VI_BOA.gz
data cropping : DONE
bands [13, 14] values got
Getting data values for S2A_MSIL2A_20170909T060631_N0205_R134_T42SVE_20170909T061506_VI_BOA.gz : DONE
Getting bands [13, 14] for S2A_MSIL2A_20170909T060631_N0205_R134_T42SVF_20170909T061506_VI_BOA.gz
data cropping : DONE
bands [13, 14] values got
Getting data values for S2A_MSIL2A_20170909T060631_N0205_R134_T42SVF_20170909T061506_VI_BOA.gz : DONE
Getting bands [13, 14] for S2A_MSIL2A_20170909T060631_N0205_R134_T42SUE_20170909T061506_VI_BOA.gz
data cropping : DONE
bands [13, 14] values got
Getting data values for S2A_MSIL2A_20170909T060631_N0205_R134_T42SUE_20170909T061506_VI_BOA.gz : DONE
*Or*
- Select from metadataframe a subframe of Vegetation Index results related to a single georeferenced tiles of interest and multiple datetimes
In [19]:
mydate_results = results[((results['startdate'] == mydates[0]) |
(results['startdate'] == mydates[1]) |
(results['startdate'] == mydates[2])) &
(results.apply(lambda row: ref_tiles[2] in row['title'] and '.gz' in row['title'], axis=1))]
mydate_results.head()
Out[19]:
enclosure | enddate | identifier | self | startdate | title | wkt | |
---|---|---|---|---|---|---|---|
10 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | c422d249e83339cca003e3cfcafadddac0d7e8f7 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | S2A_MSIL2A_20170922T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... |
18 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | 09c70577ef6af4c7f8a5083280ca8234990f2710 | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... |
31 | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-02 06:16:31.026 | 5759c6c7d6af37bf26d23eb2b9fbab94b2ae3e6c | https://catalog.terradue.com//better-wfp-00003... | 2017-09-02 06:16:31.026 | S2A_MSIL2A_20170902T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... |
- Create a new GeoDataFrame with the selected metadata plus the data values of the selected bands (set ‘all’ in order to select all the bands) cropped over the aoi_wkt1 area
In [20]:
myGDF = GeoDataFrame()
aoi_wkt = aoi_wkt2
for row in mydate_results.iterrows():
myGDF = myGDF.append(get_GDF_with_datavalues(row[1], user, api_key, ['ndvi','ndwi','mndwi','ndbi'], True, bbox=aoi_wkt.bounds), ignore_index=True)
#myGDF = myGDF.append(get_GDF_with_datavalues(row[1], user, api_key, 'all', True, bbox=aoi_wkt.bounds), ignore_index=True)
Getting bands [13, 14, 15, 16] for S2A_MSIL2A_20170922T061631_N0205_R034_T42SUF_20170922T062627_VI_BOA.gz
data cropping : DONE
bands [13, 14, 15, 16] values got
Getting data values for S2A_MSIL2A_20170922T061631_N0205_R034_T42SUF_20170922T062627_VI_BOA.gz : DONE
Getting bands [13, 14, 15, 16] for S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_20170909T061506_VI_BOA.gz
data cropping : DONE
bands [13, 14, 15, 16] values got
Getting data values for S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_20170909T061506_VI_BOA.gz : DONE
Getting bands [13, 14, 15, 16] for S2A_MSIL2A_20170902T061631_N0205_R034_T42SUF_20170902T062631_VI_BOA.gz
data cropping : DONE
bands [13, 14, 15, 16] values got
Getting data values for S2A_MSIL2A_20170902T061631_N0205_R034_T42SUF_20170902T062631_VI_BOA.gz : DONE
In [21]:
myGDF
Out[21]:
band | data | enclosure | enddate | geo_transform | identifier | projection | self | startdate | title | wkt | xsize | ysize | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | ndvi | [[824.786865234, 682.85723877, 734.915710449, ... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | c422d249e83339cca003e3cfcafadddac0d7e8f7 | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | S2A_MSIL2A_20170922T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
1 | ndwi | [[-2255.1105957, -2204.99414062, -2228.0131835... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | c422d249e83339cca003e3cfcafadddac0d7e8f7 | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | S2A_MSIL2A_20170922T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
2 | mndwi | [[-3326.7578125, -3289.30712891, -3211.9487304... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | c422d249e83339cca003e3cfcafadddac0d7e8f7 | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | S2A_MSIL2A_20170922T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
3 | ndbi | [[1158.56530762, 1169.1072998, 1059.77600098, ... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-22 06:16:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | c422d249e83339cca003e3cfcafadddac0d7e8f7 | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-22 06:16:31.026 | S2A_MSIL2A_20170922T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
4 | ndvi | [[643.766235352, 770.036437988, 749.509521484,... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | 09c70577ef6af4c7f8a5083280ca8234990f2710 | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
5 | ndwi | [[-1995.54370117, -2252.68188477, -2284.005859... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | 09c70577ef6af4c7f8a5083280ca8234990f2710 | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
6 | mndwi | [[-2947.23901367, -3397.66381836, -3254.051025... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | 09c70577ef6af4c7f8a5083280ca8234990f2710 | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
7 | ndbi | [[1011.16546631, 1239.8807373, 1047.93017578, ... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-09 06:06:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | 09c70577ef6af4c7f8a5083280ca8234990f2710 | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-09 06:06:31.026 | S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
8 | ndvi | [[771.353759766, 869.321472168, 806.651000977,... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-02 06:16:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | 5759c6c7d6af37bf26d23eb2b9fbab94b2ae3e6c | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-02 06:16:31.026 | S2A_MSIL2A_20170902T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
9 | ndwi | [[-2160.77270508, -2371.52905273, -2335.686523... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-02 06:16:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | 5759c6c7d6af37bf26d23eb2b9fbab94b2ae3e6c | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-02 06:16:31.026 | S2A_MSIL2A_20170902T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
10 | mndwi | [[-3179.72363281, -3408.71508789, -3217.656982... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-02 06:16:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | 5759c6c7d6af37bf26d23eb2b9fbab94b2ae3e6c | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-02 06:16:31.026 | S2A_MSIL2A_20170902T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
11 | ndbi | [[1094.12438965, 1128.40466309, 953.640686035,... | https://store.terradue.com/better-wfp-00003/_r... | 2017-09-02 06:16:31.026 | (377140.0, 10.0, 0.0, 4065010.0, 0.0, -10.0) | 5759c6c7d6af37bf26d23eb2b9fbab94b2ae3e6c | PROJCS["WGS 84 / UTM zone 42N",GEOGCS["WGS 84"... | https://catalog.terradue.com//better-wfp-00003... | 2017-09-02 06:16:31.026 | S2A_MSIL2A_20170902T061631_N0205_R034_T42SUF_2... | POLYGON((67.9898655668 36.0488297143,67.989865... | 4287 | 11482 |
- Show data values of NDVI bands
In [22]:
list(myGDF[myGDF['band'] == 'ndvi']['data'].values)
Out[22]:
[array([[ 824.78686523, 682.85723877, 734.91571045, ..., 0. ,
0. , 0. ],
[ 756.35009766, 706.72351074, 743.48883057, ..., 0. ,
0. , 0. ],
[ 801.19561768, 809.96002197, 819.57983398, ..., 0. ,
0. , 0. ],
...,
[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ],
[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ],
[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ]]),
array([[ 643.76623535, 770.03643799, 749.50952148, ..., 0. ,
0. , 0. ],
[ 724.31610107, 776.07647705, 798.06060791, ..., 0. ,
0. , 0. ],
[ 782.07476807, 732.40905762, 755.06469727, ..., 0. ,
0. , 0. ],
...,
[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ],
[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ],
[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ]]),
array([[ 771.35375977, 869.32147217, 806.65100098, ..., 0. ,
0. , 0. ],
[ 782.67999268, 864.54510498, 837.7401123 , ..., 0. ,
0. , 0. ],
[ 881.02728271, 843.9175415 , 742.88848877, ..., 0. ,
0. , 0. ],
...,
[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ],
[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ],
[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ]])]
Plotting data and exporting geotif¶
Plot data¶
Choose 3 bands to plot
In [23]:
bands = None
bands = myGDF[(myGDF['band'] == 'ndvi')]['data'].values
for i in range(bands.size):
bmin = bands[i].min()
bmax = bands[i].max()
bands[i] = (bands[i] - bmin)/(bmax - bmin) * 255
- Plot the 3 bands separately
In [24]:
fig = plt.figure(figsize=(20,20))
for i in [0,1,2]:
a = fig.add_subplot(1, 3, i+1)
imgplot = plt.imshow(bands[i].astype(np.uint8),
cmap='gray')
plt.tight_layout()
fig = plt.gcf()
plt.show()
fig.clf()
plt.close()
- Plot them as an RGB
In [25]:
rgb_uint8 = np.dstack(bands).astype(np.uint8)
width = 10
height = 10
plt.figure(figsize=(width, height))
img = Image.fromarray(rgb_uint8)
imgplot = plt.imshow(img)
Export a Geotiff¶
In [26]:
band_number = 3
cols = myGDF['xsize'].values[0]
rows = myGDF['ysize'].values[0]
print (cols,rows)
geo_transform = myGDF['geo_transform'].values[0]
projection = myGDF['projection'].values[0]
drv = gdal.GetDriverByName('GTiff')
ds = drv.Create('export.tif', cols, rows, band_number, gdal.GDT_Float32)
ds.SetGeoTransform(geo_transform)
ds.SetProjection(projection)
ds.GetRasterBand(1).WriteArray(bands[0], 0, 0)
ds.GetRasterBand(2).WriteArray(bands[1], 0, 0)
ds.GetRasterBand(3).WriteArray(bands[2], 0, 0)
ds.FlushCache()
(4287, 11482)
Download functionalities¶
Download a product¶
- Define the download function
In [27]:
def get_product(url, dest, api_key):
request_headers = {'X-JFrog-Art-Api': api_key}
r = requests.get(url, headers=request_headers)
open(dest, 'wb').write(r.content)
return r.status_code
- Get the reference download endpoint for the product related to a selected date (second date)
In [28]:
enclosure = myGDF[(myGDF['startdate'] == mydates[1])]['enclosure'].values[0]
enclosure
Out[28]:
'https://store.terradue.com/better-wfp-00003/_results/workflows/ec_better_ewf_wfp_01_02_01_ewf_wfp_01_02_01_0_3/run/e17e76fa-0e85-11e9-b95b-0242ac11000f/0001010-181221095105003-oozie-oozi-W/6fe1dd99-1864-4b31-b6f0-6ed2898242ae/S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_20170909T061506_VI_BOA.gz'
In [29]:
output_name = myGDF[(myGDF['startdate'] == mydates[1])]['title'].values[0]
output_name
Out[29]:
'S2A_MSIL2A_20170909T060631_N0205_R134_T42SUF_20170909T061506_VI_BOA.gz'
In [30]:
get_product(enclosure,
output_name,
api_key)
Out[30]:
200
Bulk Download¶
- Define the bulk download function
In [31]:
def get_product_bulk(row, api_key):
return get_product(row['enclosure'],
row['title'],
api_key)
- Download all the products related to a chosen date (first date)
In [32]:
date_results = results[(results['startdate'] == mydates[0]) &
(results.apply(lambda row: '.gz' in row['title'], axis=1))]
date_results.apply(lambda row: get_product_bulk(row, api_key), axis=1)
Out[32]:
8 200
9 200
10 200
11 200
dtype: int64