pbpk figures¶
The figures of a model and of individuals, see Figures: the anatomy resources, the body of an individual, the shared icons, the content of a definition, the anatomical figure, its interactive page and the publication figure. The schematic is pkpdsim.pbpk.figure (model_figure).
The anatomical figure of a model: the male and the female build on their reference individuals.
The man and the woman stand next to each other (their midlines MIDLINES
apart, the arms overlapping, the man drawn over the woman), each captioned
with its build. The bodies carry what the definition has:
- the organs in their drawn forms, sized by their volumes (
body.Body); - the connections of the model: the portal vein into the liver, the bile from the liver over the gallbladder into the duodenum, the ureters to the bladder and out, the feces, the oral route from the mouth to the stomach;
- circled icons: the tablet of an oral dose at the mouths, the drop of the blood sample at the arm vein of the man, the syringe of an intravenous dose at the arm of the woman.
Every organ has a label in one of two columns, the left one (right-aligned) pointing into the man, the right one into the woman; the builds share the structure of the definition, so one label serves both. A label shows the circled icon of the organ, its substances (filled: enters the tissue; dashed: plasma only) and, for an organ with processes, its submodel: a row per substance, the compartments plasma, interstitium, cells and the apical side (bile, urine, lumen) as columns, a chip per species the build has, arrows for the exchange, the metabolism (with its enzyme), the apical transport (with its transporter) and the filtration; below it the process lines of the schematic unless the figure is compact. The credit (the anatomy, the license, pkpdsim) belongs in the legend of a figure, never inside it.
OBSERVER_TEXT
module-attribute
¶
The text of the line of the blood sample, the observer of the arm vein.
MIDLINES
module-attribute
¶
The distance of the midlines of the man and the woman [cm].
LEFT
module-attribute
¶
The labels of the left column, pointing into the man.
RIGHT
module-attribute
¶
The labels of the right column, pointing into the woman.
TITLES
module-attribute
¶
TITLES = {
"lu": "lung",
"he": "heart",
"br": "brain",
"li": "liver",
"ki": "kidney",
"st": "stomach",
"si": "small intestine",
"la": "large intestine",
"sp": "spleen",
"pa": "pancreas",
"go": "gonads",
"mu": "muscle",
"sk": "skin",
"ad": "adipose tissue",
"bo": "bone",
"lumen": "intestinal lumen",
"urine": "urine",
"blood": "blood sample",
"iv": "intravenous dose",
}
The headings of the labels.
AnatomyFigure
¶
The anatomical figure of the content of a model on the reference man and woman.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
ModelContent
|
the content of the definition. |
required |
compact
|
bool
|
labels without the process lines (the panel of a publication figure, whose schematic shows them). |
False
|
man
|
Body | None
|
the body of the man, the reference man by default. |
None
|
woman
|
Body | None
|
the body of the woman, the reference woman by default. |
None
|
Prepare the two views.
has_submodel
¶
Whether an organ has processes (or the urine), so its label shows its submodel.
submodel
¶
The submodel grid of an organ at (x, y): the SVG, its width and height.
label
¶
A label at (x, y) of a width; the left column (side -1) right-aligned; the SVG and its height.
place
staticmethod
¶
The tops of labels near the heights of their anchors.
Overlapping labels merge into a cluster centred on the anchors of its members (pool adjacent violators); the clusters stay inside [top, bottom].
svg
¶
svg(
*,
title=True,
substances=True,
scale=3.3,
text=1.3,
left=LEFT,
right=RIGHT,
tags=False,
annotations=True,
sexes=None,
)
The figure as a standalone SVG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
bool
|
the name of the model and its builds at the top. |
True
|
substances
|
bool
|
the substances with their colours at the top. |
True
|
scale
|
float
|
the bodies [px per cm]. |
3.3
|
text
|
float
|
the scale of the labels, icons and the key. |
1.3
|
left
|
Sequence[str]
|
the labels of the left column. |
LEFT
|
right
|
Sequence[str]
|
the labels of the right column. |
RIGHT
|
tags
|
bool
|
mark the organs of the bodies for hover cards. |
False
|
annotations
|
bool
|
the labels, the substances, the connections of the
model, the captions and the key; without them the bodies with
their organs alone, e.g. for a slide ( |
True
|
sexes
|
Sequence[Sex] | None
|
the sexes which are built, which the subtitle names; |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The SVG, deterministic. |
substance_key
¶
The key (data-k) of a substance: its chip and its legend dot, sub:<sid>.
line_key
¶
The key (data-k) of a process line of a label, txt:<badge>: <text>.
anatomy_figure
¶
anatomy_figure(
definition,
path,
*,
compact=False,
title=True,
substances=True,
scale=3.3,
text=1.3,
annotations=True,
sexes=None,
)
Write the anatomical figure of a definition on the reference man and woman.
A definition of a laboratory animal (species) is drawn on its animal
(pkpdsim.pbpk.visual.animal), the sexes with a physiology in the library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition. |
required |
path
|
Path
|
the SVG file to write. |
required |
compact
|
bool
|
labels without the process lines. |
False
|
title
|
bool
|
the name of the model at the top. |
True
|
substances
|
bool
|
the substances at the top. |
True
|
scale
|
float
|
the bodies [px per cm]. |
3.3
|
text
|
float
|
the scale of the labels, icons and the key. |
1.3
|
annotations
|
bool
|
the labels, substances, connections, captions and key; without them the bodies with their organs alone, on a transparent background (e.g. for a slide). |
True
|
sexes
|
Sequence[Sex] | None
|
the sexes which are built ( |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of the figure. |
The interactive figures: hover cards on the static SVG.
One self-contained HTML file per figure (no external script or style), for the
docs and GitHub Pages: hovering an element with a data-k key shows its card,
an organ (its volumes in the reference man and woman, its UBERON ids, the form
of every substance, the processes), a substance (its mechanisms), a route, the
blood sample, the lumen or the urine; a key txt:<text> shows its own text
(a process line). The credit (pkpdsim, the anatomy or the organ icons and the
license of the anatomograms, CREDIT, ICON_CREDIT) sits in
the legend below the figure, never in a card.
The file is a whole page (html_page), which a docs page embeds in a frame,
or a snippet (html_snippet, interactive_figure(..., snippet=True)), one
<div> which a page of markdown or HTML embeds as it is: everything of the
snippet, its style and the ids of its SVG, is scoped to that <div>, so two
snippets of one model stand on one page without touching it or each other.
The factory of a model writes the snippets beside its SVG figures
(pkpdsim.pbpk.create_archive) and the release of a model repository shows
them on its index page.
CREDIT
module-attribute
¶
CREDIT = figure_credit('anatomy')
The credit of an anatomical figure, for its legend (HTML).
ICON_CREDIT
module-attribute
¶
ICON_CREDIT = figure_credit('organ icons')
The credit of a schematic, for its legend (HTML): its organ icons are the
shapes of the anatomograms (pkpdsim.pbpk.visual.icons), so the license asks
for the attribution, but the figure draws no anatomy.
CONTRACT
module-attribute
¶
The version of the payload of the sidecar write_readouts writes.
Readout
dataclass
¶
One timecourse of the model which a place of the figure reports.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
the selection in the compiled model whose values this reports, as
the id scheme gives it; it is not checked against a compiled model,
the consumer filters the ids the model does not contain. The
concentration of a species is the bracket form ( |
label |
str
|
what it is, in words ( |
unit |
str
|
the unit the model uses for it ( |
kind |
Literal['concentration', 'amount', 'rate', 'flux']
|
|
ReadoutGroup
dataclass
¶
What a key of the figure reports: its label and its readouts.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
the name of the place, for the heading of its panel. |
readouts |
tuple[Readout, ...]
|
the timecourses of the place, empty for a decoration of the drawing or a place of the model which carries no timecourse. |
figure_credit
¶
Get the credit of a figure whose drawn part follows the anatomograms (HTML).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drawn
|
str
|
what of the figure follows the anatomograms ( |
required |
library
|
str
|
the name of the library of pkpdsim which drew the figure. |
'PBPK library'
|
url
|
str
|
the docs page of that library. |
LIBRARY
|
Returns:
| Type | Description |
|---|---|
str
|
The credit: pkpdsim with its version, the library with its page, and |
str
|
the attribution of the anatomograms with their license. |
cards
¶
The hover cards of the figures by key, each a list of HTML lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
ModelContent
|
the content of the definition. |
required |
volumes
|
Mapping[str, Mapping[str, float]]
|
the organ volumes [l] (or masses [kg]) of the individuals
the figure shows, by their name ( |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
The cards of the organs, substances ( |
dict[str, list[str]]
|
( |
dict[str, list[str]]
|
lumen and the urine. |
readouts
¶
The timecourses which every key of the figure reports.
The keys are the paths of the data-k keys of the figure from the outside
in, joined by /, as the nesting of its SVG gives them: an organ (li),
a substance of an organ (li/sub:gli), a process line of an organ
(li/txt:MET: ...), the blood sample (blood, blood/sub:gli,
blood/txt:OBS: ...), the legend chip of a substance (sub:gli), the
sample icon (sample), the lumen, the urine and the feces with their
substances, the routes and the decorations of the drawing (bladder).
The three ways to point at a substance where it is sampled (sub:<sid>,
sample, blood/sub:<sid>) give the same readouts, the arm vein
observers.
The compartments of a substance in an organ follow its tissue form
(OrganContent.parts): the plasma, then for organ the one species, for
merged the tissue and its unbound form, for full the interstitium and
the cells with both unbound forms. A process line reports the flux of its
reaction (flat(organ, process.sid)); a line which carries no process
(URI, INH, SLW), a route and a decoration have no readout. An organ
reports the compartments of every substance it shows. Ids are built with
pkpdsim.pbpk.ids, the keys with the helpers of the figure writer
(substance_key, line_key). The ids are what the id scheme gives, not
checked against a compiled model: the consumer filters the ids the model
does not contain (a zonated organ, whose ids carry a zone, is not
supported, see _compartments).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
ModelContent
|
the content of the definition. |
required |
vein
|
str
|
the name of the sampling site in the line of the blood sample,
|
'arm vein'
|
Returns:
| Type | Description |
|---|---|
dict[str, ReadoutGroup]
|
The group of every key, by the key path. |
write_readouts
¶
Write the readouts of the keys of a figure beside it, for other tools.
The sidecar <svg stem>.readouts.json is {"contract": "figurereadouts/1",
"model": <sid>, "keys": {<path>: {"label": str, "readouts": [{"id",
"label", "unit", "kind"}]}}}, the paths and groups of readouts, so a
reader of the SVG needs no import of pkpdsim: it joins the data-k of the
ancestors of a clicked element into a path and looks it up. Every path the
anatomical drawing draws is a key (a decoration has no readouts). That
does not hold for the schematic figure (pkpdsim.pbpk.figure), which draws
paths readouts does not return yet (gu, gu/sub:*, ki/urine/*,
lumen/feces/*), so do not write its sidecar. The ids are those of
the id scheme and are not checked against a compiled model, the reader
filters the ones its model lacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
ModelContent
|
the content of the model the figure shows. |
required |
svg
|
Path
|
the SVG file of the figure. |
required |
vein
|
str
|
the sampling site named in the figure ( |
'arm vein'
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of the sidecar. |
html_page
¶
html_page(svg, cards, title, width, legend, credit=CREDIT)
A self-contained page of a figure with hover cards and its legend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
svg
|
str
|
the figure, whose elements carry |
required |
cards
|
dict[str, list[str]]
|
the cards by key. |
required |
title
|
str
|
the title of the page. |
required |
width
|
int
|
the width of the figure [px], the maximal width of the page. |
required |
legend
|
str
|
the legend below the figure (HTML), the credit appended. |
required |
credit
|
str
|
the credit (HTML), |
CREDIT
|
The page posts its height to the page which embeds it in a frame
({"pkpdFigure": true, "height": ...}), so the frame can fit it
(docs/javascripts/figures.js).
Returns:
| Type | Description |
|---|---|
str
|
The HTML, deterministic. |
html_snippet
¶
html_snippet(
svg, cards, scope, width, legend, credit=CREDIT
)
A snippet of a figure with hover cards and its legend, for a page.
One <div> with the figure, its legend, its cards and its script, which a
page of markdown or HTML embeds as it is, e.g. the index of a model
repository. Everything of the snippet is scoped to the <div>: the style
sheets of the snippet and of the SVG are written under its id and the ids
of the SVG carry it (_scoped_svg), so a page shows two snippets without
their styles meeting, and the script is a closure over the <div>. The
snippet brings its own light background, so it reads in a dark theme as
well, and it has no blank line, which would end it in markdown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
svg
|
str
|
the figure, whose elements carry |
required |
cards
|
dict[str, list[str]]
|
the cards by key. |
required |
scope
|
str
|
the id of the |
required |
width
|
int
|
the width of the figure [px], the maximal width of the snippet. |
required |
legend
|
str
|
the legend below the figure (HTML), the credit appended. |
required |
credit
|
str
|
the credit (HTML), |
CREDIT
|
Returns:
| Type | Description |
|---|---|
str
|
The HTML of the snippet, deterministic. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the style sheet of the SVG cannot be scoped
( |
interactive_figure
¶
Write the interactive page or snippet of a figure of a definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition. |
required |
path
|
Path
|
the HTML file to write. |
required |
figure
|
str
|
|
'anatomy'
|
snippet
|
bool
|
write the snippet of the figure ( |
False
|
sexes
|
Sequence[Sex] | None
|
the sexes which are built ( |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of the file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for another figure. |
The publication figure of a model: the anatomical figure and the schematic on one A4 page.
Panel A is the anatomical figure of both builds in compact form (the substances and the submodels, without the process text), panel B the schematic in compact form (the substance dots and the key in its top band), both at the width of the page; only the panels have to fit on the page. The legend sits below them, a caption generated from the content which explains every symbol and names the credit, also written as Markdown for the caption of a manuscript.
legend
¶
The legend of the publication figure: paragraphs of (kind, text), kind b bold, i the credit.
publication_figure
¶
Write the publication figure of a definition.
Writes <path> (the panels on the A4 page and the legend below it),
<stem>_panels.svg (the A4 page of the panels), <stem>_legend.md (the
legend as Markdown) and, with pdf, <stem>_panels.pdf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition. |
required |
path
|
Path
|
the SVG file of the figure with its legend. |
required |
pdf
|
bool
|
also write the PDF of the panels (needs the extra |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of the figure. |
Raises:
| Type | Description |
|---|---|
ImportError
|
for |
The body of an individual of the library, drawn from the anatomy resources.
An Individual is a sex, an age, a body weight and a height (the reference
individual of the library by default), a functional liver and a gestational
progress; its Quantities are the numbers of the library: the volumes of the
organs (reference_individual scaled as the build scales the lean tissues,
body_composition), the waist and the visceral and subcutaneous adipose tissue
(visceral_composition).
A Body draws it in cm, the midline at x 0 and the top of the head at y 0:
- the outline is the drawing of the sex mapped by the field of
field.py: the proportions of the age in y, the trunk stretched by the waist, the limbs and the face by the body mass index, the pregnant belly; - the layers on a raster of 0.25 cm: the subcutaneous adipose tissue as a band under the skin, its thickness the subcutaneous volume over the body surface (twice on the trunk), the muscle inside it, the thorax and the abdomen;
- the organs keep the forms of the drawing (a uniform scale and a shift only):
their positions follow the box of their cavity, their size is the cube root
of the volume over the volume of the reference individual of the sex, so the
organs of the reference fill their cavity but a share (
FREE_REF) and the space between them is visceral adipose tissue (abdomen) or mediastinum (thorax); the kidneys are moved out of the shadow of liver and spleen and the heart onto the diaphragm, so every organ shows in a frontal view.
CAVITY_ORGANS
module-attribute
¶
CAVITY_ORGANS = MappingProxyType(
{
"thorax": ("lu", "he"),
"abdomen": (
"la",
"si",
"li",
"st",
"sp",
"ki",
"pa",
"gallbladder",
"bladder",
"uterus",
),
}
)
The organs of each cavity, in the order they are drawn (later over earlier).
FREE_REF
module-attribute
¶
The share of a cavity of the reference individual which no organ covers.
FREE_MIN
module-attribute
¶
The least free share of a cavity: larger organs (a child) are scaled down together.
Quantities
dataclass
¶
The numbers of the library of an individual.
Attributes:
| Name | Type | Description |
|---|---|---|
sex |
Sex
|
the sex. |
age |
float
|
the age [years]. |
bw |
float
|
the body weight [kg]. |
height |
float
|
the height [cm]. |
bmi |
float
|
the body mass index [kg/m2]. |
bsa |
float
|
the body surface area [m2]. |
waist |
float
|
the waist circumference [cm]. |
vat |
float
|
the visceral adipose tissue [kg]. |
sat |
float
|
the subcutaneous adipose tissue [kg]. |
volumes |
Mapping[str, float]
|
the volume of every organ by its key [l]. |
Individual
dataclass
¶
An individual of the library to draw.
Attributes:
| Name | Type | Description |
|---|---|---|
sex |
Sex | str
|
the sex. |
age |
float
|
the age [years]. |
bw |
float | None
|
the body weight [kg], the reference individual of the age by default. |
height |
float | None
|
the height [cm], the reference individual of the age by default. |
liver |
float
|
the functional liver relative to the healthy one (the factor of a Child-Pugh class). |
pregnant |
float
|
the progress of a pregnancy, 0 none to 1 at term. |
label |
str
|
the caption. |
Body
¶
The drawing of an individual [cm].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
the individual. |
required |
reference
|
Body | None
|
the body of the reference individual of the sex, whose
organs set the scale; |
None
|
Compute the outline, the layers and the organs.
size_ratio
¶
The linear size of an organ relative to the reference individual, (V/V_ref)^(⅓).
toward
¶
A point inside an organ towards a side (-1 left, 1 right of the figure) [cm].
edge_point
¶
A point inside the outline at the height y of the drawing, at the outer edge of a side [cm].
svg
¶
The SVG elements of the body [cm], for a group which places and scales them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fills
|
Mapping[str, str] | None
|
colours by organ key over |
None
|
skin
|
str
|
the colour of the skin. |
SKIN
|
layers
|
bool
|
draw the subcutaneous adipose band, the muscle and the bones. |
True
|
arteries
|
bool
|
draw the arteries. |
True
|
tags
|
bool
|
mark every organ with |
False
|
stroke
|
float
|
the width of the outlines of the organs [cm]. |
0.22
|
Returns:
| Type | Description |
|---|---|
str
|
The elements, deterministic. |
reference_body
cached
¶
The body of the reference individual of a sex (cached), the scale of the organs.
body_strip
¶
Bodies side by side on one scale, the feet aligned, each with its caption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
Sequence[Individual]
|
the individuals, their |
required |
scale
|
float
|
px per cm. |
2.4
|
font
|
str
|
the font family of the captions. |
'sans-serif'
|
Returns:
| Type | Description |
|---|---|
str
|
A standalone SVG. |
The content of a definition which the figures show.
Read once from a PBPKDefinition through the readers of the schematic
(pkpdsim.pbpk.figure), so the anatomical figure, its interactive page and the
schematic show the same model: the substances with their colours and
mechanisms, per organ the chips (the substance enters the tissue or stays in
the plasma) and the process lines, the parts of every substance in every organ
(parts_for), the processes as records, the routes, the lumen, the bile, the
urine and the PD components.
SubstanceInfo
dataclass
¶
A substance of the definition: its id, name, colour and mechanisms in words.
Chip
dataclass
¶
A substance in an organ: its id, colour and whether it enters the tissue.
OrganContent
dataclass
¶
An organ of the definition.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
the |
chips |
tuple[Chip, ...]
|
the substances of the organ. |
lines |
tuple[tuple[str, str], ...]
|
the processes as (badge, text) of the schematic. |
variant |
str | None
|
the variant of the organ in words, |
parts |
Mapping[str, str]
|
the tissue form of every substance ( |
Process
dataclass
¶
A metabolism or transport of an organ (a custom reaction has kind CUS).
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
|
sid |
str
|
the id of the process. |
organ |
str
|
the |
substrate |
str
|
the substrate of a metabolism, the substance of a transport. |
products |
tuple[str, ...]
|
the products of a metabolism. |
protein |
str | None
|
the enzyme or transporter. |
membrane |
str
|
|
direction |
str
|
|
ModelContent
dataclass
¶
ModelContent(
sid,
name,
substances,
organs,
processes,
lumen_lines,
routes,
route_text,
luminal,
lumen_segments,
readouts,
bile,
urine,
pd,
)
What the figures of a definition show.
Attributes:
| Name | Type | Description |
|---|---|---|
sid |
str
|
the id of the model. |
name |
str
|
the name of the model. |
substances |
tuple[SubstanceInfo, ...]
|
the substances in the order of the definition. |
organs |
Mapping[str, OrganContent]
|
the organs by their key. |
processes |
tuple[Process, ...]
|
the processes of the chemistry. |
lumen_lines |
tuple[tuple[str, str], ...]
|
the process lines of the lumen, empty without a lumen. |
routes |
tuple[tuple[str, str], ...]
|
the routes as (kind, substance), kind |
route_text |
str
|
the routes in words. |
luminal |
tuple[str, ...]
|
the substances which reach the lumen. |
lumen_segments |
tuple[str, ...]
|
the lumen segments of the intestine in the order of the transit, empty for a single lumen and without a lumen. |
readouts |
tuple[str, ...]
|
the readouts of the library which the model requests
( |
bile |
tuple[str, ...]
|
the substances excreted into the bile. |
urine |
tuple[str, ...]
|
the substances excreted into the urine. |
pd |
tuple[tuple[str, tuple[str, ...], tuple[str, ...]], ...]
|
the PD components as (id, reads, sets). |
The icons of the figures, one graphical language for all of them.
Every icon sits on a white circle: the organs (their shapes in the anatomy
resources; the bowel for the intestine and its lumen, the body for the skin,
fat cells for the adipose tissue, whose drawn depot has no recognisable form at
this size), the oral dose (a tablet), the intravenous dose (a syringe) and the
blood sample (a drop). An icon is an SVG fragment centred at a point. The
pictogram of an impaired organ (impaired_organ) is the liver, a kidney or
the heart with its details on a card framed in the color of an impairment
class, its lost part faded.
organ
¶
The icon of an organ on a circle of diameter d, centred at (cx, cy); empty without an icon.
The icon is in the greys of palette.ORGAN_GREYS, so that the colours of a
figure are those of the substances and the tissues.
impaired_organ
¶
The pictogram of an impaired organ on a card framed in the color of its class.
The organ (li, ki or he, its shape in the anatomy resources) is drawn in
its color of palette.ORGAN_COLORS, shaded, with its details (the lobes and the
gallbladder of the liver, the cortex and the vessels and the ureter at the hilum
of a kidney, the groove of the heart); its lost part, loss of the area, is
faded. The card is white with a frame in color, so the pictogram reads in a
light and a dark theme alike. The ids of the gradient are a hash of the
arguments, unique on a page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
the organ. |
required |
cx
|
float
|
the centre of the card, x. |
required |
cy
|
float
|
the centre of the card, y. |
required |
width
|
float
|
the width of the card. |
required |
height
|
float
|
the height of the card. |
required |
loss
|
float
|
the lost fraction of the organ, 0 to 1. |
required |
color
|
str
|
the color of the class, the frame of the card. |
required |
title
|
str | None
|
the hover text, plain text (escaped here). |
None
|
sex
|
str
|
the sex of the drawing. |
'male'
|
Returns:
| Type | Description |
|---|---|
str
|
The SVG fragment, a group. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the organ has no pictogram or |
The 2D anatomy resources: the drawings of the bodies and organs of the figures.
One JSON file per species and sex in pkpdsim/resources/anatomy/, built by
scripts/visual/anatomy_assets.py from the anatomograms of the EBI Expression
Atlas (CC BY 4.0, see the NOTICE.md of the folder): the outline of the body
and its details, the organs of the library by their Organ key with their
UBERON ids, further anatomy, the landmarks of the human drawings and the body
cavities, all in the coordinates of the drawing (units of its view box, y
downwards).
RESOURCES
module-attribute
¶
The folder of the anatomy resources.
Shape
dataclass
¶
A drawn tissue: an organ of the library or further anatomy.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
the key, an |
name |
str
|
the name of the tissue. |
uberon |
tuple[str, ...]
|
the UBERON terms of the drawing which form it. |
cavity |
str | None
|
the body cavity it lies in ( |
d |
str
|
the path data. |
paths |
tuple[ndarray, ...]
|
the polylines of the path. |
Anatomy
dataclass
¶
Anatomy(
key,
species,
sex,
viewbox,
midline,
landmarks,
outline,
details,
organs,
anatomy,
cavities,
attribution,
)
The drawing of a species and sex.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
the resource ( |
species |
str
|
the species ( |
sex |
str
|
the sex ( |
viewbox |
tuple[float, float, float, float]
|
the box of the outline, x, y, width, height. |
midline |
float
|
the x of the midline of the body. |
landmarks |
Mapping[str, float]
|
the heights of the human drawings ( |
outline |
ndarray
|
the outline of the body, one closed polyline. |
details |
tuple[ndarray, ...]
|
the small shapes of the outline (eyes, nose, mouth, hands). |
organs |
Mapping[str, Shape]
|
the organs of the library by their |
anatomy |
Mapping[str, Shape]
|
further anatomy by name. |
cavities |
Mapping[str, tuple[ndarray, ...]]
|
the polylines of the cavities |
attribution |
str
|
the source, license and changes. |
parse_d
¶
The polylines of a path of the resources (M x,y x,y ... Z, absolute).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
str
|
the path data, subpaths of absolute points. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ...]
|
One array of shape (n, 2) per subpath. |
anatomy
cached
¶
The anatomy resource of a species and sex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
species
|
str
|
|
'human'
|
sex
|
str
|
|
'male'
|
Returns:
| Type | Description |
|---|---|
Anatomy
|
The drawing, read once per process. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a species and sex without a resource. |
The deformation of a human drawing into the body of an individual.
The outline of the drawing is rasterized and segmented into head, trunk, arms
and legs (Drawing). The body of an individual is the drawing mapped by a
smooth field (Field): a monotone vertical map through the landmarks gives
the proportions of the age (the head, the trunk, the legs), and every part is
stretched horizontally about its own axis by a sum of broad Gaussians over the
height, blended between the parts by blurred masks, so the outline changes
continuously and mainly by stretching in x and y. The field maps points of the
drawing (Field.__call__) and is inverted by a fixed point iteration
(Field.inverse), which the raster of the body needs.
Gaussian
module-attribute
¶
A bump of a profile over the height: centre, sigma (units of the drawing) and amplitude.
Drawing
dataclass
¶
The parts of a human drawing on its raster.
Attributes:
| Name | Type | Description |
|---|---|---|
anatomy |
Anatomy
|
the resource. |
mask |
ndarray
|
the inside of the outline. |
ys |
ndarray
|
the y of every row. |
xs |
ndarray
|
the x of every column. |
cx |
float
|
the midline. |
labels |
ndarray
|
per pixel 1 head, 2 trunk, 3 arm, 4 leg, 0 outside. |
arm_axis |
dict[int, ndarray]
|
the x of the axis of the arm per row, by side (-1, 1). |
leg_axis |
dict[int, ndarray]
|
the x of the axis of the leg per row, by side. |
half |
ndarray
|
the half width of the trunk per row. |
weights |
dict[str, ndarray]
|
the blurred masks of the parts, summing to 1. |
Field
¶
The map of a drawing onto the body of an individual (units of the drawing to cm).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Drawing
|
the drawing. |
required |
height
|
float
|
the height of the individual [cm]. |
required |
head_frac
|
float
|
the head (top to neck) as a fraction of the height. |
required |
leg_frac
|
float
|
the legs (crotch to floor) as a fraction of the height. |
required |
trunk
|
Sequence[Gaussian]
|
the relative widening of the trunk over the height. |
()
|
arm
|
Sequence[Gaussian]
|
the relative widening of the arms about their axes. |
()
|
leg
|
Sequence[Gaussian]
|
the relative widening of the legs about their axes. |
()
|
head_w
|
float
|
the width of the head relative to its height. |
1.0
|
belly
|
Gaussian | None
|
a pregnant belly, a Gaussian of the trunk (centre, sigma, amplitude). |
None
|
Build the field of an individual.
raster
¶
raster(polygons, shape, origin=(0.0, 0.0), res=RES)
The pixels inside polygons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygons
|
Sequence[ndarray]
|
closed polylines, arrays of shape (n, 2). |
required |
shape
|
tuple[int, int]
|
the shape of the raster (rows, columns). |
required |
origin
|
tuple[float, float]
|
the point of the pixel (0, 0). |
(0.0, 0.0)
|
res
|
float
|
the units per pixel. |
RES
|
Returns:
| Type | Description |
|---|---|
ndarray
|
A boolean array of the shape. |