|
4 | 4 | from ..orientations import OrientationsTable
|
5 | 5 |
|
6 | 6 |
|
7 |
| -def deserialize_input_data_tables(binary_array: bytes, name_id_map: dict, sp_binary_length_: int) -> tuple[OrientationsTable, SurfacePointsTable]: |
| 7 | +def deserialize_input_data_tables(binary_array: bytes, name_id_map: dict, |
| 8 | + sp_binary_length_: int, ori_binary_length_: int) -> tuple[OrientationsTable, SurfacePointsTable]: |
| 9 | + """ |
| 10 | + Deserializes binary data into two tables: OrientationsTable and SurfacePointsTable. |
| 11 | +
|
| 12 | + This function takes a binary array, a mapping of names to IDs, and lengths for |
| 13 | + specific parts of the binary data to extract and deserialize two distinct data |
| 14 | + tables: OrientationsTable and SurfacePointsTable. It uses the provided lengths |
| 15 | + to split the binary data accordingly and reconstructs the table contents from |
| 16 | + their respective binary representations. |
| 17 | +
|
| 18 | + Args: |
| 19 | + binary_array (bytes): A bytes array containing the serialized data for |
| 20 | + both the OrientationsTable and SurfacePointsTable. |
| 21 | + name_id_map (dict): A dictionary mapping names to IDs which is used to |
| 22 | + help reconstruct the table objects. |
| 23 | + sp_binary_length_ (int): The length of the binary segment corresponding |
| 24 | + to the SurfacePointsTable data. |
| 25 | + ori_binary_length_ (int): The length of the binary segment corresponding |
| 26 | + to the OrientationsTable data. |
| 27 | +
|
| 28 | + Returns: |
| 29 | + tuple[OrientationsTable, SurfacePointsTable]: A tuple containing two table |
| 30 | + objects: first the OrientationsTable, and second the SurfacePointsTable. |
| 31 | + """ |
8 | 32 | sp_binary = binary_array[:sp_binary_length_]
|
9 |
| - ori_binary = binary_array[sp_binary_length_:] |
| 33 | + ori_binary = binary_array[sp_binary_length_:sp_binary_length_+ori_binary_length_] |
10 | 34 | # Reconstruct arrays
|
11 | 35 | sp_data: np.ndarray = np.frombuffer(sp_binary, dtype=SurfacePointsTable.dt)
|
12 | 36 | ori_data: np.ndarray = np.frombuffer(ori_binary, dtype=OrientationsTable.dt)
|
13 | 37 | surface_points_table = SurfacePointsTable(data=sp_data, name_id_map=name_id_map)
|
14 | 38 | orientations_table = OrientationsTable(data=ori_data, name_id_map=name_id_map)
|
15 | 39 | return orientations_table, surface_points_table
|
| 40 | + |
| 41 | + |
| 42 | +def deserialize_grid(binary_array:bytes, custom_grid_length: int, topography_length: int) -> tuple[np.ndarray, np.ndarray]: |
| 43 | + """ |
| 44 | + Deserialize binary grid data into two numpy arrays. |
| 45 | +
|
| 46 | + This function takes a binary array representing a grid and splits it into two separate |
| 47 | + numpy arrays: one for the custom grid and one for the topography. The binary array is |
| 48 | + segmented based on the provided lengths for the custom grid and topography. |
| 49 | +
|
| 50 | + Args: |
| 51 | + binary_array: The binary data representing the combined custom grid and topography data. |
| 52 | + custom_grid_length: The length of the custom grid data segment in bytes. |
| 53 | + topography_length: The length of the topography data segment in bytes. |
| 54 | +
|
| 55 | + Returns: |
| 56 | + A tuple where the first element is a numpy array representing the custom grid, and |
| 57 | + the second element is a numpy array representing the topography data. |
| 58 | +
|
| 59 | + Raises: |
| 60 | + ValueError: If input lengths do not match the specified boundaries or binary data. |
| 61 | + """ |
| 62 | + |
| 63 | + total_length = len(binary_array) |
| 64 | + custom_grid_start = total_length - custom_grid_length - topography_length |
| 65 | + custom_grid_end = total_length - topography_length |
| 66 | + |
| 67 | + topography_grid_start = total_length - topography_length |
| 68 | + topography_grid_end = total_length |
| 69 | + |
| 70 | + custom_grid_binary = binary_array[custom_grid_start:custom_grid_end] |
| 71 | + topography_binary = binary_array[topography_grid_start:topography_grid_end] |
| 72 | + custom_grid = np.frombuffer(custom_grid_binary) |
| 73 | + topography = np.frombuffer(topography_binary) |
| 74 | + |
| 75 | + |
| 76 | + return custom_grid, topography |
0 commit comments