predicates module
Provide helper functions for filtering Instrument.
- INSTRUMENT_ID = abc.ABCMeta | multipac_testbench.instruments.instrument.Instrument | str
A single
Instrumentidentifier, as accepted by filter predicates. Used for building predicates, sometimes for applying predicates.
- INSTRUMENTS_ID
Identifier for one or several
Instrumentclasses or a collection of instances/names. Used to apply predicates.alias of
ABCMeta|Sequence[ABCMeta] |Sequence[str] |Sequence[Instrument]
- INSTRUMENT_FILTER
Function to filter
Instrument. Returns True if it should be kept, False if it should be discarded.alias of
Callable[[ABCMeta|Instrument|str],bool]
- MEASUREMENT_POINTS_ID = collections.abc.Collection[multipac_testbench.measurement_point.i_measurement_point.IMeasurementPoint] | collections.abc.Collection[str]
Identifier for measurement points, used in deprecated filtering arguments.
- exception InstrumentFilteringError[source]
Bases:
ValueErrorError raised when filtering logic was inconsistent.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- _to_name_set(instruments_to_ignore)[source]
Normalize instruments or names into a set of strings.
- Raises:
InstrumentFilteringError – If
instruments_to_ignorecontains or is anabc.ABCMeta.- Parameters:
instruments_to_ignore (
ABCMeta|Sequence[ABCMeta] |Sequence[str] |Sequence[Instrument])- Return type:
- dummy_instrument_filter(instrument_id)[source]
Create filter that does not filter anything.
- Parameters:
instrument_id (
ABCMeta|Instrument|str)- Return type:
- instrument_type_selector(instrument_types)[source]
Return instruments of any (sub)types of
instrument_types.Todo
Accept
strinputs?- Parameters:
instrument_types (
ABCMeta|Collection[ABCMeta])- Return type:
Callable[[ABCMeta|Instrument|str],bool]
- instrument_name_selector(instrument_names)[source]
Return instruments whose name matches any of
instrument_names.- Parameters:
instrument_names (
str|Collection[str]) – Instrument name(s) to match against. Can be a single string or a sequence of strings.- Return type:
Callable[[ABCMeta|Instrument|str],bool]- Returns:
A predicate that returns True if the instrument’s name (str, repr, or .name) matches any of the provided names.
- instrument_excluder(instruments_to_ignore)[source]
Create filter that rejects
instruments_to_ignore.- Parameters:
instruments_to_ignore (
ABCMeta|Sequence[ABCMeta] |Sequence[str] |Sequence[Instrument]) – Instrument(s) name(s),str,repror instances.- Return type:
Callable[[ABCMeta|Instrument|str],bool]- Returns:
Can be applied to
Instrumentinstances orInstrumentnames. Does not make any sense withInstrumenttypes.
- measurement_point_excluder(measurement_points)[source]
Create filter that rejects instruments located at
measurement_points.Todo
Implement predicate applying on measurement points names?
- Parameters:
measurement_points (
Collection[IMeasurementPoint] |Collection[str]) –IMeasurementPointinstances or names.- Return type:
Callable[[ABCMeta|Instrument|str],bool]- Returns:
A predicate that returns True if the instrument is NOT in a measurement point to exclude (ie if the instrument should be kept).
- combine_predicates(*predicates)[source]
Combine multiple predicates into a single filter using logical AND.
- Parameters:
*predicates (
Callable[[ABCMeta|Instrument|str],bool]) – Filters to combine. All must returnTruefor an instrument to pass.- Return type:
Callable[[ABCMeta|Instrument|str],bool]- Returns:
A filter that returns
Trueonly if allpredicatesreturnTrue. ReturnsTruefor any input if no predicates are given.
- filter_instruments(instruments_id, predicate)[source]
- Overloads:
instruments_id (Sequence[ABCMeta]), predicate (INSTRUMENT_FILTER) → list[ABCMeta]
instruments_id (Sequence[str]), predicate (INSTRUMENT_FILTER) → list[str]
instruments_id (Sequence[Instrument]), predicate (INSTRUMENT_FILTER) → list[Instrument]
instruments_id (ABCMeta), predicate (INSTRUMENT_FILTER) → ABCMeta
Apply
predicatefilter on given instruments.