fit_distortion#
- esis.optics.fit_distortion(objective, parameters, bounds, workers=1, popsize=15, maxiter=60, tol=0.05, seed=0, scale_polish=0.02, free=None, log=None, kwargs_optimizer=None)[source]#
Fit distortion parameters by a seeded capture and a local polish.
A local method alone does not reliably find the basin of the merit, so the first stage is a seeded differential evolution with a loose tolerance, which only has to land in the basin; the second is
polish(). With a deterministic objective the whole fit is reproducible.- Parameters:
objective (Callable[[ndarray], float]) – The function to minimize, of a flat parameter vector, for example a
LinearMerit. It must be picklable if workers is more than one.parameters (DistortionParameters) – The initial guess, which also defines the units and structure of the parameter vector.
bounds (tuple[DistortionParameters, DistortionParameters]) – The lower and upper bounds of the fit, in the units of parameters.
workers (int) – The number of processes evaluating the population of the capture. They are spawned rather than forked, since the parent has usually initialized a GPU by the time the capture starts.
popsize (int) – The population size of the capture per parameter.
maxiter (int) – The maximum number of generations of the capture.
tol (float) – The relative tolerance at which the capture stops.
seed (int) – The seed of the capture.
scale_polish (float) – The size of the starting simplex of the polish as a fraction of the bounds.
free (None | Sequence[str]) – The names of the fields of parameters to fit. The others are held at their starting values. If
None, every field is fit.log (None | Callable[[str], None]) – A callable to report progress.
kwargs_optimizer (None | dict[str, Any]) – Additional keyword arguments passed to
scipy.optimize.differential_evolution().
- Raises:
ValueError – If free names a field parameters does not have, or if the fields of parameters are not scalars.
RuntimeError – If the objective already fails at the starting point, which is a fault of the setup rather than a bad trial.
- Return type:
Examples
Fit one channel of the ESIS-I as-built model to the Level-1 frame that
esis.flights.f1.optics.distortion_fit()was optimized against.import named_arrays as na import esis obs = esis.flights.f1.data.level_1()[dict(time=15)] scene = esis.flights.f1.data.synth.scene_aia()[dict(time=15)] instrument = esis.flights.f1.optics.as_built(num_distribution=0) channel = instrument[dict(channel=1)] parameters = esis.optics.DistortionParameters.from_instrument(channel) merit = esis.optics.LinearMerit( instrument=channel, parameters=parameters, scene=scene, observation=obs.outputs[dict(channel=1)].value, device="cuda", ) fitted = esis.optics.fit_distortion( objective=merit, parameters=parameters, bounds=esis.flights.f1.optics.distortion_fit_bounds(parameters), workers=6, )
References to
esis.optics.fit_distortion