ParticleDetection.utils.data_conversions
Collection of function to convert between different file formats used over the course of the particle detection project, e.g. camera calibrations from MATLAB to the now used json-format.
Authors: Adrian Niemann (adrian.niemann@ovgu.de)
Date: 02.11.2022
- convert_txt_config(folder: Path)[source]
Convert camera calibrations from MATLAB’s
*.txt/*.matto*.jsonformat.This function converts a stereo camera calibration saved by MATLAB to
*.txtand*.matfiles into the*.jsonformat used by functions in this package.The resulting files are saved as
converted.jsonandworld_transformations_converted.json.- Parameters:
folder (Path) –
Folder containing the stereo calibration output, consisting of the following files:
c.txt,f.txt,c2.txt,f2.txt,kc.txt,kc2.txt,R.txt,transvek.txt,transformations.mat
- csv_combine(input_files: List[str], output_file: str = 'rods_df.csv') str[source]
Concatenates multiple
*.csvfiles to a single one.The given input files are combined into a single one. The function does not distinguish what data it is given and might fail, if it is not rod position data in all given files. The function does NOT check for duplicates.
- Parameters:
input_files (List[str]) –
*.csvfiles that contains rod position data.output_file (str, optional) – Path to the output file. If this is just a file name without a path, the parent directory of the first input file is taken as the intended file location. By default
"rods_df.csv".
- Returns:
str – Path to the written, combined file. The string is empty, if nothing has been written.
- csv_extract_colors(input_file: str) List[str][source]
Extract the rod position data into one file per color.
This functions saves a new file for each color that is present in the given data. The original file name is thereby extended by the name of the respective color, i.e.
old_name_foundcolor.csv.- Parameters:
input_file (str) –
*.csvfile that contains rod position data for multiple colors, i.e. has a column"color".- Returns:
List[str] – Returns a list of paths to the files, that were written.
- csv_split_by_frames(input_file: str, cut_frames: List[int]) List[str][source]
Splits the rod data at the given frames.
Splits the given
*.csvfile into individual files at the given frame numbers.Example:
The data has frames from 0 to 33.
cut_frames = [15, 20, 25]->
out_0_14.csv,out_15_19.csv,out_20_24.csv,out_25_33.csv- Parameters:
input_file (str) – Path to a
*.csv filecontaining rod position data.cut_frames (List[int]) – Frames at which to partition the data. All frames in the original data are perserved. The lower bound is inclusive, while the upper bound is exclusive.
- Returns:
List[str] – List of paths to the written files. This list is empty, if no files were written.
- txt2mat(input_folder: Path, frames: Iterable[int], expected_rods: int, cam1_id: str = 'gp1', cam2_id: str = 'gp2', output_folder: Path | None = None) None[source]
Read rod position data in old
*.txtformat and save it in*.matformat.Converts the rod positions from the
*.txtformat to*.matformat assuming, that only one color is saved in the given input folder. The converted files are then saved to two subfolders of the output folder, named aftercam1_idandcam2_id.- Parameters:
input_folder (Path) – Folder containing the 3D data in txt-files of format:
{frame:05d}.txtframes (Iterable[int]) – Frame numbers found in the input folder and intended to be converted.
expected_rods (int) – Number of rods to expect in one frame.
cam1_id (str, optional) – First camera’s identifier in the given dataset. By default
"gp1".cam2_id (str, optional) – Second camera’s identifier in the given dataset. By default
"gp2".output_folder (Path, optional) – Parent folder of the two output folders. By default set to the parent folder of the input folder.