From 1fa3edf796f8c24f7b514a2f0cdf2813eb6a39c5 Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Mon, 13 Jan 2025 11:13:30 +0100 Subject: [PATCH 1/6] ISL-4832 Added sort_by_time.py --- python/catalog/sort_by_time.py | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 python/catalog/sort_by_time.py diff --git a/python/catalog/sort_by_time.py b/python/catalog/sort_by_time.py new file mode 100644 index 0000000..70e51f0 --- /dev/null +++ b/python/catalog/sort_by_time.py @@ -0,0 +1,50 @@ +# ----------------- +# Copyright © 2024 ACK Cyfronet AGH, Poland. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This work was partially funded by DT-GEO Project. +# ----------------- +import numpy as np + +def sort_by_time(catalog): + """ + Sorts the given catalog based on the 'Time' column. + + Parameters: + catalog (np.ndarray): A structured NumPy array representing the catalog, where each row + contains fields like 'Time', 'ID', and others. + + Returns: + np.ndarray: The sorted catalog, where rows in 'val' fields are ordered by ascending 'Time' values. + + Raises: + ValueError: If the 'Time' column is not found in the catalog. + """ + + time_col_index = None + for idx, col in enumerate(catalog): + if col['field'] == "Time": + time_col_index = idx + + if time_col_index is None: + raise ValueError("No 'Time' field found in the catalog.") + + time_values = catalog[time_col_index]['val'].flatten() + sorted_indexes = np.argsort(time_values) + + sorted_catalog = catalog.copy() + for field in sorted_catalog: + field['val'] = field['val'][sorted_indexes] + + return sorted_catalog \ No newline at end of file From e8ed57e2a0d509b4d4cf8248be00294166277e5a Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Mon, 13 Jan 2025 11:13:45 +0100 Subject: [PATCH 2/6] ISL-4832 Added find_catalog_column.py --- python/catalog/find_catalog_column.py | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 python/catalog/find_catalog_column.py diff --git a/python/catalog/find_catalog_column.py b/python/catalog/find_catalog_column.py new file mode 100644 index 0000000..1ca6080 --- /dev/null +++ b/python/catalog/find_catalog_column.py @@ -0,0 +1,36 @@ +# ----------------- +# Copyright © 2024 ACK Cyfronet AGH, Poland. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This work was partially funded by DT-GEO Project. +# ----------------- +def find_catalog_column(catalog, field_name): + """ + Finds the index of a column in the catalog based on its field name. + + Parameters: + catalog (np.ndarray): A structured NumPy array representing the catalog, where each row + corresponds to a field with attributes like 'field', 'val', etc. + field_name (str): The field name of the entry to search for. + + Returns: + int: The index of the entry matching the given field name. + + Raises: + ValueError: If the specified field name is not found in the catalog. + """ + for idx, col in enumerate(catalog): + if col['field'] == field_name: + return idx + raise ValueError(f'No {field_name} field found in the catalog.') \ No newline at end of file From 60e52884f4aac7f6cb1938a63d6ed32166603562 Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Mon, 13 Jan 2025 12:27:50 +0100 Subject: [PATCH 3/6] ISL-4832 Adjusted sort_by_time.py script --- python/catalog/sort_by_time.py | 10 ++----- python/catalog/sort_by_time_standalone.py | 50 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 python/catalog/sort_by_time_standalone.py diff --git a/python/catalog/sort_by_time.py b/python/catalog/sort_by_time.py index 70e51f0..43c7b56 100644 --- a/python/catalog/sort_by_time.py +++ b/python/catalog/sort_by_time.py @@ -16,6 +16,7 @@ # This work was partially funded by DT-GEO Project. # ----------------- import numpy as np +from find_catalog_column import find_catalog_column def sort_by_time(catalog): """ @@ -31,14 +32,7 @@ def sort_by_time(catalog): Raises: ValueError: If the 'Time' column is not found in the catalog. """ - - time_col_index = None - for idx, col in enumerate(catalog): - if col['field'] == "Time": - time_col_index = idx - - if time_col_index is None: - raise ValueError("No 'Time' field found in the catalog.") + time_col_index = find_catalog_column(catalog, 'Time') time_values = catalog[time_col_index]['val'].flatten() sorted_indexes = np.argsort(time_values) diff --git a/python/catalog/sort_by_time_standalone.py b/python/catalog/sort_by_time_standalone.py new file mode 100644 index 0000000..70e51f0 --- /dev/null +++ b/python/catalog/sort_by_time_standalone.py @@ -0,0 +1,50 @@ +# ----------------- +# Copyright © 2024 ACK Cyfronet AGH, Poland. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This work was partially funded by DT-GEO Project. +# ----------------- +import numpy as np + +def sort_by_time(catalog): + """ + Sorts the given catalog based on the 'Time' column. + + Parameters: + catalog (np.ndarray): A structured NumPy array representing the catalog, where each row + contains fields like 'Time', 'ID', and others. + + Returns: + np.ndarray: The sorted catalog, where rows in 'val' fields are ordered by ascending 'Time' values. + + Raises: + ValueError: If the 'Time' column is not found in the catalog. + """ + + time_col_index = None + for idx, col in enumerate(catalog): + if col['field'] == "Time": + time_col_index = idx + + if time_col_index is None: + raise ValueError("No 'Time' field found in the catalog.") + + time_values = catalog[time_col_index]['val'].flatten() + sorted_indexes = np.argsort(time_values) + + sorted_catalog = catalog.copy() + for field in sorted_catalog: + field['val'] = field['val'][sorted_indexes] + + return sorted_catalog \ No newline at end of file From 9fa094a2dc28e4f1dad4702a5eabf3374ad75969 Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Mon, 13 Jan 2025 12:44:44 +0100 Subject: [PATCH 4/6] ISL-4832 Adjusted description in find_catalog_column.py, sort_by_time.py and sort_by_time_standalone.py --- python/catalog/find_catalog_column.py | 4 ++-- python/catalog/sort_by_time.py | 4 ++-- python/catalog/sort_by_time_standalone.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/python/catalog/find_catalog_column.py b/python/catalog/find_catalog_column.py index 1ca6080..0f5fb66 100644 --- a/python/catalog/find_catalog_column.py +++ b/python/catalog/find_catalog_column.py @@ -20,8 +20,8 @@ def find_catalog_column(catalog, field_name): Finds the index of a column in the catalog based on its field name. Parameters: - catalog (np.ndarray): A structured NumPy array representing the catalog, where each row - corresponds to a field with attributes like 'field', 'val', etc. + catalog (np.ndarray): A structured NumPy array representing the catalog. + https://docs.cyfronet.pl/display/ISDOC/Seismic+catalog field_name (str): The field name of the entry to search for. Returns: diff --git a/python/catalog/sort_by_time.py b/python/catalog/sort_by_time.py index 43c7b56..5874d0e 100644 --- a/python/catalog/sort_by_time.py +++ b/python/catalog/sort_by_time.py @@ -23,8 +23,8 @@ def sort_by_time(catalog): Sorts the given catalog based on the 'Time' column. Parameters: - catalog (np.ndarray): A structured NumPy array representing the catalog, where each row - contains fields like 'Time', 'ID', and others. + catalog (np.ndarray): A structured NumPy array representing the catalog. + https://docs.cyfronet.pl/display/ISDOC/Seismic+catalog Returns: np.ndarray: The sorted catalog, where rows in 'val' fields are ordered by ascending 'Time' values. diff --git a/python/catalog/sort_by_time_standalone.py b/python/catalog/sort_by_time_standalone.py index 70e51f0..e51e747 100644 --- a/python/catalog/sort_by_time_standalone.py +++ b/python/catalog/sort_by_time_standalone.py @@ -22,8 +22,8 @@ def sort_by_time(catalog): Sorts the given catalog based on the 'Time' column. Parameters: - catalog (np.ndarray): A structured NumPy array representing the catalog, where each row - contains fields like 'Time', 'ID', and others. + catalog (np.ndarray): A structured NumPy array representing the catalog. + https://docs.cyfronet.pl/display/ISDOC/Seismic+catalog Returns: np.ndarray: The sorted catalog, where rows in 'val' fields are ordered by ascending 'Time' values. From 9770709a8137dcd92610712fb3db4f205a8cb4d5 Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Mon, 13 Jan 2025 18:42:29 +0100 Subject: [PATCH 5/6] ISL-4832 Adjusted descriptions --- python/catalog/find_catalog_column.py | 4 ++-- python/catalog/sort_by_time.py | 2 +- python/catalog/sort_by_time_standalone.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/catalog/find_catalog_column.py b/python/catalog/find_catalog_column.py index 0f5fb66..a1dcd40 100644 --- a/python/catalog/find_catalog_column.py +++ b/python/catalog/find_catalog_column.py @@ -20,8 +20,8 @@ def find_catalog_column(catalog, field_name): Finds the index of a column in the catalog based on its field name. Parameters: - catalog (np.ndarray): A structured NumPy array representing the catalog. - https://docs.cyfronet.pl/display/ISDOC/Seismic+catalog + catalog (np.ndarray): A structured NumPy array representing a catalog in EPISODES Platform format: + https://docs.cyfronet.pl/display/ISDOC/Catalogs field_name (str): The field name of the entry to search for. Returns: diff --git a/python/catalog/sort_by_time.py b/python/catalog/sort_by_time.py index 5874d0e..0af065c 100644 --- a/python/catalog/sort_by_time.py +++ b/python/catalog/sort_by_time.py @@ -23,7 +23,7 @@ def sort_by_time(catalog): Sorts the given catalog based on the 'Time' column. Parameters: - catalog (np.ndarray): A structured NumPy array representing the catalog. + catalog (np.ndarray): A structured NumPy array representing a seismic catalog in EPISODES Platform format: https://docs.cyfronet.pl/display/ISDOC/Seismic+catalog Returns: diff --git a/python/catalog/sort_by_time_standalone.py b/python/catalog/sort_by_time_standalone.py index e51e747..25508a6 100644 --- a/python/catalog/sort_by_time_standalone.py +++ b/python/catalog/sort_by_time_standalone.py @@ -22,7 +22,7 @@ def sort_by_time(catalog): Sorts the given catalog based on the 'Time' column. Parameters: - catalog (np.ndarray): A structured NumPy array representing the catalog. + catalog (np.ndarray): A structured NumPy array representing a seismic catalog in EPISODES Platform format: https://docs.cyfronet.pl/display/ISDOC/Seismic+catalog Returns: From d9a962e3bb70b1dde178d8157677a9b119bbf3ce Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Wed, 19 Feb 2025 13:52:18 +0100 Subject: [PATCH 6/6] ISL-4832 Removed standalone sort by time script and added information to sort by time script that it requires find catalog column script --- python/catalog/sort_by_time.py | 2 +- python/catalog/sort_by_time_standalone.py | 50 ------------------------------- 2 files changed, 1 insertion(+), 51 deletions(-) delete mode 100644 python/catalog/sort_by_time_standalone.py diff --git a/python/catalog/sort_by_time.py b/python/catalog/sort_by_time.py index 0af065c..384ab56 100644 --- a/python/catalog/sort_by_time.py +++ b/python/catalog/sort_by_time.py @@ -20,7 +20,7 @@ from find_catalog_column import find_catalog_column def sort_by_time(catalog): """ - Sorts the given catalog based on the 'Time' column. + Sorts the given catalog based on the 'Time' column. Requires find_catalog_column script to work. Parameters: catalog (np.ndarray): A structured NumPy array representing a seismic catalog in EPISODES Platform format: diff --git a/python/catalog/sort_by_time_standalone.py b/python/catalog/sort_by_time_standalone.py deleted file mode 100644 index 25508a6..0000000 --- a/python/catalog/sort_by_time_standalone.py +++ /dev/null @@ -1,50 +0,0 @@ -# ----------------- -# Copyright © 2024 ACK Cyfronet AGH, Poland. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This work was partially funded by DT-GEO Project. -# ----------------- -import numpy as np - -def sort_by_time(catalog): - """ - Sorts the given catalog based on the 'Time' column. - - Parameters: - catalog (np.ndarray): A structured NumPy array representing a seismic catalog in EPISODES Platform format: - https://docs.cyfronet.pl/display/ISDOC/Seismic+catalog - - Returns: - np.ndarray: The sorted catalog, where rows in 'val' fields are ordered by ascending 'Time' values. - - Raises: - ValueError: If the 'Time' column is not found in the catalog. - """ - - time_col_index = None - for idx, col in enumerate(catalog): - if col['field'] == "Time": - time_col_index = idx - - if time_col_index is None: - raise ValueError("No 'Time' field found in the catalog.") - - time_values = catalog[time_col_index]['val'].flatten() - sorted_indexes = np.argsort(time_values) - - sorted_catalog = catalog.copy() - for field in sorted_catalog: - field['val'] = field['val'][sorted_indexes] - - return sorted_catalog \ No newline at end of file