isimple.core package

Submodules

isimple.core.backend module

exception isimple.core.backend.BackendSetupError(*args)[source]

Bases: isimple.core.SetupError

msg = 'Error while setting up backend'
exception isimple.core.backend.BackendError(*args)[source]

Bases: isimple.core.RootException

msg = 'Error in backend'
exception isimple.core.backend.CacheAccessError(*args)[source]

Bases: isimple.core.RootException

msg = 'Trying to access cache out of context'
class isimple.core.backend.CachingInstance(config: isimple.core.config.BaseConfig = None)[source]

Bases: isimple.core.config.Instance

Interface to diskcache.Cache

is_caching() → bool[source]
cancel_caching() → None[source]
caching(override: bool = False)[source]
class isimple.core.backend.Handler[source]

Bases: abc.ABC

set_implementation(implementation: str) → str[source]
get_implementation() → str[source]
implementation_config() → isimple.core.config.BaseConfig[source]
class isimple.core.backend.FeatureConfig[source]

Bases: isimple.core.config.BaseConfig, abc.ABC

class isimple.core.backend.Feature(elements: Tuple[isimple.core.config.Instance, ...], global_config: isimple.core.backend.FeatureConfig, config: Optional[dict] = None)[source]

Bases: abc.ABC, isimple.core.config.Configurable

A feature implements interactions between BackendElements to produce a certain value

calculate(frame: numpy.ndarray, state: numpy.ndarray = None) → Tuple[Any, Optional[numpy.ndarray]][source]

Calculate Feature for given frame and update state image (optional)

classmethod label() → str[source]
classmethod unit() → str[source]
skip
ready
set_color(color: isimple.maths.colors.Color)[source]
color

Color of the Feature in figures.

A Feature’s color must be set as not to overlap with other Features in the same FeatureSet. Therefore, <Feature>._color must be determined by FeatureSet!

state(frame: numpy.ndarray, state: numpy.ndarray) → numpy.ndarray[source]

Return the Feature instance’s state image for a given frame

value(frame: numpy.ndarray) → Any[source]

Compute the value of the Feature instance for a given frame

classmethod description() → str[source]
config
class isimple.core.backend.FeatureSet(features: Tuple[isimple.core.backend.Feature, ...])[source]

Bases: object

resolve_colors() → Tuple[isimple.maths.colors.Color, ...][source]
colors
features
class isimple.core.backend.FeatureType(string: str = None)[source]

Bases: isimple.core.config.Factory

get() → Type[isimple.core.backend.Feature][source]
config_schema() → dict[source]
class isimple.core.backend.BaseAnalyzerConfig[source]

Bases: isimple.core.config.BaseConfig

class isimple.core.backend.AnalyzerEvent[source]

Bases: enum.Enum

An enumeration.

STATUS = 'status'
CONFIG = 'config'
RESULT = 'result'
RMETAD = 'result_metadata'
class isimple.core.backend.AnalyzerState[source]

Bases: enum.IntEnum

An enumeration.

UNKNOWN = 0
INCOMPLETE = 1
CAN_LAUNCH = 2
LAUNCHED = 3
CAN_FILTER = 4
CAN_ANALYZE = 5
ANALYZING = 6
DONE = 7
CANCELED = 8
ERROR = 9
can_launch = <bound method AnalyzerState.can_launch of <enum 'AnalyzerState'>>[source]
is_launched = <bound method AnalyzerState.is_launched of <enum 'AnalyzerState'>>[source]
class isimple.core.backend.BaseVideoAnalyzer(config: isimple.core.backend.BaseAnalyzerConfig = None, eventstreamer: isimple.core.streaming.EventStreamer = None)[source]

Bases: isimple.core.config.Instance, isimple.core.RootInstance

set_model(model: isimple.core.db.BaseAnalysisModel)[source]
model
eventstreamer
set_eventstreamer(eventstreamer: isimple.core.streaming.EventStreamer = None)[source]
event(category: isimple.core.backend.AnalyzerEvent, data: dict)[source]

