Saving and loading fits#
Since the fit results are stored in an xarray Dataset, they can be easily saved as
netCDF files by serializing lmfit objects to JSON. This can be done with xarray_lmfit.save_fit():
import xarray_lmfit as xlm
xlm.save_fit(result_ds, "fit_results.nc")
The saved Dataset can be loaded back with xarray_lmfit.load_fit().
result_ds = xlm.load_fit("fit_results.nc")
Warning
Saving full model results that includes the model functions can be difficult. Instead of saving the fit results, it is recommended to save the code that can reproduce the fit. See the relevant lmfit documentation for more information.