-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathli_summary.py
executable file
·81 lines (69 loc) · 2.17 KB
/
li_summary.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
#!/usr/bin/env python3
import argparse
import glob
import os
import sys
import large_image
os.environ['GDAL_PAM_ENABLED'] = 'NO'
os.environ['CPL_LOG'] = os.devnull
format = '%6d %6d %5d %5d %s %6d%5d%5d%5d%5d%12d %-10s %s\n'
def main(opts):
sys.stdout.write(
' Width Height TileW TileH um/pix Frames C Z T XY'
' size format name\n')
paths = []
for source in opts.source:
for sourcePath in sorted(glob.glob(source)):
paths.append(sourcePath)
if opts.sort:
paths.sort()
for sourcePath in paths:
source_check(sourcePath, opts)
def source_check(sourcePath, opts): # noqa
try:
li = large_image.open(sourcePath)
except Exception:
sys.stdout.write('%-82s %s\n' % ('-- not a large image --', sourcePath))
sys.stdout.flush()
return
metadata = li.getMetadata()
um = (metadata.get('mm_x', 0) or 0) * 1000
if not um:
umstr = ' -'
elif um < 100:
umstr = '%6.3f' % um
else:
prefix = 'um kM'
val = um
idx = 0
while val >= 10000 and idx + 1 < len(prefix):
idx += 1
val /= 1000
umstr = '%4.0f%sm' % (val, prefix[idx])
sys.stdout.write(format % (
metadata['sizeX'],
metadata['sizeY'],
metadata['tileWidth'],
metadata['tileHeight'],
umstr,
len(metadata.get('frames', [])) or 1,
metadata.get('IndexRange', {}).get('IndexC', 0) or 1,
metadata.get('IndexRange', {}).get('IndexZ', 0) or 1,
metadata.get('IndexRange', {}).get('IndexT', 0) or 1,
metadata.get('IndexRange', {}).get('IndexXY', 0) or 1,
os.path.getsize(sourcePath),
li.name,
sourcePath,
))
sys.stdout.flush()
def command():
parser = argparse.ArgumentParser(
description='Report some basic metadata about large images.')
parser.add_argument('--sort', action='store_true', help='Sort input files')
parser.add_argument(
'source', nargs='+', type=str,
help='Source file to read and analyze')
opts = parser.parse_args()
main(opts)
if __name__ == '__main__':
command()