| Previous: SciParam GUI features | Up: Index | Next: Creating dialogs and notebooks |
This HTML documentation is no longer maintained. See sciparam-manual.pdf for an updated version.

Creating parameters

Import of parameter classes

SciParam contains the following parameter classes:
  • FloatParam
  • IntParam
  • StringParam
  • ChoiceParam
  • DistParam
SciParam supports accessing these in several ways, as shown here with StringParam:
  • import SciParam
    param = SciParam.StringParam('name')
    
  • import SciParam.parameter
    param = SciParam.parameter.StringParam('name')
    
  • from SciParam import FloatParam, IntParam, StringParam, ChoiceParam, DistParam
    param = StringParam('name')
    
This one is deprecated, except for saving keystrokes in interactive sessions:
  • from SciParam import *
    param = StringParam('name')
    
There are other possible ways to import them, but only these are guaranteed to work in future versions.

Every parameter instance must have a name and can have a description, a unit, a default value, a current value and a comment. Additionally there is the required flag and the notunknown flag. See the description of the SciParam class for details.

Import of classes Range and Distribution

The parameter classes can build ranges and distributions from a string, therefore you don't need to import these classes very often.

If you want to import them, use one of these methods:

  • import SciParam
    range1 = SciParam.Range()
    dist1 = SciParam.Distribution()
    
  • import SciParam.range
    import SciParam.distribution
    range1 = SciParam.range.Range()
    dist1 = SciParam.distribution.Distribution()
    
  • from SciParam import Range, Distribution
    range1 = Range()
    dist1 = Distribution()
    
This one is deprecated, except for saving keystrokes in interactive sessions:
  • from SciParam import *
    range1 = Range()
    dist1 = Distribution()
    
There are other possible ways to import them, but only these are guaranteed to work in future versions.

See the description of the Range class and the description of the Distribution class for details.

Sample code

File examples/parameter_example.py:
#!/usr/bin/env python
#
# Copyright (C) 2002 by Intevation GmbH
# Authors:
# Thomas Arendsen Hein <thomas@intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with the software for details.

"""
Scientific Parameters
"""

from SciParam import FloatParam, IntParam, StringParam, ChoiceParam, DistParam

if __name__ == "__main__":
    parameter = [
        StringParam('Name', 'a unique identifier', required=1,
                    value='Silicon',
                    comment='This is an example for a required value.\n'
                            'The user can change this comment to note the '
                            'source of this information.'),
        StringParam('Symbol', 'chemical symbol', required=1, value='Si'),
        IntParam('Atomic No',
                 'Number in the periodic table of the elements',
                 value=14, wrange='[1;260]', erange='[1;oo['),
        FloatParam('Atomic Mass', None, value=28.0855, erange='[0;oo['),
        FloatParam('Melting Point', 'under normal conditions', '°C',
                   value=1414,
                   wrange='[-273.15;4e3]', erange='[-273.15;oo['),
        FloatParam('Boiling Point', 'under normal conditions', '°C',
                   value=3265, wrange='[-270;6e3]', erange='[-273.15;oo['),
        ChoiceParam('Crystal', 'crystal structure',
                    choices=[None, 'simple cubic', 'face centered cubic',
                             'body centered cubic', 'diamond cubic',
                             'tetragonal', 'orthorombic', 'monoclinc'],
                    value='face centered cubic', long=1),
        DistParam('Temperature', 'temperature of samples', '°C',
                  default=20, value=17.5, erange='[-273.15;oo[',
                  dist=(3.7, 'normal')),
        DistParam('Volume', 'Volume of used samples', 'cm³',
                  default='2;20/uniform', erange='[0;oo['),
        ChoiceParam('Verified', 'Have these values been checked?',
                    choices=ChoiceParam.yes_no, value=0),
    ]

    for par in parameter:
        print par.name, "=", par.value
        print " comment =", par.comment
        if isinstance(par, DistParam):
            print " dist =", par.dist



| Previous: SciParam GUI features | Up: Index | Next: Creating dialogs and notebooks |

 

Info
Homepage
Screenshots
SVN
Mailing List
Bug Tracker
Related
   
News

Archive
   
Exits
Thuban
GREAT-ER.org
   
Project Team <great-er@intevation.de>
These pages are hosted by Intevation GmbH.