This commit is contained in:
Jianshun Gao 2023-06-02 18:42:18 +02:00
parent 4f86c61d78
commit eb924fa05e
7 changed files with 10543 additions and 2734 deletions

2890
20230508_Data_Analysis.ipynb Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1582
20230530_Data_Analysis.ipynb Normal file

File diff suppressed because one or more lines are too long

View File

@ -28,6 +28,8 @@ from scipy.optimize import curve_fit
import xarray as xr
import copy
log2 = log(2)
s2pi = sqrt(2*pi)
@ -442,7 +444,7 @@ class FitAnalyser():
res = "params.add("
res += "name=\"" + key + "\", "
if not params[key].expr is None:
res += "expr=" + params[key].expr +")"
res += "expr=\"" + params[key].expr +"\")"
else:
res += "value=" + f'{params[key].value:3g}' + ", "
if str(params[key].max)=="inf":
@ -597,9 +599,15 @@ class FitAnalyser():
x = dataArray[x].to_numpy()
if self.fitDim == 1:
return xr.apply_ufunc(self._fit_1D, dataArray, kwargs={'params':paramsArray,'x':x},
res = xr.apply_ufunc(self._fit_1D, dataArray, kwargs={'params':paramsArray,'x':x},
output_dtypes=[type(lmfit.model.ModelResult(self.fitModel, self.fitModel.make_params()))],
**kwargs)
if keep_attrs:
res.attrs = copy.copy(dataArray.attrs)
return res
if self.fitDim == 2:
@ -631,9 +639,14 @@ class FitAnalyser():
# kwargs["input_core_dims"][0] = ['_z']
return xr.apply_ufunc(self._fit_2D, dataArray, kwargs={'params':paramsArray,'x':_x, 'y':_y},
res = xr.apply_ufunc(self._fit_2D, dataArray, kwargs={'params':paramsArray,'x':_x, 'y':_y},
output_dtypes=[type(lmfit.model.ModelResult(self.fitModel, self.fitModel.make_params()))],
**kwargs)
if keep_attrs:
res.attrs = copy.copy(dataArray.attrs)
return res
else:

View File

@ -83,6 +83,26 @@ class ImageAnalyser():
x_end = int(center[0] + span[0] / 2)
y_end = int(center[1] + span[1] / 2)
y_start = int(center[1] - span[1] / 2)
dataSet.attrs['x_start'] = x_start
dataSet.attrs['x_end'] = x_end
dataSet.attrs['y_end'] = y_end
dataSet.attrs['y_start'] = y_start
dataSet.attrs['x_center'] = center[0]
dataSet.attrs['y_center'] = center[1]
dataSet.attrs['x_span'] = span[0]
dataSet.attrs['y_span'] = span[1]
if isinstance(dataSet, type(xr.Dataset())):
for key in list(dataSet.data_vars):
dataSet[key].attrs['x_start'] = x_start
dataSet[key].attrs['x_end'] = x_end
dataSet[key].attrs['y_end'] = y_end
dataSet[key].attrs['y_start'] = y_start
dataSet[key].attrs['x_center'] = center[0]
dataSet[key].attrs['y_center'] = center[1]
dataSet[key].attrs['x_span'] = span[0]
dataSet[key].attrs['y_span'] = span[1]
return dataSet.isel(x=slice(x_start, x_end), y=slice(y_start, y_end))

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long