Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions utils/blech_post_process_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,20 @@ def get_latest_unit_name(self,):

return unit_name, max_unit

def generate_hash(self,):
def generate_hash(self, electrode_number, waveform_count):
"""
Generate a 10 character hash for the unit
Generate a 10 character hash for the unit based on electrode and waveform count

Args:
electrode_number: int, electrode number
waveform_count: int, number of waveforms in unit

Returns:
str: 10 character hash
"""
return str(uuid.uuid4()).split('-')[0]
# Create deterministic hash from inputs
hash_input = f"{electrode_number}_{waveform_count}"
return str(uuid.uuid5(uuid.NAMESPACE_DNS, hash_input)).split('-')[0]

def save_unit(
self,
Expand Down Expand Up @@ -664,8 +673,18 @@ def save_unit(

# Get a hash for the unit to compare stored data
# with unit_descriptor table
unit_hash = self.generate_hash()

unit_hash = self.generate_hash(electrode_num, len(unit_times))

# Only check for existing hash if this isn't the first unit
if max_unit >= 0:
existing_units = self.get_saved_units_hashes()
if unit_hash in existing_units['hash'].values:
existing_unit = existing_units[existing_units['hash'] == unit_hash].iloc[0]
print(f"Unit already exists as {existing_unit['unit_name']}")
return continue_bool, existing_unit['unit_name']

print(f"Adding new unit {unit_name}")

# Add to HDF5
waveforms = self.hf5.create_array('/sorted_units/%s' % unit_name,
'waveforms', unit_waveforms)
Expand Down