No output file was created in Klusta

Hello,

I’m having trouble running Klusta on my Nwb file that I downloaded from Neurodata without borders. Although Klusta reports that it ran successfully, no output file is created. It could be because I could not extract the electrode positions from the file, I tried to do it several times, still could not extract that information.

You can find all the relevant files in the dropbox folder: Dropbox

Any guidance on how to debug this issue would be greatly appreciated.

Thank you!

from pynwb import NWBHDF5IO
import numpy as np
nwbfile_path = r'my nwb file path'

io = NWBHDF5IO(nwbfile_path, 'r',)
nwbfile = io.read()

print("The file is read successfully")

acquisition_keys = list(nwbfile.acquisition.keys())
print("Acquisition keys:", acquisition_keys)

if acquisition_keys:
    electrical_series_key = acquisition_keys[0]
    electrical_series = nwbfile.acquisition[electrical_series_key]


    sampling_rate = electrical_series.rate
    print("Sampling rate:", sampling_rate)

    
    #electrode_positions = np.column_stack((electrode_x, electrode_y, electrode_z))
    #electrode_x = nwbfile.electrodes['x'].data[:]
    #electrode_y = nwbfile.electrodes['y'].data[:]
    #electrode_z = nwbfile.electrodes['z'].data[:]

    # Combine x, y, and z coordinates into a single array
    

    # Explore the contents of the electrodes section
    #print("Electrodes attributes:", nwbfile.electrodes.fields.keys())
    #print("Electrode positions", electrode_positions)

    
    channel_groups = [[i] for i in range(len(nwbfile.electrodes))]
    print("Channel groups:", channel_groups)
else:
    print("No acquisition keys found.")
    
import numpy as np

# Construct the configuration file content
config = f"""
# Klusta configuration file

# Sampling rate
sampling_rate: {39.0625}

# Electrode positions


# Channel groups
channel_groups: {[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31], [32], [33], [34], [35], [36], [37], [38], [39], [40], [41], [42], [43], [44], [45], [46], [47], [48], [49], [50], [51], [52], [53], [54], [55], [56], [57], [58], [59], [60], [61], [62], [63], [64]}

# Filter settings
highpass_freq: 300
lowpass_freq: 6000

# Clustering parameters
num_clusters: 4
cluster_method: klustakwik2

# Output directory
output_directory: ./klusta_output
"""

# Save the configuration file
with open('klusta_config.prm', 'w') as config_file:
    config_file.write(config)


import numpy as np
raw_data = electrical_series.data[:]
#raw_data = raw_data.astype(np.int16)
raw_data_file_path = 'klusta.data.dat'
raw_data.tofile(raw_data_file_path)
print (f"Raw data saved to {raw_data_file_path}")

import subprocess

# Path to Klusta executable (ensure Klusta is installed and available in PATH)
klusta_command = 'klusta_config.prm'

try:
    # Run Klusta
    subprocess.check_call(klusta_command, shell=True)
    print("Klusta finished running successfully.")
except subprocess.CalledProcessError as e:
    # Print error message if Klusta encountered an error
    print("Error running Klusta:", e)

Hi @Steven,

I noticed that you edited my post titled “No output file was created in Klusta” recently. I could not spot any changes and was wondering if it was accidental. Could you please let me know if there was a specific reason for the edit or if it might have been just an error?

Hi @SSNab,

I edited your post for code readability.

Best,
Steven

Hi @Steven,

Of course, now it makes sense. Thanks a lot!

Best wishes,
Saule