An error occurred while loading the file. Please try again.
-
Lozac'h Loic authoredf9262a6a
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /usr/bin/python3
# -*- coding: utf-8 -*-
"""
Script permettant de trier les images Sentinel-1 en fonction de leur plateforme,
de leur orbite relative et du slice number.
Auteur: Loïc Lozac'h
"""
import xml.etree.ElementTree as ET
import os, shutil, argparse
def search_files(directory='.', matchnaming='S1',extension='dim',fictype='f'):
images=[]
matchnaming = matchnaming.upper()
extension = extension.upper()
fictype = fictype.lower()
for dirpath, dirnames, files in os.walk(directory):
if fictype != 'd':
for name in files:
# print(os.path.join(dirpath, name) + " test")
if name.upper().find(matchnaming) >= 0 and name.upper().endswith(extension):
# print(os.path.join(dirpath, name) + " OK")
abspath = os.path.abspath(os.path.join(dirpath, name))
images.append(abspath)
elif fictype == 'd':
for dirname in dirnames:
# print(os.path.join(dirpath, name) + " test")
if dirname.upper().find(matchnaming) >= 0 :
# print(os.path.join(dirpath, name) + " OK")
abspath = os.path.abspath(os.path.join(dirpath, dirname))
images.append(abspath)
else:
print("search_files type error")
exit
return images
if __name__ == "__main__":
# Make parser object
parser = argparse.ArgumentParser(description=
"""
Organize S1 calibrated files by satellite, relative orbit and slice for multi-temporal speckle filtering
""")
parser.add_argument('-s1dir', action='store', required=True, help='Directory containing Calibrated Sentinel1 in DIMAP-BEAM format')
args=parser.parse_args()
s1dim=[]
s1dim=search_files(args.s1dir)
metas1=[]
# dirsel=[]
for file in s1dim :
#---metadata parsing
tree = ET.parse(file)
root = tree.getroot()
#---metadata profile
balises = root.findall('Dataset_Sources/MDElem/MDElem/MDATTR')
metab={}
for balise in balises :
if balise.attrib['name'] == 'PRODUCT':
metab.setdefault('PRODUCT',balise.text)
elif balise.attrib['name'] == 'MISSION':
metab.setdefault('MISSION',"S"+balise.text[-2:])
elif balise.attrib['name'] == 'PASS':
metab.setdefault('PASS',balise.text[:3])
elif balise.attrib['name'] == 'REL_ORBIT':
metab.setdefault('REL_ORBIT',balise.text)
elif balise.attrib['name'] == 'slice_num':
metab.setdefault('slice_num',balise.text)
outputdir = os.path.join(args.s1dir,metab['MISSION']+"_"+"ORB"+metab['REL_ORBIT']+"_"+"SL"+metab['slice_num'])
if not os.path.exists(outputdir):
os.mkdir(outputdir)
#move
print("copy : "+file[:-3]+"*")
print("to : "+outputdir+"\n")
shutil.move(file,outputdir)
shutil.move(file[:-3]+"data",outputdir)