Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: rework force calibration documentation #699

Open
wants to merge 2 commits into
base: lazy_power
Choose a base branch
from

Conversation

JoepVanlier
Copy link
Member

@JoepVanlier JoepVanlier commented Oct 11, 2024

Why this PR?
Many people have trouble finding relevant information in the force calibration docs and given the scope of the whole thing, it's entirely understandable. I've attempted to thin the theory in the tutorials, and flesh out the fundamentals section a bit.

At the same time, we've made quite a few changes to the recommended API (providing more properties, so people don't have to poke around the raw dictionaries anymore). These are all documented in this PR.

Docs builds here: tutorial and theory.

What to look out for?
I have attempted to add a more intuitive explanation for the power spectral shape in the opening of the theory section. This is a bit more handwavey right now. I found it challenging to strike a balance between correctness and intuition there. Initially, I was writing it more along the lines of integration white noise, but then I felt that was likely still too mathematical to be a friendly introduction so I went with this instead (this was partly inspired by how Loïc dealt with this topic during his training as well). I would be happy to get some comments on it.

Copy link
Collaborator

@aafkevandenberg aafkevandenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice! Good documentation on the force calibration was really missing.

The comments I added mostly focus on being more explicit about the content of a tutorial or a figure.

Redoing a Bluelake calibration
------------------------------

We can directly slice the channel by the calibration item we want to reproduce to extract the relevant data::
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You touch on this in the previous section, but I would add the following, as this is a very common misconception:

In order to redo the Bluelake calibration, the force data that was used for calibration has to be included in the h5 file. Note that this force data is not exported nor marked by default; it has to be explicitly added to the exported file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! It's indeed a good idea to re-emphasize this, thanks!

plt.subplot(2, 2, 3)
calibration1.plot_spectrum_residual()
plt.ylim([0, 2])
plt.title(f"Stiffness: {calibration1.stiffness:.3f}, Force sensi: {calibration1.displacement_sensitivity:.2f}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plt.title(f"Residual\nStiffness: {calibration1.stiffness:.3f}, Force sensi: {calibration1.displacement_sensitivity:.2f}")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

plt.subplot(2, 2, 4)
calibration2.plot_spectrum_residual()
plt.tight_layout()
plt.title(f"Stiffness: {calibration2.stiffness:.3f}, Force sensi: {calibration2.displacement_sensitivity:.2f}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plt.title(f"Residual\nStiffness: {calibration2.stiffness:.3f}, Force sensi: {calibration2.displacement_sensitivity:.2f}")

>>> calibration1.backing
0.0

>>> calibration1.backing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calibration2.backing

.. only:: html

:nbexport:`Download this page as a Jupyter notebook <self>`

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Pylake has many options to optimize force calibration depending on the specific conditions of your experiments. The number of options.... etc'

@@ -0,0 +1,216 @@
Getting good calibrations
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This title could be more specific, eg

'Optimizing force calibration parameters'

.. only:: html

:nbexport:`Download this page as a Jupyter notebook <self>`

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First sentence should be something like this, as this is what the tutorial is really about:

'Pylake can be used to recalibrate the force using active calibration data.'

.. only:: html

:nbexport:`Download this page as a Jupyter notebook <self>`

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current introduction triggers a lot of questions like 'why did we not use this method for peak detection before' and 'when should I use this method'. I see you answer these questions a bit further down the tutorial. Instead, I would just mention at the very start that this method is less ideal for fitting a power spectrum, but very convenient for identifying spurious peaks. Maybe even call this tutorial 'automatic detection of spurious peaks'.

Copy link
Member Author

@JoepVanlier JoepVanlier Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be completely honest, we are currently still evaluating whether we should make the switch to this method (and make it the default), as it requires less work from FSEs in the field and it runs less risk of problems if identified peaks shift or new ones appear.

It's a really good point though, we should already clarify the limitations / what we are going to do in the intro. How about the following?

So far, we have been using least-squares fitting routines for force calibration.
In that case, we assume that the error in the power at each frequency is distributed according to a Gaussian distribution.
:ref:`Blocking or windowing<blocking_windowing>` the power spectrum ensures that this assumption is close enough to the truth such that the fit provides accurate estimates of the unknown parameters.
Occasionally, the power spectrum might show a spurious noise peak.
Such a peak is an outlier in the expected behavior of the spectrum and therefore interferes with the assumption of having a Gaussian error distribution.
As a result, the fit is skewed. In those cases, it can be beneficial to do a robust fit.
When a robust fit is performed, one assumes that the probability of encountering one or multiple outliers is non-negligible.
By taking this into account during fitting, the fit can be made more robust to outliers in the data.
One downside of this approach is that the current implementation does not readily provide standard errors on the parameter estimates and that it leads to a small bias in the fit results for which Pylake has no correction.
Robust fitting can be used in combination with a least-squares fit, to identify outliers automatically, in order to exclude these from a second regular least-squares fit.

@JoepVanlier JoepVanlier force-pushed the force_refactor branch 2 times, most recently from 9387c17 to ac7e97d Compare October 18, 2024 13:21
@JoepVanlier JoepVanlier force-pushed the force_refactor branch 4 times, most recently from f3f539a to 647d027 Compare October 25, 2024 14:08
@JoepVanlier JoepVanlier changed the title docs: rework force calibration documentation (wip) docs: rework force calibration documentation Oct 25, 2024
@JoepVanlier JoepVanlier marked this pull request as ready for review October 25, 2024 14:09
@JoepVanlier JoepVanlier requested review from a team as code owners October 25, 2024 14:09
@JoepVanlier JoepVanlier requested review from alessiamarcolini, rpauszek and RoelandvanWijk and removed request for a team October 25, 2024 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants