IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
numpy_data.py
1## \example em/numpy_data.py
2# Accessing density map data directly using NumPy.
3
4import IMP.em
5import IMP.core
6import IMP.atom
7import sys
8
9IMP.setup_from_argv(sys.argv, "numpy data")
10
11if not IMP.IMP_KERNEL_HAS_NUMPY:
12 print("IMP was not built with NumPy support.")
13 sys.exit(0)
14
15dmap = 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).
21m = dmap.get_data()
22print(m.shape)
23
24# We can use any NumPy method to query the data
25print(m.min(), m.mean(), m.max())
26
27# Count all voxels above some threshold
28print(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
33m[m < 0.1] = 0.0
34print(m.min(), m.mean(), m.max())
DensityMap * read_map(std::string filename, MapReaderWriter *reader)
Read a density map from a file (using the given reader) and return it.
Functionality for loading, creating, manipulating and scoring atomic structures.
Basic functionality that is expected to be used by a wide variety of IMP users.
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.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.