pymapmanager package

Submodules

pymapmanager.mmMap module

class pymapmanager.mmMap.mmMap(filePath=None, urlmap=None)[source]

Bases: object

A time-series of pymapmanager.mmStack time-points plus some book-keeping to link corresponding annotations and segments between time-points.

Parameters:
  • filePath (str) – Full file path to .txt file for the map. File is inside map folder, for map a5n it is /a5n/a5n.txt
  • urlmap (str) – Name of the map to load from a pymapmanager.mmio online repository.

Example:

from pymapmanager.mmMap import mmMap
myMapFile = 'PyMapManager/examples/exampleMaps/rr30a/rr30a.txt'
myMap = mmMap(filePath=myMapFile)

# Get the 3rd mmStack using
stack = myMap.stacks[3]

# Retrieve annotations (for a given segmentID) across all time-points in the map
pDist_values = myMap.getMapValues2('pDist', segmentID=[3])
defaultAnnotation
defaultAnnotationID
getMapDynamics(pd, thisMatrix=None)[source]
getMapValues2(stat, roiType=['spineROI'], segmentID=[], plotBad=False, plotIntBad=False)[source]

Get values of a stack annotation across all stacks in the map.

Parameters:
  • stat (str) – The stack annotation to get (corresponds to a column in mmStack.stackdb)
  • roiType (str) – xxx
  • segmentID (list) – xxx
  • plotBad (boolean) – xxx
Returns:

2D numpy array of stat values. Each row is a run of objects connected across sessions, columns are sessions, each [i][j] is a stat value

getMapValues3(pd)[source]

Get values of a stack annotation across all stacks in the map.

Parameters:pd (dict) – A plot dictionary describing what to plot. Get default from mmUtil.newplotdict().
Returns:
pd[‘x’], 2D ndarray of xstat values, rows are runs, cols are sessions, nan is where there is no stackdb annotation
pd[‘y’], same
pd[‘z’], same
pd[‘stackidx’], Each [i]j[] gives the stack centric index of annotation value at [i][j].
pd[‘mapsess’], Each [i][j] gives the map session of value at annotation [i][j].
pd[‘runrow’],
getValue(name, sessionNumber)[source]

Get a value from the map (not from a stack!).

Parameters:
  • name – Name of map value
  • sessionNumber – Session number of the stack
Returns:

Str (this is a single value)

Examples:

m.getValue('pixelsz', 2) # get the number of z-slices (pixels) of stack 2.
m.getValue('voxelx', 5) # get the x voxel size of stack 5 (in um/pixel).
m.getValue('hsStack',3) # get the name of stack 3.
ingest(tp, channel=1)[source]

Take a raw 3D .tif and populate raw/ingest/tp<tp> with single channel .tif files.

Parameters:
  • tp (int) – The timepoint to ingest
  • channel (int) – The channel to ingest, valid channels are (1,2,3)
Returns:

None

mapInfo()[source]

Get information on the map

Returns:
A dict of
mapName : Str
numSessions : Int
numChannels : Int
numMapSegments : Int

The following are string list with numSessions elements
stackNames :
importedStackName :
numSlices :
date :
time :
dx : Voxel size in um
dy : Voxel size in um
dz : Voxel size in um
px : Number of Pixels
py : Number of Pixels
pz : Number of Pixels
numChannels

Number of image channels in each stack (must be the same for all stacks).

numMapSegments

The number of line segments in the map. Corresponding segments are connected together with the segMap.

numSessions

Number of sessions (timepoints) in the map (time-series).

stacks

List of pymapmanager.mmStack in the map.

pymapmanager.mmMapAnalysis module

pymapmanager.mmMapAnalysis.getMapDynamics(map, plotDict)[source]

Calculate dynamics of annotations across a map including added, subtracted, density added, density subtracted, etc. etc.

For spines, this generates a set of analysis for each dendretic segment across sessions in a the map

Parameters:
  • map (obj) – mmMap
  • plotDict (dict) – See mmUtil.getdynamicsdict()
Returns:

list of dict. Use pandas.DataFrame.from_dict to easily view output

Example:

import pandas as pd
from IPython.display import display # displays pretty table in ipython

from pymapmanager.mmUtil import newplotdict
from pymapmanager.mmMap import mmMap
from pymapmanager.mmMapAnalysis import getMapDynamics

# load a map
filePath = '/Users/cudmore/Desktop/data/rr30a/rr30a.txt'
m = mmMap(filePath=filePath)

plotDict = newplotdict()
plotDict = getMapDynamics(m, pd)

for segmentReport in plotDict:
    display(pd.DataFrame.from_dict(segmentReport, orient='index'))
pymapmanager.mmMapAnalysis.segmentAnalysis(map, ps)[source]
Parameters:
  • map – mmMap
  • ps (dictionary) – From mmUtil.newplotdict(). Fill in plotStruct[‘xstat’] with stat of interest

pymapmanager.mmMapPlot2 module

Helper class to plot mmMap annotations.

Example:

from pymapmanager.mmMap import mmMap
from pymapmanager.mmUtil import newplotdict
%matplotlib notebook

# load a map
myMapFile = 'PyMapManager/examples/exampleMaps/rr30a/rr30a.txt'
myMap = mmMap(filePath=myMapFile)

# plot
mp = mmMapPlot2(myMap)
plotDict = newplotdict()
plotDict['segmentid'] = 1 # only map segment 1
mp.plotMap0(plotDict)
class pymapmanager.mmMapPlot2.mmMapPlot2(m)[source]

Bases: object

getUserSelection(pnt)[source]

Return session and stackdb index when user click on a window in Qt

Parameters:pnt – point selected in Qt canvas onpick()

Returns: session index, stackdb index

onclick(event)[source]

Used by Qt interface.

Parameters:event (pymapmanager.mmUtil.mmEvent) –
plotMap(fig, pd)[source]

Plot x/y values from a map.

Parameters:
  • fig – Either a matplotlib.figure.Figure if using Qt or plt.figure() if using command line or IPython/Jupyter.
  • pd (dict) – A plot dictionary describing what to plot. Get default from mmUtil.newplotdict(). Fill in [‘xstat’] and [‘ystat’] with valid stack annotation names.

Returns: None

plotMap0(fig, pd)[source]

Plot a canonical spine map of position along segment versus session.

Parameters:
  • fig – Either a matplotlib.figure.Figure if using Qt or plt.figure() if using command line or IPython/Jupyter.
  • pd – A plot dictionary describing what to plot. Get default from mmUtil.newplotdict().

Returns: None

toggledynamics(onoff=None)[source]

Turn dynamics marker color on and off

togglelines(onoff=None)[source]

Toggle lines connecting annotations between timepoint. Be carefull here on repeatedly plot these lines

x

Returns an array of x values in the plot.

y

Returns an array of y values in the plot.

pymapmanager.mmMapPool module

pymapmanager.mmStack module

class pymapmanager.mmStack.mmStack(filePath=None, name=None, numChannels=1, map=None, mapSession=None, urlmap=None)[source]

Bases: object

A stack contains a 3D Tiff, a list of 3D annotations, and optionally a number of segment tracings, pymapmanager.mmStackLine. A stack can either be a single time-point or be embeded into a session of a pymapmanager.mmMap.

Parameters:
  • filePath (str) – Full path to tiff file, this is used to open single timepoint stacks (not stacks in a map)
  • name (str) – Name of the stack. Used to fetch .tif file
  • numChannels (int) – Number of channels.
  • map (object) – Runtime object of pymapmanager.mmMap that created the stack.
  • mapSession (int) – The map session number for the stack.
annotationNames

A list of all annotation names in the stack.

These are valid names for stat passed to getStackValues2() and names for pd[‘xstat’], pd[‘ystat’], pd[‘zstat’] passed to getStackValues3().

Returns:List (str).
countObj(roiType=None)[source]

Count the number of roiType in stack

getStackValues2(stat, roiType=['spineROI'], segmentID=[], plotBad=False, plotIntBad=False)[source]

Get all values for an annotation.

Parameters:
  • stat (str) – Name of a stack annotation.
  • roiType – spineROI or otherROI.
  • segmentID – Integer list specifying stack segment number.
Returns:

1D numpy ndarray of values

getStackValues3(pd)[source]

Get values of three annotations using a plot dictionary pd.

Get a default plot dictionary from pymapmanager.mmUtil.newplotdict() and Fill in pd[‘xstat’], pd[‘ystat’], pd[‘ztat’] with valid annotationNames.

Parameters:pd (dict) – A plot dictionary describing what to plot.
Returns:
pd[‘x’], values if pd[‘xstat’], length is number of annotations matching criteria in original pd argument
pd[‘y’], values if pd[‘ystat’]
pd[‘z’], values if pd[‘zstat’]
pd[‘stackidx’], stack index of returned values
pd[‘reverse’], same length as stackdb.numObj,
reverse[i]>=0 gives index into pd[‘x’] for annotation i.
reverse[i]==’nan’ means annotation i was not included.
images

3D numpy ndarray of images. This is not valid until loadStackImages() is called. Images are in the 1st dimension, use images[0,:,:] to get the first image.

line

A pymapmanager.mmStackLine that holds 3D tracing of line segments.

loadStackImages(channel=2)[source]

Load the images for a stack. Sets ‘images’ instance variable

MapManager uses single channel .tif files. Each channel has its own file: _ch1.tif, _ch2.tif, _ch3.tif.

Parameters:channel (int) – Specifies the channel number to load.
Returns:3D numpy array of images.
Return type:images (3D ndarray)
numObj

The number of objects (annotations) in the stack. This is the number of rows in stackdb

numSegments

Number of line segments in the stack.

numSlices

Number of images in the stack.

stackdb

A pandas dataframe of annotations, one per row. Columns are annotation names.

pymapmanager.mmStackLine module

class pymapmanager.mmStackLine.mmStackLine(stack)[source]

Bases: object

A stack line represents a 3D tracing of a number of dendritic segments.

Each spineROI annotation in a mmStack is associated with one segmentID.

Example:

