| 1 | #
|
|---|
| 2 | # Place a marker at the center of mass of a map for the region above the
|
|---|
| 3 | # displayed contour level.
|
|---|
| 4 | #
|
|---|
| 5 | # Open a map file and then open this script to place the center marker.
|
|---|
| 6 | #
|
|---|
| 7 | # To place markers on more than one map, choose the map in the volume dialog
|
|---|
| 8 | # by clicking on its histogram or name (so the name above the histogram is
|
|---|
| 9 | # highlighted) and then open this script (File / Open...).
|
|---|
| 10 | #
|
|---|
| 11 |
|
|---|
| 12 | # Get highlighted volume from volume dialog
|
|---|
| 13 | import VolumeViewer as VV
|
|---|
| 14 | v = VV.active_volume()
|
|---|
| 15 |
|
|---|
| 16 | # Find highest displayed contour level.
|
|---|
| 17 | level = max(v.surface_levels)
|
|---|
| 18 |
|
|---|
| 19 | # Get 3-d array of map values.
|
|---|
| 20 | m = v.data.full_matrix()
|
|---|
| 21 |
|
|---|
| 22 | # Find indices of map values above displayed threshold.
|
|---|
| 23 | kji = (m >= level).nonzero()
|
|---|
| 24 |
|
|---|
| 25 | # Compute total mass above threshold.
|
|---|
| 26 | msum = m[kji].sum()
|
|---|
| 27 |
|
|---|
| 28 | # Compute mass-weighted center
|
|---|
| 29 | center = [(i*m[kji]).sum()/msum for i in kji]
|
|---|
| 30 | center.reverse() # k,j,i -> i,j,k index order
|
|---|
| 31 | print 'Center of mass grid index for', v.name, center
|
|---|
| 32 |
|
|---|
| 33 | # Convert index units to physical units.
|
|---|
| 34 | c = v.data.ijk_to_xyz(center)
|
|---|
| 35 |
|
|---|
| 36 | # Create marker model with same id number as volume.
|
|---|
| 37 | import VolumePath as VP
|
|---|
| 38 | mset = VP.Marker_Set(v.name + ' center')
|
|---|
| 39 | mset.marker_molecule(model_id = (v.id, v.subid))
|
|---|
| 40 |
|
|---|
| 41 | # Place marker at center position.
|
|---|
| 42 | color = (1,1,0,1) # (red, green, blue, opacity).
|
|---|
| 43 | mset.place_marker(c, rgba = color, radius = min(v.data.step))
|
|---|