Skip to content

fit.filters

The filters of the fit mappings a fit selects its data with.

A filter is called with the key of a fit mapping and the mapping and says whether the mapping passes (sbmlsim.fit.helpers.MappingFilter), see sbmlsim.fit.helpers.FitMappings.select for what a fit does with the mappings which pass. The filters here are frozen dataclasses, so they compare, pickle (into the workers of a parallel fit) and describe themselves:

  • metadata_filter by the values of the fields of the metadata of a mapping, a dataclass derived from MappingMetaData, e.g. its route and dosing; the value of a field is MappingMetaData.filter_value, which a metadata class overrides for a field it compares in another form;
  • observable_filter by the observable of a mapping (observable_id);
  • named_filter by the key of a mapping together with its study (named), since two studies can share a key;
  • filter_keys by the key of a mapping alone, what a selection by keys, e.g. the validation data or a problem read from PEtab, uses.

MetadataFilter dataclass

MetadataFilter(metadata_type, allowed, excluded)

A filter of fit mappings by the values of their metadata.

A mapping passes when every allowed field has one of its values and no excluded field has one of its values; the value of a field is the one of MappingMetaData.filter_value. Build it with metadata_filter.

Attributes:

Name Type Description
metadata_type type[MappingMetaData]

the metadata class of the mappings.

allowed tuple[tuple[str, frozenset[Hashable]], ...]

the fields with the values a mapping must have.

excluded tuple[tuple[str, frozenset[Hashable]], ...]

the fields with the values a mapping must not have.

ObservableFilter dataclass

ObservableFilter(observables)

A filter of fit mappings by their observable, see observable_id.

Attributes:

Name Type Description
observables frozenset[str]

the ids of the observables a mapping may have, the index of the data (Data.index).

NamedFilter dataclass

NamedFilter(mappings)

A filter of fit mappings by their key and study, see named.

Attributes:

Name Type Description
mappings tuple[tuple[str, frozenset[str]], ...]

the study ids with their mapping keys, sorted, so that the filter compares, pickles and describes the same for equal mappings.

KeyFilter dataclass

KeyFilter(keys)

A filter of fit mappings by their key alone, in whichever study.

Attributes:

Name Type Description
keys frozenset[str]

the keys of the mappings which pass.

observable_id

observable_id(fit_mapping)

Get the observable of a fit mapping, the index of its data.

The index of the y data of the observable (sbmlsim.data.Data.index): the selection without the brackets of a concentration, Cve_hctz for [Cve_hctz], Aurine_hctz for Aurine_hctz.

Parameters:

Name Type Description Default
fit_mapping FitMapping

the fit mapping.

required

Returns:

Type Description
str

The id of the observable, e.g. Cve_hctz.

study

study(fit_mapping)

Get the study of a fit mapping, the id of its experiment.

metadata_filter

metadata_filter(
    metadata_type, /, *, excluded=None, **allowed
)

Build a filter of fit mappings by the values of their metadata.

# not executed
filter_control = metadata_filter(
    StudyMetaData,
    route={Route.PO, Route.IV},
    excluded={"dosing": {Dosing.MULTIPLE}},
)

Parameters:

Name Type Description Default
metadata_type type[MappingMetaData]

the metadata class of the mappings, a dataclass derived from MappingMetaData.

required
excluded Mapping[str, Collection[Hashable]] | None

the fields with the values a mapping must not have.

None
**allowed Collection[Hashable]

the fields with the values a mapping must have.

{}

Returns:

Type Description
MetadataFilter

The filter, called by the selection of the mappings of a fit.

Raises:

Type Description
TypeError

if the metadata class is no dataclass (or an instance of one), has no field of a given name, or the values of a field are not a collection (a single value, also a string or None), i.e. when the module of the filters is imported.

ValueError

for a filter without clauses, with an empty set of allowed values, which would select nothing, or with an empty set of excluded values, which would exclude nothing.

observable_filter

observable_filter(observables)

Build a filter of fit mappings by their observable, e.g. the PK data.

Parameters:

Name Type Description Default
observables Collection[str]

the ids of the observables, the index of the data (Data.index), e.g. Cve_hctz.

required

Returns:

Type Description
ObservableFilter

The filter.

Raises:

Type Description
TypeError

if the observables are a single id or not a collection.

ValueError

for no observables, which would select nothing.

named

named(mappings, fit_mapping_key, fit_mapping)

Check whether a fit mapping is one of the named mappings of its study.

The key alone is not enough: two studies can share a key, so it counts only for the study it is named with.

named_filter

named_filter(mappings)

Build a filter of the fit mappings named with their study.

Parameters:

Name Type Description Default
mappings NamedMappings

the mapping keys by study id.

required

Returns:

Type Description
NamedFilter

The filter.

filter_keys

filter_keys(keys)

Build a filter which selects the fit mappings of the given keys.

A selector written by hand says what it means, e.g. "the tablets"; this one says which mappings it resolved to and is what a problem read from PEtab uses, because a condition stores the resolution and not the rule. A key selects the mapping of that key in every study, named_filter names the study as well.

Parameters:

Name Type Description Default
keys Iterable[str]

the keys of the fit mappings to select.

required

Returns:

Type Description
KeyFilter

A filter which passes exactly those mappings.