mailr16502 - /branches/uf_redesign/specific_fns/api_objects.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on May 29, 2012 - 11:25:
Author: bugman
Date: Tue May 29 11:25:19 2012
New Revision: 16502

URL: http://svn.gna.org/viewcvs/relax?rev=16502&view=rev
Log:
Split the specific API param obj loop() method into two.

The new base_loop() method loops over the parameter names according to set, 
whereas the loop()
method now supports and returns the error and simulation parameter names as 
well, if set.


Modified:
    branches/uf_redesign/specific_fns/api_objects.py

Modified: branches/uf_redesign/specific_fns/api_objects.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/specific_fns/api_objects.py?rev=16502&r1=16501&r2=16502&view=diff
==============================================================================
--- branches/uf_redesign/specific_fns/api_objects.py (original)
+++ branches/uf_redesign/specific_fns/api_objects.py Tue May 29 11:25:19 2012
@@ -153,199 +153,13 @@
             self.add('warning', scope=scope, desc='Optimisation warning')
 
 
-    def check_param(self, name):
-        """Check if the parameter exists.
-
-        @param name:        The name of the parameter to search for.
-        @type name:         str
-        @raises RelaxError: If the parameter does not exist.
-        """
-
-        # Check.
-        if name not in self._names:
-            raise RelaxError("The parameter '%s' does not exist." % name)
-
-
-    def contains(self, name):
-        """Determine if the given name is within the parameter list.
-
-        @param name:    The name of the parameter to search for.
-        @type name:     str
-        @return:        True if the parameter is within the list, False 
otherwise.
-        @rtype:         bool
-        """
-
-        # Check.
-        if name in self._names:
-            return True
-
-        # No match.
-        return False
-
-
-    def get_conv_factor(self, name):
-        """Return the conversion factor.
-
-        @param name:    The name of the parameter.
-        @type name:     str
-        @return:        The conversion factor.
-        @rtype:         float
-        """
-
-        # Parameter check.
-        self.check_param(name)
-
-        # No factor.
-        if self._conv_factor[name] == None:
-            return 1.0
-
-        # Function.
-        if isinstance(self._conv_factor[name], FunctionType) or 
isinstance(self._conv_factor[name], MethodType):
-            return self._conv_factor[name]()
-
-        # Value.
-        return self._conv_factor[name]
-
-
-    def get_default(self, name):
-        """Return the default value of the parameter.
-
-        @param name:    The name of the parameter.
-        @type name:     str
-        @return:        The default value.
-        @rtype:         None or str
-        """
-
-        # Parameter check.
-        self.check_param(name)
-
-        # Return the default value.
-        return self._defaults[name]
-
-
-    def get_desc(self, name):
-        """Return the description of the parameter.
-
-        @param name:    The name of the parameter.
-        @type name:     str
-        @return:        The description.
-        @rtype:         None or str
-        """
-
-        # Parameter check.
-        self.check_param(name)
-
-        # Return the description.
-        return self._desc[name]
-
-
-    def get_err(self, name):
-        """Return the error flag for the parameter.
-
-        @param name:    The name of the parameter.
-        @type name:     str
-        @return:        The error flag for the parameter.
-        @rtype:         bool
-        """
-
-        # Parameter check.
-        self.check_param(name)
-
-        # Return the type.
-        return self._err[name]
-
-
-    def get_grace_string(self, name):
-        """Return the Grace string for the parameter.
-
-        @param name:    The name of the parameter.
-        @type name:     str
-        @return:        The Grace string.
-        @rtype:         str
-        """
-
-        # Parameter check.
-        self.check_param(name)
-
-        # Return the value.
-        return self._grace_string[name]
-
-
-    def get_param_set(self, name):
-        """Return the parameter set that the parameter belongs to.
-
-        @param name:    The name of the parameter.
-        @type name:     str
-        @return:        The parameter set.
-        @rtype:         str
-        """
-
-        # Parameter check.
-        self.check_param(name)
-
-        # Return the type.
-        return self._param_set[name]
-
-
-    def get_sim(self, name):
-        """Return the Monte Carlo simulation flag for the parameter.
-
-        @param name:    The name of the parameter.
-        @type name:     str
-        @return:        The Monte Carlo simulation flag for the parameter.
-        @rtype:         bool
-        """
-
-        # Parameter check.
-        self.check_param(name)
-
-        # Return the type.
-        return self._sim[name]
-
-
-    def get_type(self, name):
-        """Return the Python type for the parameter.
-
-        @param name:    The name of the parameter.
-        @type name:     str
-        @return:        The Python type.
-        @rtype:         Python type object
-        """
-
-        # Parameter check.
-        self.check_param(name)
-
-        # Return the Python type.
-        return self._py_types[name]
-
-
-    def get_units(self, name):
-        """Return the units string for the parameter.
-
-        @param name:    The name of the parameter.
-        @type name:     str
-        @return:        The units string.
-        @rtype:         str
-        """
-
-        # Parameter check.
-        self.check_param(name)
-
-        # Function.
-        if isinstance(self._conv_factor[name], FunctionType) or 
isinstance(self._conv_factor[name], MethodType):
-            return self._units[name]()
-
-        # Return the value.
-        return self._units[name]
-
-
-    def loop(self, set=None):
-        """An iterator method for looping over all the parameters.
+    def base_loop(self, set=None):
+        """An iterator method for looping over all the base parameters.
 
         @keyword set:   The set of object names to return.  This can be set 
to 'all' for all names, to 'generic' for generic object names, 'params' for 
analysis specific parameter names, or to 'min' for minimisation specific 
object names.
         @type set:      str
