Binary File Class¶
- class data_classes.BinaryFile.BinaryFile(file_dir)
Bases:
File,TypeMixinRepresents a binary file and provides functionality to read and convert the binary data into a Pandas DataFrame.
- Parameters:
file_dir (str) – The directory of the binary file.
- binary_file_2_df(column_names, num_columns, num_rows=-1, size_byte=3, byte_order='big', signed=True)
Reads a binary file, converts it to integers, and stores the data in a Pandas DataFrame.
- Parameters:
column_names (list of str) – Names of the columns in the resulting DataFrame.
num_columns (int) – Number of columns in the DataFrame.
num_rows (int, optional) – Number of rows in the DataFrame. Defaults to -1, which infers the number of rows based on the data size.
size_byte (int, optional) – Number of bytes to read at once for each value. Defaults to 3.
byte_order (str, optional) – Byte order for reading binary data (‘big’ or ‘little’). Defaults to ‘big’.
signed (bool, optional) – Whether the integers are signed or unsigned. Defaults to True.
- Returns:
DataFrame containing the binary data converted to integers.
- Return type:
pd.DataFrame
Notes
The binary data is read and then converted into integers, which are arranged in a matrix format. The resulting matrix is used to create a Pandas DataFrame.
The byte order indicates the order in which the bytes are stored in memory. For PFFP binary files, the typical order is ‘big’.
- read_binary(size_byte=3)
Reads a binary file and stores the data in a list.
- Parameters:
size_byte (int, optional) – Number of bytes to read at a time. Defaults to 3, which is typical for PFFP binary files.
- Returns:
List containing chunks of binary data read from the file.
- Return type:
list of bytes
Notes
This method reads the binary data chunk by chunk, based on the specified byte size, until the end of the file is reached.