-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractlandsat.py
70 lines (31 loc) · 1.38 KB
/
extractlandsat.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 9 10:25:47 2022
@author: FALAH FAKHRI
"""
# import required packages and libraries.
import tarfile
import os
def extract_landsat(dirpath:str):
"""
extract landsat 8/9 tar images, and save them in a new concise name folders.
parameter
---------
dirpath: str path to the directory which contains the images.
dirpath should be ended up with forward slash '/' in order to complete the
extraction process in the new folders.
"""
for filename in os.listdir(dirpath):
if filename.endswith('.tar'):
name = os.path.splitext(filename)[0]
os.makedirs(dirpath +name, exist_ok=True)
file = tarfile.open(os.path.join(dirpath,filename))
for dir in os.listdir(dirpath):
if dir == name:
# print(os.path.join(dir, filename))
file.extractall(os.path.join(dirpath+dir))
print('\nextracted is done in the new folder', os.path.join(dir, filename))
def main():
pass
if __name__ == '__main__':
main()