From 0f0c72e7720b63f67941507fa5926110bfdf31f2 Mon Sep 17 00:00:00 2001 From: Yue Huang <806628409@qq.com> Date: Fri, 13 Sep 2024 21:20:32 +0800 Subject: [PATCH 1/9] Update recording_tools.py Update the method to create an empty file with the right size --- src/spikeinterface/core/recording_tools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index 5137eda545..2e93b3671b 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -131,8 +131,10 @@ def write_binary_recording( data_size_bytes = dtype_size_bytes * num_frames * num_channels file_size_bytes = data_size_bytes + byte_offset + # create a file with file_size_bytes file = open(file_path, "wb+") - file.truncate(file_size_bytes) + file.seek(file_size_bytes - 1) + file.write(b'\0') file.close() assert Path(file_path).is_file() From 2cb34c3fd6d9f2296d5c9acdc1b00d608e8531c3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 13:40:59 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spikeinterface/core/recording_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index 2e93b3671b..c18e461f90 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -134,7 +134,7 @@ def write_binary_recording( # create a file with file_size_bytes file = open(file_path, "wb+") file.seek(file_size_bytes - 1) - file.write(b'\0') + file.write(b"\0") file.close() assert Path(file_path).is_file() From 3f9a9011a958252547acc4589dca88d727a49b6a Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Fri, 13 Sep 2024 18:00:33 -0600 Subject: [PATCH 3/9] Update src/spikeinterface/core/recording_tools.py Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/recording_tools.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index c18e461f90..30cd54473c 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -133,7 +133,11 @@ def write_binary_recording( # create a file with file_size_bytes file = open(file_path, "wb+") - file.seek(file_size_bytes - 1) + if platform.system() == 'Windows': + file.seek(file_size_bytes - 1) + file.write(b"\0") + else: + file.truncate(file_size_bytes) file.write(b"\0") file.close() assert Path(file_path).is_file() From d460c1ed312f5399b11100613483c3b364ef7213 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Sep 2024 00:00:54 +0000 Subject: [PATCH 4/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spikeinterface/core/recording_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index 30cd54473c..f649e60b28 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -133,7 +133,7 @@ def write_binary_recording( # create a file with file_size_bytes file = open(file_path, "wb+") - if platform.system() == 'Windows': + if platform.system() == "Windows": file.seek(file_size_bytes - 1) file.write(b"\0") else: From 559cbaade8faaf9a0056da84069ddc9cb96faae3 Mon Sep 17 00:00:00 2001 From: Yue Huang <806628409@qq.com> Date: Mon, 16 Sep 2024 00:09:51 +0800 Subject: [PATCH 5/9] Update recording_tools.py --- src/spikeinterface/core/recording_tools.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index f649e60b28..8f42774dec 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -131,14 +131,13 @@ def write_binary_recording( data_size_bytes = dtype_size_bytes * num_frames * num_channels file_size_bytes = data_size_bytes + byte_offset - # create a file with file_size_bytes + # Create an empty file with file_size_bytes file = open(file_path, "wb+") - if platform.system() == "Windows": - file.seek(file_size_bytes - 1) - file.write(b"\0") - else: - file.truncate(file_size_bytes) + + # The previous implementation `file.truncate(file_size_bytes)` was slow on Windows (#3408) + file.seek(file_size_bytes - 1) file.write(b"\0") + file.close() assert Path(file_path).is_file() From af6c61807f75e98420eb2a849771fb29d57dd1f1 Mon Sep 17 00:00:00 2001 From: Yue Huang <806628409@qq.com> Date: Mon, 16 Sep 2024 00:18:20 +0800 Subject: [PATCH 6/9] Update recording_tools.py --- src/spikeinterface/core/recording_tools.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index 8f42774dec..77d427bc88 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -132,13 +132,11 @@ def write_binary_recording( file_size_bytes = data_size_bytes + byte_offset # Create an empty file with file_size_bytes - file = open(file_path, "wb+") + with open(file_path, "wb+") as file: + # The previous implementation `file.truncate(file_size_bytes)` was slow on Windows (#3408) + file.seek(file_size_bytes - 1) + file.write(b"\0") - # The previous implementation `file.truncate(file_size_bytes)` was slow on Windows (#3408) - file.seek(file_size_bytes - 1) - file.write(b"\0") - - file.close() assert Path(file_path).is_file() # use executor (loop or workers) From 9834996cf38e2589bdbcd44d20cbcd7a4afee205 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 16 Sep 2024 18:34:09 +0200 Subject: [PATCH 7/9] Fix metrics widgets for convert_dtypes --- src/spikeinterface/widgets/metrics.py | 3 +++ src/spikeinterface/widgets/tests/test_widgets.py | 2 +- src/spikeinterface/widgets/utils_sortingview.py | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/widgets/metrics.py b/src/spikeinterface/widgets/metrics.py index 2fbd0e31eb..813e7d7b63 100644 --- a/src/spikeinterface/widgets/metrics.py +++ b/src/spikeinterface/widgets/metrics.py @@ -235,6 +235,9 @@ def plot_sortingview(self, data_plot, **backend_kwargs): values = check_json(metrics.loc[unit_id].to_dict()) values_skip_nans = {} for k, v in values.items(): + # convert_dypes returns NaN as None or np.nan (for float) + if v is None: + continue if np.isnan(v): continue values_skip_nans[k] = v diff --git a/src/spikeinterface/widgets/tests/test_widgets.py b/src/spikeinterface/widgets/tests/test_widgets.py index debcd52085..80f58f5ad9 100644 --- a/src/spikeinterface/widgets/tests/test_widgets.py +++ b/src/spikeinterface/widgets/tests/test_widgets.py @@ -73,7 +73,7 @@ def setUpClass(cls): spike_amplitudes=dict(), unit_locations=dict(), spike_locations=dict(), - quality_metrics=dict(metric_names=["snr", "isi_violation", "num_spikes"]), + quality_metrics=dict(metric_names=["snr", "isi_violation", "num_spikes", "amplitude_cutoff"]), template_metrics=dict(), correlograms=dict(), template_similarity=dict(), diff --git a/src/spikeinterface/widgets/utils_sortingview.py b/src/spikeinterface/widgets/utils_sortingview.py index d18c581b6b..a6cc562ba2 100644 --- a/src/spikeinterface/widgets/utils_sortingview.py +++ b/src/spikeinterface/widgets/utils_sortingview.py @@ -106,9 +106,9 @@ def generate_unit_table_view( if prop_name in sorting_props: property_values = sorting.get_property(prop_name) elif prop_name in qm_props: - property_values = qm_data[prop_name].values + property_values = qm_data[prop_name].to_numpy() elif prop_name in tm_props: - property_values = tm_data[prop_name].values + property_values = tm_data[prop_name].to_numpy() else: warn(f"Property '{prop_name}' not found in sorting, quality_metrics, or template_metrics") continue @@ -137,9 +137,9 @@ def generate_unit_table_view( if prop_name in sorting_props: property_values = sorting.get_property(prop_name) elif prop_name in qm_props: - property_values = qm_data[prop_name].values + property_values = qm_data[prop_name].to_numpy() elif prop_name in tm_props: - property_values = tm_data[prop_name].values + property_values = tm_data[prop_name].to_numpy() # Check for NaN values and round floats val0 = np.array(property_values[0]) From ca0d99c64535067965fe73777bc0b3ccf31fe840 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 16 Sep 2024 18:38:17 +0200 Subject: [PATCH 8/9] Add #3417 --- doc/releases/0.101.1.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/releases/0.101.1.rst b/doc/releases/0.101.1.rst index c24372868c..f68cd65e46 100644 --- a/doc/releases/0.101.1.rst +++ b/doc/releases/0.101.1.rst @@ -72,6 +72,7 @@ curation: widgets: +* Fix metrics widgets for convert_dtypes (#3417) * Fix plot motion for multi-segment (#3414) * Sortingview: only round float properties (#3406) * Fix widgets tests and add test on unit_table_properties (#3354) From 12f089b15a9d12cbafde1442dca2aa0c5cafa71b Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 16 Sep 2024 19:10:44 +0200 Subject: [PATCH 9/9] Add #3408 --- doc/releases/0.101.1.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/releases/0.101.1.rst b/doc/releases/0.101.1.rst index f68cd65e46..eeb54566a6 100644 --- a/doc/releases/0.101.1.rst +++ b/doc/releases/0.101.1.rst @@ -15,6 +15,7 @@ Main changes: core: +* Update the method of creating an empty file with right size when saving binary files (#3408) * Refactor pandas save load and convert dtypes (#3412) * Check run info completed only if it exists (back-compatibility) (#3407) * Fix argument spelling in check for binary compatibility (#3409)