carputils
Doxygen code documentation for the python framework controlling openCARP
Functions
carputils.model.protocols.PEERP_subroutines Namespace Reference

Functions

def stimulate_to_find_if_persistent (args, cmd_ref, job, mesh_name, simid, start_S2, stim)
 Stimulates starting at the start_S2 +300 timepoint until +1500 to see if the arrythmia is persistent. More...
 
def get_last_act_index (vm)
 Gets the time index of the last ACT. More...
 
def pacing_s1_sinus_s2_stim_point (args, cmd, job, mesh_name, simid, Stimulus sinus_elecs, start_S2, start_state_file, stim_point, tsav_state)
 Pace at first from the sinus node and then from the stimulation point after start_S2 ms. More...
 
def get_element_from_dat (dat_file, index_node)
 Gets float value for a single point in a dat file. More...
 
def get_ring_around_stim_point (args, stim_point_index, mesh_name, stim_point, tag_str)
 Generates the ring of nodes on which PEERP checks whether the S2 stimulus captured and whether an arrhythmia persists. More...
 
def get_surface_ring (mesh_name, ring_base, stim_point_index, stim_point, size, geom_type, tag_str)
 Writes the PEERP ring measured along the mesh (RING_DISTANCE 'surface', see get_ring_around_stim_point). More...
 
def read_mesh_elements (mesh_name)
 Reads an openCARP mesh ({mesh_name}.pts, {mesh_name}.elem). More...
 
def get_stimulated_nodes (pts, stim_point, stim_size, geom_type)
 Selects the nodes inside the S2 electrode the same way openCARP does (point_in_shape, nodal selection). More...
 
def distance_along_mesh (pts, elements, sources)
 Shortest distance from each node to the nearest source node along straight segments between nodes of a common element (the mesh edges; for elements with more than three nodes also their diagonals, which lie inside the element). More...
 
def update_refactory_window_bounds (M2, OptimizationTimePoints time_pts, simid, tsav_state)
 
def update_lower_bound_when_refractory (simid, float start_S2, new_offset=60)
 Updates the lower bound which happens when the simulation is refactory (Low M2). More...
 
def update_upper_bound_non_refractory (simid, float start_S2, new_offset=60)
 Updates the upper bound of the search window if the previous S2 stimuli did create a depolarizing wave (non-refractory) More...
 
def compute_apd (apd_file_name, args, job, steady_state_dir)
 
def store_init_arrhythmia_to_file (index_node, job, n_beat, simid, start_S2)
 Saves the current arrhythmia at the index_node to saved.txt and also stores the corresponding .igb file. More...
 
def get_closest_tsav_to_act (last_ACT_i, tsav_states)
 Get the closest openCARP save state to the last ACT. More...
 
def write_convergence_data (str simid, OptimizationTimePoints time_pts, int iterations, time_taken, M2, M2_mean)
 
def create_debug_csv ()
 
def define_save_states_for_stim (stim_start, times_array)
 
def store_reentry (index_node, job, n_beat, start_S2)
 
def store_non_reentry (index_node, job, n_beat, start_S2)
 
def get_id_of_stimulation_point (mesh_name, simid, stim_point)
 

Function Documentation

◆ compute_apd()

def carputils.model.protocols.PEERP_subroutines.compute_apd (   apd_file_name,
  args,
  job,
  steady_state_dir 
)

◆ create_debug_csv()

def carputils.model.protocols.PEERP_subroutines.create_debug_csv ( )

◆ define_save_states_for_stim()

def carputils.model.protocols.PEERP_subroutines.define_save_states_for_stim (   stim_start,
  times_array 
)

◆ distance_along_mesh()

def carputils.model.protocols.PEERP_subroutines.distance_along_mesh (   pts,
  elements,
  sources 
)

Shortest distance from each node to the nearest source node along straight segments between nodes of a common element (the mesh edges; for elements with more than three nodes also their diagonals, which lie inside the element).

