gotran.common package

Submodules

gotran.common.dicts module

class gotran.common.dicts.adict(**kwargs)[source]

Bases: dict

A dictionary with attribute-style access. It maps attribute access to the real dictionary.

copy() → a shallow copy of D[source]
class gotran.common.dicts.odict(iterable=None)[source]

Bases: dict

A simple ordered dict

clear() → None. Remove all items from D.[source]
items() → a set-like object providing a view on D's items[source]
iteritems()[source]
iterkeys()[source]
itervalues()[source]
keys() → a set-like object providing a view on D's keys[source]
pop(k[, d]) → v, remove specified key and return the corresponding value.[source]

If key is not found, d is returned if given, otherwise KeyError is raised

popitem() → (k, v), remove and return some (key, value) pair as a[source]

2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D[source]
update([E, ]**F) → None. Update D from dict/iterable E and F.[source]

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() → an object providing a view on D's values[source]

gotran.common.disk module

gotran.common.disk.load(basename, latest_timestamp=False, collect=False)[source]

Load data using cPickle

@type basename : str @param basename : The name of the file where the data will be loaded from, ‘.cpickle’ will be appended to the file name if not provided @type latest_timestamp : bool @param latest_timestamp : If true return the data from latest version of saved data with the same basename @type collect : bool @param collect : If True collect all data with the same basename and the same parameters

gotran.common.disk.save(basename, **data)[source]

Save data using cPickle

@type basename : str @param basename : The name of the file to save the data in, .cpickle will be appended to the file name if not provided @param data : The actuall data to be saved.

gotran.common.disk.present_time_str()[source]

Returns the present time nicely formated

gotran.common.options module

Module contents

class gotran.common.Logger(name)[source]

Bases: object

add_log_indent(increment=1)[source]

Add to indentation level.

add_logfile(filename=None, mode='a')[source]
begin_log(*message)[source]

Begin task: write message and increase indentation level.

debug(*message)[source]

Write debug message.

end_log()[source]

End task: write a newline and decrease indentation level.

error(*message, **kwargs)[source]

Write error message and raise an exception.

flush_logger()[source]

Flush the log handler

get_log_handler()[source]

Get handler for logging.

get_log_level()[source]

Get log level.

get_logfile_handler(filename)[source]
get_logger()[source]

Return message logger.

info(*message)[source]

Write info message.

info_blue(*message)[source]

Write info message in blue.

info_green(*message)[source]

Write info message in green.

info_red(*message)[source]

Write info message in red.

log(level, *message)[source]

Write a log message on given log level

pop_log_level()[source]

Pop log level from the level stack, reverting to before the last push_level.

push_log_level(level)[source]

Push a log level on the level stack.

remove_logfile(filename)[source]
set_default_exception(exception)[source]
set_log_handler(handler)[source]

Replace handler for logging.

To add additional handlers instead of replacing the existing, use log.get_logger().addHandler(myhandler).

See the logging module for more details.

set_log_indent(level)[source]

Set indentation level.

set_log_level(level)[source]

Set log level.

set_log_prefix(prefix)[source]

Set prefix for log messages.

set_raise_error(value)[source]
suppress_logging()[source]

Suppress all logging

type_error(*message, **kwargs)[source]

Write error message and raise a type error exception.

value_error(*message, **kwargs)[source]

Write error message and raise a value error exception.

warning(*message)[source]

Write warning message.

wrap_log_message(message, symbol='*')[source]
exception gotran.common.GotranException[source]

Bases: RuntimeError

Base class for ModelParameters exceptions

gotran.common.ClassType

alias of builtins.type

gotran.common.float_format()[source]
gotran.common.reduce(function, sequence[, initial]) → value

Apply a function of two arguments cumulatively to the items of a sequence, from left to right, so as to reduce the sequence to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5). If initial is present, it is placed before the items of the sequence in the calculation, and serves as a default when the sequence is empty.

gotran.common.rjust(s, *args, **kwargs)[source]
gotran.common.VALUE_JUST(s, *args, **kwargs)
gotran.common.param2value(param)[source]
gotran.common.value_formatter(value, width=0)[source]

Return a formated string of a value

Parameters:
  • value (any) – The value which is formatted
  • width (int) – A min str length value
class gotran.common.Range(ge=None, le=None, gt=None, lt=None)[source]

Bases: object

A simple class for helping checking a given value is within a certain range

format(value, width=0)[source]

Return a formated range check of the value

Parameters:
  • value (scalar) – A value to be used in checking range
  • width (int) – A min str length value
format_in(value, width=0)[source]

Return a formated range check

Parameters:
  • value (scalar) – A value to be used in checking range
  • width (int) – A min str length value
