Skip to content

Commit

Permalink
calibration: add some convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Jan 13, 2025
1 parent a38edbc commit 8518a17
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lumicks/pylake/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def stop(self):
return self._src.stop

@property
def data(self) -> npt.ArrayLike:
def data(self) -> npt.NDArray:
"""The primary values of this channel slice"""
return self._src.data

Expand Down Expand Up @@ -801,7 +801,7 @@ def to_dataset(self, parent, name, **kwargs):
return dset

@property
def data(self) -> npt.ArrayLike:
def data(self) -> npt.NDArray:
if self._cached_data is None:
self._cached_data = np.asarray(self._src_data)
return self._cached_data
Expand Down Expand Up @@ -932,7 +932,7 @@ def to_dataset(self, parent, name, **kwargs):
return dset

@property
def data(self) -> npt.ArrayLike:
def data(self) -> npt.NDArray:
if self._cached_data is None:
self._cached_data = np.asarray(self._src_data)
return self._cached_data
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def __len__(self):
return 0

@property
def data(self) -> npt.ArrayLike:
def data(self) -> npt.NDArray:
return np.empty(0)

@property
Expand Down
21 changes: 21 additions & 0 deletions lumicks/pylake/force_calibration/calibration_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections import UserDict

from lumicks.pylake.channel import Slice, Continuous, empty_slice
from lumicks.pylake.force_calibration.convenience import calibrate_force
from lumicks.pylake.force_calibration.calibration_models import DiodeCalibrationModel
from lumicks.pylake.force_calibration.detail.calibration_properties import (
CalibrationPropertiesMixin,
Expand Down Expand Up @@ -183,6 +184,26 @@ def __repr__(self):
)
return f"{self.__class__.__name__}({properties})"

def plot(self):
if not self.voltage:
raise ValueError(
"This calibration item does not contain the raw data. If you still have the "
"timeline force data, you can de-calibrate that and perform the re-calibration"
"manually. See the pylake tutorial on force calibration for more information."
)

self.recalibrate_with().plot()

def recalibrate_with(self, **params):
"""Returns a calibration structure with some parameters overridden.
For a full list of parameters to override, please see
:func:`~lumicks.pylake.calibrate_force()`"""
active_data = {"driving_data": self.driving.data} if self.active_calibration else {}
return calibrate_force(
self.voltage.data, **(self.calibration_params() | active_data | params)
)

@_verify_full
def _model_params(self):
"""Returns parameters with which to create an active or passive calibration model"""
Expand Down

0 comments on commit 8518a17

Please sign in to comment.