Push an event

Parameters:
  • category – event category
  • data – event data
Returns:

commit() → bool[source]

Save video analysis configuration to history database

can_launch() → bool[source]
can_filter() → bool[source]
can_analyze() → bool[source]
launched
set_state(state: int, push: bool = True)[source]
state
done
state_transition(push: bool = True) → int[source]

Handle state transitions

set_busy(busy: bool, push: bool = True)[source]
busy
busy_context(busy_state: isimple.core.backend.AnalyzerState = None, done_state: isimple.core.backend.AnalyzerState = None)[source]
cancel() → None[source]
error() → None[source]
set_progress(progress: float, push: bool = True)[source]
progress
config
analyze() → bool[source]
position
cached
has_results
status() → dict[source]
push_status()[source]
get_config(do_tag=False) → dict[source]
set_config(config: dict, silent: bool = False) → dict[source]
launch() → bool[source]
caching()[source]

Caching context: propagated context to every object in _instances that implements caching

cache_open()[source]
cache_close()[source]
time(message: str = '', logger=<Logger isimple.core.backend (DEBUG)>)[source]
timing
export()[source]
description
class isimple.core.backend.AnalyzerType(string: str = None)[source]

Bases: isimple.core.config.Factory

get() → Type[isimple.core.backend.BaseVideoAnalyzer][source]
config_schema() → dict[source]

isimple.core.config module

class isimple.core.config.Factory(string: str = None)[source]

Bases: isimple.core.EnforcedStr

get() → type[source]
classmethod get_str(mapped_value)[source]
options
descriptions
default
config_schema() → dict[source]
class isimple.core.config.extend(factory: Type[isimple.core.config.Factory], key: Optional[str] = None)[source]

Bases: object

isimple.core.config.untag(d: dict) → dict[source]
class isimple.core.config.NpArray[source]

Bases: numpy.ndarray

classmethod validate(v: Any) → str[source]
class isimple.core.config.BaseConfig[source]

Bases: pydantic.main.BaseModel, isimple.core.Described

Abstract class for configuration data.

  • Usage, where SomeConfig is a subclass of BaseConfig:
    • Instantiating:
      ```

      config = SomeConfig() config = SomeConfig(field1=1.0, field2=’text’) config = SomeConfig(**dict_with_fields_and_values)

      ```

    • Updating:
      ```

      config(field1=1.0, field2=’text’) config(**dict_with_fields_and_values)

      ```

    • Saving:
      ```

      dict_with_fields_and_values = config.to_dict()

      ```

  • Writing BaseConfig subclasses:
    • Use the @extends(ConfigType) decorator to make your configuration
      class accessible from the ConfigType Factory (defined below)
    • Configuration keys are declared as pydantic Field instances
      • Must be type-annotated for type resolution to work properly!
```

from pydantic import Field from isimple.core.config import BaseConfig

@extend(ConfigType) class SomeConfig(BaseConfig):

field1: int = Field(default=42) field2: SomeNestedConfig = Field(default_factory=SomeOtherConfig)

```

class Config[source]

Bases: object

pydantic configuration class

arbitrary_types_allowed = False
use_enum_value = True
validate_assignment = True
json_encoders = {<class 'numpy.ndarray'>: <class 'list'>}
to_dict(do_tag: bool = False) → dict[source]

Return the configuration as a serializable dict. :param do_tag: if True, add configuration class and version fields to the dict :return: dict

tag(d: dict) → dict[source]
class isimple.core.config.ConfigType(string: str = None)[source]

Bases: isimple.core.config.Factory

get() → Type[isimple.core.config.BaseConfig][source]
config_schema() → dict[source]
class isimple.core.config.Configurable[source]

Bases: isimple.core.Described

classmethod config_class()[source]
classmethod config_schema()[source]
class isimple.core.config.Instance(config: isimple.core.config.BaseConfig = None)[source]

Bases: isimple.core.config.Configurable

config

isimple.core.db module

class isimple.core.db.SessionWrapper[source]

