mjolnir.calibration#

This module defines classes that handle calibration of parameters.

Classes

AverageSequenceLearner1D(function, sequence)

Learns the values of noisy functions at given points.

CalibrationHandler(logical_station)

Base class for calibration handlers.

CcdCalibrationHandler(logical_station[, ...])

Calibration handler for the CCD.

PowerCalibration(wavelength, timestamp, ...)

Handles calibration of a variable neutral density filter.

PowerCalibrationHandler(logical_station[, ...])

Calibration handler for the ND filter.

RejectionFeedbackHandler(logical_station[, ...])

Calibration handler for the excitation rejection feedback.

class mjolnir.calibration.AverageSequenceLearner1D(function, sequence, min_samples=50, max_samples=9223372036854775807, min_error=0)[source]#

Bases: AverageLearner1D

Learns the values of noisy functions at given points.

Parameters:
  • function (Callable[[...], Any])

  • sequence (Sequence[Any])

  • min_samples (int)

  • max_samples (int)

  • min_error (float)

done()[source]#
Return type:

bool

new()[source]#

Create a copy of ~adaptive.AverageLearner1D without the data.

remove_unfinished()[source]#

Remove uncomputed data from the learner.

Return type:

None

tell(seed_x, y)[source]#

Tell the learner about a single value.

Parameters:
  • x (A value from the function domain)

  • y (A value from the function image)

  • seed_x (tuple[int, Real])

Return type:

None

tell_pending(seed_x)[source]#

Tell the learner that ‘x’ has been requested such that it’s not suggested again.

Parameters:

seed_x (tuple[int, Real])

Return type:

None

class mjolnir.calibration.CalibrationHandler(logical_station)[source]#

Bases: ABC, _Handler

Base class for calibration handlers.

Parameters:

logical_station (Station)

abstractmethod calibrate(*args, **kwargs)[source]#

Performs a calibration.

Return type:

Any

abstract property calibration: Any#

The calibration function.

abstract property folder: Path#

The folder in which to store serialized calibration data.

abstractmethod load_calibration_from_file(*args, **kwargs)[source]#

Loads serialized calibration data.

Return type:

Any

class mjolnir.calibration.CcdCalibrationHandler(logical_station, exposure_time=0.1, number_accumulations=2, n_pts=9, folder='C:/Data/Triton/calibration/ccd')[source]#

Bases: CcdCalibrationHandler, CcdCalibrationHandler, CalibrationHandler, ABC, _Handler, object

Calibration handler for the CCD.

Parameters:
  • exposure_time (float) – The duration of exposure for CCD data.

  • number_accumulations (int) – The number of accumulations to perform for each CCD data.

  • n_pts (int) – The number of calibration points (wavelenghts).

  • folder (str | pathlib.Path) – The folder where to store calibration data.

  • logical_station (Station)

property folder#

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

class mjolnir.calibration.PowerCalibration(wavelength, timestamp, angle, power, error, log=False)[source]#

Bases: object

Handles calibration of a variable neutral density filter.

Parameters:
property age: float#

The calibration age in seconds.

angle: ndarray[tuple[Any, ...], dtype[float]]#
property angle_to_power#
property angle_to_power_deriv#

The calibration function’s derivative.

property bounds: tuple[float, float]#

The bounds of the calibration range.

error: ndarray[tuple[Any, ...], dtype[float]]#
log: bool = False#
plot()[source]#

Plot the calibration function.

power: ndarray[tuple[Any, ...], dtype[float]]#
property power_to_angle#

The inverted calibration function.

rescaled(wavelength, angle_callback, power_callback, target_power=None, target_angle=None, n_samples=50)[source]#

The calibration function rescaled by a global factor.

Parameters:
  • wavelength (float) – The wavelength at which to rescale.

  • angle_callback (Parameter) – The callback to set and get the angle.

  • power_callback (Parameter) – The callback to get the power.

  • target_power (float | None) – The power to reach at a given angle. Takes precedence over target_angle.

  • target_angle (float | None) – The angle at which to rescale for the given wavelength.

  • n_samples (int) – The number of power samples to average over.

timestamp: float#
wavelength: float#
class mjolnir.calibration.PowerCalibrationHandler(logical_station, sampling=None, loss=0.1, dtheta=0.5, duration=300.0, min_samples=25, nsamples=None, npoints=None, ntasks=1, wait=0.0, folder='C:/Data/Triton/calibration/nd_filter', learner_kwargs=<factory>)[source]#

Bases: PowerCalibrationHandler, PowerCalibrationHandler, CalibrationHandler, ABC, _Handler, object

Calibration handler for the ND filter.

Parameters:
  • sampling (Literal['sequential', 'adaptive'] | None) – Use a naive sequential or adaptive sampling. Defaults to the value of power_calibration_strategy.

  • loss (float | None) – The maximum sampling loss. If None, it is not used for the goal.

  • dtheta (float | None) – The maximum spacing between adjacent sample points. Ignored if npoints is given or sampling is ‘adaptive’.

  • duration (float | None) – The maximum duration.

  • min_samples (int | None) – The minimum number of samples taken for each average. If None, it is not used for the goal.

  • nsamples (int | None) – The minimum number of total samples. If None, it is not used for the goal.

  • npoints (int | None) – The minimum number of points to be sampled. If None, it is not used for the goal.

  • ntasks (int) – The number of points the executor visits per batch.

  • wait (float) – Sleep for this amount of time before taking a power measurement.

  • folder (str | pathlib.Path) – The folder to save learners in.

  • learner_kwargs (dict) – Additional kwargs for the adaptive learner.

  • logical_station (Station)

property folder#

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

class mjolnir.calibration.RejectionFeedbackHandler(logical_station, slit_width=1000, fs=14.0, t_avg_max=15, alpha=0.05, redfactor=3.0, deltainit=0.1, deltatol=0.01, feps=10, mask=(False, True, True))[source]#

Bases: _Handler

Calibration handler for the excitation rejection feedback.

Parameters:
  • slit_width (float) – The spectrometer exit slit width.

  • fs (float) – The Time Tagger digitization rate.

  • t_avg_max (float) – Maximum averaging duration.

  • alpha (float) – Relative error to achieve when sampling.

  • redfactor (float) – Optimization parameter.

  • deltatol (float) – Optimization parameter.

  • deltainit (float) – Optimization parameter.

  • feps (float) – Optimization parameter.

  • mask (tuple[int, int, int]) – A boolean mask defining the rotator axes to optimize.

  • logical_station (Station)

alpha: float = 0.05#
cache: dict[float, tuple[float, ...]]#
calibrate(new_wav, old_wav=None)[source]#
Parameters:
deltainit: float = 0.1#
deltatol: float = 0.01#
feps: float = 10#
fs: float = 14.0#
mask: tuple[int, int, int] = (False, True, True)#
redfactor: float = 3.0#
slit_width: float = 1000#
t_avg_max: float = 15#
throughput: float = nan#