Ejemplo n.º 1
0
 def to_db(self, user, config_id=None, properties={}):
     """
         Save a configuration to the database
         @param user: User object
         @param config_id: PK of the config object to update (None for creation)
     """
     instrument = Instrument.objects.get(name=INSTRUMENT_NAME)
     # Find or create a reduction process entry and update it
     if config_id is not None:
         reduction_config = get_object_or_404(ReductionConfiguration, pk=config_id, owner=user)
         reduction_config.name = self.cleaned_data['reduction_name']
     else:
         reduction_config = ReductionConfiguration(owner=user,
                                                   instrument=instrument,
                                                   name=self.cleaned_data['reduction_name'])
         reduction_config.save()
     
     # Find experiment
     process_experiment(reduction_config, self.cleaned_data['experiment'],INSTRUMENT_NAME)
             
     # Set the parameters associated with the reduction process entry
     try:
         property_dict = copy.deepcopy(self.cleaned_data)
         property_dict.update(properties)
         properties = json.dumps(property_dict)
         reduction_config.properties = properties
         reduction_config.save()
     except:
         logger.error("Could not process reduction properties: %s" % sys.exc_value)
     
     return reduction_config.pk
Ejemplo n.º 2
0
 def to_db(self, user, config_id=None):
     """
         Save a configuration to the database
         @param user: User object
         @param config_id: PK of the config object to update (None for creation)
     """
     instrument = Instrument.objects.get(name=INSTRUMENT_NAME)
     # Find or create a reduction process entry and update it
     if config_id is not None:
         reduction_config = get_object_or_404(ReductionConfiguration, pk=config_id, owner=user)
         reduction_config.name = self.cleaned_data['reduction_name']
     else:
         reduction_config = ReductionConfiguration(owner=user,
                                                   instrument=instrument,
                                                   name=self.cleaned_data['reduction_name'])
         reduction_config.save()
     
     # Find experiment
     process_experiment(reduction_config, self.cleaned_data['experiment'],INSTRUMENT_NAME)
             
     # Set the parameters associated with the reduction process entry
     try:
         property_dict = copy.deepcopy(self.cleaned_data)
         # Make sure we have a background transmission empty
         property_dict['background_transmission_empty']=property_dict['transmission_empty']
         # This configuration requires that we fit the beam center
         property_dict['fit_direct_beam'] = True
         # Set the sensitivity calculation flag as needed
         if len(property_dict['sensitivity_file'])>0:
             property_dict['perform_sensitivity']=True
         properties = json.dumps(property_dict)
         reduction_config.properties = properties
         reduction_config.save()
     except:
         logger.error("Could not process reduction properties: %s" % sys.exc_value)
     
     return reduction_config.pk