From 8edc025402cb38c44ecf42164e70f4bc96777a4b Mon Sep 17 00:00:00 2001 From: balakumaran Date: Mon, 19 Apr 2021 17:34:51 +0530 Subject: [PATCH] Added: Sentinelsat - download and extract --- .gitignore | 2 +- data/.gitignore | 4 ++++ download_data.py | 24 ++++++++++++++++++++++++ s2_vegetation.py | 23 +++++++---------------- 4 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 data/.gitignore create mode 100644 download_data.py diff --git a/.gitignore b/.gitignore index a731826..7b4539d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ *.pyc -input_details.py +input_details.py \ No newline at end of file diff --git a/data/.gitignore b/data/.gitignore new file mode 100644 index 0000000..44c5ea8 --- /dev/null +++ b/data/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/download_data.py b/download_data.py new file mode 100644 index 0000000..f6bd6fb --- /dev/null +++ b/download_data.py @@ -0,0 +1,24 @@ +from sentinelsat import SentinelAPI +import zipfile +import os + +def download_data (username, password, latitude, longitude): + api = SentinelAPI(username, + password, 'https://scihub.copernicus.eu/dhus') + footprint = f'POINT ({latitude} {longitude})' + data_populate = api.query(footprint, date=('NOW-12MONTHS','NOW'), + order_by='cloudcoverpercentage', + platformname='Sentinel-2', + processinglevel='Level-2A', + cloudcoverpercentage=(0,10)) + data_database = api.to_geodataframe(data_populate) + data_database_sorted = data_database.sort_values('cloudcoverpercentage', + ascending=True).reset_index() + print(data_database_sorted['index'].iloc[0]) + print("\ndownloading data... please wait...\n") + data_download = api.download(data_database_sorted['index'].iloc[0], + directory_path='./data') + print("\ndownload complete!\n") + zip = zipfile.ZipFile(os.path.join('.', 'data', + data_download['title'] + '.zip')) + zip.extractall('./data') \ No newline at end of file diff --git a/s2_vegetation.py b/s2_vegetation.py index dbdbb24..153b958 100644 --- a/s2_vegetation.py +++ b/s2_vegetation.py @@ -1,19 +1,10 @@ -from sentinelsat import SentinelAPI -import geopandas as gpd -import pandas as pd -from shapely.geometry import MultiPolygon, Polygon -import numpy as np -import os - import input_details +from download_data import download_data -api = SentinelAPI(input_details.username, input_details.password, 'https://scihub.copernicus.eu/dhus') - -footprint = f'POINT ({input_details.latitude} {input_details.longitude})' -print(footprint) - -data_populate = api.query(footprint, date=('NOW-12MONTHS','NOW'), order_by='cloudcoverpercentage', platformname='Sentinel-2', processinglevel='Level-2A', cloudcoverpercentage=(0,10)) -print(len(data_populate)) +def main(): + username, password = input_details.username, input_details.password + latitude, longitude = input_details.latitude, input_details.longitude + download_data(username, password, latitude, longitude) -data_database = api.to_geodataframe(data_populate) -print(data_database) \ No newline at end of file +if __name__ == '__main__': + main()