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
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
def to_db(self, user, reduction_id=None, config_id=None): """ Save reduction properties to DB. If we supply a config_id, the properties from that configuration will take precedence. If no config_id is supplied and the reduction_id provided is found to be associated to a configuration, make a new copy of the reduction object so that we don't corrupt the configured reduction. @param user: User object @param reduction_id: pk of the ReductionProcess entry @param config_id: pk of the ReductionConfiguration entry """ if not self.is_valid(): raise RuntimeError, "Reduction options form invalid" if reduction_id is None: reduction_id = self.cleaned_data['reduction_id'] # Find or create a reduction process entry and update it if reduction_id is not None: reduction_proc = get_object_or_404(ReductionProcess, pk=reduction_id, owner=user) # If the user changed the data to be reduced, create a new reduction process entry new_reduction = not reduction_proc.data_file==self.cleaned_data['data_file'] # If the reduction process is configured and the config isn't the provided one config_obj = reduction_proc.get_config() new_reduction = new_reduction or (config_obj is not None and not config_obj.id == config_id) else: new_reduction = True if new_reduction: eqsans = Instrument.objects.get(name=INSTRUMENT_NAME) reduction_proc = ReductionProcess(owner=user, instrument=eqsans) reduction_proc.name = self.cleaned_data['reduction_name'] reduction_proc.data_file = self.cleaned_data['data_file'] reduction_proc.save() # Set the parameters associated with the reduction process entry config_property_dict = {} property_dict = copy.deepcopy(self.cleaned_data) property_dict['reduction_id'] = reduction_proc.id if config_id is not None: reduction_config = get_object_or_404(ReductionConfiguration, pk=config_id, owner=user) if reduction_proc not in reduction_config.reductions.all(): reduction_config.reductions.add(reduction_proc) config_property_dict = json.loads(reduction_config.properties) property_dict.update(config_property_dict) reduction_proc.name = reduction_config.name reduction_proc.save() for item in reduction_config.experiments.all(): if item not in reduction_proc.experiments.all(): reduction_proc.experiments.add(item) try: properties = json.dumps(property_dict) reduction_proc.properties = properties reduction_proc.save() except: logger.error("Could not process reduction properties: %s" % sys.exc_value) # Find experiment process_experiment(reduction_proc, self.cleaned_data['experiment'], instrument_name=INSTRUMENT_NAME) return reduction_proc.pk