-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_percentage_L2A.py
48 lines (33 loc) · 1.29 KB
/
cloud_percentage_L2A.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 30 14:28:20 2023
@author: pierreaudisio
"""
import os
from zipfile import ZipFile
from zipfile import BadZipFile
# Repository containing the product folder
directory = "/media/pierreaudisio/Maxtor/IRD/Sentinel2/Nouvelle_Calédonie"
folders = os.listdir(directory)
#Extracting from zip file utf-8, the xml file
n = 0
cloud_percent= {}
for i in folders:
if (".zip" in i):
directory_zip = directory + "/" + i
try:
with ZipFile(directory_zip) as myzip:
a = ZipFile.namelist(myzip)
file_xml = a[0]
file_xml = file_xml[:48] + "/" + file_xml[:48] + "_MTD_ALL.xml"
with myzip.open(file_xml) as myfile:
_xml = (myfile.read())
# Searching cloud percentage on xml file
cloud_file = _xml.decode("utf-8")
position = cloud_file.find("CloudPercent")
cloud_percent[directory_zip[47:]] = cloud_file[position+14:position+16]
n += 1
# Using except to avoid inturreption of the processing because of a corrupt file
except BadZipFile:
print("Error with: ",directory_zip)