forked from Neooolee/WHUS2-CD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoprocess.py
53 lines (45 loc) · 1.56 KB
/
Autoprocess.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
49
50
51
52
53
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 30 19:03:22 2018
@author: Neoooli
"""
import zipfile
import os
"""
The source file should be organized as:
sourcedir
/S2A_MSIL1C_20180429T032541_N0206_R018_T49SCV_20180429T062304.zip
/S2A_MSIL1C_20180722T030541_N0206_R075_T49RFP_20180722T060550.zip
...
"""
def unzip_file(zip_file_name, zip_output_dir, mode='rb'):
zip_file = open(zip_file_name, mode)
zip_fn = zipfile.ZipFile(zip_file)
namelist = zip_fn.namelist()
for item in namelist:
zip_fn.extract(item, zip_output_dir)
zip_fn.close()
zip_file.close()
print("Unzipping finished!")
return namelist[0]
origin_dir = "/data/whus-cd+/"
pattern = ".zip"
name = 'unziped'
zippedoutput_dir = origin_dir + name
if not os.path.exists(zippedoutput_dir):
os.makedirs(zippedoutput_dir)
for in_file in os.listdir(origin_dir):
if pattern in in_file:
zip_file_path = os.path.join(origin_dir, in_file)
safe_in_file_path = unzip_file(zip_file_path, zippedoutput_dir)
print("{} processing finished!\n".format(safe_in_file_path))
print("All zipped file finished!")
'''
After run unzip.py, the dataset will be organized as follows:
sourcedir
/S2A_MSIL1C_20180429T032541_N0206_R018_T49SCV_20180429T062304.SAFE
/AUX_DATA...
/S2A_MSIL1C_20180722T030541_N0206_R075_T49RFP_20180722T060550.SAFE
/AUX_DATA...
'''
os.system("python fuseimg.py")