upxo.interfaces.os.osops module
- upxo.interfaces.os.osops.get_file_path(target_file_name=None)[source]
its subdirectories.
Parameters: - root_dir_path (str): The path to the directory where the search should start. It should be an absolute path. - target_file_name (str): The name of the file to search for, including the extension.
Returns: - str: The full path to the found file if the file exists within the directory tree; otherwise, None.
This function walks through all directories and subdirectories starting from root_dir_path, searching for target_file. If the file is found, the function immediately returns the full path to the file. If the search completes without finding the file, the function returns None.
Example
- get_file_path(search_for_file=True,
target_file_name=’_ctf_header_CuCrZr_1.txt’)
- upxo.interfaces.os.osops.get_path_UPXODIR_L1(dirname='src')[source]
- Permitted options for dirname are currently:
data
demos
dev_scripts
docs
external_contributions
gallery
logs
profiling
src
tests
tutorials
- upxo.interfaces.os.osops.load_file(valobj, folder_path, file_name_with_ext, datatype='string', encoding='utf-8', loadas='line_by_line', datatype_return='default', isCTFheader=False, isCTF=False, isCRC=False, isEAlist=False, seperator_inline='tab', validate_before=True)[source]
Load a text file
- Parameters:
valobj – upxo validation class instance
folder_path – COmplete path to the directory having the file
file_name_with_ext – Complete filenamre with the extension
datatype – Tyepe of data in the text file
encoding – Encoding to use while reading the file contents
loadas –
Specifies how the data is to be loaded or read. Options include:
line_by_line— data is read line by line; each line becomes an element of a list.
datatype_return –
Specifies if thw read data is to be converted into any other format before being returned to the calling function scope. Options:
'default'— no conversion.'np'— validated as numeric and converted to a numpy array.'numlist'— validated as numeric and converted to a list.
isCTFheader – Specifies whether the file being read is a CTF header file
isCTF – Specifies whether the file being read is a EBSD CTF file. If True, returned will be a dictionary having keys ‘header’ and ‘values’
isCRC – Specifies whether the file being read is a EBSD CRC file. If True, returned will be a dictionary having keys ‘header’ and ‘values’
seperator_inline – Specifies the seperator in a line. If ‘default’, none will be specified
validate_before – Specifies whether path and filenames should be validated beforehand.
Examples
from upxo._sup.validation_values import _validation from upxo.interfaces.os.osops import load_file
valobj = _validation() folder_path = get_path_UPXOsrcDIR() file_name_with_ext = ‘_ctf_header_CuCrZr_1.txt’ get_file_path(target_file_name=file_name_with_ext)
- load_file(valobj,
folder_path=None, file_name_with_ext=None, datatype=’string’, encoding=’utf-8’, loadas=’line_by_line’, datatype_return=’default’, isCTFheader=False, isCTF=False, isCRC=False, seperator_inline=’default’, validate_before=True)
- upxo.interfaces.os.osops.load_files(folder_path=None, locinfo='defloc', fileContent='ctf_header', filename_full='_ctf_header_CuCrZr_1.txt', prefix_string='UPXO_mcgs_CTF_slice_', suffix_start=0, suffix_incr=1, suffix_end=49, ext='.txt', encoding='utf-8', readMode='line_by_line')[source]
Load un-encrypted text, data, and HDF5 files.
Supports
.txt,.dat,.ctf,.crc,.h5df,.dream3d.Examples
Load a CTF file header:
data = load_files(locinfo='defloc', fileContent='ctf_header', filename_full='_ctf_header_CuCrZr_1.txt')
- upxo.interfaces.os.osops.find_n_to_targetDIR(cwd: Path, target_dir_name: str) int[source]
Find the depth to reach
target_dir_namefromcwd.- Parameters:
cwd (Path) – Current working directory as a
Pathobject.target_dir_name (str) – Name of the target directory to locate.
- Returns:
Number of
cwd.parentssteps needed to reach the target.- Return type:
- Raises:
ValueError – If
target_dir_nameis not a parent ofcwd.
Examples
>>> from pathlib import Path >>> n = find_n_to_targetDIR(Path('C:/proj/src/upxo/meshing'), 'src')
- upxo.interfaces.os.osops.error_handler(func)[source]
Decorator to handle exceptions and log file operations.
- upxo.interfaces.os.osops.data_importer(func)[source]
Decorator to abstract the data importing functionality.
- upxo.interfaces.os.osops.data_exporter(func)[source]
Decorator to abstract the data exporting functionality.