Skip to content

Commit

Permalink
Merge pull request #697 from NeurodataWithoutBorders/alessio_recommen…
Browse files Browse the repository at this point in the history
…dations

Recommendations from Alessio
  • Loading branch information
CodyCBakerPhD authored Apr 3, 2024
2 parents d70d73a + bcb6829 commit 2977e5c
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions pyflask/manageNeuroconv/manage_neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ def generate_test_data(output_path: str):
import spikeinterface
from spikeinterface.extractors import NumpyRecording
from spikeinterface.exporters import export_to_phy
from spikeinterface.preprocessing import scale, bandpass_filter, resample

base_path = Path(output_path)
spikeglx_output_folder = base_path / "spikeglx"
Expand All @@ -1067,33 +1068,29 @@ def generate_test_data(output_path: str):
duration_in_s = 3.0
number_of_units = 50
number_of_channels = 385 # Have to include 'sync' channel to be proper SpikeGLX. TODO: artificiate sync pulses
ap_conversion_factor_to_uV = 2.34375
conversion_factor_to_uV = 2.34375
ap_sampling_frequency = 30_000.0
lf_sampling_frequency = 2_500.0
downsample_factor = int(ap_sampling_frequency / lf_sampling_frequency)

# Generate synthetic spiking and voltage traces with waveforms around them
artificial_ap_band, spiking = spikeinterface.generate_ground_truth_recording(
artificial_ap_band_in_uV, spiking = spikeinterface.generate_ground_truth_recording(
durations=[duration_in_s],
sampling_frequency=ap_sampling_frequency,
num_channels=number_of_channels,
dtype="float32",
num_units=number_of_units,
seed=0, # Fixed seed for reproducibility
)
artificial_ap_band.set_channel_gains(gains=ap_conversion_factor_to_uV)
waveform_extractor = spikeinterface.extract_waveforms(recording=artificial_ap_band, sorting=spiking, mode="memory")
int16_artificial_ap_band = artificial_ap_band.astype(dtype="int16")

# Approximate behavior of LF band with filter and downsampling
# TODO: currently looks a little out of scale?
artificial_lf_filter = spikeinterface.preprocessing.bandpass_filter(
recording=artificial_ap_band, freq_min=10, freq_max=300
)
int16_artificial_lf_band = NumpyRecording(
traces_list=artificial_lf_filter.get_traces()[::downsample_factor],
sampling_frequency=lf_sampling_frequency,
)

unscaled_artificial_ap_band = scale(recording=artificial_ap_band_in_uV, gain=1 / conversion_factor_to_uV)
int16_artificial_ap_band = unscaled_artificial_ap_band.astype(dtype="int16")
int16_artificial_ap_band.set_channel_gains(conversion_factor_to_uV)

unscaled_artificial_lf_filter = bandpass_filter(recording=unscaled_artificial_ap_band, freq_min=0.5, freq_max=1_000)
unscaled_artificial_lf_band = resample(recording=unscaled_artificial_lf_filter, resample_rate=2_500)
int16_artificial_lf_band = unscaled_artificial_lf_band.astype(dtype="int16")
int16_artificial_lf_band.set_channel_gains(conversion_factor_to_uV)

ap_file_path = spikeglx_output_folder / "Session1_g0" / "Session1_g0_imec0" / "Session1_g0_t0.imec0.ap.bin"
ap_meta_file_path = spikeglx_output_folder / "Session1_g0" / "Session1_g0_imec0" / "Session1_g0_t0.imec0.ap.meta"
Expand All @@ -1115,6 +1112,10 @@ def generate_test_data(output_path: str):
io.write(lf_meta_content)

# Make Phy folder
waveform_extractor = spikeinterface.extract_waveforms(
recording=artificial_ap_band_in_uV, sorting=spiking, mode="memory"
)

export_to_phy(
waveform_extractor=waveform_extractor, output_folder=phy_output_folder, remove_if_exists=True, copy_binary=False
)
Expand Down

0 comments on commit 2977e5c

Please sign in to comment.