Skip to content

Commit

Permalink
Added: Sentinelsat - download and extract
Browse files Browse the repository at this point in the history
  • Loading branch information
balakumaran247 committed Apr 19, 2021
1 parent e795bf1 commit 8edc025
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.pyc
input_details.py
input_details.py
4 changes: 4 additions & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
24 changes: 24 additions & 0 deletions download_data.py
Original file line number Diff line number Diff line change
@@ -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')
23 changes: 7 additions & 16 deletions s2_vegetation.py
Original file line number Diff line number Diff line change
@@ -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)
if __name__ == '__main__':
main()

0 comments on commit 8edc025

Please sign in to comment.