Tools¶
tools
¶
Utility functions for file handling, log parsing, and data processing.
read_log_time
¶
Read a log file and find the line containing the given keyphrase. Return the timestamp extracted from this line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keyphrase
|
str
|
The string to search in the log file. |
required |
logfile
|
str or Path
|
Path to the log file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tstart |
datetime or None
|
The timestamp extracted from the log file, or None if not found. |
date |
date or None
|
The date (YYYY-MM-DD) extracted from the log file, or None if not found. |
Source code in pils/utils/tools.py
read_alvium_log_time
¶
Read Alvium camera log file and extract timestamps and frame numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keyphrase
|
str
|
The string to search in the log file (e.g., "Saving frame"). |
required |
logfile
|
str or Path
|
Path to the log file. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns 'timestamp' (Float64) and 'frame_num' (Int64). Returns empty DataFrame if no matches found. |
Source code in pils/utils/tools.py
drop_nan_and_zero_cols
¶
Drop any columns in the given DataFrame that consist entirely of NaN or zero values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame to be cleaned. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
df |
DataFrame
|
DataFrame with any columns consisting of entirely NaN or zero values removed. |
Source code in pils/utils/tools.py
get_path_from_keyword
¶
Find file(s) in directory tree matching a keyword.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dirpath
|
str or Path
|
Directory to search in. |
required |
keyword
|
str
|
Filename keyword to match. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
paths |
str, list of str, or None
|
Single path if one match, list of paths if multiple, None if no matches. |
Source code in pils/utils/tools.py
is_ascii_file
¶
Check if a given file is written in ASCII.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_bytes
|
bytes
|
Bytes from the file to be checked. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
is_ascii |
bool
|
True if the file is written in ASCII, False otherwise. |
Source code in pils/utils/tools.py
get_logpath_from_datapath
¶
Given a sensor or camera file path, return the *_file.log in the aux folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datapath
|
str or Path
|
Path to sensor or camera data file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logpath |
Path
|
Path to the log file. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no log file found in parent directory. |
FileExistsError
|
If multiple log files found. |