Commit b3180834 authored by Adan Salazar Garibay's avatar Adan Salazar Garibay

proposition of library to work with Sentinel data

parents
#!/bin/python
# Copyright (C) 2018 Adan Salazar <asalazargaribay@gmail.com>
#
#
# This file is part of GeoSentinel
#
#
# GeoSentinel is free software you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GeoSentinel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with StereoVision. If not, see <http://www.gnu.org/licenses/>.
"""
Example of dowloading Sentinel images from the Copernicus Open Access Hub < https://scihub.copernicus.eu/dhus/#/home >
"""
from sentinelsat.sentinel import read_geojson, geojson_to_wkt
from argparse import ArgumentParser
from geosentinel.ui_utils import (download_sentinel_mages, SENTINEL_ARGUMENTS)
def main():
"""
Download all Sentinel images from the Copernicus Hub and save them in the folder specified by the user.
Please run: python dowload_images --help before usage
First, parse arguments provided by the user. Then choose the images that are in the
dates and polygon provided by the user, then remove the images that do not overlap more than 30 %
of the input polygon and the polygon of the image. Finally, download the remaining images.
"""
parser = ArgumentParser(description="Download Sentinel images from the Copernicus Hub",
parents=[SENTINEL_ARGUMENTS])
args = parser.parse_args()
path_json=args.input_file
args.footprint = geojson_to_wkt(read_geojson(path_json))
download_sentinel_mages(args)
if __name__ == "__main__":
main()
#!/bin/python
# Copyright (C) 2018 Adan Salazar <asalazargaribay@gmail.com>
#
#
# This file is part of GeoSentinel
#
#
# GeoSentinel is free software you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GeoSentinel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with StereoVision. If not, see <http://www.gnu.org/licenses/>.
"""
Example of finding Sentinel files in a specific directory
"""
from argparse import ArgumentParser
from geosentinel.ui_utils import (find_files, SENTINEL_FIND_ARGUMENTS)
def main():
"""
Find all Sentinel files in the folder specified by the user and print the number files and the list of files.
Please run: python find_sentinel_files --help before usage
"""
parser = ArgumentParser(description="Find Sentinel files in the folder specified by the user",
parents=[SENTINEL_FIND_ARGUMENTS])
args = parser.parse_args()
list_files = find_files(args)
print "There is/are %d " % len(list_files) + args.plattform + " file(s)"
print list_files
if __name__ == "__main__":
main()
# Copyright (C) 2018 Adan Salazar <asalazargaribay@gmail.com>
#
#
# This file is part of GeoSentinel
#
#
# GeoSentinel is free software you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GeoSentinel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with StereoVision. If not, see <http://www.gnu.org/licenses/>.
"""
Utilities for GeoSentinel.
Modules:
* "products" - Sentinel products
* "ui_utils" - Utilities for user interaction
* "exceptions" - Various exceptions
Sentinel products
******************
.. automodule:: geosentinel.products
User interface utilities
************************
.. automodule:: geosentinel.ui_utils
Exceptions
**********
.. automodule:: geosentinel.exceptions
"""
\ No newline at end of file
# Copyright (C) 2018 Adan Salazar <asalazargaribay@gmail.com>
#
#
# This file is part of GeoSentinel
#
#
# GeoSentinel is free software you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GeoSentinel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with StereoVision. If not, see <http://www.gnu.org/licenses/>.
#
"""
Various exceptions for working with GeoSentinel.
Classes:
* "ImageNotFoundError"
"""
class ImageNotFoundError(Exception):
"""No image could be found in searched image."""
class FilesNotFoundError(Exception):
"""No files could be found in searched folder."""
\ No newline at end of file
# Copyright (C) 2018 Adan Salazar <asalazargaribay@gmail.com>
#
#
# This file is part of GeoSentinel
#
#
# GeoSentinel is free software you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GeoSentinel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with StereoVision. If not, see <http://www.gnu.org/licenses/>.
"""
Classes for having some Sentinel Products
Classes:
* "SentinelData" - Class for Sentinel satellites configuration
* "SentinelOneProducts" - A class that obtains Sentinel1 products
"""
class SentinelData(object):
""" Class for Sentinel satellites configuration """
def __init__(self):
"""
Initialize Sentinel Data.
"""
self.username = 'asalazarg'
self.password='geo135asg'
self.URL_Sentinel='https://scihub.copernicus.eu/dhus'
self.init_date = None
self.end_date = None
self.product_type = None
self.platform_name = None
self.interest_footprint = None
self.image_polygon = None
self.plot_width = 7
self.plot_height = 7
self.intersection_th = 30
# Copyright (C) 2018 Adan Salazar <asalazargaribay@gmail.com>
#
#
# This file is part of GeoSentinel
#
#
# GeoSentinel is free software you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GeoSentinel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with StereoVision. If not, see <http://www.gnu.org/licenses/>.
"""
Utilities for user interaction with the "stereo" package.
Variables:
* "SENTINEL_ARGUMENTS" - "argparse.ArgumentParser" for working with Sentinel products
Functions:
* "find_files" - Discover Sentinel files in directory
* "download_sentinel_mages" - Calibrate chessboard images discovered in a folder
* "check_existing_directory" -
"""
from argparse import ArgumentParser
import os
from collections import OrderedDict
from osgeo import ogr
from sentinelsat.sentinel import SentinelAPI #read_geojson, geojson_to_wkt
from geosentinel.products import SentinelData
#from Sentinel.exceptions import ImageNotFoundError
#: Command line arguments for collecting information about Sentinel data and products
SENTINEL_ARGUMENTS = ArgumentParser(add_help=False)
SENTINEL_ARGUMENTS.add_argument("init_date", help="initial date for dowloading period.")
SENTINEL_ARGUMENTS.add_argument("end_date", help="final date for dowloading period.")
SENTINEL_ARGUMENTS.add_argument("product_type", help="sentinel product type {SLC, GRD, IW }")
SENTINEL_ARGUMENTS.add_argument("plattform", help="sentinel-1 or sentinel-2")
SENTINEL_ARGUMENTS.add_argument("overlap", type=int, help="Percentage of overlapping between the polygon "
"provided by the user and the polygon of the image")
SENTINEL_ARGUMENTS.add_argument("output_folder", help="Folder to download Sentinel files ")
SENTINEL_FIND_ARGUMENTS = ArgumentParser(add_help=False)
SENTINEL_FIND_ARGUMENTS.add_argument("folder", help="Folder to find Sentinel files ")
SENTINEL_FIND_ARGUMENTS.add_argument("plattform", help="sentinel-1 or sentinel-2")
def find_files(args):
folder = args.folder
satelite = args.plattform
files = os.listdir(folder)
if(satelite=="Sentinel-1"):
namfil1 = 'S1A_'
namfil2 = 'S1B_'
files = [f for f in files if f.startswith(namfil1) or f.startswith(namfil2)]
if(satelite=="Sentinel-2"):
namfil1 = 'S2A_'
namfil2 = 'S2B_'
files = [f for f in files if f.startswith(namfil1) or f.startswith(namfil2)]
return files
def check_existing_directory(folder) :
if not os.path.exists(folder):
os.makedirs(folder)
print folder + " was created"
else:
print folder + " exists "
def download_sentinel_mages(args):
check_existing_directory(args.output_folder)
products = SentinelData()
api = SentinelAPI(products.username, products.password, products.URL_Sentinel)
products.interest_footprint = args.footprint
products.init_date = args.init_date
products.end_date = args.end_date
products.product_type = args.product_type
products.platform_name = args.platform
products.intersection_th = args.overlap
products_list = api.query(products.interest_footprint,
date = (products.init_date, products.end_date),
producttype = products.product_type,
platformname = products.platform_name)
polyfootprint = ogr.CreateGeometryFromWkt(products.interest_footprint)
areafootprint = polyfootprint.GetArea()
# filtering products that their intersection is less than --intersection_th
products_down = OrderedDict()
products_down = products_list.copy()
# convert to pandas
products_df = api.to_dataframe(products_list)
counter = 0
for i in range(len(products_list)):
inputpoly = ogr.CreateGeometryFromWkt(products_df.footprint[i])
intersectionpoly = polyfootprint.Intersection(inputpoly)
intersectionpoly_area = intersectionpoly.GetArea()
por_intersection = (intersectionpoly_area*100)/areafootprint
print "area from elemet % :" , intersectionpoly_area
print "Intersection zone % :" , por_intersection
if(por_intersection <= products.intersection_th):
# Deleting element
del products_down[products_df.uuid[i]]
counter = counter + 1
#print ("%d found elements that are not going to be downloaded" % counter)
#print ("Downloading %d elements ..." % len(products_down) )
os.chdir(args.output_folder)
api.download_all(products_down)
# Copyright (C) 2018 Adan Salazar <asalazargaribay@gmail.com>
#
#
# This file is part of GeoSentinel
#
#
# GeoSentinel is free software you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GeoSentinel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with StereoVision. If not, see <http://www.gnu.org/licenses/>.
from setuptools import setup
setup(name="stereo",
version="1.0",
description=("Library and utilities for Stereo cameras calibration"),
author="Adan Salazar",
author_email="asalazargaribay@gmail.com",
packages=["geosentinel"],
url="none",
download_url="none",
license="GNU GPL",
#requires=["numpy"],
provides=["geosentinel"],
classifiers=["Development Status :: 5 - Production/Stable",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"License :: Freely Distributable",
"License :: OSI Approved :: GNU General Public License v3 "
"or later (GPLv3+)",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2.7",
"Topic :: Multimedia :: Graphics :: Capture"])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment