-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
calibration: add private api for motion blur model
- Loading branch information
1 parent
122c6a1
commit 2bbe1e9
Showing
4 changed files
with
167 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
lumicks/pylake/force_calibration/tests/test_camera_calibration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from lumicks.pylake.force_calibration.calibration_models import ( | ||
ActiveCalibrationModel, | ||
PassiveCalibrationModel, | ||
) | ||
from lumicks.pylake.force_calibration.power_spectrum_calibration import ( | ||
fit_power_spectrum, | ||
calculate_power_spectrum, | ||
) | ||
|
||
from .data.simulate_ideal import simulate_calibration_data | ||
|
||
|
||
# @pytest.mark.slow | ||
def test_camera_calibration(): | ||
np.random.seed(909) | ||
f_drive = 16.8 | ||
sample_rate = 500 | ||
shared_params = { | ||
"bead_diameter": 1.01, | ||
"viscosity": 1.002e-3, | ||
"temperature": 20, | ||
} | ||
params = { | ||
**shared_params, | ||
"duration": 600, | ||
"sample_rate": sample_rate, | ||
"stiffness": 0.05, | ||
"pos_response_um_volt": 0.618, | ||
"driving_sinusoid": (500, f_drive), | ||
"diode": None, | ||
} | ||
|
||
oversampling = 128 | ||
pos, nano = simulate_calibration_data( | ||
**params, anti_aliasing="integrate", oversampling=oversampling | ||
) | ||
passive_model = PassiveCalibrationModel(**shared_params, fast_sensor=True) | ||
|
||
active_model = ActiveCalibrationModel( | ||
force_voltage_data=pos, | ||
driving_data=nano, | ||
**shared_params, | ||
sample_rate=sample_rate, | ||
driving_frequency_guess=f_drive, | ||
fast_sensor=True, | ||
) | ||
|
||
# Consider aliasing and motion blur | ||
models = ( | ||
model._motion_blur(1.0 / sample_rate)._alias_model(sample_rate, 20) | ||
for model in (passive_model, active_model) | ||
) | ||
|
||
distance_responses = [0.6234771740528027, 0.623431094357452] | ||
stiffnesses = [0.04950015364112712, 0.04950747132648579] | ||
force_responses = [30.86221590734949, 30.864497027941212] | ||
|
||
ps = calculate_power_spectrum(pos, sample_rate, fit_range=(25, 1000), num_points_per_block=200) | ||
for model, rd, kappa, rf in zip(models, distance_responses, stiffnesses, force_responses): | ||
calibration = fit_power_spectrum(ps, model) | ||
np.testing.assert_allclose(calibration["Rd"].value, rd) | ||
np.testing.assert_allclose(calibration["Rf"].value, rf) | ||
np.testing.assert_allclose(calibration["kappa"].value, kappa) |