14.1.8. Miscellaneous

14.1.8.1. mosaic.settings module

Load analysis settings from a JSON file.

Created:

8/24/2012

Author:

Arvind Balijepalli <arvind.balijepalli@nist.gov>

License:

See LICENSE.TXT

ChangeLog:

3/20/23 AB Add support for pyabf
5/13/21 AB Include chimeraTrajio in default settings.
4/19/19 AB Added an option (trackBaseline) to continuously track the opent channel baseline current during an analysis.
9/22/17 AB Removed the filterEventPadding option to eventSegment.
7/15/17 AB Add the filterEventPadding option to eventSegment.
3/16/16 AB Replaced InitThreshold with StepSize in default settings for ADEPT and warn users when InitThreshold is used.
8/24/15 AB Updated algorithm names.
6/24/15 AB Added an option to unlink the RC constants in stepResponseAnalysis.
3/20/15 AB Added MaxEventLength to multiStateAnalysis settings
3/6/15 JF Corrected formatting on cusumLevelAnalysis and multiStateAnalysis dictionary file
3/6/15 AB Added MinStateLength parameter for multiStateAnalysis to dictionary
2/14/15 AB Added default settings for cusumLevelAnalysis.
8/20/14 AB Changed precedence of settings file search to datpath/.settings,
datpath/settings, coderoot/.settings and coderoot/settings
8/6/14 AB Add a function to parse a settings string.
9/5/13 AB Check for either .settings or settings in data directory
and code root. Warn when using default settings
8/24/12 AB Initial version
class mosaic.settings.settings(datpath, defaultwarn=True)[source]

Bases: object

Initialize a settings object.

Args:
  • datpath : Specify the location of the settings file. If a settings file is not found, return default settings.

  • defaultwarn : If True warn the user if a settings file was not found in the path specified by datpath.

getSettings(section)[source]

Return settings for a specified section as a Python dict.

Args:
  • section : specifies the section for which settings are requested. Returns an empty dictionary if the settings file doesn’t exist the section is not found.

14.1.8.2. mosaic.utilities.ionic_current_stats module

Created:

10/30/2014

Author:

Arvind Balijepalli <arvind.balijepalli@nist.gov>

License:

See LICENSE.TXT

ChangeLog:

5/24/19 AB Python 3.7 port
7/29/16 KB Added weights to histogram fitting
15/12/15 KB Added error checking and limits to baseline calculations
10/30/14 AB Initial version
mosaic.utilities.ionic_current_stats.OpenCurrentDist(dat, limit, minBaseline=-1, maxBaseline=-1)[source]

Calculate the mean and standard deviation of a time-series.

Args:
  • dat : time-series data

  • limit : limit the calculation to the top 50% (+0.5) of the range, bottom 50% (-0.5) or the entire range (0). Any other value of limit will cause it to be reset to 0 (i.e. full range).

14.1.8.3. mosaic.utilities.util module

A collection of utility functions

mosaic.utilities.util.avg(dat)[source]

Calculate the average of a list of reals

mosaic.utilities.util.commonest(dat)[source]

Return the most common element in a list.

mosaic.utilities.util.decimate(dat, size)[source]

Decimate dat for a specified window size.

mosaic.utilities.util.filter(dat, windowSz)[source]

Filter the data using a convolution. Returns an array of size len(dat)-windowSz+1 if dat is longer than windowSz. If len(dat) < windowSz, raise WindowSizeError

mosaic.utilities.util.flat2(dat)[source]

Flatten a 2D array to a list

mosaic.utilities.util.partition(dat, size)[source]

Partition a list into sub-lists, each of length size. If the number of elements in dat does not partition evenly, the last sub-list will have fewer elements.

mosaic.utilities.util.sd(dat)[source]

Wrapper for numpy std

mosaic.utilities.util.selectS(dat, nSigma, mu, sd)[source]

Select and return data from a list that lie within nSigma * SD of the mean.

14.1.8.4. mosaic.utilities.mosaicLogFormat module

An object that allows arbitrary formatting of log text.

Created:

09/12/2015

Author:

Arvind Balijepalli <arvind.balijepalli@nist.gov>

License:

See LICENSE.TXT

ChangeLog:

06/14/16 AB Added a new Python property class mimic to add log property set, get and del.
06/13/16 AB Remove mosaicLogFormat class
09/12/15 AB Initial version
mosaic.utilities.mosaicLogFormat._d(msg, *args)[source]

