Scripts: compress.py

File compress.py, 2.0 KB (added by goddard, 13 years ago)
Line 
1#
2# Copy a series of map files to a single Chimera map (HDF5) file.
3# Use compression and optionally crop and threshold and change the value type
4# for each map.
5#
6# runscript compress.py *.mrc out.cmap 14,213,0,511,539,144 150 int16 1.5,1.5,2.4
7#
8# The arguments are input map files, output map name, subregion bounds
9# (xmin,ymin,zmin,xmax,ymax,zmax), threshold, new value type, and grid spacing.
10# Arguments subregion, threshold, new value type, grid spacing can be
11# specified as the string none or omitted.
12#
13# This was written to compress map time series for Bessel beam cell motion
14# data from Lillian Fritz-Laylin.
15#
16def compress_maps(input_files, output_file, subregion = None, threshold = None,
17 value_type = None, grid_spacing = None):
18 for i,p in enumerate(input_files):
19 run('open %s' % p)
20 m = 0 # Model id number
21 if not subregion is None:
22 run('vop scale #%d subregion %s' % (m, subregion))
23 m += 1
24 if not threshold is None:
25 run('vop threshold #%d min %s' % (m, threshold))
26 m += 1
27 if not value_type is None:
28 run('vop scale #%d valueType %s' % (m, value_type))
29 m += 1
30 if not grid_spacing is None:
31 run('volume #%d voxelSize %s' % (m, grid_spacing))
32 mp = chimera.openModels.list(id = m)[0]
33 mp.data.name = '%04d' % i
34 run('volume #%d save %s saveFormat cmap compress true append true'
35 % (m, output_file))
36 run('close all')
37
38def run(command):
39 from chimera import replyobj, runCommand
40 replyobj.status(command)
41 replyobj.info(command + '\n')
42 runCommand(command)
43
44
45if not 'arguments' in locals() or len(arguments) < 2 or len(arguments) > 6:
46 import Commands
47 raise Commands.CommandError('Require 2 to 6 arguments: runscript compress.py '
48 '<input-files> <output-file> <subregion> '
49 '<threshold> <value-type> <grid-spacing>')
50
51import glob
52input_files = glob.glob(arguments[0])
53input_files.sort()
54args = tuple((None if a == 'none' else a) for a in arguments[1:])
55compress_maps(input_files, *args)