anndata.ann.annlocation package¶
Submodules¶
anndata.ann.annlocation.disjoint module¶
- filename
sppas.src.anndata.annlocation.disjoint.py
- author
Brigitte Bigi
- contact
- summary
Represent the disjoint interval localization of an annotation.
- class anndata.ann.annlocation.disjoint.sppasDisjoint(intervals=None)[source]¶
Bases:
anndata.ann.annlocation.localization.sppasBaseLocalization
Localization of a serie of intervals in time.
- __init__(intervals=None)[source]¶
Create a new sppasDisjoint instance.
- Parameters
intervals – (list of sppasInterval)
- append_interval(interval)[source]¶
Return the sppasInterval at the given index.
- Parameters
interval – (sppasInterval)
- middle()[source]¶
Return a sppasPoint() at the middle of the time interval.
To be tested.
- Returns
(sppasPoint)
- set(other)[source]¶
Set self members from another sppasDisjoint instance.
- Parameters
other – (sppasDisjoint)
- set_begin(tp)[source]¶
Set the begin sppasPoint instance to new sppasPoint.
- Parameters
tp – (sppasPoint)
- set_end(tp)[source]¶
Set the end sppasPoint instance to new sppasPoint.
- Parameters
tp – (sppasPoint)
anndata.ann.annlocation.duration module¶
- filename
sppas.src.anndata.annlocation.duration.py
- author
Brigitte Bigi
- contact
- summary
Represent a duration taking into account the radius of points.
- class anndata.ann.annlocation.duration.sppasDuration(value, vagueness=0.0)[source]¶
Bases:
object
Representation of a duration with vagueness.
Represents a duration identified by 2 float values:
the duration value;
the duration margin.
- __init__(value, vagueness=0.0)[source]¶
Create a new sppasDuration instance.
- Parameters
value – (float) value of the duration.
vagueness – (float) represents the vagueness of the value.
- set(other)[source]¶
Set the value/vagueness of another sppasDuration instance.
- Parameters
other – (sppasDuration)
anndata.ann.annlocation.durationcompare module¶
- filename
sppas.src.anndata.annlocation.durationcompare.py
- author
Brigitte Bigi
- contact
- summary
Comparison methods for durations, used by the filter system.
- class anndata.ann.annlocation.durationcompare.sppasDurationCompare[source]¶
Bases:
sppas.src.structs.basecompare.sppasBaseCompare
Comparison methods for sppasDuration.
- static eq(duration, x)[source]¶
Return True if duration is equal to x.
- Parameters
duration – (sppasDuration)
x – (int, float)
- Returns
(bool)
- static ge(duration, x)[source]¶
Return True if duration is greater or equal than x.
- Parameters
duration – (sppasDuration)
x – (int, float)
- Returns
(bool)
- static gt(duration, x)[source]¶
Return True if duration is greater than x.
- Parameters
duration – (sppasDuration)
x – (int, float)
- Returns
(bool)
- static le(duration, x)[source]¶
Return True if duration is lower or equal than x.
- Parameters
duration – (sppasDuration)
x – (int, float)
- Returns
(bool)
anndata.ann.annlocation.interval module¶
- filename
sppas.src.anndata.annlocation.interval.py
- author
Brigitte Bigi
- contact
- summary
Represent the interval localization of an annotation.
- class anndata.ann.annlocation.interval.sppasInterval(begin, end)[source]¶
Bases:
anndata.ann.annlocation.localization.sppasBaseLocalization
Localization of an interval between two sppasPoint instances.
An interval is identified by two sppasPoint objects:
one is representing the beginning of the interval;
the other is representing the end of the interval.
- __init__(begin, end)[source]¶
Create a new sppasInterval instance.
- Parameters
begin – (sppasPoint)
end – (sppasPoint)
Degenerated interval is forbidden, i.e. begin > end.
- static check_interval_bounds(begin, end)[source]¶
Check bounds of a virtual interval.
- Parameters
begin – (sppasPoint)
end – (sppasPoint)
- static check_types(begin, end)[source]¶
True only if begin and end are both the same types of sppasPoint.
- Parameters
begin – any kind of data
end – any kind of data
- Returns
Boolean
- combine(other)[source]¶
Return a sppasInterval, the combination of two intervals.
- Parameters
other – (sppasInterval) the other interval to combine with.
- duration()[source]¶
Overridden. Return the duration of the time interval.
- Returns
(sppasDuration) Duration and its vagueness.
- middle()[source]¶
Return a sppasPoint() at the middle of the time interval.
To be tested.
- Returns
(sppasPoint)
- middle_value()[source]¶
Return the middle value of the time interval.
Return a float value even if points are integers.
- Returns
(float) value.
- set(other)[source]¶
Set self members from another sppasInterval instance.
- Parameters
other – (sppasInterval)
- set_begin(tp)[source]¶
Set the begin of the interval to a new sppasPoint.
Attention: it is a reference assignment.
- Parameters
tp – (sppasPoint)
- set_end(tp)[source]¶
Set the end of the interval to a new sppasPoint.
Attention: it is a reference assignment.
- Parameters
tp – (sppasPoint)
- set_radius(radius)[source]¶
Set a radius value to begin and end points.
- Parameters
radius – (int or float)
- Raise
ValueError
anndata.ann.annlocation.intervalcompare module¶
- filename
sppas.src.anndata.annlocation.intervalcompare.py
- author
Brigitte Bigi
- contact
- summary
Comparison methods of 2 intervals, used by the filter system.
This class is inspired by both the “Allen’s Interval Algebra” and INDU. James Allen, in 1983, proposed an algebraic framework named Interval Algebra (IA), for qualitative reasoning with time intervals where the binary relationship between a pair of intervals is represented by a subset of 13 atomic relation, that are:
distinct because no pair of definite intervals can be related
by more than one of the relationships;
exhaustive because any pair of definite intervals are described
by one of the relations;
qualitative (rather than quantitative) because no numeric time
spans are considered.
These relations and the operations on them form the “Allen’s Interval Algebra”.
Using this calculus, given facts can be formalized and then used for automatic reasoning. Relations are: before, after, meets, met by, overlaps, overlapped by, starts, started by, finishes, finished by, contains, during and equals.
Pujari, Kumari and Sattar proposed INDU in 1999: an Interval & Duration network. They extended the IA to model qualitative information about intervals and durations in a single binary constraint network. Duration relations are: greater, lower and equal. INDU comprises of 25 basic relations between a pair of two intervals.
For convenience reasons, and because this class will be used to filter annotated data (and not reasoning), it implements the following methods:
‘before’ ‘before_equal’ ‘before_greater’ ‘before_lower’ ‘after’ ‘after_equal’ ‘after_greater’ ‘after_lower’ ‘meets’ ‘meets_equal’ ‘meets_greater’ ‘meets_lower’ ‘metby’ ‘metby_equal’ ‘metby_greater’ ‘metby_lower’ ‘overlaps’ ‘overlaps_equal’ ‘overlaps_greater’ ‘overlaps_lower’ ‘overlappedby’ ‘overlappedby_equal’ ‘overlappedby_greater’ ‘overlappedby_lower’ ‘starts’ ‘startedby’ ‘finishes’ ‘finishedby’ ‘contains’ ‘during’ ‘equals’
So that they are not distinct. Some of them accept parameters so they are not exhaustive too.
- class anndata.ann.annlocation.intervalcompare.sppasIntervalCompare[source]¶
Bases:
sppas.src.structs.basecompare.sppasBaseCompare
SPPAS implementation of interval’comparisons.
Includes “Allen’s Interval Algebra” and INDU, with several options. This class can be used to compare any of the localization-derived classes:
sppasInterval(): begin and end points are used,
sppasDisjoint(): the first and the last points are used and then it is considered a full interval.
sppasPoint(): considered like a degenerated interval.
- static after(i1, i2, max_delay=None, **kwargs)[source]¶
Return True if i1 follows i2.
This is part of the Allen algebra.
- Parameters
i1 – |--------|
i2 – |-------|
max_delay – (int/float/sppasDuration) Maximum delay between the end of i2 and the beginning of i1.
**kwargs –
unused.
- static before(i1, i2, max_delay=None, **kwargs)[source]¶
Return True if i1 precedes i2.
This is part of the Allen algebra.
- static before_equal(i1, i2, *args)[source]¶
Return True if i1 precedes i2 and the durations are equals.
This is part of the INDU algebra.
- static before_greater(i1, i2, *args)[source]¶
Return True if i1 precedes i2 and the duration of i1 is greater.
This is part of the INDU algebra.
- Parameters
i1 – |-----------|
i2 – |-----|
max_delay – (int/float/sppasDuration) Maximum delay between the end of i1 and the beginning of i2.
- static before_lower(i1, i2, *args)[source]¶
Return True if i1 precedes i2 and the duration of i1 is lower.
This is part of the INDU algebra.
- Parameters
i1 – |-----|
i2 – |------------|
max_delay – (int/float/sppasDuration) Maximum delay between the end of i1 and the beginning of i2.
- static contains(i1, i2, **kwargs)[source]¶
Return True if i1 contains i2.
- Parameters
i1 – |------------|
i2 – |----|
**kwargs –
unused.
- static during(i1, i2, **kwargs)[source]¶
Return True if i1 is located during i2.
- Parameters
i1 – |----|
i2 – |------------|
**kwargs –
unused.
- static finishedby(i1, i2, **kwargs)[source]¶
Return True if i1 finishes the same and starts before of i2.
- Parameters
i1 – |---------|
i2 – |----|
**kwargs –
unused.
- static finishes(i1, i2, **kwargs)[source]¶
Return True if i1 finishes the same and starts within of i2.
- Parameters
i1 – |----|
i2 – |---------|
**kwargs –
unused.
- static overlappedby(i1, i2, overlapped_min=None, percent=False, **kwargs)[source]¶
Return True if i1 overlapped by i2.
- static overlaps(i1, i2, overlap_min=None, percent=False, **kwargs)[source]¶
Return True if i1 overlaps with i2.
- static startedby(i1, i2, **kwargs)[source]¶
Return True if i1 is started at the start of i2 interval.
- Parameters
i1 – |----------|
i2 – |----|
**kwargs –
unused.
- static starts(i1, i2, **kwargs)[source]¶
Return True if i1 starts at the start of i2 and finishes within it.
- Parameters
i1 – |----|
i2 – |----------|
**kwargs –
unused.
anndata.ann.annlocation.localization module¶
- filename
sppas.src.anndata.annlocation.localization.py
- author
Brigitte Bigi
- contact
- summary
a base class to represent the localization of an annotation.
- class anndata.ann.annlocation.localization.sppasBaseLocalization[source]¶
Bases:
object
Represents a base class for any kind of localization.
- duration()[source]¶
Return the duration of the localization.
Must be overridden
- Returns
(sppasDuration) Duration and its vagueness.
- is_disjoint()[source]¶
Return True if this object is an instance of sppasDisjoint.
Should be overridden.
- is_interval()[source]¶
Return True if this object is an instance of sppasInterval.
Should be overridden.
anndata.ann.annlocation.localizationcompare module¶
- filename
sppas.src.anndata.annlocation.localizationcompare.py
- author
Brigitte Bigi
- contact
- summary
Comparison methods of 2 localizations, used by the filter system.
- class anndata.ann.annlocation.localizationcompare.sppasLocalizationCompare[source]¶
Bases:
sppas.src.structs.basecompare.sppasBaseCompare
Comparison methods for sppasBaseLocalization.
anndata.ann.annlocation.location module¶
- filename
sppas.src.anndata.annlocation.location.py
- author
Brigitte Bigi
- contact
- summary
Represent the list of possible localizations of an annotation.
- class anndata.ann.annlocation.location.sppasLocation(localization=None, score=None)[source]¶
Bases:
object
Location of an annotation of a tier.
sppasLocation allows to store a set of localizations with their scores. This class is using a list of lists, i.e. a list of pairs (localization, score). This is the best compromise between memory usage, speed and readability.
- __init__(localization=None, score=None)[source]¶
Create a new sppasLocation instance and add the entry.
- Parameters
localization – (Localization or list of localizations)
score – (float or list of float)
If a list of alternative localizations are given, the same score is assigned to all items.
- append(localization, score=None)[source]¶
Add a localization into the list.
- Parameters
localization – (Localization) the localization to append
score – (float)
- get_best()[source]¶
Return a copy of the best localization.
- Returns
(sppasLocalization) localization with the highest score.
- get_score(loc)[source]¶
Return the score of a localization or None if it is not in.
- Parameters
loc – (sppasLocalization)
- Returns
score: (float)
- match_duration(dur_functions, logic_bool='and')[source]¶
Return True if a duration matches all or any of the functions.
- Parameters
dur_functions – list of (function, value, logical_not)
logic_bool – (str) Apply a logical “and” or “or”
- Returns
(bool)
function: a function in python with 2 arguments: dur/value
value: the expected value for the duration (int/float/sppasDuration)
logical_not: boolean
- Example
Search if a duration is exactly 30ms
>>> d.match([(eq, 0.03, False)])
- Example
Search if a duration is not 30ms
>>> d.match([(eq, 0.03, True)]) >>> d.match([(ne, 0.03, False)])
- Example
Search if a duration is comprised between 0.3 and 0.7 >>> l.match([(ge, 0.03, False), >>> (le, 0.07, False)], logic_bool=”and”)
See sppasDurationCompare() to get a list of functions.
- match_localization(loc_functions, logic_bool='and')[source]¶
Return True if a localization matches all or any of the functions.
- Parameters
loc_functions – list of (function, value, logical_not)
logic_bool – (str) Apply a logical “and” or a logical “or”
between the functions. :returns: (bool)
function: a function in python with 2 arguments: loc/value
value: the expected value for the localization (int/float/sppasPoint)
logical_not: boolean
- Example
Search if a localization is after (or starts at) 1 minutes
>>> l.match([(rangefrom, 60., False)])
- Example
Search if a localization is before (or ends at) 3 minutes
>>> l.match([(rangeto, 180., True)])
- Example
Search if a localization is between 1 min and 3 min
>>> l.match([(rangefrom, 60., False), >>> (rangeto, 180., False)], logic_bool="and")
See sppasLocalizationCompare() to get a list of functions.
- remove(localization)[source]¶
Remove a localization of the list.
- Parameters
localization – (sppasLocalization) the loc to be removed
- set_radius(radius)[source]¶
Set a radius value to all localizations.
- Parameters
radius – (int, float) New radius value
- Raise
AnnDataTypeError, AnnDataNegValueError
anndata.ann.annlocation.point module¶
- filename
sppas.src.anndata.annlocation.point.py
- author
Brigitte Bigi
- contact
- summary
Represent a point made of a midpoint and a radius.
- class anndata.ann.annlocation.point.sppasPoint(midpoint, radius=None)[source]¶
Bases:
anndata.ann.annlocation.localization.sppasBaseLocalization
Localization of a point for any numerical representation.
Represents a point identified by a midpoint value and a radius value. Generally, time is represented in seconds, as a float value ; frames are represented by integers like ranks.
In this class, the 3 relations <, = and > take into account a radius value, that represents the uncertainty of the localization. For a point x, with a radius value of rx, and a point y with a radius value of ry, these relations are defined as:
x = y iff |x - y| <= rx + ry
x < y iff not(x = y) and x < y
x > y iff not(x = y) and x > y
- Example 1
Strictly equals:
x = 1.000, rx=0.
y = 1.000, ry=0.
x = y is true
x = 1.00000000000, rx=0.
y = 0.99999999675, ry=0.
x = y is false
- Example 2
Using the radius:
x = 1.0000000000, rx=0.0005
y = 1.0000987653, ry=0.0005
x = y is true (accepts a margin of 1ms between x and y)
x = 1.0000000, rx=0.0005
y = 1.0011235, ry=0.0005
x = y is false
So… an overlap of the vagueness “area” makes the two points equals: |------------rx----------X-----ry===rx----Y--------ry------|
- __init__(midpoint, radius=None)[source]¶
Create a sppasPoint instance.
- Parameters
midpoint – (float, int) midpoint value.
radius – (float, int) represents the vagueness of the point.
Radius must be of the same type as midpoint.
- static check_types(x, y)[source]¶
True only if midpoint and radius are both of the same types.
- Parameters
x – any kind of data
y – any kind of data
- Returns
Boolean
- duration()[source]¶
Overrides. Return the duration of the point.
- Returns
(sppasDuration) Duration and its vagueness.
- set(other)[source]¶
Set self members from another sppasPoint instance.
- Parameters
other – (sppasPoint)
- set_midpoint(midpoint)[source]¶
Set the midpoint value.
In versions < 1.9.8, it was required that midpoint >= 0. Negative values are now accepted because some annotations are not properly synchronized and then some of them can be negative.
- Parameters
midpoint – (float, int) is the new midpoint value.
- Raise
AnnDataTypeError
Module contents¶
- filename
sppas.src.anndata.annlocation.__init__.py
- author
Brigitte Bigi
- contact
- summary
the anchor in time of an annotation.
- class anndata.ann.annlocation.sppasBaseLocalization[source]¶
Bases:
object
Represents a base class for any kind of localization.
- duration()[source]¶
Return the duration of the localization.
Must be overridden
- Returns
(sppasDuration) Duration and its vagueness.
- is_disjoint()[source]¶
Return True if this object is an instance of sppasDisjoint.
Should be overridden.
- is_interval()[source]¶
Return True if this object is an instance of sppasInterval.
Should be overridden.
- class anndata.ann.annlocation.sppasDisjoint(intervals=None)[source]¶
Bases:
anndata.ann.annlocation.localization.sppasBaseLocalization
Localization of a serie of intervals in time.
- __init__(intervals=None)[source]¶
Create a new sppasDisjoint instance.
- Parameters
intervals – (list of sppasInterval)
- append_interval(interval)[source]¶
Return the sppasInterval at the given index.
- Parameters
interval – (sppasInterval)
- middle()[source]¶
Return a sppasPoint() at the middle of the time interval.
To be tested.
- Returns
(sppasPoint)
- set(other)[source]¶
Set self members from another sppasDisjoint instance.
- Parameters
other – (sppasDisjoint)
- set_begin(tp)[source]¶
Set the begin sppasPoint instance to new sppasPoint.
- Parameters
tp – (sppasPoint)
- set_end(tp)[source]¶
Set the end sppasPoint instance to new sppasPoint.
- Parameters
tp – (sppasPoint)
- class anndata.ann.annlocation.sppasDuration(value, vagueness=0.0)[source]¶
Bases:
object
Representation of a duration with vagueness.
Represents a duration identified by 2 float values:
the duration value;
the duration margin.
- __init__(value, vagueness=0.0)[source]¶
Create a new sppasDuration instance.
- Parameters
value – (float) value of the duration.
vagueness – (float) represents the vagueness of the value.
- set(other)[source]¶
Set the value/vagueness of another sppasDuration instance.
- Parameters
other – (sppasDuration)
- class anndata.ann.annlocation.sppasDurationCompare[source]¶
Bases:
sppas.src.structs.basecompare.sppasBaseCompare
Comparison methods for sppasDuration.
- static eq(duration, x)[source]¶
Return True if duration is equal to x.
- Parameters
duration – (sppasDuration)
x – (int, float)
- Returns
(bool)
- static ge(duration, x)[source]¶
Return True if duration is greater or equal than x.
- Parameters
duration – (sppasDuration)
x – (int, float)
- Returns
(bool)
- static gt(duration, x)[source]¶
Return True if duration is greater than x.
- Parameters
duration – (sppasDuration)
x – (int, float)
- Returns
(bool)
- static le(duration, x)[source]¶
Return True if duration is lower or equal than x.
- Parameters
duration – (sppasDuration)
x – (int, float)
- Returns
(bool)
- class anndata.ann.annlocation.sppasInterval(begin, end)[source]¶
Bases:
anndata.ann.annlocation.localization.sppasBaseLocalization
Localization of an interval between two sppasPoint instances.
An interval is identified by two sppasPoint objects:
one is representing the beginning of the interval;
the other is representing the end of the interval.
- __init__(begin, end)[source]¶
Create a new sppasInterval instance.
- Parameters
begin – (sppasPoint)
end – (sppasPoint)
Degenerated interval is forbidden, i.e. begin > end.
- static check_interval_bounds(begin, end)[source]¶
Check bounds of a virtual interval.
- Parameters
begin – (sppasPoint)
end – (sppasPoint)
- static check_types(begin, end)[source]¶
True only if begin and end are both the same types of sppasPoint.
- Parameters
begin – any kind of data
end – any kind of data
- Returns
Boolean
- combine(other)[source]¶
Return a sppasInterval, the combination of two intervals.
- Parameters
other – (sppasInterval) the other interval to combine with.
- duration()[source]¶
Overridden. Return the duration of the time interval.
- Returns
(sppasDuration) Duration and its vagueness.
- middle()[source]¶
Return a sppasPoint() at the middle of the time interval.
To be tested.
- Returns
(sppasPoint)
- middle_value()[source]¶
Return the middle value of the time interval.
Return a float value even if points are integers.
- Returns
(float) value.
- set(other)[source]¶
Set self members from another sppasInterval instance.
- Parameters
other – (sppasInterval)
- set_begin(tp)[source]¶
Set the begin of the interval to a new sppasPoint.
Attention: it is a reference assignment.
- Parameters
tp – (sppasPoint)
- set_end(tp)[source]¶
Set the end of the interval to a new sppasPoint.
Attention: it is a reference assignment.
- Parameters
tp – (sppasPoint)
- set_radius(radius)[source]¶
Set a radius value to begin and end points.
- Parameters
radius – (int or float)
- Raise
ValueError
- class anndata.ann.annlocation.sppasIntervalCompare[source]¶
Bases:
sppas.src.structs.basecompare.sppasBaseCompare
SPPAS implementation of interval’comparisons.
Includes “Allen’s Interval Algebra” and INDU, with several options. This class can be used to compare any of the localization-derived classes:
sppasInterval(): begin and end points are used,
sppasDisjoint(): the first and the last points are used and then it is considered a full interval.
sppasPoint(): considered like a degenerated interval.
- static after(i1, i2, max_delay=None, **kwargs)[source]¶
Return True if i1 follows i2.
This is part of the Allen algebra.
- Parameters
i1 – |--------|
i2 – |-------|
max_delay – (int/float/sppasDuration) Maximum delay between the end of i2 and the beginning of i1.
**kwargs –
unused.
- static before(i1, i2, max_delay=None, **kwargs)[source]¶
Return True if i1 precedes i2.
This is part of the Allen algebra.
- static before_equal(i1, i2, *args)[source]¶
Return True if i1 precedes i2 and the durations are equals.
This is part of the INDU algebra.
- static before_greater(i1, i2, *args)[source]¶
Return True if i1 precedes i2 and the duration of i1 is greater.
This is part of the INDU algebra.
- Parameters
i1 – |-----------|
i2 – |-----|
max_delay – (int/float/sppasDuration) Maximum delay between the end of i1 and the beginning of i2.
- static before_lower(i1, i2, *args)[source]¶
Return True if i1 precedes i2 and the duration of i1 is lower.
This is part of the INDU algebra.
- Parameters
i1 – |-----|
i2 – |------------|
max_delay – (int/float/sppasDuration) Maximum delay between the end of i1 and the beginning of i2.
- static contains(i1, i2, **kwargs)[source]¶
Return True if i1 contains i2.
- Parameters
i1 – |------------|
i2 – |----|
**kwargs –
unused.
- static during(i1, i2, **kwargs)[source]¶
Return True if i1 is located during i2.
- Parameters
i1 – |----|
i2 – |------------|
**kwargs –
unused.
- static finishedby(i1, i2, **kwargs)[source]¶
Return True if i1 finishes the same and starts before of i2.
- Parameters
i1 – |---------|
i2 – |----|
**kwargs –
unused.
- static finishes(i1, i2, **kwargs)[source]¶
Return True if i1 finishes the same and starts within of i2.
- Parameters
i1 – |----|
i2 – |---------|
**kwargs –
unused.
- static overlappedby(i1, i2, overlapped_min=None, percent=False, **kwargs)[source]¶
Return True if i1 overlapped by i2.
- static overlaps(i1, i2, overlap_min=None, percent=False, **kwargs)[source]¶
Return True if i1 overlaps with i2.
- static startedby(i1, i2, **kwargs)[source]¶
Return True if i1 is started at the start of i2 interval.
- Parameters
i1 – |----------|
i2 – |----|
**kwargs –
unused.
- static starts(i1, i2, **kwargs)[source]¶
Return True if i1 starts at the start of i2 and finishes within it.
- Parameters
i1 – |----|
i2 – |----------|
**kwargs –
unused.
- class anndata.ann.annlocation.sppasLocalizationCompare[source]¶
Bases:
sppas.src.structs.basecompare.sppasBaseCompare
Comparison methods for sppasBaseLocalization.
- class anndata.ann.annlocation.sppasLocation(localization=None, score=None)[source]¶
Bases:
object
Location of an annotation of a tier.
sppasLocation allows to store a set of localizations with their scores. This class is using a list of lists, i.e. a list of pairs (localization, score). This is the best compromise between memory usage, speed and readability.
- __init__(localization=None, score=None)[source]¶
Create a new sppasLocation instance and add the entry.
- Parameters
localization – (Localization or list of localizations)
score – (float or list of float)
If a list of alternative localizations are given, the same score is assigned to all items.
- append(localization, score=None)[source]¶
Add a localization into the list.
- Parameters
localization – (Localization) the localization to append
score – (float)
- get_best()[source]¶
Return a copy of the best localization.
- Returns
(sppasLocalization) localization with the highest score.
- get_score(loc)[source]¶
Return the score of a localization or None if it is not in.
- Parameters
loc – (sppasLocalization)
- Returns
score: (float)
- match_duration(dur_functions, logic_bool='and')[source]¶
Return True if a duration matches all or any of the functions.
- Parameters
dur_functions – list of (function, value, logical_not)
logic_bool – (str) Apply a logical “and” or “or”
- Returns
(bool)
function: a function in python with 2 arguments: dur/value
value: the expected value for the duration (int/float/sppasDuration)
logical_not: boolean
- Example
Search if a duration is exactly 30ms
>>> d.match([(eq, 0.03, False)])
- Example
Search if a duration is not 30ms
>>> d.match([(eq, 0.03, True)]) >>> d.match([(ne, 0.03, False)])
- Example
Search if a duration is comprised between 0.3 and 0.7 >>> l.match([(ge, 0.03, False), >>> (le, 0.07, False)], logic_bool=”and”)
See sppasDurationCompare() to get a list of functions.
- match_localization(loc_functions, logic_bool='and')[source]¶
Return True if a localization matches all or any of the functions.
- Parameters
loc_functions – list of (function, value, logical_not)
logic_bool – (str) Apply a logical “and” or a logical “or”
between the functions. :returns: (bool)
function: a function in python with 2 arguments: loc/value
value: the expected value for the localization (int/float/sppasPoint)
logical_not: boolean
- Example
Search if a localization is after (or starts at) 1 minutes
>>> l.match([(rangefrom, 60., False)])
- Example
Search if a localization is before (or ends at) 3 minutes
>>> l.match([(rangeto, 180., True)])
- Example
Search if a localization is between 1 min and 3 min
>>> l.match([(rangefrom, 60., False), >>> (rangeto, 180., False)], logic_bool="and")
See sppasLocalizationCompare() to get a list of functions.
- remove(localization)[source]¶
Remove a localization of the list.
- Parameters
localization – (sppasLocalization) the loc to be removed
- set_radius(radius)[source]¶
Set a radius value to all localizations.
- Parameters
radius – (int, float) New radius value
- Raise
AnnDataTypeError, AnnDataNegValueError
- class anndata.ann.annlocation.sppasPoint(midpoint, radius=None)[source]¶
Bases:
anndata.ann.annlocation.localization.sppasBaseLocalization
Localization of a point for any numerical representation.
Represents a point identified by a midpoint value and a radius value. Generally, time is represented in seconds, as a float value ; frames are represented by integers like ranks.
In this class, the 3 relations <, = and > take into account a radius value, that represents the uncertainty of the localization. For a point x, with a radius value of rx, and a point y with a radius value of ry, these relations are defined as:
x = y iff |x - y| <= rx + ry
x < y iff not(x = y) and x < y
x > y iff not(x = y) and x > y
- Example 1
Strictly equals:
x = 1.000, rx=0.
y = 1.000, ry=0.
x = y is true
x = 1.00000000000, rx=0.
y = 0.99999999675, ry=0.
x = y is false
- Example 2
Using the radius:
x = 1.0000000000, rx=0.0005
y = 1.0000987653, ry=0.0005
x = y is true (accepts a margin of 1ms between x and y)
x = 1.0000000, rx=0.0005
y = 1.0011235, ry=0.0005
x = y is false
So… an overlap of the vagueness “area” makes the two points equals: |------------rx----------X-----ry===rx----Y--------ry------|
- __init__(midpoint, radius=None)[source]¶
Create a sppasPoint instance.
- Parameters
midpoint – (float, int) midpoint value.
radius – (float, int) represents the vagueness of the point.
Radius must be of the same type as midpoint.
- static check_types(x, y)[source]¶
True only if midpoint and radius are both of the same types.
- Parameters
x – any kind of data
y – any kind of data
- Returns
Boolean
- duration()[source]¶
Overrides. Return the duration of the point.
- Returns
(sppasDuration) Duration and its vagueness.
- set(other)[source]¶
Set self members from another sppasPoint instance.
- Parameters
other – (sppasPoint)
- set_midpoint(midpoint)[source]¶
Set the midpoint value.
In versions < 1.9.8, it was required that midpoint >= 0. Negative values are now accepted because some annotations are not properly synchronized and then some of them can be negative.
- Parameters
midpoint – (float, int) is the new midpoint value.
- Raise
AnnDataTypeError