Skip to content

Commit

Permalink
Copied demo into colab
Browse files Browse the repository at this point in the history
  • Loading branch information
wagenadl committed May 3, 2023
1 parent 50c3061 commit c47beb0
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
leechem.egg-info

13 changes: 6 additions & 7 deletions demo.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#!/usr/bin/python3

import em170428

import leechem
import numpy as np
import matplotlib.pyplot as plt

############ GENERAL PREPARATION #####################################
# Connect to the tracing database
db = em170428.sbemdb.SBEMDB()
db = leechem.sbemdb.SBEMDB()

# Create a mapping object for converting between various forms of neuron ID
mp = em170428.mapping.Mapping()
mp = leechem.mapping.Mapping()

############ VSD/EPHYS EXAMPLE #######################################
# Load electrophysiology/VSD trial #9 (an example of local bending)
tr = em170428.trials.Trial(9)
tr = leechem.trials.Trial(9)

# Extract timing of electrophysiological stimulus
stm = tr.stimuli()['P_VL']
Expand Down Expand Up @@ -44,7 +43,7 @@

############ VSD/EM EXAMPLE ##########################################
# Load electrophysiology/VSD trial #6 (an example of fictive swimming)
tr = em170428.trials.Trial(6)
tr = leechem.trials.Trial(6)

# Extract timestamps for the VSD recording
tt = tr.vsd().timestamps()[0]
Expand Down Expand Up @@ -155,7 +154,7 @@
plt.title('Postsynaptic distance along tree for synapses from DI-1(R) onto DE-3(R)')

########################## RAW EM DATA EXAMPLE #1 ######################
idb = em170428.sbemimage.ImageDB()
idb = leechem.sbemimage.ImageDB()
# A series of 2x-zoom steps into the raw data
f, ax = plt.subplots(3,3)
x = 30
Expand Down
1 change: 1 addition & 0 deletions em170428/__init__.py → leechem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import confidence
from . import trials
from . import sbemimage
__version__ = '1.2'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 2 additions & 4 deletions em170428/confidence.py → leechem/confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import errno
import os
import re
from . import webaccess

class Confidence:
def __init__(self, csvfn=None):
Expand All @@ -26,11 +27,8 @@ def __init__(self, csvfn=None):
self.gmapconf = {}
self.vsd2tree = {}

if csvfn is None:
here = os.path.dirname(__file__)
csvfn = here + '/../data/confidence.csv'
lines = []
with open(csvfn) as f:
with webaccess.opentextfile(csvfn, "confidence.csv") as f:
dl = csv.unix_dialect()
rdr = csv.reader(f, dl)
for row in rdr:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 3 additions & 5 deletions em170428/mapping.py → leechem/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import csv
import errno
import os
from . import webaccess

class Mapping:
def __init__(self, csvfn=None):
Expand Down Expand Up @@ -31,12 +32,9 @@ def __init__(self, csvfn=None):
self.can2uct = {}
self.roiid2roi = {}
self.roi2roiid = {}

if csvfn is None:
here = os.path.dirname(__file__)
csvfn = here + '/../data/mapping.csv'

lines = []
with open(csvfn) as f:
with webaccess.opentextfile(csvfn, "mapping.csv") as f:
dl = csv.unix_dialect()
rdr = csv.reader(f, dl)
for row in rdr:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions em170428/runinfo.py → leechem/runinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import math
import sys
import os.path
from . import webaccess

