Deletete api.pi
Browse files
api.py
DELETED
@@ -1,84 +0,0 @@
|
|
1 |
-
from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt
|
2 |
-
from datetime import datetime, timedelta,date
|
3 |
-
import zipfile
|
4 |
-
import rasterio
|
5 |
-
from rasterio.plot import show
|
6 |
-
from PIL import Image
|
7 |
-
import matplotlib.pyplot as plt
|
8 |
-
import numpy as np
|
9 |
-
import pandas as pd
|
10 |
-
import os
|
11 |
-
from glob import glob
|
12 |
-
from tqdm import tqdm
|
13 |
-
#from haversine import haversine, Unit
|
14 |
-
#from xml.etree import ElementTree as et
|
15 |
-
import xmltodict
|
16 |
-
import json
|
17 |
-
import warnings
|
18 |
-
import shutil
|
19 |
-
from shapely.geometry import Point
|
20 |
-
from shapely.geometry.polygon import Polygon
|
21 |
-
warnings.filterwarnings('ignore')
|
22 |
-
|
23 |
-
##
|
24 |
-
def unzip():
|
25 |
-
files = glob('*.zip')
|
26 |
-
for file in files:
|
27 |
-
with zipfile.ZipFile(file, 'r') as zip_ref:
|
28 |
-
zip_ref.extractall()
|
29 |
-
|
30 |
-
|
31 |
-
##
|
32 |
-
def select_best_cloud_coverage_tile():
|
33 |
-
tile_names = {}
|
34 |
-
cld_prob = []
|
35 |
-
folders = glob('*.SAFE')
|
36 |
-
for fold in folders:
|
37 |
-
metadata_path = fold+"/MTD_MSIL2A.xml"
|
38 |
-
xml_file=open(metadata_path,"r")
|
39 |
-
xml_string=xml_file.read()
|
40 |
-
python_dict=xmltodict.parse(xml_string)
|
41 |
-
cld = float(python_dict["n1:Level-2A_User_Product"]["n1:Quality_Indicators_Info"]["Cloud_Coverage_Assessment"])
|
42 |
-
tile_names[cld] = fold
|
43 |
-
cld_prob.append(cld)
|
44 |
-
name = tile_names[min(cld_prob)]
|
45 |
-
dates = name.split('_')[2][:8]
|
46 |
-
acquisition_date = datetime.strptime(dates, "%Y%m%d")
|
47 |
-
today = datetime.now()
|
48 |
-
delta = (today - acquisition_date)
|
49 |
-
days_ago = delta.days
|
50 |
-
return name,min(cld_prob),days_ago
|
51 |
-
|
52 |
-
##
|
53 |
-
def find_good_tile(df, point):
|
54 |
-
for row in tqdm(df.itertuples(),total=len(df)):
|
55 |
-
tile_name = row.tiles
|
56 |
-
coordinate = row.coords
|
57 |
-
x = coordinate.replace(']','')
|
58 |
-
x = x.replace('[','')
|
59 |
-
x = x.replace("'",'')
|
60 |
-
tab = [[float(x.split(",")[i]),float(x.split(",")[i+1])] for i in range(0,len(x.split(",")),2)]
|
61 |
-
polygon = Polygon(tab)
|
62 |
-
result = polygon.contains(point)
|
63 |
-
if result:
|
64 |
-
print(tile_name)
|
65 |
-
return tile_name
|
66 |
-
|
67 |
-
return 404
|
68 |
-
|
69 |
-
##
|
70 |
-
def delete_tiles():
|
71 |
-
files = glob('*.zip')
|
72 |
-
folders1 = glob('*.SAFE')
|
73 |
-
folders2 = glob("*.tmp")
|
74 |
-
for f in files:
|
75 |
-
os.remove(f)
|
76 |
-
for fold in folders1:
|
77 |
-
shutil.rmtree(fold, ignore_errors=True)
|
78 |
-
|
79 |
-
for fold in folders2:
|
80 |
-
shutil.rmtree(fold, ignore_errors=True)
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|