IMP logo
IMP Reference Guide  2.16.0
The Integrative Modeling Platform
numpy_data.py
1 ## \example em/numpy_data.py
2 # Accessing density map data directly using NumPy.
3 
4 from __future__ import print_function
5 import IMP.em
6 import IMP.core
7 import IMP.atom
8 import sys
9 
10 IMP.setup_from_argv(sys.argv, "numpy data")
11 
12 if not IMP.IMP_KERNEL_HAS_NUMPY:
13  print("IMP was not built with NumPy support.")
14  sys.exit(0)
15 
16 dmap = IMP.em.read_map(
18 
19 # We can get the actual voxel data as a 3D NumPy array
20 # This is a view of the data in `dmap`, not a copy, so is efficient
21 # (however, it should not be used after the `dmap` object itself is destroyed).
22 m = dmap.get_data()
23 print(m.shape)
24 
25 # We can use any NumPy method to query the data
26 print(m.min(), m.mean(), m.max())
27 
28 # Count all voxels above some threshold
29 print(m[m >= 0.1].size)
30 
31 # We can also change the data; here we do the equivalent of
32 # IMP.em.get_threshold_map() in place, i.e. clear any voxel that is
33 # below the threshold
34 m[m < 0.1] = 0.0
35 print(m.min(), m.mean(), m.max())
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
Basic utilities for handling cryo-electron microscopy 3D density maps.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
Basic functionality that is expected to be used by a wide variety of IMP users.
Functionality for loading, creating, manipulating and scoring atomic structures.