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.
|
title
|
Title for the plot.
DEFAULT:
|
Source code in src/echosms/plotting.py
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
plot_shape_surface(shapes, ax)
Plot an echoSMs anatomical surface shape.
Normally called via plot_specimen().
| PARAMETER | DESCRIPTION |
|---|---|
shapes
|
Surface shapes to be plotted
|
ax
|
A matplotlib axis.
|
Source code in src/echosms/plotting.py
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.
|
title
|
Title for the plot.
DEFAULT:
|
Source code in src/echosms/plotting.py
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
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
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
mesh_from_datastore(shapes)
Create trimesh instances from an echoSMs datastore surface shape.
| 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
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
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
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
273 274 275 276 277 278 279 280 281 282 283 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 | |
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
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
383 384 385 386 387 388 389 390 391 392 393 394 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 | |
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.
|
|