Skip to content

parser

A tool for easy parsing output data from different electrode mapping systems. dgm-parser is part of the tool environment being developed for the DGM project, aimed at solving a wide range of modeling problems in cardiology.

Usage

For a more in-depth overview, please check the package documentation and examples.

Reading

For ease of use, CARTO, Rhytmia and OpenCARP all have a load(args*) function to retrieve points, triangles and scalars in one go. More specific loading functions are also available. Please check the package documentation.

Writing

Write points and scalars to the DGM LAT_p{aop}.txt file format using dgm_writer.DGMWriter.

CartoReader

CartoReader can load and parse any type of data from the CARTO mapping system.

load(filepath, cutout=True) staticmethod

Load coordinates, triangles and scalars.

Parameters:

Name Type Description Default
filepath str

The path to the mesh file.

required
cutout bool

Remove annotated cutouts or not. Defaults to True.

True

Returns:

Name Type Description
tuple tuple[ndarray, ndarray, ndarray]

A tuple containing a list of coordinates, triangle idx and scalars

load_ablation(filepath_coord, filepath_time) staticmethod

Parse exported ablation data.

Parameters:

Name Type Description Default
filepath_coord str

Filepath to the ablation coordinates file.

required
filepath_time str

Filepath to the ablation timestamps file.

required

Returns:

Type Description
DataFrame

dataframe with coordinates and timestamps of ablation points.

load_car_file(filepath, columns=None) staticmethod

Load and parse CARTO _car file.

Parameters:

Name Type Description Default
filepath str

The path to the mesh file.

required

Returns:

Type Description
DataFrame

dataframe containing point and map data.

load_map(data, map_name) staticmethod

Load map data from xml. Measured points, ppi and scar.

load_meshfile(filepath) staticmethod

Load mesh data from a file into vertices and triangles.

Parameters:

Name Type Description Default
filepath str

The path to the mesh file.

required

Returns:

Name Type Description
tuple tuple[DataFrame, DataFrame]

A tuple containing two DataFrames: - vertices: Vertex data with coordinates, normals, and group IDs. - triangles: Triangle data with vertex indices, normals, and group IDs.

load_signal(filepath, gain=1, channels=None) staticmethod

Load signal electrograms of a single point.

Parameters:

Name Type Description Default
filepath str

Path of the file to parse.

required
gain float

Raw ECG to mV converting coefficient.

1
channels dict

Channels names and columns names.

None

Returns:

Type Description
DataFrame

pd.DataFrame[N, 5]: Unipolar, Bipolar, ECG, CS. Data is sourced from

DataFrame

specified reference channels in files header, if indicated.

load_signals(root, tag, idx, gain=1, channels=None) staticmethod

Load signals for all points in the id list

Parameters:

Name Type Description Default
root str

Root folder of the exported point signal files.

required
tag str

Map name of the point signal files.

required
idx list

List of points idx.

required
gain int

Raw ECG to mV converting coefficient. Defaults to 1.

1
channels dict

Channels names and columns names.

None

load_study_file(filepath) staticmethod

load_tag_info(data) staticmethod

Get tags name, color, etc.

Parameters:

Name Type Description Default
data dict

CARTO XML data.

required

Returns:

Type Description
DataFrame

pd.DataFrame: Tags name, color, etc.

DgmReader

load_lat_file(filepath) staticmethod

Get point coordinates and LAT.

Parameters:

Name Type Description Default
filepath str

Path to the DGM point file.

required

Returns:

Type Description
DataFrame

pd.DataFrame: Point data.

DgmWriter

Writer for DGM files.

write_lat_file(points, scalars, path='') staticmethod

Write coordinates and scalars to a DGM LAT file.

Parameters:

Name Type Description Default
points Tuple

List of x, y, z coordinates.

required
scalars List

List of LAT values.

required
path str

Folder where to write output files.

''

MonoAlg3DReader

MonoAlg3DReader can load and parse any type of data made by MonoAlg3D.

get_all_variables(geometry) staticmethod

Extract names of all variables in the simulation.

Parameters:

Name Type Description Default
geometry vtk object

Geometry where the variables are found.

required

Returns:

Name Type Description
list ndarray

Array of variables.

load(filepath, tag='Vm', block_nr=0, timeset=1) staticmethod

Load coordinates, triangles and scalars.

Parameters:

Name Type Description Default
filepath str

The path to the mesh file.

required
tag str

Defaults to 'Vm'.

'Vm'
block_nr int

Defaults to 0.

0
timeset int

Defaults to 1.

1

Returns:

Name Type Description
tuple tuple[ndarray, ndarray, ndarray, ndarray]

A tuple containing a list of coordinates, element ids, scalars and voltages.

load_base_polydata(filepath) staticmethod

Loads only base geometry of the simulation.

Parameters:

Name Type Description Default
filepath str

Path to the simulation .case file.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Polydata object.

load_full_polydata(filepath, block_nr=0, timeset=1) staticmethod

Loads full polydata object with all variable arrays in all timesteps. We only pass the .case file. All other files should be present in the same folder.

Parameters:

Name Type Description Default
filepath str

Path to the simulation .case file.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Polydata object.

load_mesh(filepath) staticmethod

load_metadata(filepath) staticmethod

Load all metadata of the input case.

Parameters:

Name Type Description Default
filepath str

Filepath of the input file.

required

Returns:

Name Type Description
tuple tuple[str, str]

Tags and root name of the case.

signal_to_lat(voltages, threshold=-30, fs=100) staticmethod

OpencarpReader

