result.scan¶
The result of a scan, see sbmlsim.simulator.Simulator.run.
A ScanResult wraps one xarray.Dataset:
- dimensions: the dimensions of the scan in their order, then
timewhen every simulation has the same output times and_pointotherwise, i.e.(*dims, time)or(*dims, _point), the layout of the timecourses of pkpdutils; - variables: one per selection over
(*dims, time)or(*dims, _point); in the ragged layout of_pointevery simulation keeps its own time points and the variabletimeover(*dims, _point)holds them, padded withNaN;statusover the dimensions of the scan for a run withon_error="flag"; - coordinates: the labels of every dimension, every changed target of a
dimension of values along its dimension (
<dimension>.<target>when the target is also a variable of the result, which keeps the plain name), andtimeon a grid; attrs:dims, the dimensions of the scan in their order,units, the unit of every variable and coordinate,scanandintegrator_settings, the provenance,changes, the times of the changes after the start of the simulations in the time of the result, anderrorsfor a run withon_error="flag".
The output of a simulation has two time points at the time of a change after
the start, the state before the change and the state after it, as at an event
of the model; the time of a grid then appears twice. The idioms of xarray
which need a unique index raise at such a time, e.g. ds.interp, ds.sel
with method="nearest" and ds.reindex: ScanResult.interpolate puts a
result on other times, sel(time=t) at a change selects both rows and
isel one of them.
nca and to_timecourses hand a PK analysis and a timecourse over to
pkpdutils, whose layout (*dims, time) the result has.
xarray does the rest: res["[X]"].sel(dose=10), res.ds.to_dataframe().
ScanResult
¶
The result of a scan, see the module.
Attributes:
| Name | Type | Description |
|---|---|---|
ds |
the dataset. |
Wrap a dataset which follows the layout of the module.
quantity
¶
Get the values of a variable or coordinate with its unit.
The cv of a summary is dimensionless; a variable with a dimension
statistic which holds statistics of different units needs a
selection of the statistic first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
the variable or coordinate. |
required |
ureg
|
UnitRegistry | None
|
the unit registry of the quantity, the one of the package by default; e.g. the registry of a simulation experiment. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if the key holds labels, has no unit, or mixes units. |
nca
¶
Get the analysis of a PK observable as the result of pkpdutils.
The kept parameters of the observable, <id>.<parameter>, with their
units and its flags over the dimensions of the scan. A point which
failed has NaN parameters and the flags NCAFlag.NO_DATA, which
pkpdutils gives a sample without data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observable
|
str
|
the id of the PK observable. |
required |
Returns:
| Type | Description |
|---|---|
NCAResult
|
The |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the result does not keep the flags of the observable. |
to_timecourses
¶
Get a timecourse of the result as the timecourses of pkpdutils.
pkpdutils takes a time once: of the states before and after a change
at its time (changes of the attributes) the timecourse has the
state after it, as a PK observable analyses it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
the variable, a timecourse. |
required |
**kwargs
|
Any
|
the other arguments of |
{}
|
Returns:
| Type | Description |
|---|---|
Timecourses
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the variable is no timecourse of the result. |
time_points
¶
Get the times of the grid, or the union of the times of the simulations.
A time which a simulation has twice, the states before and after a
change or an event of the model at it, is twice in the union, so an
interpolation onto the union keeps the jump, see interpolate.
interpolate
¶
Get the result on a grid of times.
Every simulation is interpolated linearly onto the times, see
sbmlsim.result.timecourse.grid_weights; a time outside of a
simulation is NaN. A simulation has the states before and after a
change and an event of the model at its time, and time points closer
than the resolution of its time (sbmlsim.simulator.plan.time_tolerance
of its first and last time) are one jump: a time of the grid before a
change is interpolated toward the state before it, the time of a
change (changes of the attributes) sees the state after it, and the
first of two equal times of the grid the state before it. The
variables without a time stay as they are.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
ArrayLike | Quantity
|
the times of the grid, numbers in the time unit of the result or a quantity. |
required |
Returns:
| Type | Description |
|---|---|
ScanResult
|
The result with the dimension |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the times are a quantity and the result has no
unit of time or another one, see |
summary
¶
Get statistics of the variables over dimensions of the scan.
A result in the ragged layout is interpolated onto the union of its
time points first, or onto times; the union has a time point per step
of every simulation, so it is refused above MAX_UNION_ELEMENTS
elements (points of the scan times time points).
sd is the sample standard deviation and cv the ratio of sd and
mean; a quantile q is the statistic q<q>, e.g. q0.05. NaN,
e.g. of a failed point, is skipped. The unit of a variable is the unit
of its statistics, except of cv, a ratio, which statistic_units in
the attributes records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dims
|
str | Sequence[str] | None
|
the dimensions to reduce, every dimension of the scan by default. |
None
|
statistics
|
Sequence[str]
|
statistics of |
STATISTICS
|
quantiles
|
Sequence[float]
|
quantiles between 0 and 1. |
()
|
times
|
ArrayLike | Quantity | None
|
the times to interpolate onto before, numbers in the time unit of the result or a quantity; the union of the time points of a ragged result by default. |
None
|
Returns:
| Type | Description |
|---|---|
ScanResult
|
The result with the dimension |
ScanResult
|
dimensions. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a dimension is no dimension of the scan, a statistic is unknown, a quantile is outside of [0, 1] or the union of the time points of a ragged result is too large. |
to_netcdf
¶
Write the result as netCDF4, the attributes as JSON.
The attributes must be JSON serializable, numpy scalars and arrays are written as numbers and lists.
from_netcdf
classmethod
¶
Read a result written by to_netcdf.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the file has no attributes of a result. |
time_magnitudes
¶
Get times as numbers in a unit of time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
ArrayLike | Quantity
|
numbers in the unit or a quantity. |
required |
unit
|
str | None
|
the unit of time of a model or a result; |
required |
owner
|
str
|
what has the unit, for a message. |
'The model'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The times, one dimensional. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the times are a quantity and the owner has no unit of time, or one the quantity cannot be converted to. |