Parameters
ptsNode coordinates (n, 3)
elementsList of (element type, connectivity, tags) as returned by read_mesh_elements
sourcesIndices of the source nodes
Returns
distance per node (n,), inf for nodes not connected to any source

◆ get_closest_tsav_to_act()

def carputils.model.protocols.PEERP_subroutines.get_closest_tsav_to_act (   last_ACT_i,
  tsav_states 
)

Get the closest openCARP save state to the last ACT.

Parameters
last_ACT_i
tsav_statesArray of tsav times :return:

◆ get_element_from_dat()

def carputils.model.protocols.PEERP_subroutines.get_element_from_dat (   dat_file,
  index_node 
)

Gets float value for a single point in a dat file.

Parameters
dat_fileCorresponding .dat file
index_nodeThe index of the node in the dat file :return:

◆ get_id_of_stimulation_point()

def carputils.model.protocols.PEERP_subroutines.get_id_of_stimulation_point (   mesh_name,
  simid,
  stim_point 
)

◆ get_last_act_index()

def carputils.model.protocols.PEERP_subroutines.get_last_act_index (   vm)

Gets the time index of the last ACT.

Parameters
vm:return:

◆ get_ring_around_stim_point()

def carputils.model.protocols.PEERP_subroutines.get_ring_around_stim_point (   args,
  stim_point_index,
  mesh_name,
  stim_point,
  tag_str 
)

Generates the ring of nodes on which PEERP checks whether the S2 stimulus captured and whether an arrhythmia persists.

The distance is chosen by get_config().RING_DISTANCE: 'euclidean': surface nodes at a straight-line distance 2*stim_size < x < 3*stim_size from the stimulation point (meshtool extract surface). 'surface': surface nodes whose distance to the nearest stimulated node, measured along the mesh, lies in (2*stim_size - r, 3*stim_size - r), where r is the electrode extent from the stimulation point (stim_size for a sphere, stim_size/2 for a box), and whose straight-line distance to every stimulated node exceeds 2*stim_size - r. In a flat sheet this is the same band as 'euclidean'. On curved or folded surfaces the straight-line ring lies further away along the surface than intended, so the wave needs longer to reach it; the along-mesh ring keeps the intended distance. The ring file is named by node and stim size, so runs with different stim sizes can share a mesh directory.

Parameters
argsHas to contain args.stim_size and optionally args.stim_geom_type (1 sphere, 2 box; default 2)
stim_point_indexThe index of the stimulation point
mesh_nameThe name of the main mesh
stim_pointThe coordinates of the stimulation point
tag_strElement tags of the atrial surface, comma separated; empty for all elements
Returns
Path of the .vtx file holding the ring nodes

◆ get_stimulated_nodes()

def carputils.model.protocols.PEERP_subroutines.get_stimulated_nodes (   pts,
  stim_point,
  stim_size,
  geom_type 
)

Selects the nodes inside the S2 electrode the same way openCARP does (point_in_shape, nodal selection).

Parameters
ptsNode coordinates (n, 3)
stim_pointCentre of the electrode
stim_sizeSphere radius (geom_type 1) or box edge length (geom_type 2)
geom_type1 sphere, 2 box
Returns
indices of the stimulated nodes and the electrode extent from the centre

◆ get_surface_ring()

def carputils.model.protocols.PEERP_subroutines.get_surface_ring (   mesh_name,
  ring_base,
  stim_point_index,
  stim_point,
  size,
  geom_type,
  tag_str 
)

Writes the PEERP ring measured along the mesh (RING_DISTANCE 'surface', see get_ring_around_stim_point).

Parameters
mesh_nameThe name of the main mesh
ring_basePath prefix of the ring file
stim_point_indexThe index of the stimulation point
stim_pointThe coordinates of the stimulation point
sizeStimulus size (sphere radius or box edge length)
geom_typeElectrode shape, 1 sphere, 2 box
tag_strElement tags of the atrial surface, comma separated; empty for all elements
Returns
Path of the .vtx file holding the ring nodes

