nca.auc¶
Vectorized trapezoid areas of timecourses.
Every function works on (N, n) arrays, one row per curve, without a loop
over the rows. Missing points (NaN in the time or the value) are moved to the
end of every row by pack_valid, so that the segments between consecutive
valid points are the columns of the arrays segment_areas returns.
The trapezoid rules are the ones of Gabrielsson & Weiner (2016, ch. 2.8) and
of the Phoenix WinNonlin NCA, compared against alternative numerical
integration schemes by Yeh & Kwan (1978), Chiou (1978) and Purves (1992): on
a segment from (t1, c1) to (t2, c2) with dt = t2 - t1 the linear rule
gives the area dt (c1 + c2) / 2 and the first moment
dt (t1 c1 + t2 c2) / 2; the logarithmic rule, exact for a mono-exponential
decline, gives the area dt (c1 - c2) / L and the moment
dt (t1 c1 - t2 c2) / L + dt² (c1 - c2) / L² with L = ln(c1 / c2).
take_rows
¶
Element idx[i] of row i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
array |
required |
idx
|
ndarray
|
one column index per row |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The selected elements |
pack_valid
¶
Move the valid points of every row to the front, keeping their order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
ndarray
|
times of shape |
required |
c
|
ndarray
|
values of shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The packed times, the packed values (both padded with |
ndarray
|
number of valid points per row. |
segment_areas
¶
Areas and first moments of the segments between consecutive packed points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp
|
ndarray
|
packed times |
required |
cp
|
ndarray
|
packed values |
required |
n_valid
|
ndarray
|
valid points per row |
required |
method
|
AUCMethod
|
trapezoid rule |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The areas and the first moments, both of shape |
ndarray
|
beyond the valid points of its row is 0. |
auc_aumc
¶
Area and first moment of every row, optionally only over a time window.
A segment counts as a whole or not at all, so the window covers the intended
interval exactly when a point of the packed arrays lies on each of its
bounds; interpolate_at and insert_point add such a point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp
|
ndarray
|
packed times |
required |
cp
|
ndarray
|
packed values |
required |
n_valid
|
ndarray
|
valid points per row |
required |
method
|
AUCMethod
|
trapezoid rule |
required |
t_start
|
ndarray | None
|
per row, only segments starting at or after this time count |
None
|
t_end
|
ndarray | None
|
per row, only segments ending at or before this time count |
None
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
|
time_above_threshold
¶
Total time the linearly interpolated curve is above a threshold, per row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp
|
ndarray
|
packed times |
required |
cp
|
ndarray
|
packed values |
required |
n_valid
|
ndarray
|
valid points per row |
required |
threshold
|
float
|
the threshold |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The total time above the threshold |
interpolate_at
¶
Value of every row at a query time by interpolation between the bracketing points.
Linear interpolation, or logarithmic interpolation on a segment the
trapezoid method treats logarithmically. NaN outside the observed
times of a row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp
|
ndarray
|
packed times |
required |
cp
|
ndarray
|
packed values |
required |
n_valid
|
ndarray
|
valid points per row |
required |
t_query
|
ndarray
|
one query time per row |
required |
method
|
AUCMethod
|
trapezoid rule |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The interpolated values |
insert_point
¶
Insert one point per row and repack in time order.
A row whose new time or value is NaN is left unchanged (its arrays are
still one column wider).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp
|
ndarray
|
packed times |
required |
cp
|
ndarray
|
packed values |
required |
n_valid
|
ndarray
|
valid points per row |
required |
t_new
|
ndarray
|
time of the new point per row |
required |
c_new
|
ndarray
|
value of the new point per row |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray, ndarray]
|
The packed times and values |