Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions | Variables
CellMLToNektar.utilities Namespace Reference

Classes

class  Colourable
 
class  NotifyHandler
 
class  OnlyDebugFilter
 
class  OnlyTheseSourcesFilter
 
class  OnlyWarningsFilter
 
                                            #

Logging # # More...

 
class  Sentinel
 
class  unitary_iterator
 

Functions

def DEBUG
 
def LOG
 
def amara_parse
 
def element_path
 
def element_path_cmp
 
def element_xpath
 
def brief_xml
 
def call_if
 
                                                   #

Miscellaneous functions # # More...

 
def max_i
 
def prid
 
def add_dicts
 
def open_output_stream
 
def close_output_stream
 

Variables

list __all__
 
tuple DFS = Enum('White', 'Gray', 'Black')
 
                                                  #

Miscellaneous classes # # More...

 

Detailed Description

Copyright (c) 2005-2016, University of Oxford.
All rights reserved.

University of Oxford means the Chancellor, Masters and Scholars of the
University of Oxford, having an administrative office at Wellington
Square, Oxford OX1 2JD, UK.

This file is part of Chaste.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
 * Neither the name of the University of Oxford nor the names of its
   contributors may be used to endorse or promote products derived from this
   software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

def CellMLToNektar.utilities.add_dicts (   r,
  ds 
)
Add multiple dictionaries together.

Updates the first input dictionary by adding values from
subsequent inputs.  Produces a dictionary with keys taken from the
input dictionaries, and values being the sum of the corresponding
values in all inputs.
Assumes values are numeric.

Definition at line 284 of file utilities.py.

Referenced by CellMLToNektar.pycml.mathml_apply.tree_complexity(), and CellMLToNektar.pycml.mathml_piecewise.tree_complexity().

285 def add_dicts(r, *ds):
286  """Add multiple dictionaries together.
287 
288  Updates the first input dictionary by adding values from
289  subsequent inputs. Produces a dictionary with keys taken from the
290  input dictionaries, and values being the sum of the corresponding
291  values in all inputs.
292  Assumes values are numeric.
293  """
294  for d in ds:
295  for k, v in d.iteritems():
296  r[k] = r.get(k, 0) + v
297 
def CellMLToNektar.utilities.amara_parse (   source,
  uri = None,
  rules = None,
  binderobj = None,
  prefixes = None 
)
Convenience function for parsing XML.

Works just as amara.parse, except that if source is '-' then
it reads from standard input.

Definition at line 192 of file utilities.py.

Referenced by CellMLToNektar.pycml.amara_parse_cellml(), CellMLToNektar.utilities.unitary_iterator.next(), and CellMLToNektar.translators.ConfigurationStore.read_configuration_file().

193  prefixes=None):
194  """Convenience function for parsing XML.
195 
196  Works just as amara.parse, except that if source is '-' then
197  it reads from standard input.
198  """
199  if source == '-':
200  return amara.parse(sys.stdin, uri=uri, rules=rules,
201  binderobj=binderobj, prefixes=prefixes)
202  else:
203  return amara.parse(source, uri=uri, rules=rules,
204  binderobj=binderobj, prefixes=prefixes)
205 
def CellMLToNektar.utilities.brief_xml (   elt)
Print a more concise version of elt.xml() that omits all attributes.

Definition at line 232 of file utilities.py.

233 def brief_xml(elt):
234  """Print a more concise version of elt.xml() that omits all attributes."""
235  s = ''
236  if getattr(elt, 'nodeType', None) == Node.ELEMENT_NODE:
237  children = getattr(elt, 'xml_children', [])
238  if children:
239  s += '<' + elt.localName + '>'
240  for child in children:
241  s += brief_xml(child)
242  s += '</' + elt.localName + '>'
243  else:
244  s += '<' + elt.localName + '/>'
245  else:
246  s += str(elt)
247  return s
248 
def CellMLToNektar.utilities.call_if (   tf,
  callable,
  args,
  kwargs 
)

                                                   #

Miscellaneous functions # #

Call the given callable with the given arguments iff tf is True.

Definition at line 255 of file utilities.py.

Referenced by CellMLToNektar.translators.ConfigurationStore._find_transmembrane_currents_from_voltage_ode().