from pymapmanager.mmMap import mmMap
myMapFile = 'PyMapManager/examples/exampleMaps/rr30a/rr30a.txt'
myMap = mmMap(filePath=myMapFile)

# Get the (x,y,z) values, in um, of the 2nd mmStack tracing
xyz = myMap.stacks[2].getLine()
getLine(segmentID=[])[source]

Get the x/y/z values of a line tracing. Pass segmentID to get just one tracing. Note, x/y are in um, z is in slices!

Parameters:segmentID (list) – List of int specifying which segmentID, pass [] to get all.
Returns:numpy ndarray of (x,y,z)
getLineLength(segmentID, smoothz=None)[source]

Get the 3D line length for one segment (um)

Parameters:
  • segmentID (int) – Stack centric segmentID, different from other functions, requires an int (not a list)
  • smoothz (int) – Smooth Z
Returns:

3D length (float) of segmentID

getLineValues3(pd)[source]
Parameters:pd (dict) – See mmUtil.newplotdict()

Returns: pd with [‘x’], [‘y’], and [‘z’] values filled in as numpy ndarray

linedb = None

Pandas dataframe of line with (x,y,z,ID) columns.

stack = None

The parent stack

pymapmanager.mmStackPool module

class pymapmanager.mmStackPool.mmStackPool(path)[source]

Bases: object

Load all .tif stacks in a folder.

Parameters:path (str) – Full path to a folder containing .tif files.

Example:

        path = myMapFile = 'PyMapManager/examples/exampleMaps/'
stacks = mmStackPool(path)
for stack in stacks:
    print(stack)
stacks

List of pymapmanager.mmStack in the mmStackPool.

pymapmanager.mmUtil module

Utility functions and classes for PyMapManager.

class pymapmanager.mmUtil.mmEvent(map, sessIdx, stackdbIdx)[source]

Bases: object

Class used by Qt to broadcast events. Events can be user events like ‘spine selection’ or program events like ‘map opened’

getText()[source]

Returns a human readable string describing the event.

For example: ‘Users Select sess:3 stackdbIdx:2, runRow:58’

spineSelection(map, sessIdx, stackdbIdx)[source]

Make a single spine selection event

Parameters:
pymapmanager.mmUtil.newplotdict()[source]

Get a new default plot dictionary.

The plot dictionary is used to tell plot functions what to plot (e.g. [‘xtat’] and [‘ystat’]).

All plot function return the same plot dictionary with keys filled in with values that were plotted (e.g. [‘x’] and [‘y’]).

Example:

import pymapmanager as pmm

path = 'PyMapManager/examples/exampleMaps/rr30a/rr30a.txt'
map = pmm.mmMap(path)
plotdict = pmm.mmUtil.newplotdict()
plotdict['xstat'] = 'days'
plotdict['ystat'] = 'pDist' # position of spine on its parent segment
plotdict = map.getMapValues3(plotdict)

# display with matplotlib
plotdict['x']
plotdict['y']

pymapmanager.mmio module

Use this to load (get) files from a mmserver. This is a temporary wrapper as mmserver is currently a Flask server (slow). Eventually transition this to use proper online repository like ndio.

To Do: add Rest interface to get number of timepoints in a map?

Examples:

from pymapmanager.mmio import mmio
s = mmio.mmio()
        Success, the server at http://robertcudmore.org/mmserver/ is up and running!

s.maplist()
        ["rr30a", "rr58c"]

# these are the basic files that we can get for map 'rr30a'
# they will each return text that can be converted to a stringio and read into python (numpy and/or panda)
s.getfile('header', 'rr30a')
s.getfile('objmap', 'rr30a')
s.getfile('segmap', 'rr30a')
s.getfile('stackdb', 'rr30a', timepoint=0)
s.getfile('line', 'rr30a', timepoint=0)
s.getfile('int', 'rr30a', timepoint=0, channel=1)

# a bad request looks like this
s.getfile('header', 'bad map')
        error: mmio.getfile() received a 404 for url: http://robertcudmore.org/mmserver/public/bad map/header

# upload a map
map = '/Users/cudmore/MapManagerData/richard/Nancy/rr30a'
s.postmap(map)
Notes::

Header files are saved with

Stackdb, int, and line files are saved with

class pymapmanager.mmio.mmio(server_url='http://cudmore.duckdns.org:5010/', username='public')[source]

Bases: object

getfile(type, mapname, timepoint=None, channel=None)[source]

Get a file from a map.

Parameters:
  • type (str) – One of (header, objmap, segmap, stackdb, line, int)
  • mapname (str) –
  • timepoint (int) –
  • channel (int) – Required for type=int
To Do::
Server should mirror mmMap and mmStack. For example, merge stackdb and int
getimage(mapname, timepoint, slice, channel=1)[source]

Get an image from a map.

Parameters:
  • mapname (str) –
  • timepoint (int) –
  • slice (int) –
  • channel (int) –
Note::
For now this is the whole 3D stack, need to make it one slice.
maplist()[source]

Return list of maps for user username

postmap(mapFolder)[source]

Post a map to the server.

Parameters:mapFolder (str) full path to map folder (local machine) –

Module contents