Shapes
This is the API reference for code that works with the echoSMs anatomical datastore and associated model shapes.
echosms.plotting
Functions to create plots of specimens.
plot_shape_categorised_voxels(s, title='')
Plot the specimen's categorised voxels.
Normally called via plot_specimen().
| PARAMETER | DESCRIPTION |
|---|---|
s
|
The categorised voxel shape data structure as per the echoSMs datastore.
TYPE:
|
title
|
Title for the plot.
TYPE:
|
Source code in src/echosms/plotting.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
plot_shape_geometric(shapes, ax)
Plot an echoSMs geometric shape.
Normally called via plot_specimen().
| PARAMETER | DESCRIPTION |
|---|---|
shapes
|
Geometric shapes to be plotted
TYPE:
|
ax
|
A matplotlib axis.
|
Source code in src/echosms/plotting.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
plot_shape_outline(shapes, axs)
Plot an echoSMs anatomical outline shape.
Normally called via plot_specimen().
| PARAMETER | DESCRIPTION |
|---|---|
shapes
|
Outline shapes to be plotted
TYPE:
|
axs
|
Two matplotlib axes - one for the dorsal view and one for the lateral view
TYPE:
|
Source code in src/echosms/plotting.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
plot_shape_surface(shapes, ax)
Plot an echoSMs anatomical surface shape.
Normally called via plot_specimen().
| PARAMETER | DESCRIPTION |
|---|---|
shapes
|
Surface shapes to be plotted
TYPE:
|
ax
|
A matplotlib axis.
|
Source code in src/echosms/plotting.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
plot_shape_voxels(s, title='')
Plot the specimen's voxels.
Normally called via plot_specimen().
| PARAMETER | DESCRIPTION |
|---|---|
s
|
The voxel shape data structure as per the echoSMs datastore.
TYPE:
|
title
|
Title for the plot.
TYPE:
|
Source code in src/echosms/plotting.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
plot_specimen(specimen, dataset_label='', title='', savefile=None, dpi=150)
Plot the specimen shape.
Produces a relevant plot for all echoSMs anatomical datastore shape types.
| PARAMETER | DESCRIPTION |
|---|---|
specimen
|
Specimen data as per the echoSMs anatomical datastore schema.
TYPE:
|
dataset_label
|
Used to form a plot title if
TYPE:
|
title
|
A title for the plot.
TYPE:
|
savefile
|
Filename to save the plot to. If None, generate the plot in the interactive terminal (if that's supported).
TYPE:
|
dpi
|
The resolution of the figure in dots per inch.
TYPE:
|
Source code in src/echosms/plotting.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
echosms.conversions
Functions that convert between different echoSMs datastore shape representations.
dwbaorganism_from_datastore(shape)
Create a DWBAorganism instance from an echoSMs datastore shape.
Converts the centreline and width/height definition of a shape into that required by the echoSMs implementation of the DWBA (centreline, tangential, and radii vectors).
| PARAMETER | DESCRIPTION |
|---|---|
shape
|
The shape to convert, in the echoSMs datastore
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
An instance of DWBAorganism
|
|
Notes
The DWBA simulates a circular shape but the echoSMs datastore shape can store non- circular shapes (via the height and width). This function uses the height information and ignores the width information.
If mass_density_ratio and sound_speed_ratio are present into the shape dict,
these are used. If not, default values are used by DWBorganism().
Source code in src/echosms/conversions.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
krmorganism_from_datastore(shapes)
Create a KRMorganism instance from an echoSMs datastore shape.
Converts the centreline and width/height definition of a shape into that required by the echoSMs implementation of the KRM (straight centreline, width, upper and lower heights from the centreline).
| PARAMETER | DESCRIPTION |
|---|---|
shapes
|
The shapes to convert, in the echoSMs datastore
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Instances of KRMorganism
|
|
Notes
The shape with name body becomes the main organism body and all other shapes become
inclusions. If there is no shape with name of body, the first shape is used for the body.
The KRM uses just one sound speed and density per shape, but datastore shapes can have values per x-axis value. The mean of the sound speed and density values are used if so.
Datastore shapes can have non-zero y-axis values but these are ignored when creating a KRMorganism instance.
Source code in src/echosms/conversions.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
mesh_from_geometric(shapes)
Create a triangulated mesh from a datastore geometric shape.
| PARAMETER | DESCRIPTION |
|---|---|
shapes
|
Geometric shapes defined as per the echoSMs datastore schema.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Trimesh
|
The mesh resulting from the merging of the input shapes. |
Source code in src/echosms/conversions.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
mesh_from_surface(shapes)
Create trimesh instances of an echoSMs datastore surface shapes.
| PARAMETER | DESCRIPTION |
|---|---|
shapes
|
The shapes to convert, in the echoSMs datastore
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Trimesh]
|
The shapes in trimesh form, in the same order as the input. |
Source code in src/echosms/conversions.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
outline_from_dwba(x, z, radius, anatomical_feature='body', boundary='pressure-release')
Convert DWBA shape to the echoSMs outline shape representation.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
The x values of the centreline
|
z
|
The distance of the centreline from z = 0. Positive values are towards the dorsal surface and negative values towards the ventral surface.
|
radius
|
The radius of the shape at each x coordinate
|
anatomical_feature
|
The anatomical feature for this shape, as per the echoSMs datastore schema.
TYPE:
|
boundary
|
The boundary type for this shape, as per the echoSMs datastore schema.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
An echoSMs outline shape representation.
|
|
Source code in src/echosms/conversions.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
outline_from_krm(x, height_u, height_l, width, anatomical_feature='body', boundary='pressure-release')
Convert KRM shape representation to the echoSMs outline shape representation.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
The x values of the centreline
TYPE:
|
height_u
|
The distance from z = 0 to the upper part of the shape at each x coordinate. Positive values are towards the dorsal surface and negative values towards the ventral surface.
TYPE:
|
height_l
|
The distance from z = 0 to the lower part of the shape at each x coordinate. Positive values are towards the dorsal surface and negative values towards the ventral surface.
TYPE:
|
width
|
The width of the shape at each x coordinate
TYPE:
|
anatomical_feature
|
The anatomical feature for this shape, as per the echoSMs datastore schema.
TYPE:
|
boundary
|
The boundary type for this shape, as per the echoSMs datastore schema.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
An echoSMs outline shape representation.
|
|
Source code in src/echosms/conversions.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
outline_to_surface(outline, num_pts=20, mesh_len=2.0)
Convert an outline shape to a surface shape.
| PARAMETER | DESCRIPTION |
|---|---|
outline
|
An echoSMs outline shape.
TYPE:
|
num_pts
|
The number of points to place on each cross-sectional ellipse.
TYPE:
|
mesh_len
|
The desired typical mesh length as a percentage of overall object size
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, list]
|
An echoSMs surface shape with shape metadata as per the input shape. |
Notes
Each outline cross-sectional ellipse is represented by a polygon with num_pts
vertices. Triangles are created that join the vertices on adjacent polygons.
The two ends are meshed using an ear slicing algorithm (using the mapbox_earcut package, a
Python binding to a C++ implementation of the
algorithm).
The mesh is then remeshed using the pymeshlab isotropic remeshing algorithm.
Source code in src/echosms/conversions.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
surface_from_stl(stl_file, dim_scale=1.0, anatomical_feature='body', boundary='pressure-release')
Create an echoSMs surface shape from an .stl file.
| PARAMETER | DESCRIPTION |
|---|---|
stl_file
|
An .stl file
TYPE:
|
dim_scale
|
Scaling factor applied to the node positions. Use to convert from one length unit to another (e.g., 1e-3 will convert from mm to m).
TYPE:
|
anatomical_feature
|
The anatomical feature for this shape, as per the echoSMs datastore schema.
TYPE:
|
boundary
|
The boundary type for this shape, as per the echoSMs datastore schema.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
An echoSMs surface shape representation. |
Notes
This function uses a call to load_mesh() from the trimesh library to read the
.stl file. If there are problems with loading your .stl file, please refer to the
trimesh documentation.
Source code in src/echosms/conversions.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
surface_to_outline(shape, slice_thickness=0.005)
Convert a surface shape to an outline shape.
| PARAMETER | DESCRIPTION |
|---|---|
shape
|
An echoSMs surface shape.
TYPE:
|
slice_thickness
|
The slice thickness [m] used when generating the outline.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
An echoSMs outline shape with shape metadata as per the input shape. |
Notes
The conversion projects the surface shape to get dorsal and lateral outlines and then slices along the x-axis at a configurable resolution to produce the outline shape.
Source code in src/echosms/conversions.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
volume_from_datastore(voxels)
Create a 3D numpy array from nested lists.
| PARAMETER | DESCRIPTION |
|---|---|
voxels
|
The datastore 3D voxel structure (list of list of list)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
A numpy 3D array.
|
|
Source code in src/echosms/conversions.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |