Skip to content

Instantly share code, notes, and snippets.

View bendichter's full-sized avatar
🏠
Working from home

Ben Dichter bendichter

🏠
Working from home
View GitHub Profile
@bendichter
bendichter / constrained_array.py
Created January 8, 2024 20:04
constrainedarray
from typing import Tuple, Type, Any, Union, Optional
from pydantic import BaseModel
import numpy as np
def get_shape(data):
"""
Get the shape of various data structures: NumPy array, h5py dataset, Zarr dataset, or a nested list of arbitrary depth.
Parameters
@bendichter
bendichter / convert_ephys_dandiset_to_bids.ipynb
Last active December 18, 2023 15:06
convert_ephys_dandiset_to_bids
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bendichter
bendichter / grouped_barplot.py
Last active July 15, 2022 18:34
plot a grouped barplot
import matplotlib.pyplot as plt
import numpy as np
from typing import List, Optional
def grouped_barplot(
data,
clabels: List[str],
xlabels: List[str],
from itertools import chain, repeat
from bisect import bisect_left
from datetime import datetime, timedelta
import numpy as np
import matplotlib.pyplot as plt
data = [
{
# first run:
#
#!git log --all --numstat --pretty=format:'--%h--%ad--%aN' --no-renames > git.log
import datetime
import matplotlib.pyplot as plt
import pandas as pd
from pprint import pprint
import matplotlib.ticker
2022-06-01 11:34:17,098 [ INFO] Logs saved in /Users/bendichter/Library/Logs/dandi-cli/20220601153356Z-59646.log
(base) MacBook-Pro-3:~ bendichter$ dandi download https://dandiarchive.org/dandisets/000053/versions/"draft"/assets/?path="sub-npJ3/sub-npJ3_ses-20190504_behavior.nwb"
(base) MacBook-Pro-3:~ bendichter$
(base) MacBook-Pro-3:~ bendichter$
(base) MacBook-Pro-3:~ bendichter$
(base) MacBook-Pro-3:~ bendichter$ dandi download https://dandiarchive.org/dandisets/000053/versions/"draft"/assets/?path="sub-npJ3/sub-npJ3_ses-20190504_behavior.nwb"
(base) MacBook-Pro-3:~ bendichter$
(base) MacBook-Pro-3:~ bendichter$ cat /Users/bendichter/Library/Logs/dandi-cli/20220601153356Z-59646.log
2022-06-01T11:33:56-0400 [INFO ] dandi 59646:8602854912 dandi v0.40.0, hdmf v3.2.1, pynwb v2.0.1, h5py v3.1.0
2022-06-01T11:33:56-0400 [INFO ] dandi 59646:8602854912 sys.argv = ['/Users/bendichter/opt/miniconda3/bin/dandi', 'download', 'https://dandiarchive.org/dandisets/000053/versions/draft/assets/?path=sub-npJ3/
@bendichter
bendichter / download_figshare_collection.py
Created April 27, 2022 21:36
Iterate over an entire collection and download each file from each article
import os
import json
import requests
from tqdm import tqdm
from urllib.request import urlretrieve
BASE_URL = 'https://api.figshare.com/v2'
def download_collection(collection_id, destination):
@bendichter
bendichter / h5pytree.py
Last active March 23, 2022 00:54
draw tree structure of h5py File
import h5py
def print_group(group: h5py.Group):
name = group.name.split('/')[-1]
return f"{name} ({len(group.keys())} objects)/"
def print_dataset(dataset: h5py.Dataset):
name = dataset.name.split('/')[-1]
return f"{name} {dataset.shape}, {dataset.dtype}"
@bendichter
bendichter / generate_md.py
Last active February 25, 2021 23:22
nwb conversion
from jinja2 import Template
_str = """## Converting data to NWB
Below is a collection of simple conversion scripts that are all tested against small
proprietary examples files. They are all optimized to handle very large data by iteratively
steping through large files and read/writing them one piece at a time. They also leverage
lossless compression within HDF5, which allows you to make large datasets smaller without
losing any data. We have seen this reduce large datasets by up to 66%!
{% for modality_name, modality_value in _dict.items() %}