polyfemos.parser.functionparser

Functions to parse filepaths from strings following the internal function syntax

copyright

2019, University of Oulu, Sodankyla Geophysical Observatory

license

GNU Lesser General Public License v3.0 or later (https://spdx.org/licenses/LGPL-3.0-or-later.html)

Public Functions

polyfemos.parser.functionparser.compose(op, f1, f2)[source]

A function to compose functions

Parameters
  • op (func) – A two argument function

  • f1,f2 (float, int, bool, func) – value or function, given function should take one argument, if value given, it will be changed in to one-argument function

Return type

func

Returns

A one argument function

polyfemos.parser.functionparser.function_from_str(functionstr)[source]

Creates a simple function from given string.

The functionstr may or may not be inside parentheses, the functionstr may not contain any other brackets (except curly brackets intead of <= and >= operations if wanted).

Available operations in execution order, Order of execution of same operations is from left to right. Note that all of the operations take two arguments.

Operation

Alias

Description

**

^

power

*

multiplication

/

division

+

addition

-

substracion

<

lesser than

<=

{

lesser or equal

>

greater than

>=

}

greater or equal

==

=

equal

!=

!

not equal

&

and

|

or

r

round, <num>r<decimals>

Available values

Value

Alias

Description

X

The variable/argument in the resulting function

False

F

boolean False

True

T

boolean False

Example functionstr values

(False)
(X<4.0|X>7|X==5)
(X<4.0|X>7)
(X<=4.0|X>=7)
(X*0.001r3)
(X*10./27.+5.r3)
(X<=-1)
Parameters

functionstr (str) –

Return type

func

Returns

A one-argument function which returns either boolean or numeral depending on the used operations