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)#
```ignore Convert CSV file to a HDF5 file.
- Parameters:
- filename
str
Path to the CSV file
- outname
str
Name of the output HDF5 file
- columns
list
[int
], optional List of columns to convert containing t,x,y,z,(optional vx,vy,vz), by default [0,1,2,3]
- delimiter
str
, optional Pattern for separating numbers in a csv file, by default ‘,’
- headerbool, optional
True if the CSV file contains a header, by default True
- comment
str
, 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
- radius
float
, optional Particle radius, by default 0.0
- sampling_steps
int
, optional Number of sampling steps for the savitzky-golay filter to calculate the velocity, by default 9
- filename
- Returns:
- static csv_multi(filename, outname, columns=..., delimiter='","', header=True, comment='"#"', vel=False, interpolate=False, radius=0.0, method='"id_line"')#
```ignore 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 particleis 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 andtheir 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:
- filename
str
Path to the CSV file
- outname
str
Name of the output HDF5 file
- columns
list
[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
- comment
str
, 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
- radius
float
, optional Radius of the particle, by default 0.0
- method
str
, 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 particleis 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 andtheir time column. The
columns
argument must contain the id column as the first element.
, by default chain
- filename
- 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:
- filenames
str
Path to the CSV files
- outname
str
Name of the output HDF5 file
- columns
list
[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
- comment
str
, 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
- radius
float
, optional Radius of the particle
- filenames
- 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:
- filenames
list
[str
] List of VTK files to convert, the list must be ordered by time and filenames must contain the timestep.
- timestep
float
Time between two timesteps.
- outname
str
Name of the output HDF5 file.
- filter
str
, 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_name
str
, optional Name of the velocity field in the vtk files, by default “v”.
- radius_field_name
str
, optional Name of the radius field in the vtk files, by default “radius”.
- id_field_name
str
, optional Name of the id field in the vtk files, by default “id”.
- type_field_name
str
, optional Name of the type field in the vtk files, by default “type”.
- diameter_field_name
str
, optional Name of the diameter field in the vtk files, by default None.
- filenames
- Returns:
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:
- folder
str
Path to the folder containing the VTK files Folder must only contain one type of vtk files
- timestep
float
Time between two timesteps
- outname
str
Name of the output HDF5 file
- filter
str
, optional Regex Filter to apply to the data in order to extract the time for each file, by default r”(d+).vtk”
- velocity_field_name
str
, optional Name of the velocity field in the vtk files, by default “v”
- radius_field_name
str
, optional Name of the radius field in the vtk files, by default “radius”
- id_field_name
str
, optional Name of the id field in the vtk files, by default “id”
- type_field_name
str
, optional Name of the type field in the vtk files, by default “type”
- diameter_field_name
str
, optional Name of the diameter field in the vtk files, by default None
- folder
- Returns:
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", >>> )