from flask import Flask, render_template, request\r
from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt\r
from datetime import date\r
+from processing_snappy import calculate_snow_cover\r
+from processing_snappy import CONFIG as snappy_config\r
+import processed_data\r
import os\r
\r
\r
# change to the directory where the Sentinel data will be downloaded\r
os.chdir(CACHE_DIR) #../UI/data\r
\r
- # ID: rscryosphere and Pass: cryosphere\r
- api = SentinelAPI('yannikmallmann', 'fernerkundung', 'https://scihub.copernicus.eu/dhus')\r
# This is the WKT polygon for Zugspitze\r
#footprint = "POLYGON((10.960922241210938 47.38998234483188,10.960922241210938 47.4291324348703,11.051216125488281 47.4291324348703,11.051216125488281 47.38998234483188,10.960922241210938 47.38998234483188))"\r
footprint = request.form['wkt']\r
date_list = list(date_1)\r
start_date = date_list[0]\r
end_date = date_list[1]\r
+\r
# if a month with two numbers is chosen, len(date) = 12 else 11\r
if len(start_date) == 12:\r
year_start = int(start_date[0:4])\r
day_end = int(end_date[10:11])\r
elif not end_date[9] == '0':\r
day_end = int(end_date[9:11]) \r
+\r
+\r
+ # ID: rscryosphere and Pass: cryosphere\r
+ api = SentinelAPI('yannikmallmann', 'fernerkundung', 'https://scihub.copernicus.eu/dhus')\r
\r
# the date format is date = (from_date,to_date). date(yyyy,mm,dd)\r
products = api.query(footprint,\r
platformname='Sentinel-2', # you can also search Sentinel-1 datasets: 'Sentinel-1'\r
producttype="S2MSI2A") # you can also search Sentinel-2 datasets product type: 'S2MSI1C' or 'S2MSI2A'\r
\r
- #displays the list of products\r
- # https://scihub.copernicus.eu/userguide/BatchScripting\r
- # uuid of the product can be usd with wget\r
- print(products) # this is the list of the available satellite scene. go to the variable explorer to see the number of scenes\r
-\r
#download product\r
api.download_all(products) # Keep this commented unless you are ready to download the products\r
-\r
+ calculate_snow_cover(CACHE_DIR,snappy_config)\r
\r
return render_template('pass.html', prefix=PROXY_PREFIX, a=area, start=start, end=end)\r
\r
-\r
@app.route("/help.html")\r
def helphtml():\r
return render_template('help.html', prefix=PROXY_PREFIX)\r
\r
\r
\r
-def main(path_data, path_out, path_ndsi, path_ndvi, config):\r
+def calculate_snow_cover(path_data, config, path_out=None, path_ndsi=None, path_ndvi=None):\r
+\r
+ path_out = path_out if path_out else path_data + "/out"\r
+ path_ndsi = path_ndsi if path_ndsi else path_data + "/ndsi"\r
+ path_ndvi = path_ndvi if path_ndvi else path_data + "/ndvi"\r
+\r
+\r
for zip_file in os.listdir(path_data):\r
if zip_file.endswith('.zip'):\r
with zipfile.ZipFile(path_data + zip_file, 'r') as zip_ref:\r
- zip_ref.extractall(path_data)\r
+ if not os.path.exists(path_out+'/data'):\r
+ os.makedirs(path_out+'/data')\r
+ zip_ref.extractall(path_data+'/data')\r
os.remove(path_data + zip_file)\r
\r
if not os.path.exists(path_out):\r
os.makedirs(path_ndsi)\r
\r
\r
- for files in os.listdir(path_data):\r
+ for files in os.listdir(path_data+'/data/'):\r
snowcover_filepath = path_out + files + '_snowcover.tif'\r
\r
if os.path.exists(snowcover_filepath):\r
print('done')\r
\r
if __name__== "__main__":\r
- main(PATH_DATA, PATH_OUT, PATH_NDSI, PATH_NDVI, CONFIG)\r
+ calculate_snow_cover(PATH_DATA, CONFIG, PATH_OUT, PATH_NDSI, PATH_NDVI)\r