TILESIZE = 512
IMAGESIZE = TILESIZE * 33
Expand Down Expand Up @@ -51,9 +52,7 @@ def __init__(self, ifn=None):
class, loading the data from the given hdf5 file.
pp = RUNINFO() loads the data from the 'positionsummary.h5'
file in the em170428 directory.'''
if ifn is None:
here = os.path.dirname(__file__)
ifn = here + '/../data/positionsummary.h5'
ifn = webaccess.ensurefile(ifn, "positionsummary.h5")
self.f = h5.File(ifn, 'r')

BLEND = 1024
Expand Down
File renamed without changes.
8 changes: 2 additions & 6 deletions em170428/sbemdb.py → leechem/sbemdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sqlite3
import errno
import os
from . import webaccess

class LineSegmentGeom:
def _dif(pa, pb):
Expand Down Expand Up @@ -62,12 +63,7 @@ def __init__(self, dbfn=None):
'''SBEMDB - Pythonic access to SBEMDB
db = SBEMDB(dbfn) opens the given database file. db = SBEMDB() opens
the database file in the em170428 directory.'''
if dbfn is None:
here = os.path.dirname(__file__)
dbfn = here + '/../data/170428_pub.sbemdb'
if not os.path.isfile(dbfn):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
dbfn)
dbfn = webaccess.ensurefile(dbfn, "170428_pub.sbemdb")
self.db = sqlite3.connect(dbfn)
self.dbfn = dbfn

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions em170428/trials.py → leechem/trials.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import h5py
import errno
import os
import em170428.salpa
from . import salpa
import urllib.request
import io

Expand Down Expand Up @@ -76,7 +76,7 @@ def trace(self, k, tau=100, poly=None):
for k in range(poly+1):
y -= p[k] * x**(poly-k)
elif tau is not None:
s = em170428.salpa.Salpa(tau=tau)
s = salpa.Salpa(tau=tau)
y = s.apply(y)
return (y, '%')

Expand Down
37 changes: 19 additions & 18 deletions em170428/uCT.py → leechem/uCT.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,38 @@ def __init__(self, h5fn=None):
uct = UCT(h5fn) opens the given "uCT-somata.h5" file.
uct = UCT() opens the default file in the em170428 directory.
'''
if h5fn is None:
here = os.path.dirname(__file__)
h5fn = here + '/../data/uCT-somata.h5'
with h5py.File(h5fn, 'r') as h5:
self.somapos = h5['somapos']['value'][:] * 2
self.exitpoint = h5['dpp']['value'][:]
self.lut = h5['dc']['value'][:]
self.tails = {}
tt = h5['tails']['value']
for k in tt.keys():
if k.startswith('_'):
k1= int(k[1:])
t = tt[k]
t = t['value']
if len(t)==3:
self.tails[k1] = t[:]
else:
self.tails[k] = [[],[],[]]
h5fn = webaccess.ensurefile(h5fn, "uCT-somata.h5")
with h5py.File(h5fn, 'r') as h5:
self.somapos = h5['somapos']['value'][:] * 2
self.exitpoint = h5['dpp']['value'][:]
self.lut = h5['dc']['value'][:]
self.tails = {}
tt = h5['tails']['value']
for k in tt.keys():
if k.startswith('_'):
k1= int(k[1:])
t = tt[k]
t = t['value']
if len(t)==3:
self.tails[k1] = t[:]
else:
self.tails[k] = [[],[],[]]

def somaPosition(self, uctid):
'''SOMAPOSITION - Position of a soma
x,y,z = SOMAPOSITION(uctid) returns the position of a soma.
UCTID must be a UCT ID (for instance, DE3_R is 1; DI1_R is 66).
X, Y, Z are in UCT pixel coordinates.'''
return self.somapos[:,uctid-1]

def exitPointPosition(self, uctid):
'''EXITPOINTPOSITION - Position of a exit point
x,y,z = EXITPOINTPOSITION(uctid) returns the position of the point
where the principal neurite of a cell exits the neuropil.
UCTID must be a UCT ID (for instance, DE3_R is 1; DI1_R is 66).
X, Y, Z are in UCT pixel coordinates.'''
return self.exitpoint[:,uctid-1]

def tailPosition(self, uctid):
'''TAILPOSITION - Position of a tail
x,y,z = TAILPOSITION(uctid) returns the position of the “tail”
Expand Down
41 changes: 41 additions & 0 deletions leechem/webaccess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/python3

import urllib.request
import shutil
import os
from contextlib import contextmanager
import codecs

@contextmanager
def opentextfile(fn, dflt):
if fn is not None:
yield open(fn, mode)
here = os.path.dirname(__file__)
localfn = here + "/../data/" + dflt
if os.path.isfile(localfn):
yield open(localfn, mode)
url = "https://leechem.caltech.edu/170428/pydata/" + dflt
try:
req = urllib.request.urlopen(url)
yield codecs.iterdecode(req, "utf-8")
except urllib.request.HTTPError:
raise RuntimeError(f"Could not access {url}")


def ensurefile(fn, dflt):
if fn is not None:
return fn
here = os.path.dirname(__file__)
localfn = here + "/../data/" + dflt
if os.path.isfile(localfn):
return localfn

url = "https://leechem.caltech.edu/170428/pydata/" + dflt
localfn = "./" + dflt
try:
with urllib.request.urlopen(url) as response:
with open(localfn, 'wb') as fd:
shutil.copyfileobj(response, fd)
except urllib.request.HTTPError:
raise RuntimeError(f"Could not download {url}")
return localfn
4 changes: 4 additions & 0 deletions pypipush.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

python3 setup.py sdist
twine upload dist/leechem-1.2.tar.gz
15 changes: 15 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from setuptools import setup, find_packages

from leechem import __version__

setup(
name='leechem',
version=__version__,

url='https://github.com/wagenadl/leechem',
author='Daniel A. Wagenaar',
author_email='[email protected]',
packages=find_packages(),
install_requires=['numpy']
#py_modules=['leechem'],
)

0 comments on commit c47beb0

Please sign in to comment.