-
Notifications
You must be signed in to change notification settings - Fork 7
/
filterNoValues.py
executable file
·98 lines (69 loc) · 1.72 KB
/
filterNoValues.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
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
97
98
"""
"""
import numpy as np
from osgeo import gdal
import argparse
import os
import csv
def is_raster_empty(file):
"""
"""
raster = gdal.Open(file)
raster_band = raster.GetRasterBand(1)
band_array = np.array(raster_band.ReadAsArray())
if np.max(band_array) > 0:
print("OK")
empty = False
else:
print("PROBLEM")
empty = True
return empty
def are_rasters_empty(directory):
"""
"""
total_list = []
for file in os.listdir(directory):
empty = is_raster_empty(directory + "/" + file)
if empty:
result = "Problem"
else:
result = "OK"
single_list = [file, result]
total_list.append(single_list)
return total_list
def create_file_list(list):
"""
"""
with open("novalues_list.csv", "w") as f:
wr = csv.writer(f)
wr.writerows(list)
def delete_files(file_list):
"""
"""
for file in file_list:
command = "rm %s" % file
os.system(command)
def delete_file(file):
"""
"""
command = "rm %s" % file
os.system(command)
def move_file(filename, folderpath):
"""
Moves a file to a new folder
"""
os.system("mv " + filename + " " + folderpath)
if __name__ == "__main__":
"""
"""
parser = argparse.ArgumentParser(epilog='Type in directory of TIFs with\
this script in the parent directory.')
parser.add_argument('directory', help='The directory that the TIFs are in')
args = parser.parse_args()
directory = args.directory
for filename in directory:
file = directory + "/" + filename
if is_raster_empty(file):
delete_file(file)
else:
continue