@@ -402,6 +402,12 @@ def _apply_resolution_function(
402402 """
403403 model .resolution_function = PercentageFwhm (5.0 )
404404
405+ @staticmethod
406+ def _auto_set_background (experiment : DataSet1D ) -> None :
407+ """Set the model background to the minimum y-value of the experiment data."""
408+ if experiment .model is not None and len (experiment .y ) > 0 :
409+ experiment .model .background = max (np .min (experiment .y ), 1e-10 )
410+
405411 def load_new_experiment (self , path : Union [Path , str ]) -> None :
406412 new_experiment = load_as_dataset (str (path ))
407413 new_index = len (self ._experiments )
@@ -412,6 +418,7 @@ def load_new_experiment(self, path: Union[Path, str]) -> None:
412418
413419 self ._apply_experiment_metadata (path , new_experiment , f'Experiment { new_index } ' )
414420 new_experiment .model = self .models [model_index ]
421+ self ._auto_set_background (new_experiment )
415422 self ._experiments [new_index ] = new_experiment
416423 self ._with_experiments = True
417424 self ._apply_resolution_function (new_experiment , self .models [model_index ])
@@ -473,6 +480,7 @@ def load_all_experiments_from_file(self, path: Union[Path, str]) -> int:
473480 data_key = data_key ,
474481 )
475482 new_experiment .model = self .models [model_index ]
483+ self ._auto_set_background (new_experiment )
476484 self ._experiments [new_index ] = new_experiment
477485 self ._apply_resolution_function (new_experiment , self .models [model_index ])
478486
@@ -484,6 +492,7 @@ def load_experiment_for_model_at_index(self, path: Union[Path, str], index: Opti
484492
485493 self ._apply_experiment_metadata (path , experiment , f'Experiment { index } ' )
486494 experiment .model = self .models [index ]
495+ self ._auto_set_background (experiment )
487496 self ._experiments [index ] = experiment
488497 self ._with_experiments = True
489498 self ._apply_resolution_function (experiment , self ._models [index ])
@@ -727,6 +736,7 @@ def _from_dict_extract_experiments(self, project_dict: dict) -> Dict[int, DataSe
727736 ye = project_dict ['experiments' ][key ][2 ],
728737 xe = project_dict ['experiments' ][key ][3 ],
729738 model = self ._models [project_dict ['experiments_models' ][key ]],
739+ auto_background = False ,
730740 )
731741 return experiments
732742
0 commit comments