Exemplo n.º 1
0
 def _p_tconst(pattern, pwave):
     """P waves temporal constraints"""
     BASIC_TCONST(pattern, pwave)
     tnet = pattern.last_tnet
     tnet.add_constraint(pwave.start, pwave.end, C.PW_DURATION)
     #We find the associated QRS.
     beats = pattern.evidence[o.QRS]
     qidx = qrsidx + len(beats) if qrsidx < 0 else qrsidx
     qrs = beats[qidx]
     if qidx > 0:
         tnet.set_before(beats[qidx - 1].end, pwave.start)
     tnet.add_constraint(pwave.start, qrs.start, C.N_PR_INTERVAL)
     tnet.set_before(pwave.end, qrs.start)
     if len(pattern.evidence[o.PWave]) > 10:
         #The mean and standard deviation of the PQ measurements will
         #influence the following observations.
         if qidx % 2 == 0:
             pqmean, pqstd = pattern.hypothesis.meas.pq
         else:
             pqs = _get_measures(pattern, True)[2]
             pqmean, pqstd = np.mean(pqs), np.std(pqs)
         if not np.isnan(pqmean) and not np.isnan(pqstd):
             interv = Iv(int(pqmean - 2 * pqstd), int(pqmean + 2 * pqstd))
             if interv.overlap(C.N_PR_INTERVAL):
                 tnet.add_constraint(pwave.start, qrs.start, interv)
Exemplo n.º 2
0
 def _t_tconst(pattern, twave):
     """
     Temporal constraints of the T Waves wrt the corresponding QRS complex.
     """
     BASIC_TCONST(pattern, twave)
     tnet = pattern.last_tnet
     obseq = pattern.obs_seq
     idx = pattern.get_step(twave)
     beats = pattern.evidence[o.QRS]
     qidx = qrsidx + len(beats) if qrsidx < 0 else qrsidx
     qrs = beats[qidx]
     if qidx > 1:
         refsq = beats[qidx - 1].earlystart - beats[qidx - 2].lateend
         tnet.add_constraint(qrs.time, twave.end,
                             Iv(0, max(0, refsq - C.TQ_INTERVAL_MIN)))
     if idx > 0 and isinstance(obseq[idx - 1], o.PWave):
         pwave = obseq[idx - 1]
         tnet.add_constraint(
             pwave.end, twave.start,
             Iv(C.ST_INTERVAL.start, C.PQ_INTERVAL.end + C.QRS_DUR.end))
     if qidx < len(beats) - 1:
         tnet.set_before(twave.end, beats[qidx + 1].start)
     #ST interval
     tnet.add_constraint(qrs.end, twave.start, C.ST_INTERVAL)
     #QT duration
     tnet.add_constraint(qrs.start, twave.end, C.N_QT_INTERVAL)
     #RT variation
     if qidx % 2 == 0:
         rtmean, rtstd = pattern.hypothesis.meas.rt
         #We also define a constraint on T wave end based on the last
         #distance between normal and ectopic QRS.
         if qidx > 0:
             tnet.add_constraint(
                 qrs.end, twave.end,
                 Iv(0,
                    beats[qidx - 1].earlystart - beats[qidx - 2].lateend))
     else:
         rts = _get_measures(pattern, 1)[2]
         rtmean, rtstd = np.mean(rts), np.std(rts)
     if rtmean > 0:
         #The mean and standard deviation of the PQ measurements will
         #influence the following observations.
         maxdiff = (C.QT_ERR_STD
                    if len(pattern.evidence[o.TWave]) < 10 else rtstd)
         maxdiff = max(maxdiff, C.MIN_QT_STD)
         interv = Iv(int(rtmean - 2.5 * maxdiff),
                     int(rtmean + 2.5 * maxdiff))
         #We avoid possible inconsistencies with constraint introduced by
         #the rhythm information.
         try:
             existing = tnet.get_constraint(qrs.time, twave.end).constraint
         except KeyError:
             existing = Iv(-np.inf, np.inf)
         if interv.overlap(existing):
             tnet.add_constraint(qrs.time, twave.end, interv)
