Skip to content

Instantly share code, notes, and snippets.

View ajtritt's full-sized avatar

Andrew Tritt ajtritt

  • Lawrence Berkeley National Laboratory
  • Oakland, CA
View GitHub Profile
@ajtritt
ajtritt / firing_rate_extension.py
Created July 29, 2017 05:04
fix of example extension and dynamic class
#fix of https://gist.github.com/nicain/be598d5b7be5f2ffe1fd7e8d27c87ec3
#
from pynwb.spec import NWBNamespaceBuilder, NWBGroupSpec, NWBAttributeSpec
import numpy as np
from pynwb import get_class, load_namespaces
mylab = 'alleninstitute'
ns_path = "%s.namespace.yaml" % mylab
ext_source = "%s.extensions.yaml" % mylab
@ajtritt
ajtritt / regref_dim_scales.py
Last active August 2, 2017 18:26
Using a slice to label a dimension with HDF5
import os
import h5py
import numpy as np
# Create compound data type
# a table with columns channel ID, xyz-coordinates, and impedence
coord_dt = np.dtype([('x', np.float), ('y', np.float), ('z', np.float)])
ch_dt = np.dtype([("id", np.int), ("coord", coord_dt), ("imp", np.float)])
# Make a fake channel table
@ajtritt
ajtritt / example_table.py
Created August 16, 2017 04:09
An example of how to use NWBDatasetSpec to create a table
import numpy as np
from pynwb import get_class, load_namespaces
from datetime import datetime
from pynwb import NWBFile
import pandas as pd
from form.backends.hdf5 import HDF5IO
from pynwb import get_build_manager
ns_path = "alleninstitute.namespace.yaml"
ext_source = "alleninstitute.extensions.yaml"
@ajtritt
ajtritt / example_table_no_group.py
Created August 16, 2017 04:13
An example of how to create and use a table by itself
import numpy as np
from pynwb import get_class, load_namespaces
from datetime import datetime
from pynwb import NWBFile
import pandas as pd
from form.backends.hdf5 import HDF5IO
from pynwb import get_build_manager
ns_path = "alleninstitute.namespace.yaml"
ext_source = "alleninstitute.extensions.yaml"
@ajtritt
ajtritt / iso_time_benchmark.py
Created August 30, 2017 16:24
Benchamark ISO time arithmetic
from datetime import datetime
from timeit import timeit
iso_setup = '''
from datetime import datetime
iso_start = "2017-08-30T16:01:18Z"
iso_end = "2017-08-30T16:01:20Z"
fmt = "%Y-%m-%dT%H:%M:%SZ"
'''
@ajtritt
ajtritt / io_scenarios.py
Last active September 22, 2017 04:27
Examples of how to use PyNWB in certain I/O scenarios
import pynwb
foo_ext_path = 'foo.namespace.yaml' # custom extension
foo_nwb_path = 'foo.nwb' # file using custom extension
bar_ext_path = 'bar.namespace.yaml' # another custom extension
bar_nwb_path = 'bar.nwb' # file using this other custom extension
baz_nwb_path = 'baz.nwb' # file with no extensions
############ READ #############
@ajtritt
ajtritt / simple_parallelize.py
Created October 6, 2017 19:39
A script to demonstrate how parallelize embarassingly parallel problems using core Python functionality
import filterframework
import pynwb
import multiprocessing # this is a core Python package
def my_analysis_func(...):
# user writes this
...
nwb_file = pynwb.NWBFile(...)
query_string = 'a toy query string'
@ajtritt
ajtritt / nwb_backward.py
Last active October 12, 2017 21:06
get_builder_dt and get_builder_ns for nwb 1.x
def get_builder_ns(self, builder):
return 'core'
def get_builder_dt(self, builder):
attrs = builder.attributes
ndt = attrs.get('neurodata_type')
if ndt == 'Module':
return 'ProcessingModule'
elif ndt == 'TimeSeries':
@ajtritt
ajtritt / jongbloets_icephys.py
Created December 7, 2017 19:19
Writing Intracellular Ephys data (for Bart Jongbloets)
""" import the pynwb packages"""
from pynwb import NWBFile, TimeSeries, get_manager
from pynwb.form.backends.hdf5 import HDF5IO
from pynwb.icephys import CurrentClampSeries
from pynwb.icephys import VoltageClampSeries
import datetime
import numpy as np
import os
experimentID = 'BJ5523'#folderPath.split('/')[-1]
@ajtritt
ajtritt / mschacter_example.py
Created January 13, 2018 01:20
Some code that exposed a bug
"""
This code was breaking at write. See https://github.com/NeurodataWithoutBorders/pynwb/issues/317
mschachter hacked PyNWB and then had problems reading. See https://github.com/NeurodataWithoutBorders/pynwb/issues/318
This commit should fix both of these issues: https://github.com/NeurodataWithoutBorders/pynwb/commit/72fafa686748de25571d0abd6aa43cd3ab889bb9
"""
import json
from datetime import datetime
import numpy as np