-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdata_check.py
45 lines (42 loc) · 1.62 KB
/
data_check.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
import os
from osgeo import gdal
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument( "--feature_path", default='origin_data/feature/', type=str)
parser.add_argument( "--label_path", default='origin_data/label/label1.tif', type=str)
args = parser.parse_args()
def get_tiff_attributes(tiff_path):
tiff = gdal.Open(tiff_path)
width, height = tiff.RasterXSize, tiff.RasterYSize
transform = tiff.GetGeoTransform()
return width, height, transform
consistency = {"w": [], "h":[], "transform":[]}
#label
w, h, transform = get_tiff_attributes(args.label_path)
consistency["w"].append(w)
consistency["h"].append(h)
consistency["transform"].append([int(value) for value in transform])
#feature
for tif_data in os.listdir(args.feature_path,):
w, h, transform = get_tiff_attributes(os.path.join(args.feature_path, tif_data))
print('Reading '+tif_data+' data.')
consistency["w"].append(w)
consistency["h"].append(h)
consistency["transform"].append([int(value) for value in transform])
consistency["w"] = set(consistency["w"])
consistency["h"] = set(consistency["h"])
if(len(consistency["w"])!=1):
print("The width of the data is different")
print(consistency["w"])
sys.exit()
if(len(consistency["h"])!=1):
print("The height of the data is different")
print(consistency["h"])
sys.exit()
flag = consistency["transform"][0] # Get the first tuple in the list
if(not(all(t == flag for t in consistency["transform"]))):
print("The transform of the data is different")
print(consistency["transform"])
sys.exit()
print("Congratulations! There are no problems with the data.")