Converter#

class up4.Converter#

Bases: object

Convert particle data from a given format to HDF5 (H5Part-like).

Methods

vtk:

Convert VTK file to a HDF5 file

vtk_from_folder:

Convert all VTK files in a folder to a HDF5 file

csv:

Convert CSV file to a HDF5 file

static csv(filename, outname, columns=..., delimiter=',', header=True, comment='#', vel=False, interpolate=False, radius=0.0, sampling_steps=9)#

Convert CSV file to a HDF5 file.

Parameters:
filenamestr

Path to the CSV file

outnamestr

Name of the output HDF5 file

columnslist[int], optional

List of columns to convert containing t,x,y,z,(optional vx,vy,vz), by default [0,1,2,3]

delimiterstr, optional

Pattern for separating numbers in a csv file, by default ‘,’

headerbool, optional

True if the CSV file contains a header, by default True

commentstr, optional

Comment character to ignore, by default ‘#’

velbool, optional

If true the velocity will be computed from the position using the savitzky-golay filter, by default False

interpolatebool, optional

If true the particle positions will be interpolated in order to have a constant timestep, by default False

radiusfloat, optional

Particle radius, by default 0.0

sampling_stepsint, optional

Number of sampling steps for the savitzky-golay filter to calculate the velocity, by default 9

Returns:
None
static csv_multi(filename, outname, columns=..., delimiter='","', header=True, comment='"#"', vel=False, interpolate=False, radius=0.0, method='"id_line"')#

Convert CSV file containing multiple particles into a HDF5 file.

There can be different ways how this is achieved, therefore the function takes an argument called method which can be one of the following:

  • chain: The particles are chained in the file, i.e. the first particle

    is followed by the second, the second by the third, etc. all particles are stored in one file

  • id_line: This algorithm sorts the particles by their id column and

    their time column. The columns argument must contain the id column as the first element.

no other method is implemented yet. If you want to use another method, please contact the developers.

Parameters:
filenamestr

Path to the CSV file

outnamestr

Name of the output HDF5 file

columnslist[int], optional

List of columns to convert containing t,x,y,z, (optional vx,vy,vz), by default [0,1,2,3]

headerbool, optional

True if the CSV file contains a header, by default True

commentstr, optional

Comment character to ignore, by default “#”

velbool, optional

If true the velocity will be computed from the position using the savitzky-golay filter, by default False

interpolatebool, optional

If true the particle positions will be interpolated in order to have a constant timestep, by default False

radiusfloat, optional

Radius of the particle, by default 0.0

methodstr, optional

Method to use to convert the CSV file. Can be one of the following:

  • chain: The particles are chained in the file, i.e. the first particle

    is followed by the second, the second by the third, etc. all particles are stored in one file

  • id_line: This algorithm sorts the particles by their id column and

    their time column. The columns argument must contain the id column as the first element.

, by default chain

static csv_multi_files(filenames, outname, times, columns=..., delimiter=',', header=True, comment='#', vel=False, interpolate=False, radius=0.0)#

Convert CSV file containing multiple particles into a HDF5 file.

There can be different ways how this is achieved, therefore the function takes an argument called method which can be one of the following:

  • chain: The particles are chained in the file, i.e. the first particle

    is followed by the second, the second by the third, etc. all particles are stored in one file.

  • id_line: This algorithm sorts the particles by their id column and

    their time column. The columns argument must contain the id column as the first element.

no other method is implemented yet. If you want to use another method, please contact the developers.

Parameters:
filenamesstr

Path to the CSV files

outnamestr

Name of the output HDF5 file

columnslist[int], optional

List of columns to convert containing pid,x,y,z,(optional vx,vy,vz) Default: [0,1,2,3]

headerbool, optional

True if the CSV file contains a header Default: True

commentstr, optional

Comment character to ignore Default: “#”

velbool, optional

If true the velocity will be computed from the position using the savitzky-golay filter Default: False

interpolatebool, optional

If true the particle positions will be interpolated in order to have a constant timestep Default: False