format_not_in(value, width=0)[source]

Return a formated range check

Parameters:
  • value (scalar) – A value to be used in checking range
  • width (int) – A min str length value
gotran.common.format_time(time)[source]

Return a formated version of the time argument

Parameters:time (float) – Time given in sections
class gotran.common.Timer(task)[source]

Bases: object

Timer class

classmethod timings()[source]

Return all registered timings

gotran.common.list_timings()[source]

List all registered timings

gotran.common.clear_timings()[source]

Clear all registered timings

gotran.common.tic()[source]

Start timing

gotran.common.toc()[source]

Return timing since last toc/tic

gotran.common.is_iterable(obj)[source]

Test for iterable

Parameters:obj (any) – Object which is beeing tested
gotran.common.add_iterable(iterable, initial=None)[source]

Sum the content of an iterable

gotran.common.camel_capitalize(name)[source]

Camel capitalize a str

gotran.common.tuplewrap(arg)[source]

Wrap the argument to a tuple if it is not a tuple

gotran.common.listwrap(arg)[source]

Wrap the argument to a list if it is not a list

gotran.common.check_arginlist(arg, lst, name='arg')[source]

Check that arg is in lst

gotran.common.check_arg(arg, argtypes, num=-1, context=None, itemtypes=None, ge=None, le=None, gt=None, lt=None)[source]

Type check for positional arguments

Parameters:
  • arg (any) – The argument to be checked
  • argtypes (type, tuple) – The type of which arg should be
  • num (int (optional)) – The argument positional number
  • context (type, function/method (optional)) – The context of the check. If context is a class the check is assumed to be during creation. If a function/method the contex is assumed to be a call to that function/method
  • itemtypes (type (optional)) – If given argtypes must be a tuple or list and itemtypes forces each item to be a certain type
  • ge (scalar (optional)) – Greater than or equal, range control of argument
  • le (scalar (optional)) – Lesser than or equal, range control of argument
  • gt (scalar (optional)) – Greater than, range control of argument
  • lt (scalar (optional)) – Lesser than, range control of argument
gotran.common.check_kwarg(kwarg, name, argtypes, context=None, itemtypes=None, ge=None, le=None, gt=None, lt=None)[source]

Type check for keyword arguments

Parameters:
  • kwarg (any) – The keyword argument to be checked
  • name (str) – The name of the keyword argument
  • argtypes (type, tuple) – The type of which arg should be
  • context (type, function/method (optional)) – The context of the check. If context is a class the check is assumed to be during creation. If a function/method the contex is assumed to be a call to that function/method
  • itemtypes (type (optional)) – If given argtypes must be a tuple or list and itemtypes forces each item to be a certain type
  • ge (scalar (optional)) – Greater than or equal, range control of argument
  • le (scalar (optional)) – Lesser than or equal, range control of argument
  • gt (scalar (optional)) – Greater than, range control of argument
  • lt (scalar (optional)) – Lesser than, range control of argument
gotran.common.quote_join(list_of_str)[source]

Join a list of strings with quotes and commans

gotran.common.deprecated(func)[source]

This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.

class gotran.common.adict(**kwargs)[source]

Bases: dict

A dictionary with attribute-style access. It maps attribute access to the real dictionary.

copy() → a shallow copy of D[source]
class gotran.common.odict(iterable=None)[source]

Bases: dict

A simple ordered dict

clear() → None. Remove all items from D.[source]
items() → a set-like object providing a view on D's items[source]
iteritems()[source]
iterkeys()[source]
itervalues()[source]
keys() → a set-like object providing a view on D's keys[source]
pop(k[, d]) → v, remove specified key and return the corresponding value.[source]

If key is not found, d is returned if given, otherwise KeyError is raised

popitem() → (k, v), remove and return some (key, value) pair as a[source]

2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D[source]
update([E, ]**F) → None. Update D from dict/iterable E and F.[source]

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() → an object providing a view on D's values[source]
gotran.common.load(basename, latest_timestamp=False, collect=False)[source]

Load data using cPickle

@type basename : str @param basename : The name of the file where the data will be loaded from, ‘.cpickle’ will be appended to the file name if not provided @type latest_timestamp : bool @param latest_timestamp : If true return the data from latest version of saved data with the same basename @type collect : bool @param collect : If True collect all data with the same basename and the same parameters

gotran.common.save(basename, **data)[source]

Save data using cPickle

@type basename : str @param basename : The name of the file to save the data in, .cpickle will be appended to the file name if not provided @param data : The actuall data to be saved.

gotran.common.present_time_str()[source]

Returns the present time nicely formated