src.amarium package
Submodules
src.amarium.checks module
Module to provide sanity checks for user inputs and other routine quality checks during execution.
- author:
Julian M. Kleber
- src.amarium.checks.check_delete_dir(dir_name: str) None[source]
The check_delete_dir function checks if a directory exists and deletes it.
- Parameters:
dir_name – str: Used to Specify the directory name.
- Returns:
None. :doc-author: Julian M. Kleber
- src.amarium.checks.check_header_and_data(data: List[Any], header: List[Any]) None[source]
The check_header_and_data function checks that the length of the data and header lists are equal. If they are not, it raises a RuntimeError with an appropriate message.
- Parameters:
data – List[Any]: Used to Pass in the data to be written.
header – List[Any]: Used to Ensure that the header and data have the same number of fields.
- Returns:
A boolean value. :doc-author: Julian M. Kleber
- src.amarium.checks.check_make_dir(dir_name: str) None[source]
The check_make_dir function checks if a directory exists. If it does not exist, the function creates it.
- Parameters:
dir_name – str: Used to Specify the folder name.
- Returns:
None. :doc-author: Trelent
- src.amarium.checks.check_make_file_name_suffix(file_name: str, suffix: str = '') str[source]
The check_name_plot function checks that the file_name ends with .png. If it does not, then check_name_plot appends .png to the end of the file_name.
- Parameters:
file_name – Used to Specify the name of the file to be plotted.
- Returns:
The file_name with the correct file extension. :doc- author: Trelent
src.amarium.csv_utils module
src.amarium.encryption module
Module for encryption of files. Useful for all kinds of situtations.
- author:
Julian M. Kleber
- src.amarium.encryption.decrypt_file(encrypted_file: str, private_key_path: str)[source]
The decrypt_file function takes in an encrypted file and a private key, then decrypts the file using the private key.
- Parameters:
encrypted_file – str: Used to Pass the file name of the encrypted file to be decrypted.
private_key – str: Used to Read the private key file and decrypt the encrypted message.
- Returns:
The original message. :doc-author: Julian M. Kleber
- src.amarium.encryption.encrypt_file(file_name: str, public_key_file: str, in_place: bool = False, save_file: str | None = None) None[source]
The encrypt_file function takes a file name, public key, and optional in-place flag. It then encrypts the contents of the file using the provided public key. If in_place is True, it will overwrite the original file with its encrypted version. Otherwise it will create a new encrypted version of that file.
- Parameters:
file_name:str – Used to Specify the name of the file to be
encrypted. :param public_key:str: Used to Specify the name of the public key file. :param in_place:bool=False: Used to Determine whether the file should be overwritten or not. :param save_ file:Optional[str]=None:
- param file_name:
str: Used to Specify the name of the file to be
encrypted. :param public_key: str: Used to Specify the name of the public key file. :param in_place: bool=False: Used to Determine whether the file should be overwritten or not. :param save_ file:Optional[str]=None: :param file_name: str: Used to Specify the name of the file to be
encrypted.
- Parameters:
public_key – str: Used to Specify the name of the public key file.
in_place – bool=False: Used to Determine whether the file should be overwritten or not. :param save_ file:Optional[str]=None:
file_name – str: Used to Specify the name of the file to be encrypted.
public_key – str: Used to Specify the name of the public key file.
in_place – bool=False: Used to Determine whether the file should be overwritten or not. :param save_ file:Optional[str]=None:
file_name – str: Used to Specify the name of the file to be encrypted.
public_key – str: Used to Specify the name of the public key file.
in_place – bool=False: Used to Determine whether the file should be overwritten or not.
save_file – Optional[str]=None: Used to Allow the user to specify a file name for saving the encrypted file.
- Returns:
None. :doc-author: Julian M. Kleber
- src.amarium.encryption.generate_asymmetric_keys(key_size: int, private_key_name: str, public_key_name: str, write_secret: bool) Tuple[bytes, bytes][source]
The generate_asymmetric_keys function generates a private key and public key pair. The keys are generated using the RSA algorithm with a specified bit size. The keys are then written to files in PEM format.
- Parameters:
key_size – int: Used to specify the size of the key that will be generated.
private_key_name – str: Used to Name the private key file.
public_key_name – str: Used to specify the name of the public key file.
- Returns:
The private and public keys. :doc-author: Julian M. Kleber
src.amarium.utils module
Collection of utitly functions for file I/O operations. The purpose is especially for scientific computing, thus numpy is involved in some functions. Copyright (C) 2022 Julian M. Kleber This program comes with ABSOLUTELY NO WARRANTY.”.
author: Julian M. Kleber
- src.amarium.utils.attach_slash(raw_string: str) str[source]
The attach_slash function takes a string as input and returns the same string with a slash appended to it. If the input already ends in a slash, then no change is made.
- Parameters:
raw_string – str: Used to Specify the type of data that is being passed into the function.
- Returns:
A string with a trailing slash. :doc-author: Julian M. Kleber
- src.amarium.utils.b64encode_string(input: str) str[source]
enocdes string to b64. Useful for APIs
- Parameters:
input (str) – string to be encoded
- Returns:
encoded input string
- Return type:
str
- src.amarium.utils.combine_dirs(dir_1: str, dir_2: str) str[source]
The combine dirs function chains two dir names
- Parameters:
dir_1 – str: Param for first dir
dir_2 – str: Param for second dir
- Returns:
A string with a trailing slash. :doc-author: Julian M. Kleber
- src.amarium.utils.convert_str_to_bool(bool_str: str) None[source]
The convert_str_to_bool function takes a string and converts it to a boolean. The function is used in the main() function to convert the override value from a string to a boolean.
- Parameters:
bool_str – str: Used to Specify the type of data that will be passed into the function.
- Returns:
None. :doc-author: Julian M. Kleber
- src.amarium.utils.copy_dir(old_dir: str, new_dir: str, overwrite=True) None[source]
The copy_dir function takes two arguments, old_dir and new_dir. It copies all files from the old directory to the new directory. If either of these directories do not end with a “/”, it will be added.
- Parameters:
old_dir – str: Used to Specify the directory that you want to copy from.
new_dir – str: Used to Specify the new directory that you want to copy your files into.
- Returns:
None. :doc-author: Julian M. Kleber
- src.amarium.utils.copy_file(file_name: str, destination: str, overwrite: bool = False) None[source]
Function to copy a file with implemented checks and overwriting functionality.
- Param:
file_name: str: specify the file to be copied
- Param:
destination: str: specify the destination file name (not directory)
- Param:
overwrite: bool: Defaults to false. :author: Julian M. Kleber
- src.amarium.utils.delete_all_files_in_dir(dir_name: str) None[source]
The function deletes all files within the specified directory.
- Parameters:
dir_name – str: Used to specify the directory
file_name – str=””: Used to specify the name of the file.
suffix – str=”.out”: Used to specify the file extension.
- Returns:
None :suffix: :doc-author: Julian M. Kleber
- src.amarium.utils.delete_empty_dir(dir_name: str) None[source]
The delete_dir function deletes an empty directory.
- Parameters:
file_name – str: Used to Specify the name of the file that will be deleted.
- Returns:
None. :doc-author: Julian M. Kleber
- src.amarium.utils.delete_file(file_name: str) None[source]
The delete_file function deletes a file from the local directory.
- Parameters:
file_name – str: Used to Specify the name of the file that will be deleted.
- Returns:
None. :doc-author: Julian M. Kleber
- src.amarium.utils.insert_string_in_file_name(file_name: str, insertion: str, suffix: str) str[source]
The insert_string_in_file_name function takes a file_name and inserts a string into the name. The insertion is placed before the extension of the file_name, or if there is no extension, it will be placed at the end of the file_name with an suffix specified by you.
- Parameters:
file_name – str: Used to Specify the file name that you want to insert a string into.
insertion – str: Used to Specify the string that will be inserted into the file name.
suffix – str: Used to Specify the file suffix.
- Returns:
A string. :doc-author: Julian M. Kleber
- src.amarium.utils.load_json_from_file(file_name: str) Dict[Any, Any][source]
The load_json_from_file function takes a file name as input and returns the contents of that file in JSON format.
- Parameters:
file_name – str: Used to Specify the file name of the json file to be loaded.
- Returns:
A dictionary of the data in the file. :doc-author: Julian M. Kleber
- src.amarium.utils.make_date_file_name(prefix: str = '', file_name: str = '', suffix: str = '') str[source]
The make_date_file_name function creates a file name with the date and time stamp in the format YYYY-MM-DD_HH:MM:SS.out. The prefix, file_name, and suffix are optional arguments that can be used to specify what string should precede the date stamp in the file_name (prefix), what string should be appended after the date stamp (suffix), or both (file_name). If no arguments are provided, then make_date_file_name will use default values for all three arguments.
- Parameters:
prefix – str=””: Used to ddd a prefix to the file name.
file_name – str=””: Used to specify the name of the file.
suffix – str=”.out”: Used to specify the file extension.
- Returns:
A string that is the combination of prefix, file_name and suffix. :doc-author: Julian M. Kleber
- src.amarium.utils.make_full_filename(prefix: str, file_name: str) str[source]
The make_full_filename function takes a prefix and a file_name as input. If the prefix is None, then the file_name is returned unchanged. Otherwise, if the file name starts with ‘http://’ or ‘ftp://’, then it’s assumed to be an URL and the full_filename will contain both the prefix and file_name; otherwise, only return full_filename = file_name.
- Parameters:
prefix – Used to Add a prefix to the file_name.
file_name – Used to Create a full file_name for the file to be downloaded.
- Returns:
The full file_name with the prefix added to the beginning of the file_name.
- Doc-author:
Trelent
- src.amarium.utils.prepare_file_name_saving(file_name: str, prefix: str | Type[None] | None = None, suffix: str | Type[None] | None = None) str[source]
The prepare_file_name_saving function takes a prefix and file name as input. It checks to see if the directory exists, and makes it if not. Then it returns the full path of the file.
- Parameters:
prefix – str: Used to specify the folder where the file will be saved.
file_name – str: Used to specify the name of the file to be saved.
- Returns:
The full path of the file name. :doc-author: Julian M. Kleber
- src.amarium.utils.remove_all_files_from_dir(dir: str) None[source]
Removes all files in the specified directory without deleting the directory
- Parameters:
dir (str) – Path to the directory that shall be cleared
- src.amarium.utils.save_json_to_file(dictionary: Dict[Any, Any], file_name: str) None[source]
The save_json function saves a dictionary to a json file.
- Parameters:
dictionary – Used to store the data that will be saved.
file_name – str=None: Used to specify a file name.
- Returns:
A string with the name of the file that was just created. :doc-author: Julian M. Kleber
- src.amarium.utils.search_subdirs(dir_name: str) Tuple[List[str], List[str]][source]
The search_subdirs function takes a directory name as input and returns a tuple of two lists. The first list contains all the files in the directory, including those in subdirectories. The second list contains all the subdirectories.
- Parameters:
dir_name – str: Used to Specify the directory that we want to search.
- Returns:
A tuple of two lists. :doc-author: Julian M. Kleber
- src.amarium.utils.write_tar(target_dir: str, file_name: str) None[source]
The write_tar function takes a target directory and an output name as arguments. It then creates a tar file with the given output name, and adds all files in the target directory to it.
- Parameters:
target_dir – str: Used to Specify the directory that you want to compress.
out_name – str: Used to Specify the name of the tar file that will be created.
- Returns:
None. :doc-author: Julian M. Kleber