From e27c46fb01daa82f653096dd44d68c95d3afafa6 Mon Sep 17 00:00:00 2001 From: Rahil Doshi <rahil.doshi@fau.de> Date: Thu, 8 Aug 2024 17:26:38 +0200 Subject: [PATCH] Fix bugs, final working implementation for data_handler with test cases --- src/materials/alloys/Alloy.py | 2 +- src/materials/data_handler/create_test_files.py | 3 ++- src/materials/data_handler/data_handler.py | 7 +++++-- .../data_handler/test_files/test_data_normal1.txt | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/materials/alloys/Alloy.py b/src/materials/alloys/Alloy.py index 0be9db4b0..cbe3ab2ff 100644 --- a/src/materials/alloys/Alloy.py +++ b/src/materials/alloys/Alloy.py @@ -58,7 +58,7 @@ class Alloy: self.temperature_boil = interpolate_temperature_boil(self.elements, self.composition) def interpolate_property(self, T: VariableTypes, temp_array: ValueTypes, prop_array: ValueTypes, prop_name: str, - temp_array_limit=5, force_lookup=False): + temp_array_limit=6, force_lookup=False): """ Perform interpolation based on the type of temperature array (equidistant or not). diff --git a/src/materials/data_handler/create_test_files.py b/src/materials/data_handler/create_test_files.py index 952d212db..862ac1804 100644 --- a/src/materials/data_handler/create_test_files.py +++ b/src/materials/data_handler/create_test_files.py @@ -1,5 +1,6 @@ import os + def create_test_files() -> None: """ Creates a folder named 'test_files' and generates test files with predefined contents. @@ -24,7 +25,7 @@ def create_test_files() -> None: 3050 54.5 3000 54.0 2900 53.0 -2800 52.1 +2800 52.0 """, "test_files/test_data_variable_spacing.txt": """Temp Density 3400 58.0 diff --git a/src/materials/data_handler/data_handler.py b/src/materials/data_handler/data_handler.py index 86a1aca53..b582b3c04 100644 --- a/src/materials/data_handler/data_handler.py +++ b/src/materials/data_handler/data_handler.py @@ -81,6 +81,9 @@ def clean_temperature_data(temp: np.ndarray, prop: np.ndarray) -> Tuple[np.ndarr # common_diff = bin_edges[np.argmax(hist)] # Most frequent temperature difference unique_diffs, counts = np.unique(diffs, return_counts=True) common_diff = unique_diffs[np.argmax(counts)] + if np.max(counts) < 2: + print("No repeated temperature differences found. Returning original data.") + return temp, prop print(f"Most common temperature difference: {common_diff}") except Exception as e: print(f"Error calculating most common difference: {e}") @@ -249,7 +252,7 @@ def run_tests() -> None: Runs predefined tests to validate data reading and processing functions. """ test_cases = [ - # {"name": "Normal Case", "file_path": "test_files/test_data_normal.txt"}, + {"name": "Normal Case", "file_path": "test_files/test_data_normal.txt"}, # {"name": "Normal Case 1", "file_path": "test_files/test_data_normal1.txt"}, # {"name": "Case with Variable Spacing", "file_path": "test_files/test_data_variable_spacing.txt"}, # {"name": "Case with Sparse Data", "file_path": "test_files/test_data_sparse.txt"}, @@ -262,7 +265,7 @@ def run_tests() -> None: # {"name": "Mismatched Columns", "file_path": "test_files/test_data_mismatched_columns.txt"}, # {"name": "Missing Data Entries", "file_path": "test_files/test_data_missing_data.txt"}, # {"name": "Ascending density_temperature values", "file_path": "test_files/test_data_density_temperature_ascending.txt"}, - {"name": "Descending density_temperature values", "file_path": "test_files/test_data_density_temperature_descending.txt"} + # {"name": "Descending density_temperature values", "file_path": "test_files/test_data_density_temperature_descending.txt"} ] for case in test_cases: diff --git a/src/materials/data_handler/test_files/test_data_normal1.txt b/src/materials/data_handler/test_files/test_data_normal1.txt index 32f113e46..7fc31a159 100644 --- a/src/materials/data_handler/test_files/test_data_normal1.txt +++ b/src/materials/data_handler/test_files/test_data_normal1.txt @@ -6,4 +6,4 @@ Temp Density 3050 54.5 3000 54.0 2900 53.0 -2800 52.1 +2800 52.0 -- GitLab