Ejemplo n.º 1
0
 def __init__(self, fileobject, transform_function):
     SavccMatrix.__init__(self, fileobject, transform_function)
     # Add normalization factors
     logging.log(ULTRADEBUG, "Initializing normalization array")
     # Default behavior: no normalization
     self.normfactors=[1.0]*self._height
     # Tentative normalization array name
     array_filename=self._expected_norm_array_name()
     logging.debug("Trying to load a normalization array from disk. The "
                   "file should be named %s.", array_filename)
     # Make sure that only one process or thread at a time can attempt to get 
     # the normalization factors
     _normfactor_lock.acquire()
     try:
         try:
             self._load_normalization_factors(open(array_filename, 'rb'))
             logging.debug('Normalization factors loaded from disk.')
         except IOError:
             logging.debug("Unable to load normalization factors from disk.")
             self._generate_normalization_factors()
             # Only save normalization factors if they are not a StringIO
             # object
             if not isinstance(fileobject, StringIO.StringIO):
                 logging.debug("Saving normalization factors to %s",
                               array_filename)
                 try:
                     self._save_normalization_factors(open(array_filename,
                                                           'wb'))
                 except IOError:
                     logging.warn("Unable to save the normalization array. "
                                  "It will have to be regenerated each "
                                  "time.")
     finally:
         _normfactor_lock.release()
Ejemplo n.º 2
0
 def __init__(self, fileobject, transform_function):
     SavccMatrix.__init__(self, fileobject, transform_function)
     # Add normalization factors
     logging.log(ULTRADEBUG, "Initializing normalization array")
     # Default behavior: no normalization
     self.normfactors = [1.0] * self._height
     # Tentative normalization array name
     array_filename = self._expected_norm_array_name()
     logging.debug(
         "Trying to load a normalization array from disk. The "
         "file should be named %s.", array_filename)
     # Make sure that only one process or thread at a time can attempt to get
     # the normalization factors
     _normfactor_lock.acquire()
     try:
         try:
             self._load_normalization_factors(open(array_filename, 'rb'))
             logging.debug('Normalization factors loaded from disk.')
         except IOError:
             logging.debug(
                 "Unable to load normalization factors from disk.")
             self._generate_normalization_factors()
             # Only save normalization factors if they are not a StringIO
             # object
             if not isinstance(fileobject, StringIO.StringIO):
                 logging.debug("Saving normalization factors to %s",
                               array_filename)
                 try:
                     self._save_normalization_factors(
                         open(array_filename, 'wb'))
                 except IOError:
                     logging.warn("Unable to save the normalization array. "
                                  "It will have to be regenerated each "
                                  "time.")
     finally:
         _normfactor_lock.release()
Ejemplo n.º 3
0
 def __setstate__(self, state):
     SavccMatrix.__setstate__(self, state['base'])
     self.normfactors=state['normfact']
Ejemplo n.º 4
0
 def __getstate__(self):
     return {'base': SavccMatrix.__getstate__(self),
             'normfact': self.normfactors}
Ejemplo n.º 5
0
 def __setstate__(self, state):
     SavccMatrix.__setstate__(self, state['base'])
     self.normfactors = state['normfact']
Ejemplo n.º 6
0
 def __getstate__(self):
     return {
         'base': SavccMatrix.__getstate__(self),
         'normfact': self.normfactors
     }