256 def call_if(tf, callable, *args, **kwargs):
257  """Call the given callable with the given arguments iff tf is True."""
258  if tf:
259  return callable(*args, **kwargs)
260 
def call_if
# Miscellaneous functions # # ...
Definition: utilities.py:255
def CellMLToNektar.utilities.close_output_stream (   stream)
Close the given output stream, unless it's one of the standard streams
(i.e. sys.stdout or sys.stderr).
Note that closing a stream multiple times is safe.

Definition at line 314 of file utilities.py.

Referenced by CellMLToNektar.validator.run(), and CellMLToNektar.translators.run().

315 def close_output_stream(stream):
316  """
317  Close the given output stream, unless it's one of the standard streams
318  (i.e. sys.stdout or sys.stderr).
319  Note that closing a stream multiple times is safe.
320  """
321  if not stream is sys.stdout and not stream is sys.stderr:
322  stream.close()
def CellMLToNektar.utilities.DEBUG (   facility,
  args 
)
Log a debug message to facility.

Arguments are treated as for the print statement.

Definition at line 95 of file utilities.py.

Referenced by CellMLToNektar.processors.UnitsConverter._apply_special_conversion_for_nested_expr(), CellMLToNektar.pycml.cellml_model._check_assigned_vars(), CellMLToNektar.pycml.cellml_model._check_cellml_subset(), CellMLToNektar.optimize.LinearityAnalyser._check_expr(), CellMLToNektar.processors.UnitsConverter._check_special_conversion(), CellMLToNektar.pycml.cellml_model._check_variable_mappings(), CellMLToNektar.pycml.cellml_model._classify_variables(), CellMLToNektar.pycml.cellml_variable._decrement_usage_count(), CellMLToNektar.optimize.LookupTableAnalyser._determine_unneeded_tables(), CellMLToNektar.translators.ConfigurationStore._find_transmembrane_currents_from_voltage_ode(), CellMLToNektar.pycml.cellml_variable._get_binding_time(), CellMLToNektar.pycml.mathml_eq._get_binding_time(), CellMLToNektar.pycml.mathml_ci._reduce(), CellMLToNektar.pycml.mathml_apply._reduce(), CellMLToNektar.pycml.mathml_constructor._reduce_elt(), CellMLToNektar.pycml.mathml_units_mixin._set_element_in_units(), CellMLToNektar.pycml.mathml_units_mixin_choose_nearest._set_in_units(), CellMLToNektar.pycml.cellml_model._validate_component_hierarchies(), CellMLToNektar.optimize.LinearityAnalyser.analyse_for_jacobian(), CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut(), CellMLToNektar.processors.UnitsConverter.convert_mapping(), CellMLToNektar.translators.ConfigurationStore.expose_variables(), CellMLToNektar.translators.ConfigurationStore.find_lookup_variables(), CellMLToNektar.translators.ConfigurationStore.find_membrane_capacitance(), CellMLToNektar.translators.ConfigurationStore.find_transmembrane_potential(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.translators.ConfigurationStore.read_configuration_file(), CellMLToNektar.pycml.cellml_variable.remove_rdf_annotations(), CellMLToNektar.translators.run(), CellMLToNektar.validator.CellMLValidator.validate(), and CellMLToNektar.pycml.cellml_model.validate().

95 
96 def DEBUG(facility, *args):
97  """Log a debug message to facility.
98 
99  Arguments are treated as for the print statement.
100  """
101  logger = logging.getLogger(facility)
102  if logger.isEnabledFor(logging.DEBUG):
103  logger.debug(' '.join(map(str, args)))
104 
def CellMLToNektar.utilities.element_path (   elt)
Find the path from the root element to this element.

Definition at line 206 of file utilities.py.

Referenced by CellMLToNektar.utilities.element_path_cmp(), and CellMLToNektar.utilities.element_xpath().

207 def element_path(elt):
208  """Find the path from the root element to this element."""
209  if hasattr(elt, 'xml_parent'):
210  idx = 0
211  for child in elt.xml_parent.xml_children:
212  if getattr(child, 'nodeType', None) == Node.ELEMENT_NODE:
213  idx += 1
214  if child is elt:
215  break
216  return element_path(elt.xml_parent) + [idx]
217  else:
218  return []
219 
def CellMLToNektar.utilities.element_path_cmp (   e1,
  e2 
)
Compare 2 elements by comparing their paths from the root element.

Definition at line 220 of file utilities.py.

References CellMLToNektar.utilities.element_path().

221 def element_path_cmp(e1, e2):
222  """Compare 2 elements by comparing their paths from the root element."""
223  return cmp(element_path(e1), element_path(e2))
224 
def CellMLToNektar.utilities.element_xpath (   elt)
Return an xpath expression that will select this element.

Definition at line 225 of file utilities.py.

References CellMLToNektar.utilities.element_path().

Referenced by CellMLToNektar.pycml.MathsError._generate_message().

226 def element_xpath(elt):
227  """Return an xpath expression that will select this element."""
228  indices = element_path(elt)
229  xpath = u'/*[' + u']/*['.join(map(str, indices)) + u']'
230  return xpath
231 
def CellMLToNektar.utilities.LOG (   facility,
  level,
  args 
)
Log a message to facility with the given level.

Arguments are treated as for the print statement.

Definition at line 105 of file utilities.py.

Referenced by CellMLToNektar.translators.ConfigurationStore.find_lookup_variables().

106 def LOG(facility, level, *args):
107  """Log a message to facility with the given level.
108 
109  Arguments are treated as for the print statement.
110  """
111  logger = logging.getLogger(facility)
112  if logger.isEnabledFor(level):
113  logger.log(level, ' '.join(map(str, args)))
def CellMLToNektar.utilities.max_i (   it)
Find the maximum entry of an iterable, and return it with its index.

Returns (i, m) where i is the index of m, the maximum entry of `it`.

Definition at line 261 of file utilities.py.

Referenced by CellMLToNektar.pycml.mathml_piecewise.tree_complexity().

262 def max_i(it):
263  """Find the maximum entry of an iterable, and return it with its index.
264 
265  Returns (i, m) where i is the index of m, the maximum entry of `it`.
266  """
267  idx, m = None, None
268  for i, val in enumerate(it):
269  if m is None or val > m:
270  m, idx = val, i
271  return idx, m
272 
def CellMLToNektar.utilities.open_output_stream (   fname)
Open fname for output.

fname should be a local filename, or '-' for standard output.
Additionally, the names 'stdout' and 'stderr' have the usual
special meanings.

Definition at line 298 of file utilities.py.

Referenced by CellMLToNektar.validator.run(), and CellMLToNektar.translators.run().

299 def open_output_stream(fname):
300  """Open fname for output.
301 
302  fname should be a local filename, or '-' for standard output.
303  Additionally, the names 'stdout' and 'stderr' have the usual
304  special meanings.
305  """
306  if fname == '-' or fname == 'stdout':
307  stream = sys.stdout
308  elif fname == 'stderr':
309  stream = sys.stderr
310  else:
311  stream = open(fname, 'w')
312  return stream
313 
def CellMLToNektar.utilities.prid (   obj,
  show_cls = False 
)
Get the id of an object as a hex string, optionally with its class/type.

Definition at line 273 of file utilities.py.

274 def prid(obj, show_cls=False):
275  """Get the id of an object as a hex string, optionally with its class/type."""
276  if obj is None:
277  s = 'None'
278  else:
279  s = hex(id(obj))
280  if show_cls:
281  s += str(type(obj))
282  return s
283 

Variable Documentation

list CellMLToNektar.utilities.__all__
Initial value:
1 = ['OnlyWarningsFilter', 'OnlyDebugFilter', 'OnlyTheseSourcesFilter', 'NotifyHandler',
2  'DEBUG', 'LOG',
3  'Colourable', 'DFS', 'Sentinel', 'unitary_iterator',
4  'amara_parse', 'element_path', 'element_path_cmp', 'element_xpath', 'brief_xml',
5  'call_if', 'max_i', 'prid', 'add_dicts',
6  'open_output_stream', 'close_output_stream']

Definition at line 45 of file utilities.py.

tuple CellMLToNektar.utilities.DFS = Enum('White', 'Gray', 'Black')

                                                  #

Miscellaneous classes # #

Definition at line 121 of file utilities.py.