◆ pacing_s1_sinus_s2_stim_point()

def carputils.model.protocols.PEERP_subroutines.pacing_s1_sinus_s2_stim_point (   args,
  cmd,
  job,
  mesh_name,
  simid,
Stimulus  sinus_elecs,
  start_S2,
  start_state_file,
  stim_point,
  tsav_state 
)

Pace at first from the sinus node and then from the stimulation point after start_S2 ms.

Parameters
args
cmd
job
mesh_name
simid
sinus_elecsThe sinus region defined as -stimulius[0].geometry, >sinus node id<
start_S2Start time of the S2 stimulus
start_state_file
stim_pointThe stimulation point for the S2 stimulus
tsav_stateFirst save point. Also start_S2-1 and start_S2+60 are saved :return:

◆ read_mesh_elements()

def carputils.model.protocols.PEERP_subroutines.read_mesh_elements (   mesh_name)

Reads an openCARP mesh ({mesh_name}.pts, {mesh_name}.elem).

Parameters
mesh_nameThe name of the mesh without extension
Returns
node coordinates (n, 3) and a list of (element type, connectivity (m, k), tags (m,)) per element type

◆ stimulate_to_find_if_persistent()

def carputils.model.protocols.PEERP_subroutines.stimulate_to_find_if_persistent (   args,
  cmd_ref,
  job,
  mesh_name,
  simid,
  start_S2,
  stim 
)

Stimulates starting at the start_S2 +300 timepoint until +1500 to see if the arrythmia is persistent.

Parameters
argsHas to include args.M_lump for mass lumping option
cmd_ref
jobJob object for executing on cmd
mesh_name
simidSimulation ID for openCARP
start_S2
stimStimulation parameters. Should be a stimulus without a current, to just see the result of the previous S2 stimuli :return:

◆ store_init_arrhythmia_to_file()

def carputils.model.protocols.PEERP_subroutines.store_init_arrhythmia_to_file (   index_node,
  job,
  n_beat,
  simid,
  start_S2 
)

Saves the current arrhythmia at the index_node to saved.txt and also stores the corresponding .igb file.

Parameters
index_node
job
n_beat
simid
start_S2:return:

◆ store_non_reentry()

def carputils.model.protocols.PEERP_subroutines.store_non_reentry (   index_node,
  job,
  n_beat,
  start_S2 
)

◆ store_reentry()

def carputils.model.protocols.PEERP_subroutines.store_reentry (   index_node,
  job,
  n_beat,
  start_S2 
)

◆ update_lower_bound_when_refractory()

def carputils.model.protocols.PEERP_subroutines.update_lower_bound_when_refractory (   simid,
float  start_S2,
  new_offset = 60 
)

Updates the lower bound which happens when the simulation is refactory (Low M2).

Parameters
simidMain working directoryold_file = os.path.join(str(simid), 'vm.igb')
start_S2Start of the S2 stimulus in ms
new_offsetOffset of the S2 stimulus in ms which will be stored in state_upper_bound.roe :return:

◆ update_refactory_window_bounds()

def carputils.model.protocols.PEERP_subroutines.update_refactory_window_bounds (   M2,
OptimizationTimePoints  time_pts,
  simid,
  tsav_state 
)

◆ update_upper_bound_non_refractory()

def carputils.model.protocols.PEERP_subroutines.update_upper_bound_non_refractory (   simid,
float  start_S2,
  new_offset = 60 
)

Updates the upper bound of the search window if the previous S2 stimuli did create a depolarizing wave (non-refractory)

Parameters
simidMain working directoryold_file = os.path.join(str(simid), 'vm.igb')
start_S2Start of the S2 stimulus in ms
new_offsetOffset of the S2 stimulus in ms which will be stored in state_upper_bound.roe :return:

◆ write_convergence_data()

def carputils.model.protocols.PEERP_subroutines.write_convergence_data ( str  simid,
OptimizationTimePoints  time_pts,
int  iterations,
  time_taken,
  M2,
  M2_mean 
)