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
import numpy as np
import random
from pynwb.spec import NWBDatasetSpec, NWBNamespaceBuilder, NWBGroupSpec, NWBDtypeSpec
from pynwb import get_class, load_namespaces, NWBFile, NWBHDF5IO
from datetime import datetime
ns_path = "soltesz.namespace.yaml"
ext_source = "soltesz.extensions.yaml"
@bendichter
bendichter / auto_extensions.py
Last active August 24, 2018 05:09
WIP NWB auto classes
from pynwb.spec import NWBDatasetSpec, NWBNamespaceBuilder, NWBGroupSpec, NWBAttributeSpec
from pynwb.form.spec import RefSpec
from pynwb import register_class, load_namespaces, NWBFile, NWBHDF5IO
from pynwb.form.utils import docval
from pynwb.file import Subject, NWBContainer, MultiContainerInterface, NWBDataInterface
from pynwb.device import Device
from datetime import datetime
@bendichter
bendichter / widget_threading.py
Created April 4, 2020 19:02
Example of how to thread a plotting widget so that only the latest command is run
from ipywidgets import VBox, Button, HTML
import time
from threading import Thread
from queue import Queue
class MyWidget(VBox):
def __init__(self):
super(MyWidget, self).__init__()
# MIT LICENSE
import datetime
import plotly.graph_objs as go
from plotly.subplots import make_subplots
import numpy as np
import dash_core_components as dcc
import dash_html_components as html
import dash
from datetime import datetime, timedelta
import plotly.graph_objs as go
import numpy as np
import dash_core_components as dcc
import dash_html_components as html
import dash
def display_eletrode_turns(all_turn_data):
"""
from datetime import datetime, timedelta
import plotly.graph_objs as go
from plotly.subplots import make_subplots
import numpy as np
import dash_core_components as dcc
import dash_html_components as html
import dash
def discrete_colorscale(bvals, colors):
"""
## set up env via bash:
conda create -n stream_nwb -c conda-forge -y python=3.7 hdf5=1.12.0 jupyter pip
conda activate stream_nwb
pip install nwbwidgets
pip install git+https://github.com/NeurodataWithoutBorders/pynwb
pip install git+https://github.com/hdmf-dev/hdmf
git clone https://github.com/satra/h5py.git
cd h5py
HDF5_DIR=~/Users/bendichter/opt/anaconda3/envs/stream_nwb/ pip install --force-reinstall --no-binary=h5py .
@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() %}
@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 / 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):