IMP logo
IMP Reference Guide  develop.7400db2aee,2024/11/24
The Integrative Modeling Platform
numpy_data.py
1 ## \example em/numpy_data.py
2 # Accessing density map data directly using NumPy.
3 
4 import IMP.em
5 import IMP.core
6 import IMP.atom
7 import sys
8 
9 IMP.setup_from_argv(sys.argv, "numpy data")
10 
11 if not IMP.IMP_KERNEL_HAS_NUMPY:
12  print("IMP was not built with NumPy support.")
13  sys.exit(0)
14 
15 dmap = IMP.em.read_map(
17 
18 # We can get the actual voxel data as a 3D NumPy array
19 # This is a view of the data in `dmap`, not a copy, so is efficient
20 # (however, it should not be used after the `dmap` object itself is destroyed).
21 m = dmap.get_data()
22 print(m.shape)
23 
24 # We can use any NumPy method to query the data
25 print(m.min(), m.mean(), m.max())
26 
27 # Count all voxels above some threshold
28 print(m[m >= 0.1].size)
29 
30 # We can also change the data; here we do the equivalent of
31 # IMP.em.get_threshold_map() in place, i.e. clear any voxel that is
32 # below the threshold
33 m[m < 0.1] = 0.0
34 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.