Exemplo n.º 3
0
def _p_qrs_tconst(pattern, pwave):
    """
    Temporal constraints of the P Waves wrt the corresponding QRS complex
    """
    tnet = pattern.tnet
    tnet.add_constraint(pwave.start, pwave.end, C.PW_DURATION)
    #We find the QRS observed just before that P wave.
    idx = pattern.get_step(pwave)
    if idx > 0 and isinstance(pattern.trseq[idx - 1][1], o.QRS):
        qrs = pattern.trseq[idx - 1][1]
        #PR interval
        tnet.add_constraint(pwave.start, qrs.start, C.N_PR_INTERVAL)
        tnet.set_before(pwave.end, qrs.start)
        if len(pattern.evidence[o.PWave]) > 10:
            #The mean and standard deviation of the PQ measurements will
            #influence the following observations.
            pqmean, pqstd = pattern.hypothesis.meas.pq
            interv = Iv(int(pqmean - 2 * pqstd), int(pqmean + 2 * pqstd))
            if interv.overlap(C.N_PR_INTERVAL):
                tnet.add_constraint(pwave.start, qrs.start, interv)
Exemplo n.º 4
0
 def _t_tconst(pattern, twave):
     """
     Temporal constraints of the T Waves wrt the corresponding QRS complex.
     """
     BASIC_TCONST(pattern, twave)
     tnet = pattern.last_tnet
     #We find the associated QRS.
     beats = pattern.evidence[o.QRS]
     qidx = qrsidx + len(beats) if qrsidx < 0 else qrsidx
     qrs = beats[qidx]
     if qidx < len(beats) - 1:
         tnet.set_before(twave.end, beats[qidx + 1].start)
     #ST interval
     tnet.add_constraint(qrs.end, twave.start, C.ST_INTERVAL)
     #QT duration
     tnet.add_constraint(qrs.start, twave.end, C.N_QT_INTERVAL)
     #RT variation
     if not _is_ectopic(qidx):
         rtmean, rtstd = pattern.hypothesis.meas.rt
     else:
         rts = _get_measures(pattern, True)[2]
         rtmean, rtstd = np.mean(rts), np.std(rts)
     if rtmean > 0:
         #The mean and standard deviation of the PQ measurements will
         #influence the following observations.
         maxdiff = (C.QT_ERR_STD
                    if len(pattern.evidence[o.TWave]) < 10 else rtstd)
         maxdiff = max(maxdiff, C.MIN_QT_STD)
         interv = Iv(int(rtmean - 2.5 * maxdiff),
                     int(rtmean + 2.5 * maxdiff))
         #We avoid possible inconsistencies with constraint introduced by
         #the rhythm information.
         try:
             existing = tnet.get_constraint(qrs.time, twave.end).constraint
         except KeyError:
             existing = Iv(-np.inf, np.inf)
         if interv.overlap(existing):
             tnet.add_constraint(qrs.time, twave.end, interv)
Exemplo n.º 5
0
    def test_overlap(self):
        inter1 = Interval(0, 10)
        inter2 = Interval(15, 20)
        assert not inter1.overlap(inter2)
        assert not inter2.overlap(inter1)

        assert inter1.overlap(inter1)
        assert inter2.overlap(inter2)

        inter2 = Interval(-6, 0)
        assert not inter1.overlap(inter2)
        assert not inter2.overlap(inter1)

        inter2 = Interval(-6, 5)
        assert inter1.overlap(inter2)
        assert inter2.overlap(inter1)

        inter2 = Interval(10, 15)
        assert not inter1.overlap(inter2)
        assert not inter2.overlap(inter1)

        inter2 = Interval(4, 15)
        assert inter1.overlap(inter2)
        assert inter2.overlap(inter1)