コード例 #1
0
ファイル: fiber_tissue.py プロジェクト: teosbpl/myokit
 def relog(_logf, _logt, _dt):
     # Get first occurence of error
     ifirstf, kfirstf = find_error_position(_logf)
     ifirstt, kfirstt = find_error_position(_logt)
     if kfirstf is None and kfirstt is None:
         raise myokit.FindNanError('Error condition not found in logs.')
     elif kfirstf is None:
         ifirst = ifirstt
     elif kfirstt is None:
         ifirst = ifirstf
     elif ifirstf == 0 or ifirstt == 0:
         raise myokit.FindNanError(
             'Unable to work with simulation logs where the error'
             ' condition is met in the very first data point.')
     else:
         ifirst = min(ifirstf, ifirstt)
     # Position to start deep search at
     istart = ifirst - 1
     # Get last logged states before error
     statef = []
     statet = []
     for dims in myokit.dimco(*self._ncellsf):
         pre = '.'.join([str(x) for x in dims]) + '.'
         for s in self._modelf.states():
             statef.append(_logf[pre + s.qname()][istart])
     for dims in myokit.dimco(*self._ncellst):
         pre = '.'.join([str(x) for x in dims]) + '.'
         for s in self._modelt.states():
             statet.append(_logt[pre + s.qname()][istart])
     # Get last time before error
     time = _logf[time_varf][istart]
     # Save current state & time
     old_statef = self._statef
     old_statet = self._statet
     old_time = self._time
     self._statef = statef
     self._statet = statet
     self._time = time
     # Run until next time point, log every step
     duration = _logf[time_varf][ifirst] - time
     log = myokit.LOG_BOUND + myokit.LOG_STATE
     _logf, _logt = self.run(duration,
                             logf=log,
                             logt=log,
                             log_interval=_dt,
                             report_nan=False)
     # Reset simulation to original state
     self._statef = old_statef
     self._statet = old_statet
     self._time = old_time
     # Return new logs
     return _logf, _logt
コード例 #2
0
 def relog(_log, _dt):
     # Get first occurence of error
     ifirst, kfirst = find_error_position(_log)
     if kfirst is None:
         raise myokit.FindNanError('Error condition not found in log.')
     if ifirst == 0:
         raise myokit.FindNanError(
             'Unable to work with simulation logs where the error'
             ' condition is met in the very first data point.')
     # Position to start deep search at
     istart = ifirst - 1
     # Get last logged state before error
     state = []
     for dims in myokit.dimco(*self._dims):
         pre = '.'.join([str(x) for x in dims]) + '.'
         for s in self._model.states():
             state.append(_log[pre + s.qname()][istart])
     # Get last time before error
     time = _log[time_var][istart]
     # Save current state & time
     old_state = self._state
     old_time = self._time
     self._state = state
     self._time = time
     # Run until next time point, log every step
     duration = _log[time_var][ifirst] - time
     _log = self.run(duration,
                     log=myokit.LOG_BOUND + myokit.LOG_STATE,
                     log_interval=_dt,
                     report_nan=False)
     # Reset simulation to original state
     self._state = old_state
     self._time = old_time
     # Return new log
     return _log
コード例 #3
0
 def find_error_position(_log):
     # Find first occurence of out-of-bounds error
     ifirst = None
     kfirst = None
     post = '.' + watch_var.qname()
     lower, upper = safe_range
     for dims in myokit.dimco(*self._dims):
         key = '.'.join([str(x) for x in dims]) + post
         ar = np.array(_log[key], copy=False)
         i = np.where((ar < lower) | (ar > upper) | np.isnan(ar)
                      | np.isinf(ar))[0]
         if len(i) > 0:
             i = i[0]
             if ifirst is None:
                 kfirst = key
                 ifirst = i
             elif i < ifirst:
                 kfirst = key
                 ifirst = i
             if i == 0:
                 break
     return ifirst, kfirst