oasislmf.pytools.kat.manager¶
Attributes¶
Functions¶
|
Check file path extensions are all identical |
|
Find and check csv files for consistent and present headers |
|
Checks headers found in csv file matches excpected headers for file type |
|
Search for index of headers_to_search in headers of csv file |
|
Concats CSV files in order they are passed in. |
|
Concats CSV files in order determined by the header_idxs and sort_fn |
|
Concats Binary files in order they are passed in. |
|
Merge sorted chunks using a k-way merge algorithm |
|
Merge sorted chunks using a k-way merge algorithm |
|
Concats Binary files in order determined out_type and their respective merge functions |
|
Concats Parquet files in order they are passed in. |
|
Merge sorted chunks using a k-way merge algorithm |
|
Concats Parquet files in order determined out_type and their respective merge functions |
|
Concatenate output files (optionally sorted) |
|
Module Contents¶
- oasislmf.pytools.kat.manager.check_file_extensions(file_paths)[source]¶
Check file path extensions are all identical
- Parameters:
file_paths (List[str | os.PathLike]) – List of csv file paths.
- Returns:
file extension as a str
- Return type:
ext (str)
- oasislmf.pytools.kat.manager.find_csv_with_header(stack, file_paths)[source]¶
Find and check csv files for consistent and present headers
- Parameters:
stack (ExitStack) – Exit Stack.
file_paths (List[str | os.PathLike]) – List of csv file paths.
- Returns:
Bool list of files with header present header (str): Header to write
- Return type:
files_with_header (List[bool])
- oasislmf.pytools.kat.manager.check_correct_headers(headers, file_type)[source]¶
Checks headers found in csv file matches excpected headers for file type
- oasislmf.pytools.kat.manager.get_header_idxs(headers, headers_to_search)[source]¶
Search for index of headers_to_search in headers of csv file
- oasislmf.pytools.kat.manager.csv_concat_unsorted(stack, file_paths, files_with_header, headers, out_file)[source]¶
Concats CSV files in order they are passed in.
- Parameters:
stack (ExitStack) – Exit Stack.
file_paths (List[str | os.PathLike]) – List of csv file paths.
files_with_header (List[bool]) – Bool list of files with header present
headers (List[str]) – Headers to write
out_file (str | os.PathLike) – Output Concatenated CSV file.
- oasislmf.pytools.kat.manager.csv_concat_sort_by_headers(stack, file_paths, files_with_header, headers, header_idxs, sort_fn, out_file, **sort_kwargs)[source]¶
Concats CSV files in order determined by the header_idxs and sort_fn
- Parameters:
stack (ExitStack) – Exit Stack.
file_paths (List[str | os.PathLike]) – List of csv file paths.
files_with_header (List[bool]) – Bool list of files with header present
headers (List[str]) – Headers to write
header_idxs (List[int]) – Indices of headers to sort by
sort_fn (Callable[[List[int]], Any]) – Sort function to apply to header_idxs
out_file (str | os.PathLike) – Output Concatenated CSV file.
**sort_kwargs – additional keyword arguments passed to sort_fn
- oasislmf.pytools.kat.manager.bin_concat_unsorted(stack, file_paths, out_file)[source]¶
Concats Binary files in order they are passed in.
- Parameters:
stack (ExitStack) – Exit Stack.
file_paths (List[str | os.PathLike]) – List of bin file paths.
out_file (str | os.PathLike) – Output Concatenated Binary file.
- oasislmf.pytools.kat.manager.merge_elt_data(memmaps)[source]¶
Merge sorted chunks using a k-way merge algorithm
- Parameters:
memmaps (List[np.memmap]) – List of temporary file memmaps
- Yields:
buffer (ndarray) – yields sorted buffer from memmaps
- oasislmf.pytools.kat.manager.merge_plt_data(memmaps)[source]¶
Merge sorted chunks using a k-way merge algorithm
- Parameters:
memmaps (List[np.memmap]) – List of temporary file memmaps
- Yields:
buffer (ndarray) – yields sorted buffer from memmaps
- oasislmf.pytools.kat.manager.bin_concat_sort_by_headers(stack, file_paths, file_type, out_type, out_file)[source]¶
Concats Binary files in order determined out_type and their respective merge functions
- Parameters:
stack (ExitStack) – Exit Stack.
file_paths (List[str | os.PathLike]) – List of bin file paths.
file_type (int) – File type int matching KAT_NAMES index
out_type (str) – Out type str between “elt” and “plt”
out_file (str | os.PathLike) – Output Concatenated Binary file.
- oasislmf.pytools.kat.manager.parquet_concat_unsorted(file_paths, out_file)[source]¶
Concats Parquet files in order they are passed in.
- Parameters:
file_paths (List[str | os.PathLike]) – List of parquet file paths.
out_file (str | os.PathLike) – Output Concatenated Parquet file.
- oasislmf.pytools.kat.manager.parquet_kway_merge(file_paths, keys, chunk_size=100000)[source]¶
Merge sorted chunks using a k-way merge algorithm
- Parameters:
file_paths (List[str | os.PathLike]) – List of parquet file paths.
keys (List[str]) – List of keys to sort by
chunk_size (int) – Chunk size for reading parquet files. Defaults to 100000.
- Yields:
buffer (pa.Table) – yields sorted pyarrow table from input files
- oasislmf.pytools.kat.manager.parquet_concat_sorted(file_paths, out_type, out_file, chunk_size=100000)[source]¶
Concats Parquet files in order determined out_type and their respective merge functions
- Parameters:
file_paths (List[str | os.PathLike]) – List of parquet file paths.
out_type (str) – Out type str between “elt” and “plt”
out_file (str | os.PathLike) – Output Concatenated Parquet file.
chunk_size (int) – Chunk size for reading parquet files. Defaults to 100000.
- oasislmf.pytools.kat.manager.run(out_file, file_type=None, files_in=None, dir_in=None, concatenate_selt=False, concatenate_melt=False, concatenate_qelt=False, concatenate_splt=False, concatenate_mplt=False, concatenate_qplt=False, unsorted=False)[source]¶
Concatenate output files (optionally sorted)
- Parameters:
out_file (str | os.PathLike) – Output Concatenated file.
file_type (str, optional) – Input file type suffix, if not discernible from input files. Defaults to None.
files_in (List[str | os.PathLike], optional) – Individual file paths to concatenate. Defaults to None.
dir_in (str | os.PathLike, optional) – Path to the directory containing files for concatenation. Defaults to None.
concatenate_selt (bool, optional) – Concatenate SELT file. Defaults to False.
concatenate_melt (bool, optional) – Concatenate MELT file. Defaults to False.
concatenate_qelt (bool, optional) – Concatenate QELT file. Defaults to False.
concatenate_splt (bool, optional) – Concatenate SPLT file. Defaults to False.
concatenate_mplt (bool, optional) – Concatenate MPLT file. Defaults to False.
concatenate_qplt (bool, optional) – Concatenate QPLT file. Defaults to False.
unsorted (bool, optional) – Do not sort by event/period ID. Defaults to False.