-        @returns:   The parameter names.
-        @rtype:     str
+        @returns:       The parameter names.
+        @rtype:         str
         """
 
         # Loop over the parameters.
@@ -359,7 +173,218 @@
             # Yield the parameter name.
             yield name
 
-        # Yield the minimisation names.
-        if set == 'all' or set == 'min':
-            for name in ['chi2', 'iter', 'f_count', 'g_count', 'h_count', 
'warning']:
-                yield name
+
+    def check_param(self, name):
+        """Check if the parameter exists.
+
+        @param name:        The name of the parameter to search for.
+        @type name:         str
+        @raises RelaxError: If the parameter does not exist.
+        """
+
+        # Check.
+        if name not in self._names:
+            raise RelaxError("The parameter '%s' does not exist." % name)
+
+
+    def contains(self, name):
+        """Determine if the given name is within the parameter list.
+
+        @param name:    The name of the parameter to search for.
+        @type name:     str
+        @return:        True if the parameter is within the list, False 
otherwise.
+        @rtype:         bool
+        """
+
+        # Check.
+        if name in self._names:
+            return True
+
+        # No match.
+        return False
+
+
+    def get_conv_factor(self, name):
+        """Return the conversion factor.
+
+        @param name:    The name of the parameter.
+        @type name:     str
+        @return:        The conversion factor.
+        @rtype:         float
+        """
+
+        # Parameter check.
+        self.check_param(name)
+
+        # No factor.
+        if self._conv_factor[name] == None:
+            return 1.0
+
+        # Function.
+        if isinstance(self._conv_factor[name], FunctionType) or 
isinstance(self._conv_factor[name], MethodType):
+            return self._conv_factor[name]()
+
+        # Value.
+        return self._conv_factor[name]
+
+
+    def get_default(self, name):
+        """Return the default value of the parameter.
+
+        @param name:    The name of the parameter.
+        @type name:     str
+        @return:        The default value.
+        @rtype:         None or str
+        """
+
+        # Parameter check.
+        self.check_param(name)
+
+        # Return the default value.
+        return self._defaults[name]
+
+
+    def get_desc(self, name):
+        """Return the description of the parameter.
+
+        @param name:    The name of the parameter.
+        @type name:     str
+        @return:        The description.
+        @rtype:         None or str
+        """
+
+        # Parameter check.
+        self.check_param(name)
+
+        # Return the description.
+        return self._desc[name]
+
+
+    def get_err(self, name):
+        """Return the error flag for the parameter.
+
+        @param name:    The name of the parameter.
+        @type name:     str
+        @return:        The error flag for the parameter.
+        @rtype:         bool
+        """
+
+        # Parameter check.
+        self.check_param(name)
+
+        # Return the type.
+        return self._err[name]
+
+
+    def get_grace_string(self, name):
+        """Return the Grace string for the parameter.
+
+        @param name:    The name of the parameter.
+        @type name:     str
+        @return:        The Grace string.
+        @rtype:         str
+        """
+
+        # Parameter check.
+        self.check_param(name)
+
+        # Return the value.
+        return self._grace_string[name]
+
+
+    def get_param_set(self, name):
+        """Return the parameter set that the parameter belongs to.
+
+        @param name:    The name of the parameter.
+        @type name:     str
+        @return:        The parameter set.
+        @rtype:         str
+        """
+
+        # Parameter check.
+        self.check_param(name)
+
+        # Return the type.
+        return self._param_set[name]
+
+
+    def get_sim(self, name):
+        """Return the Monte Carlo simulation flag for the parameter.
+
+        @param name:    The name of the parameter.
+        @type name:     str
+        @return:        The Monte Carlo simulation flag for the parameter.
+        @rtype:         bool
+        """
+
+        # Parameter check.
+        self.check_param(name)
+
+        # Return the type.
+        return self._sim[name]
+
+
+    def get_type(self, name):
+        """Return the Python type for the parameter.
+
+        @param name:    The name of the parameter.
+        @type name:     str
+        @return:        The Python type.
+        @rtype:         Python type object
+        """
+
+        # Parameter check.
+        self.check_param(name)
+
+        # Return the Python type.
+        return self._py_types[name]
+
+
+    def get_units(self, name):
+        """Return the units string for the parameter.
+
+        @param name:    The name of the parameter.
+        @type name:     str
+        @return:        The units string.
+        @rtype:         str
+        """
+
+        # Parameter check.
+        self.check_param(name)
+
+        # Function.
+        if isinstance(self._conv_factor[name], FunctionType) or 
isinstance(self._conv_factor[name], MethodType):
+            return self._units[name]()
+
+        # Return the value.
+        return self._units[name]
+
+
+    def loop(self, set=None, error_names=False, sim_names=False):
+        """An iterator method for looping over all the parameters.
+
+        @keyword set:           The set of object names to return.  This can 
be set to 'all' for all names, to 'generic' for generic object names, 
'params' for analysis specific parameter names, or to 'min' for minimisation 
specific object names.
+        @type set:              str
+        @keyword error_names:   A flag which if True will add the error 
object names as well.
+        @type error_names:      bool
+        @keyword sim_names:     A flag which if True will add the Monte 
Carlo simulation object names as well.
+        @type sim_names:        bool
+        @returns:               The parameter names.
+        @rtype:                 str
+        """
+
+        # Loop over and yield the parameters.
+        for name in self.base_loop(set=set):
+            yield name
+
+        # Error names.
+        if error_names:
+            for name in self.base_loop(set=set):
+                if self.get_err(name):
+                    yield name + '_err'
+
+        # Sim names.
+        if sim_names:
+            for name in self.base_loop(set=set):
+                if self.get_sim(name):
+                    yield name + '_sim'




Related Messages


Powered by MHonArc, Updated Tue May 29 11:40:02 2012