acept.acept_utils
Module containing utility functions for ACEPT
Module Contents
Functions
|
Climb directory path upwards |
Returns the absolute path to the given relative POSIX path to a file or directory (relative to /src/acept) |
|
Derives output file path for modified file from input file path |
|
Copy file or directories including subdirectories and files recursively. The copying operation will continue |
|
|
Replace a sub string of all files names in a directory |
Deletes all files with the given pattern in the given directory |
|
|
Combines all csv files with the given pattern in the given directory into a single csv file. |
|
Appends file_2 to file_1 column-wise and writes the result to the CSV file output_file. |
Key function to extract the number after the last "_" in the filename for sorting. |
- acept.acept_utils.uppath(filepath: str, n: int) str[source]
Climb directory path upwards
- Parameters:
- Returns:
Path to the directory n levels upwards
- Return type:
Example
>>> uppath("/parent/temp/dir/file.txt", 1) '/parent/temp/dir'
- acept.acept_utils.absolute_path_from_relative_posix(posix_relative_to_src_files: str) str[source]
Returns the absolute path to the given relative POSIX path to a file or directory (relative to /src/acept)
Example
>>> absolute_path_from_relative_posix("../../data/plz/plz-5stellig.shp") 'path/to/the/acept/repository/data/plz/plz-5stellig.shp'
- acept.acept_utils.derive_output_path_from_filepath(output_base: str, filename: str, file_extension, mod_filename_suffix='_mod', up=1) str[source]
Derives output file path for modified file from input file path
- Parameters:
output_base (str) – base directory path for modified files
filename (str) – path of input file
file_extension – filename extension of input file e.g. ‘.shp’
mod_filename_suffix – suffix for the modified filename before the filename extension. Default: ‘_mod’
up – path levels above file. Default: 1 = Parent directory of input file
- Returns:
output path of modified shape file
- Return type:
- acept.acept_utils.copy_file_or_directory_recursively(src_path: str, dst_path: str) str[source]
Copy file or directories including subdirectories and files recursively. The copying operation will continue if it encounters existing directories, and files within the dst tree will be overwritten by corresponding files from the src tree.
- acept.acept_utils.rename_files_in_directory(path: str, old_substring: str, new_substring: str)[source]
Replace a sub string of all files names in a directory
- acept.acept_utils.delete_files_or_directory_recursively_with_pattern(directory: str, pattern: str)[source]
Deletes all files with the given pattern in the given directory
- acept.acept_utils.combine_csv_profiles_with_pattern(src_directory: str, pattern: str, csv_profiles_path: str, new_header: list = None, key_function: callable = None, skip_rows: int = 0, column_name: str = None, in_delimiter: str = ';', debug: bool = False) pandas.DataFrame[source]
Combines all csv files with the given pattern in the given directory into a single csv file.
- Parameters:
src_directory (str) – Path to the directory with the csv files
pattern (str) – Filename pattern of the csv files to combine
csv_profiles_path (str) – Path to the csv file to write the combined profile to
new_header (list) – New header for the combined profile
key_function (callable) – Function to extract the number after the last “_” in the filename for sorting. If None, the files are sorted alphabetically.
skip_rows (int) – Number of rows to skip in the csv files
column_name (str) – Name of the column to extract from the csv files
in_delimiter (str) – Delimiter of the input csv files
debug (bool) – Print debug information
- Returns:
Combined profile as pandas dataframe
- Return type:
- acept.acept_utils.concat_csv_profiles_columnwise(file_1: str, file_2: str, output_file: str, in_delimiter_1: str = ';', in_delimiter_2: str = ';', out_delimiter: str = ';', add_index: bool = True)[source]
Appends file_2 to file_1 column-wise and writes the result to the CSV file output_file.
- Parameters:
file_1 (str) – Path to the first csv file
file_2 (str) – Path to the second csv file
output_file (str) – Path to the output csv file
in_delimiter_1 (str) – Delimiter of the first csv file
in_delimiter_2 (str) – Delimiter of the second csv file
out_delimiter (str) – Delimiter of the output csv file
add_index (bool) – Add an index to the output csv file