Bases: object

Wrapper object for a SQLAlchemy session factory.

connect(session_wrapper: isimple.core.db.SessionWrapper)[source]

Share the session factory of another SessionWrapper instance

session()[source]

SQLAlchemy session context manager.

Opens a SQLAlchemy session and commits after the block is done. Changes are rolled back if an exception is raised. Usage:

with self.session() as s:
    # interact with the database here
class isimple.core.db.DbModel(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, isimple.core.db.SessionWrapper

Abstract database model class.

Subclasses should

get(attr: str) → Any[source]

Get attribute value from database

session(add: bool = True)[source]

SQLAlchemy session context manager.

Opens a SQLAlchemy session and commits after the block is done. Changes are rolled back if an exception is raised. Usage:

with self.session() as s:
    # interact with the database here

Calls DbModel._pre() before yielding the session and DbModel._post() after the block is completed.

Parameters:add (bool) – add model(s) after opening the session
class isimple.core.db.FileModel(path: str)[source]

Bases: isimple.core.db.DbModel

Abstrat database model for files.

Files are hashed and resolved in order to keep a single entry per file.

id = Column(None, Integer(), table=None, primary_key=True, nullable=False)
hash = Column(None, String(), table=None)
path = Column(None, String(), table=None)
used = Column(None, DateTime(), table=None)
resolved

Whether the FileModel has been resolved.

resolve() → isimple.core.db.FileModel[source]

Resolve the file by its SHA1 hash. todo: reference to util.hash_file

If the computed hash is new, the file is committed to the database. Otherwise, the original entry is re-used.

Returns:The current instance if the file is new, or a new FileModel instance representing the original database entry.
Return type:FileModel
class isimple.core.db.BaseAnalysisModel(**kwargs)[source]

Bases: isimple.core.db.DbModel

AnalysisModel interface

get_name() → str[source]
get_config_json() → Optional[str][source]

Get the current configuration in JSON

load_config(video_path: str, design_path: str = None, include: List[str] = None) → Optional[dict][source]

Load configuration from the database

undo_config(context: str = None) → Optional[dict][source]

Undo configuration. If a context is supplied, ensure that the context field changes, but the other fields remain the same

redo_config(context: str = None) → Optional[dict][source]

Redo configuration. If a context is supplied, ensure that the context field changes, but the other fields remain the same

store() → None[source]

Store analysis information from wrapped BaseVideoAnalyzer to the database

isimple.core.interface module

class isimple.core.interface.InterfaceFactory(string: str = None)[source]

Bases: isimple.core.config.Factory

get() → Type[isimple.core.config.Configurable][source]
config_schema() → dict[source]
class isimple.core.interface.HandlerConfig[source]

Bases: isimple.core.config.BaseConfig, abc.ABC

class isimple.core.interface.TransformConfig[source]

Bases: isimple.core.config.BaseConfig

Undefined transform

class isimple.core.interface.TransformInterface[source]

Bases: isimple.core.config.Configurable, abc.ABC

validate(matrix: Optional[numpy.ndarray]) → bool[source]
from_coordinates(roi: isimple.maths.coordinates.Roi, from_shape: tuple) → numpy.ndarray[source]
to_coordinates(to_shape: tuple) → numpy.ndarray[source]
estimate(roi: isimple.maths.coordinates.Roi, from_shape: tuple, to_shape: tuple) → numpy.ndarray[source]
invert(matrix: Optional[numpy.ndarray]) → Optional[numpy.ndarray][source]
transform(transform: numpy.ndarray, img: numpy.ndarray, shape: Tuple[int, int]) → numpy.ndarray[source]
coordinate(transform: numpy.ndarray, coordinate: isimple.maths.coordinates.ShapeCoo, shape: Tuple[int, int]) → isimple.maths.coordinates.ShapeCoo[source]
class isimple.core.interface.FilterConfig[source]

Bases: isimple.core.config.BaseConfig

Undefined filter

ready

Return true if filter can be applied ~ this configuration. Override for specific filter implementations

class isimple.core.interface.FilterInterface[source]

Bases: isimple.core.config.Configurable, abc.ABC

Handles pixel filtering operations

set_filter(filter, color: isimple.maths.colors.Color)[source]
mean_color(filter) → isimple.maths.colors.Color[source]
filter(filter, image: numpy.ndarray, mask: numpy.ndarray = None) → numpy.ndarray[source]
class isimple.core.interface.FilterType(string: str = None)[source]

Bases: isimple.core.interface.InterfaceFactory

get() → Type[isimple.core.interface.FilterInterface][source]
class isimple.core.interface.TransformType(string: str = None)[source]

Bases: isimple.core.interface.InterfaceFactory

get() → Type[isimple.core.interface.TransformInterface][source]

isimple.core.streaming module

class isimple.core.streaming.BaseStreamer[source]

Bases: abc.ABC

push(value: Any)[source]
stream() → Generator[Any, None, None][source]
stop()[source]
classmethod mime_type() → str[source]
classmethod content_type()[source]
class isimple.core.streaming.JsonStreamer[source]

Bases: isimple.core.streaming.BaseStreamer

class isimple.core.streaming.EventStreamer[source]

Bases: isimple.core.streaming.JsonStreamer

event(category: str, id: str, data: Any)[source]

Push a JSON event

Parameters:
  • category – event category
  • id – UUID of event source
  • data – event data
Returns:

class isimple.core.streaming.FrameStreamer[source]

Bases: isimple.core.streaming.BaseStreamer

class isimple.core.streaming.JpegStreamer[source]

Bases: isimple.core.streaming.FrameStreamer

class isimple.core.streaming.StreamHandler[source]

Bases: isimple.core.Lockable

A singleton object to handle streaming frames from methods

register(instance: object, method, stream_type: Type[isimple.core.streaming.BaseStreamer] = None) → isimple.core.streaming.BaseStreamer[source]

Register method, start a streamer. If method has been registered already, return its streamer.

is_registered(instance: object, method=None) → bool[source]
push(instance: object, method, data)[source]

If method is registered, push data to its streamer.

unregister(instance: object, method=None)[source]

Unregister method: stop its streamer & delete

update()[source]
stop()[source]
isimple.core.streaming.stream(method)[source]

Decorator for streaming methods. To stream frames, the wrapped method should be registered

in the global StreamHandler streams.

Module contents

exception isimple.core.RootException(*args)[source]

Bases: Exception

msg = ''
exception isimple.core.SetupError(*args)[source]

Bases: isimple.core.RootException

class isimple.core.EnforcedStr(string: str = None)[source]

Bases: str

options
descriptions
describe
default
class isimple.core.Endpoint(signature: _GenericAlias, streaming: isimple.core._Streaming = <_Streaming 'off'>)[source]

Bases: object

compatible(method: Callable) → bool[source]
signature
streaming
registered
name
add(method)[source]
register(name: str)[source]
class isimple.core.EndpointRegistry[source]

Bases: object

class isimple.core.InstanceRegistry[source]

Bases: isimple.core.EndpointRegistry

This one is global, collects callables that expose endpoints

expose(endpoint: isimple.core.Endpoint)[source]
exposes(endpoint: isimple.core.Endpoint)[source]
endpoints
class isimple.core.ImmutableRegistry(endpoints: isimple.core.InstanceRegistry = None)[source]

Bases: isimple.core.EndpointRegistry

expose(endpoint: isimple.core.Endpoint)[source]
exposes(endpoint: isimple.core.Endpoint)[source]
endpoints
class isimple.core.Described[source]

Bases: object

class isimple.core.Lockable[source]

Bases: abc.ABC

lock()[source]
cancel()[source]
error()[source]
canceled
errored
clear_cancel()[source]
clear_error()[source]
class isimple.core.RootInstance[source]

Bases: isimple.core.Lockable

get_id()[source]
id
instance_mapping
get(endpoint: isimple.core.Endpoint, index: int = None) → Callable[source]