-
Notifications
You must be signed in to change notification settings - Fork 0
/
compress_particles_demo.py
44 lines (31 loc) · 1.53 KB
/
compress_particles_demo.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
import os
import pyapr
def main():
"""
This demo applies lossy compression to the particle intensities, with the background level and quantization factor
set interactively.
"""
io_int = pyapr.filegui.InteractiveIO()
fpath_apr = io_int.get_apr_file_name() # get APR file path from gui
# Instantiate objects
apr = pyapr.APR()
parts = pyapr.ShortParticles()
# Read APR and particles from file
pyapr.io.read(fpath_apr, apr, parts)
# Interactive WNL compression
pyapr.viewer.interactive_compression(apr, parts)
# Write compressed APR to file
fpath_apr_save = io_int.save_apr_file_name() # get file path from gui
pyapr.io.write(fpath_apr_save, apr, parts)
# Size of original and compressed APR files in MB
original_file_size = os.path.getsize(fpath_apr) * 1e-6
compressed_file_size = os.path.getsize(fpath_apr_save) * 1e-6
# Uncompressed pixel image size (assuming 16-bit datatype)
original_image_size = 2e-6 * apr.x_num(apr.level_max()) * apr.y_num(apr.level_max()) * apr.z_num(apr.level_max())
print("Original APR File Size: {:7.2f} MB".format(original_file_size))
print("Lossy Compressed APR File Size: {:7.2f} MB".format(compressed_file_size))
# compare uncompressed pixel image size to compressed APR file sizes
print("Original Memory Compression Ratio: {:7.2f} ".format(original_image_size/original_file_size))
print("Lossy Memory Compression Ratio: {:7.2f} ".format(original_image_size/compressed_file_size))
if __name__ == '__main__':
main()