本文整理汇总了Python中lmfit.Parameters方法的典型用法代码示例。如果您正苦于以下问题:Python lmfit.Parameters方法的具体用法?Python lmfit.Parameters怎么用?Python lmfit.Parameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lmfit
的用法示例。
在下文中一共展示了lmfit.Parameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extract_strategy
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def extract_strategy(param, name):
"""
Extract given strategy from param dict.
Parameters
----------
param : dict
saving all parameters
name : str
strategy name
Returns
-------
dict :
with given strategy as value
"""
param_new = copy.deepcopy(param)
return {k: v[name] for k, v in six.iteritems(param_new)
if k != 'non_fitting_values'}
示例2: cal_r2
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def cal_r2(y, y_cal):
"""
Calculate r2 statistics.
Parameters
----------
y : array
exp data
y_cal : array
fitted data
Returns
-------
float
"""
sse = np.sum((y-y_cal)**2)
sst = np.sum((y - np.mean(y))**2)
return 1-sse/sst
示例3: index_peaks
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def index_peaks(self, tolerance=0.1, *args, **kwargs):
"""Assigns hkl indices to peaks in the diffraction profile.
Parameters
----------
tolerance : float
The n orientations with the highest correlation values are returned.
keys : list
If more than one phase present in library it is recommended that
these are submitted. This allows a mapping from the number to the
phase. For example, keys = ['si','ga'] will have an output with 0
for 'si' and 1 for 'ga'.
*args : arguments
Arguments passed to the map() function.
**kwargs : arguments
Keyword arguments passed to the map() function.
Returns
-------
matching_results : ProfileIndexation
"""
return index_magnitudes(np.array(self.magnitudes), self.simulation, tolerance)
示例4: Cmatrix
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def Cmatrix(x, y, sx, sy, theta):
"""
Construct a correlation matrix corresponding to the data.
The matrix assumes a gaussian correlation function.
Parameters
----------
x, y : array-like
locations at which to evaluate the correlation matirx
sx, sy : float
major/minor axes of the gaussian correlation function (sigmas)
theta : float
position angle of the gaussian correlation function (degrees)
Returns
-------
data : array-like
The C-matrix.
"""
C = np.vstack([elliptical_gaussian(x, y, 1, i, j, sx, sy, theta) for i, j in zip(x, y)])
return C
示例5: Bmatrix
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def Bmatrix(C):
"""
Calculate a matrix which is effectively the square root of the correlation matrix C
Parameters
----------
C : 2d array
A covariance matrix
Returns
-------
B : 2d array
A matrix B such the B.dot(B') = inv(C)
"""
# this version of finding the square root of the inverse matrix
# suggested by Cath Trott
L, Q = eigh(C)
# force very small eigenvalues to have some minimum non-zero value
minL = 1e-9*L[-1]
L[L < minL] = minL
S = np.diag(1 / np.sqrt(L))
B = Q.dot(S)
return B
示例6: save_image
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def save_image(self, outname):
"""
Save the image data.
This is probably only useful if the image data has been blanked.
Parameters
----------
outname : str
Name for the output file.
"""
hdu = self.global_data.img.hdu
hdu.data = self.global_data.img._pixels
hdu.header["ORIGIN"] = "Aegean {0}-({1})".format(__version__, __date__)
# delete some axes that we aren't going to need
for c in ['CRPIX3', 'CRPIX4', 'CDELT3', 'CDELT4', 'CRVAL3', 'CRVAL4', 'CTYPE3', 'CTYPE4']:
if c in hdu.header:
del hdu.header[c]
hdu.writeto(outname, overwrite=True)
self.log.info("Wrote {0}".format(outname))
return
示例7: _fit_islands
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def _fit_islands(self, islands):
"""
Execute fitting on a list of islands
This function just wraps around fit_island, so that when we do multiprocesing
a single process will fit multiple islands before returning results.
Parameters
----------
islands : list of :class:`AegeanTools.models.IslandFittingData`
The islands to be fit.
Returns
-------
sources : list
The sources that were fit.
"""
self.log.debug("Fitting group of {0} islands".format(len(islands)))
sources = []
for island in islands:
res = self._fit_island(island)
sources.extend(res)
return sources
示例8: fix_shape
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def fix_shape(source):
"""
Ensure that a>=b for a given source object.
If a<b then swap a/b and increment pa by 90.
err_a/err_b are also swapped as needed.
Parameters
----------
source : object
any object with a/b/pa/err_a/err_b properties
"""
if source.a < source.b:
source.a, source.b = source.b, source.a
source.err_a, source.err_b = source.err_b, source.err_a
source.pa += 90
return
示例9: theta_limit
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def theta_limit(theta):
"""
Angle theta is periodic with period pi.
Constrain theta such that -pi/2<theta<=pi/2.
Parameters
----------
theta : float
Input angle.
Returns
-------
theta : float
Rotate angle.
"""
while theta <= -1 * np.pi / 2:
theta += np.pi
while theta > np.pi / 2:
theta -= np.pi
return theta
示例10: nena
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def nena(locs, info, callback=None):
bin_centers, dnfl_ = next_frame_neighbor_distance_histogram(locs, callback)
def func(d, a, s, ac, dc, sc):
f = a * (d / s ** 2) * _np.exp(-0.5 * d ** 2 / s ** 2)
fc = (
ac
* (d / sc ** 2)
* _np.exp(-0.5 * (d ** 2 + dc ** 2) / sc ** 2)
* _iv(0, d * dc / sc)
)
return f + fc
pdf_model = _lmfit.Model(func)
params = _lmfit.Parameters()
area = _np.trapz(dnfl_, bin_centers)
median_lp = _np.mean([_np.median(locs.lpx), _np.median(locs.lpy)])
params.add("a", value=area / 2, min=0)
params.add("s", value=median_lp, min=0)
params.add("ac", value=area / 2, min=0)
params.add("dc", value=2 * median_lp, min=0)
params.add("sc", value=median_lp, min=0)
result = pdf_model.fit(dnfl_, params, d=bin_centers)
return result, result.best_values["s"]
示例11: calibrate
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def calibrate(cls, xs: tuple, t: float, parameters: [Parameters, tuple]) -> tuple:
"""
SIR model derivatives at t.
:param xs: variables that we are solving for, i.e. [S]usceptible, [I]nfected, [R]emoved
:param t: time parameter, inactive for this model
:param parameters: parameters of the model (not including initial conditions), i.e. beta, gamma, N
:return: tuple, the derivatives dSdt, dIdt, dRdt of each of the S, I, R variables
"""
s, i, r = xs
if isinstance(parameters, Parameters):
beta = parameters['beta'].value
gamma = parameters['gamma'].value
N = parameters['N'].value
elif isinstance(parameters, tuple):
beta, gamma, N = parameters
else:
raise ValueError("Cannot recognize parameter input")
dSdt = - beta * s * i / N
dIdt = beta * s * i / N - gamma * i
dRdt = gamma * i
return dSdt, dIdt, dRdt
示例12: residual
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def residual(self, parameters: Parameters, time_range: np.arange, data: np.ndarray) -> np.ndarray:
"""
Obtain fit error (to minimize).
:param parameters: parameters to use (which we are usually minimizing the residual for)
:param time_range: time range for solution (over which we obtain the residual)
:param data: data to fit the models too (i.e. compute residuals in terms of)
:return:
"""
initial_conditions = []
for variable in self.initial_conditions:
initial_conditions.append(parameters[variable].value)
# obtain solution given current initial conditions and parameters
solution = self.solve(time_range, initial_conditions, parameters)
# compute residual, using custom error function if it has been passed in
residual = solution - data if self.error is None else self.error(solution, data, parameters)
if self.fit_period is not None:
residual = residual[-self.fit_period:]
return residual.ravel()
示例13: calculate_engine_idle_fuel_consumption
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def calculate_engine_idle_fuel_consumption(
idle_fuel_consumption_model, co2_params_calibrated=None):
"""
Calculates fuel consumption at hot idle engine speed [g/s].
:param idle_fuel_consumption_model:
Idle fuel consumption model.
:type idle_fuel_consumption_model: IdleFuelConsumptionModel
:param co2_params_calibrated:
CO2 emission model parameters (a2, b2, a, b, c, l, l2, t, trg).
The missing parameters are set equal to zero.
:type co2_params_calibrated: lmfit.Parameters
:return:
Fuel consumption at hot idle engine speed [g/s].
:rtype: float
"""
return idle_fuel_consumption_model.consumption(co2_params_calibrated)[0]
示例14: _select_initial_friction_params
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def _select_initial_friction_params(co2_params_initial_guess):
"""
Selects initial guess of friction params l & l2 for the calculation of
the motoring curve.
:param co2_params_initial_guess:
Initial guess of CO2 emission model params.
:type co2_params_initial_guess: lmfit.Parameters
:return:
Initial guess of friction params l & l2.
:rtype: float, float
"""
params = co2_params_initial_guess.valuesdict()
return sh.selector(('l', 'l2'), params, output_type='list')
# noinspection PyUnusedLocal
示例15: _missing_co2_params
# 需要导入模块: import lmfit [as 别名]
# 或者: from lmfit import Parameters [as 别名]
def _missing_co2_params(params, *args, _not=False):
"""
Checks if all co2_params are not defined.
:param params:
CO2 emission model parameters (a2, b2, a, b, c, l, l2, t, trg).
:type params: dict | lmfit.Parameters
:param _not:
If True the function checks if not all co2_params are defined.
:type _not: bool
:return:
If is missing some parameter.
:rtype: bool
"""
s = {'a', 'b', 'c', 'a2', 'b2', 'l', 'l2', 't0', 'dt', 'trg'}
if _not:
return set(params).issuperset(s)
return not set(params).issuperset(s)