Skip to content

Instantly share code, notes, and snippets.

View h-mayorquin's full-sized avatar

Heberto Mayorquin h-mayorquin

View GitHub Profile
@h-mayorquin
h-mayorquin / sleap_io_testing.py
Created October 22, 2022 13:15
Generates artificial examples for sleap_io
import numpy as np
from sleap_io import (
PredictedInstance,
Skeleton,
Track,
Video,
Node,
LabeledFrame,
Labels,
)
@h-mayorquin
h-mayorquin / visualize_imaging_extractor.py
Created December 3, 2022 14:10
Visualize imaging extractor
import numpy as np
from pathlib import Path
data_dir_path = Path("/home/heberto/Murthy-data-share/one2one-mapping")
tiff_dir_path = data_dir_path / "raw_data" / "calcium_imaging" / "example_tiffs"
tiff_file_path_list = list(tiff_dir_path.iterdir())
tiff_file_path = tiff_file_path_list[0]
import pickle
import timeit
from pathlib import Path
from statistics import mean, stdev
from spikeinterface.extractors import SpikeGLXRecordingExtractor
from spikeinterface.core import load_extractor, BaseRecording
def pickling(recording):
pickled_recording = pickle.dumps(recording)
@h-mayorquin
h-mayorquin / datalad_installer.yml
Last active April 25, 2023 09:42
Install datalad in different fyle systems
- name: Installad datalad
run: |
pip install datalad-installer
if [ ${{ runner.os }} = 'Linux' ]; then
datalad-installer --sudo ok git-annex --method datalad/packages
elif [ ${{ runner.os }} = 'macOS' ]; then
datalad-installer --sudo ok git-annex --method brew
elif [ ${{ runner.os }} = 'Windows' ]; then
datalad-installer --sudo ok git-annex --method datalad/git-annex:release
fi
@h-mayorquin
h-mayorquin / reduce_mearec.py
Created March 30, 2023 12:27
Minimal program to eliminate unecessary fields in an hdf5 file
import os
import h5py
def remove_fields(input_file, output_file, fields_to_remove):
with h5py.File(input_file, "r") as input_h5:
with h5py.File(output_file, "w") as output_h5:
for key in input_h5.keys():
if key not in fields_to_remove:
input_h5.copy(key, output_h5)
@h-mayorquin
h-mayorquin / deeply_nested_spikeglx_to_bin.py
Last active April 5, 2023 14:29
writing_deeply_nested_spikeglx_to_bin
import tempfile
import os
import shutil
from pathlib import Path
from tempfile import tempdir
from spikeinterface.core.datasets import download_dataset
from spikeinterface.extractors import SpikeGLXRecordingExtractor
from spikeinterface.core.segmentutils import concatenate_recordings
@h-mayorquin
h-mayorquin / snippet_encoder_loggin.py
Created April 13, 2023 15:01
Debug errors in Spikeinterface json encoder
try:
file_path.write_text(
json.dumps(dump_dict, indent=4, cls=SIJsonEncoder),
encoding='utf8',
)
except TypeError as e:
accepted_type = [str, int, float, bool or None]
def log_value_types_of_dict(dictionary):
if isinstance(dictionary, dict):
@h-mayorquin
h-mayorquin / sam_memory_profiling.py
Last active May 2, 2023 14:54
Memory profiling but memmap sam
from pathlib import Path
import time
import os
import mmap
import itertools
import numpy as np
import matplotlib.pyplot as plt
import psutil
from tqdm.auto import tqdm
@h-mayorquin
h-mayorquin / segfault.py
Created May 1, 2023 13:05
Segmentation fault with memmaps examples
import mmap
import os
from pathlib import Path
import numpy as np
def count_int16_elements(file_path):
file_size = os.path.getsize(file_path)
int16_size = np.dtype(np.int16).itemsize
return file_size // int16_size
@h-mayorquin
h-mayorquin / recall_for_peak_detector.py
Created May 4, 2023 10:18
Recall for peak detectionr
def calculate_peaks_spike_recall(peaks, sorting_ground_truth, tolerance_ms=0.4):
"""
Calculate the spike recall of the peaks (which are the output of a peak detection method)
against a ground truth of spike_trains. This function is used to test the quality of a peak detection method
in the context of a specific sorting.
Recall close to 1 means that all the spike in the spike_train are present in a peak whereas recall
close to 0 means that no spike in the spike_train are present in a peak.
More technically, this calculates the number of True positives divided by