OpencarpReader can load and parse any type of data from OpenCARP simulations.

load(vtk_filepath, igb_filepath, scale=1000, scar=True) staticmethod

Load coordinates, triangles and scalars.

Parameters:

Name Type Description Default
vtk_filepath str

The path to the mesh file.

required
igb_filepath str

The path to the mesh file.

required
scale int

Conversion factor to ms. Defaults to 1000.

1000
scar bool

Remove scar tissue from mesh or not. Defaults to True.

True

Returns:

Name Type Description
tuple tuple[ndarray, ndarray, ndarray]

A tuple containing a list of coordinates, triangle ids and scalars

load_elem_file(filepath, element_type='Tr') staticmethod

Load mesh elements from file.

Parameters:

Name Type Description Default
filepath str

Filepath to the input file.

required
element_type str

Mesh element type. Defaults to 'Tr'.

'Tr'

Returns:

Type Description
DataFrame

dataframe with elements data.

load_igb_file(filepath) staticmethod

Parse OpenCARP .igb file.

Parameters:

Name Type Description Default
filepath str

Filepath to the igb file.

required

Returns:

Type Description
DataFrame

np.ndarray with parsed simulation data.

load_mesh(pts_filepath, elem_filepath, scale=1000, element_type='Tr') staticmethod

Load mesh from .pts and .elem files. By defaults, elements are triangles.

Parameters:

Name Type Description Default
pts_filepath str

The path to the points file.

required
elem_filepath str

The path to the elements file.

required
scale int

Conversion factor to ms. Defaults to 1000.

1000
element_type str

Type of geometric elements of the mesh. Defaults to "Tr".

'Tr'

Returns:

Name Type Description
tuple (DataFrame, DataFrame)

Dataframes of points and triangles.

load_pts_file(filepath, scale=1) staticmethod

load_signal(signals, index, tag='unipolar') staticmethod

load_signals(igb_data, tag='unipolar') staticmethod

load_vtk_file(filepath, scale=1000) staticmethod

Load OpenCARP .vtk file.

Parameters:

Name Type Description Default
filepath str

Filepath to the vtk file.

required
scale int

Conversion factor to ms. Defaults to 1000.

1000

Returns:

Name Type Description
dict dict

Mesh data.

signal_to_lat(data, voltage=-40) staticmethod

Convert opencarp signal data to lats.

Parameters:

Name Type Description Default
data ndarray

Data from parsed igb file.

required
voltage optional

Voltage threshold. Defaults to -40.

-40

Returns:

Type Description
ndarray

lat values.

OpticalReader

OpticalReader can load optical mapping data from a .mat file and returns a PolyData mesh and LATs.

load(filepath, window_length=100, start_time=0, end_time=-1, resolution=0.375) staticmethod

Load coordinates, triangles and scalars.

Parameters:

Name Type Description Default
filepath str

The path to the mesh file.

required
window_length int

Defaults to 100.

100
start_time int

Defaults to 0.

0
end_time int

Defaults to 1.

-1
resolution float

Defaults to 0.375.

0.375

Returns:

Name Type Description
tuple tuple[ndarray, ndarray, ndarray]

A tuple containing a list of coordinates, triangle idx and scalars

load_signals(filepath) staticmethod

Loads the optical signals from a specified filename.

RhythmiaReader

RhythmiaReader can load and parse any type of data from the Rhythmia mapping system.

load(filepath, cutout=True) staticmethod

Load coordinates, triangles and scalars.

Parameters:

Name Type Description Default
filepath str

The path to the matlab file.

required
cutout bool

Remove annotated cutouts or not. Defaults to True.

True

Returns:

Name Type Description
tuple tuple[ndarray, ndarray, ndarray]

A tuple containing a list of coordinates, triangle ids and scalars

load_ablation(filepath) staticmethod

Load ablations.mat file.

Parameters:

Name Type Description Default
filepath str

Path to the ablation file

required

Returns:

Type Description
DataFrame

pd.DataFrame: Ablation points

load_mat_file(filepath) staticmethod

Load MATLAB file containing maps.

Parameters:

Name Type Description Default
filepath str

Path to the ablation file

required

Returns:

Name Type Description
dict dict

MATLAB data.

load_mesh_data(data) staticmethod

Extract mesh points and triangle point ids from matlab data. Points contains coordinates, local activation time and voltage data.

Parameters:

Name Type Description Default
data DataFrame

Parsed matlab data.

required

Returns:

Name Type Description
tuple (DataFrame, DataFrame)

Points and triangles.

load_metadata(data, keys=None) staticmethod

Load metadata from a mat file.

Parameters:

Name Type Description Default
data dict

MATLAB data containing mesh with annotations.

required
keys list

List of metadata keys to extract. Default list includes common keys.

None

Returns:

Name Type Description
dict dict

A dictionary containing the loaded metadata.

load_points_data(data) staticmethod

Extract all point data.

Parameters:

Name Type Description Default
data DataFrame

Parsed matlab data.

required

Returns:

Type Description
DataFrame

dataframe with data of points.

load_signal(data, index) staticmethod

Load signal of a specific point from matlab data.

Parameters:

Name Type Description Default
data DataFrame

Parsed matlab data.

required
index int

Index of the point.

required

Returns:

Type Description
DataFrame

dataframe with signal data.

load_signals(data, idx) staticmethod

Load signal data of multiple points.

Parameters:

Name Type Description Default
data DataFrame

Parsed matlab data.

required
idx list

Indices of the points.

required

Returns:

Type Description
DataFrame

dataframe with signal data of the requested points.