Preparing
Functions to be used for preparing the experimental data for batch processing.
check_column_headers(data_dir, exception_headers=None)
Check that all files in a directory have the same column headers and that column headers don't contain spaces. A ValueError will be raised if the column headers don't match or if a column header contains a space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
str
|
Path to the directory containing the files to be checked. |
required |
exception_headers
|
List[str]
|
List of column headers that are allowed to be different between files. |
None
|
Source code in paramaterial/preparing.py
check_for_duplicate_files(data_dir)
Check that there are no duplicate files in a directory by hashing the contents of the files. A ValueError will be raised if there are duplicate files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
str
|
Path to the directory containing the files to be checked. |
required |
Source code in paramaterial/preparing.py
check_formatting(data_dir, info_path=None, skip_headers=None)
Performs various checks on the formatting of the data files and info table. Will print out formatting checks and warnings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
Union[str, DataSet]
|
Path to folder containing data files. A DataSet is also accepted, as in paramaterial 0.1.x, in which
case the 0.1.x checks are run on its data_dir ( |
required |
info_path
|
str
|
Path to info table spreadsheet. |
None
|
skip_headers
|
List[str]
|
Headers that can be different across data files. Other headers must be consistent. |
None
|
Source code in paramaterial/preparing.py
convert_gleeble_output_files_to_csv(directory_path)
Convert all files in a directory from Gleeble output format to csv format.
Source code in paramaterial/preparing.py
copy_data_and_rename_by_test_id(data_in, data_out, info_table, test_id_col='test_id')
Rename files in data directory by test_id in info table and copy to new directory. The info_table must have a column named 'old_filename' containing the original filenames and a column named 'test_id'. The new filenames will be the test_ids with the extension '.csv'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_in
|
str
|
Path to the directory containing the data to be copied. |
required |
data_out
|
str
|
Path to the directory where the data will be copied. |
required |
info_table
|
DataFrame
|
DataFrame containing the metadata for the tests. |
required |
test_id_col
|
Column in the info table containing the test_ids. |
'test_id'
|
Returns:
| Type | Description |
|---|---|
|
None |
Source code in paramaterial/preparing.py
experimental_matrix(info_table, index, columns, as_heatmap=False, title=None, xlabel=None, ylabel=None, tick_params=None, **kwargs)
Make an experimental matrix showing the distribution of test across metadata categories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info_table
|
DataFrame
|
DataFrame containing the metadata for the tests. |
required |
index
|
Union[str, List[str]]
|
Column(s) of the info_table to use as the index of the matrix. |
required |
columns
|
Union[str, List[str]]
|
Column(s) of the info_table to use as the columns of the matrix. |
required |
as_heatmap
|
bool
|
If True, return a heatmap of the matrix. If False, return the matrix as a DataFrame. |
False
|
title
|
str
|
Title of the heatmap. |
None
|
xlabel
|
str
|
Label for the x-axis of the heatmap. |
None
|
ylabel
|
str
|
Label for the y-axis of the heatmap. |
None
|
tick_params
|
Dict
|
Parameters to pass to the ax.tick_params method of matplotlib. |
None
|
**kwargs
|
Additional keyword arguments to pass to the heatmap function. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[DataFrame, Axes]
|
If as_heatmap is False, returns a DataFrame of the experimental matrix. |
Union[DataFrame, Axes]
|
If as_heatmap is True, returns a heatmap of the experimental matrix. |
Source code in paramaterial/preparing.py
format_data_file_contents(raw_data_dir, prepared_data_dir, header_rows=None, delimiter=',', header_rename_dict=None)
Format CSV files in a directory by combining column headers into one row and changing delimeter to a comma.
Args: - directory_path: Path to the directory containing the original data files. - formatted_directory_path: Path to the directory where formatted files will be saved. - rename_dict: Dictionary mapping original column names to new column names. - header_rows: List of rows to use as headers (0-indexed). Rows above the highest-indexed row will be dropped. The original headers will be combined into a single row in the formatted files. - delimiter: Delimiter used in the CSV file. This will be changed to a comma in the formatted files.
Example usage:
format_data_file_contents('data/00 raw data', 'data/01 prepared data', header_rename_dict={'Total Strain': 'Strain', 'True Stress': 'Stress'}, header_rows=[0, 1], delimiter=' ')
Source code in paramaterial/preparing.py
rename_data_files(data_dir, rename_table, old_filename_col='old_filename', test_id_col='test_id')
Rename data files in a directory based on test ID mappings provided in an info table.
Args: - directory_path (str): Path to the directory containing the data files to be renamed. - info_table (pd.DataFrame): DataFrame containing the metadata for the tests. - old_filename_col (str): Column name in the info table for the old filenames. - test_id_col (str): Column name in the info table for the test IDs.
Example usage:
rename_data_files(data_dir='data/01 prepared data', rename_table='info/00 rename list.xlsx', old_filename_col='old filename', test_id_col='test id')