コード例 #1
0
    def __init__(self, rules):
        """
        __init__()
        Purpose:    Constructor for the Quality Control class.  Handles the parsing of the rule strings (parses out the arguments list so it can 
                        determine what variables it needs from the file), and calls eval() to convert to a Python function object.
        Parameters: rules [type=list,tuple]
                        A list of strings that can be evaluated to Python function objects (easiest way is the lambda keyword).
        """
        self.rules = {}

        if len(rules) == 0:
            warning("No rules given for quality control.")
            return

        for rule in rules:
            # Eliminate multiple spaces between "lambda" and the opening parenthesis of the argument list (screws up the next line if there are extra spaces)
            rule = re.sub(r"(?<=lambda)[\s]+", " ", rule)

            # Parse out the argument list to the function
            match = re.search(r"(?<=lambda )[\w, ]+(?= *:)", rule)

            # Get the variables from the match object
            variables = match.group(0)

            # Evaluate the rule (should be a python lambda function) and stick it in the dictionary, with the variables in the argument list as the key
            self.rules[variables] = eval(rule)

        return
コード例 #2
0
ファイル: hootpy.py プロジェクト: pulsatrixwx/PulsatrixWx
 def _clearCache(self,variable=None):
     """
     _clearCache() [protected]
     Purpose:    Clear the global cache of raw data to free up the memory.
     Parameters: [none]
     Returns:    [nothing]
     """
     if variable is None:
         for nc_variable in self._var_name_cache:
             # Delete data in the global namespace
             del globals()[nc_variable] 
             del globals()["%s_units" % nc_variable]
         self._var_name_cache = [ ]
     else:
         try:
             del globals()[variable]
             del globals()['%s_units' % variable]
             self._var_name_cache.remove(variable)
         except KeyError:
             warning("Variable %s does not exist in the cache" % variable)
     return