Format a debug log message. This function will automatically append calling function name and file/line number.

Parameters:
  • msg : Log message formatted using the Python formatter class.

  • args : Message arguments.

Usage:

Log an integer or a float variable.

_d("Var x has value {0}", x)

_d("Var y is a float with value {0:0.2f} to 2 decimal places.", y)
mosaic.utilities.mosaicLogFormat._dprop(msg, *args)[source]

Format a debug log message for a class property. This function will automatically append calling function name and file/line number.

Parameters:
  • msg : Log message formatted using the Python formatter class.

  • args : Message arguments.

Usage:

Log a property that returns an integer or a float.

_dprop("Var x has value {0}", x)

_dprop("Var y is a float with value {0:0.2f} to 2 decimal places.", y)
class mosaic.utilities.mosaicLogFormat.mosaic_property(fget=None, fset=None, fdel=None, doc=None)[source]

Bases: object

Emulate Python property. Add support to the getter and setter methods to automatically log properties in debug mode. The new class can be used exactly as the built-in Python property class, for example as a decorator

class foo:
        def __init__(self):
                self.x=100

        @mosaic_property
        def x(self):
                return self.x

        @x.setter
        def x(self, val):
                self.x=val

Adapted from: https://docs.python.org/2/howto/descriptor.html#properties.

14.1.8.5. mosaic.utilities.mosaicLogging module

An implementation of Python logging heavily adapted from http://stackoverflow.com/questions/15727420/using-python-logging-in-multiple-modules.

Created:

5/29/2016

Author:

Arvind Balijepalli <arvind.balijepalli@nist.gov>

License:

See LICENSE.TXT

ChangeLog:

5/30/16 AB Strip whitespace from rotating file handler messages.
5/29/16 AB Initial version
class mosaic.utilities.mosaicLogging.MessageFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]

Bases: Formatter

format(record)[source]

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

class mosaic.utilities.mosaicLogging.mosaicLogging(*args, **kwargs)[source]

Bases: object

A custom logging class that uses the Python logging facility. Logs are automatically saved to a metaMDIO instance, and to a file log when DeveloperMode is active.

static getLogger(name=None, dbHnd=None)[source]

Get a logger instance.

Parameters:
  • name : Logger name

  • dbHnd : MetaMDIO handle to allow logs to be saved to the database.

Usage:

In this example, we get an instance of a logger with the module name and log a debug message.

logger=mosaicLogging().getLogger(__name__)

logger.debug("Test debug message")

14.1.8.6. mosaic.utilities.mosaicTiming module

A class that provides platform independent timing and function profiling utilities.

Created:

4/10/2016

Author:

Arvind Balijepalli <arvind.balijepalli@nist.gov>

License:

See LICENSE.TXT

ChangeLog:

4/14/21 AB Windows fixes
6/17/16 AB Only profile functions in DeveloperMode. Log timing output.
4/10/16 AB Initial version
class mosaic.utilities.mosaicTiming.mosaicTiming[source]

Bases: object

Profile code by attaching an instance of this class to any function. All the methods in this class are valid for the function being profiled.

FunctionTiming(func)[source]

Pass the function to be profiled as an argument. Alternatively with python 2.4+, attach a decorator to the function being profiled.

Parameters:
  • func : function to be profiled

Usage:
funcTimer=mosaicTiming.mosaicTiming()

@funcTimer.FunctionTiming
def someFunc():
                print 'doing something'

# summarize the profiling results for someFunc
funcTimer.PrintStatistics()
PrintCurrentTime()[source]

Print timing results of the most recent function call

PrintStatistics()[source]

Print average timing results of the function call

Reset(funcname=None)[source]

Reset all profiling data collected for a specified function or all stored functions.

time()[source]

A platform independent timing function.

14.1.8.7. mosaic.utilities.fit_funcs module

Fit functions used in processing algorithms.

Created:

10/30/2014

Author:

Arvind Balijepalli <arvind.balijepalli@nist.gov>

License:

See LICENSE.TXT

ChangeLog:

12/09/15 KB Added a wrapper for multiStateFunc
6/24/15 AB Relaxed stepResponseFunc to include different RC constants
for up and down states.
12/31/14 AB Changed multi-state function to include a separate tau for
each state following Balijepalli et al, ACS Nano 2014.
11/19/14 AB Initial version