radiusfloat, optional

Radius of the particle

static vtk(filenames, timestep, outname, filter='(\\d+).vtk', velocity_field_name='v', radius_field_name='radius', id_field_name='id', type_field_name='type', diameter_field_name=None)#

Convert VTK file to a HDF5 file.

Parameters:
filenameslist[str]

List of VTK files to convert, the list must be ordered by time and filenames must contain the timestep.

timestepfloat

Time between two timesteps.

outnamestr

Name of the output HDF5 file.

filterstr, optional

Regex Filter to apply to the data in order to extract the time for each file, by default r”(d+).vtk”. up4 dispatches the correct converter based on the filter extension.

velocity_field_namestr, optional

Name of the velocity field in the vtk files, by default “v”.

radius_field_namestr, optional

Name of the radius field in the vtk files, by default “radius”.

id_field_namestr, optional

Name of the id field in the vtk files, by default “id”.

type_field_namestr, optional

Name of the type field in the vtk files, by default “type”.

diameter_field_namestr, optional

Name of the diameter field in the vtk files, by default None.

Returns:
None

Examples

Convert legacy VTK files to HDF5

>>> from up4 import Converter
>>> 
>>> Converter.vtk(
>>>     filenames=["file1.vtk", "file2.vtk"],
>>>     timestep=1e-5,
>>>     outname="output.hdf5",
>>>     filter=r"(\d+).vtk",
>>>     velocity_field_name="v",
>>>     radius_field_name="radius",
>>>     id_field_name="id",
>>>     type_field_name="type",
>>>     diameter_field_name=None,
>>> )

Convert XML VTK (unstructured grid format) files to HDF5

>>> from up4 import Converter
>>> 
>>> Converter.vtk(
>>>     filenames=["file1.vtu", "file2.vtu"],
>>>     timestep=1e-5,
>>>     outname="output.hdf5",
>>>     filter=r"(\d+).vtu",
>>>     velocity_field_name="v",
>>>     id_field_name="id",
>>>     type_field_name="type",
>>>     diameter_field_name="diameter",
>>> )
static vtk_from_folder(folder, timestep, outname, filter='(\\d+).vtk', velocity_field_name='v', radius_field_name='radius', id_field_name='id', type_field_name='type', diameter_field_name=None)#

Convert all VTK files in a folder to a HDF5 file.

Parameters:
folderstr

Path to the folder containing the VTK files Folder must only contain one type of vtk files

timestepfloat

Time between two timesteps

outnamestr

Name of the output HDF5 file

filterstr, optional

Regex Filter to apply to the data in order to extract the time for each file, by default r”(d+).vtk”

velocity_field_namestr, optional

Name of the velocity field in the vtk files, by default “v”

radius_field_namestr, optional

Name of the radius field in the vtk files, by default “radius”

id_field_namestr, optional

Name of the id field in the vtk files, by default “id”

type_field_namestr, optional

Name of the type field in the vtk files, by default “type”

diameter_field_namestr, optional

Name of the diameter field in the vtk files, by default None

Returns:
None

Examples

Convert legacy VTK files to HDF5

>>> from up4 import Converter
>>> 
>>> Converter.vtk_from_folder(
>>>     folder="folder",
>>>     timestep=1e-5,
>>>     outname="output.hdf5",
>>>     filter=r"(\d+).vtk",
>>>     velocity_field_name="v",
>>>     radius_field_name="radius",
>>>     id_field_name="id",
>>>     type_field_name="type",
>>>     diameter_field_name=None,
>>> )

Convert XML VTK (unstructured grid format) files to HDF5

>>> from up4 import Converter
>>> 
>>> Converter.vtk_from_folder(
>>>     folder="folder",
>>>     timestep=1e-5,
>>>     outname="output.hdf5",
>>>     filter=r"(\d+).vtu",
>>>     velocity_field_name="v",
>>>     id_field_name="id",
>>>     type_field_name="type",
>>>     diameter_field_name="diameter",
>>> )