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 / ddp_bug_mwe.py
Created June 3, 2021 03:55
DDP bug MWE
import argparse
import os
import socket
import torch
from torch import nn
import torch.nn.functional as F
from torchvision import transforms
from torchvision.datasets import MNIST
from torch.utils.data import DataLoader, random_split
import pytorch_lightning as pl
@ajtritt
ajtritt / convert_npy.py
Created August 3, 2020 20:55
Concatenate one or more .npy files into a dataset into an HDF5 file
import argparse
import sys
import h5py
import numpy as np
desc = '''
Concatenate one or more .npy files into a dataset into an HDF5 file
'''
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('output_h5', help='the .h5 file to write converted data to')
@ajtritt
ajtritt / interval.py
Created March 28, 2018 03:01
An interval tree that only supports insertion and point-query
BLACK = 0
RED = 1
class Interval(object):
def __init__(self, start, end):
self.__start = start
self.__end = end
self.__max = end
self.__left = None
@ajtritt
ajtritt / property_override.py
Created March 13, 2018 21:49
demonstrate override property
class MyClass(object):
def __init__(self, p):
self.__x = p
@property
def x(self):
return self.__x
@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
@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 / 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 / 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 / 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 / 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"
'''