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

PowerSpectrum: improve diagnostic value power spectrum api #695

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* Added parameter `titles` to customize title of each subplot in [`Kymo.plot_with_channels()`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.kymo.Kymo.html#lumicks.pylake.kymo.Kymo.plot_with_channels).
* Added [`KymoTrack.sample_from_channel()`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.kymotracker.kymotrack.KymoTrack.html#lumicks.pylake.kymotracker.kymotrack.KymoTrack.sample_from_channel) to downsample channel data to the time points of a kymotrack.
* Added support for file names with spaces in [`lk.download_from_doi()`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.download_from_doi.html#lumicks.pylake.download_from_doi).
* Allow showing the ranges that were excluded from a power spectrum by passing `show_excluded=True` to [`PowerSpectrum.plot()`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.force_calibration.power_spectrum.PowerSpectrum.html#lumicks.pylake.force_calibration.power_spectrum.PowerSpectrum.plot).
* Allow plotting the ranges that were excluded from fitting and the active calibration peak when plotting a calibration result using `show_excluded=True` and `show_active_peak=True` in [`CalibrationResults.plot()`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.force_calibration.power_spectrum_calibration.CalibrationResults.html#lumicks.pylake.force_calibration.power_spectrum_calibration.CalibrationResults.plot).

## v1.5.3 | 2024-10-29

Expand Down
21 changes: 18 additions & 3 deletions lumicks/pylake/force_calibration/calibration_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,27 @@ def number_of_samples(self):
"""Number of fitted samples (-)."""
return self.ps_data.total_sampled_used

def plot(self):
"""Plot the fitted spectrum"""
def plot(self, show_excluded=False, show_active_peak=False):
"""Plot the fitted spectrum

Parameters
----------
show_excluded : bool
Show fitting regions excluded from the fit
show_active_peak : bool
Show active calibration peak when available
"""
import matplotlib.pyplot as plt

self.ps_data.plot(label="Data")
if show_active_peak and not hasattr(self.model, "output_power"):
raise ValueError("This is not an active calibration")

self.ps_data.plot(label="Data", show_excluded=show_excluded)
self.ps_model.plot(label="Model")

if show_active_peak:
self.model.output_power.ps.plot(label="Active peak")

plt.legend()

def plot_spectrum_residual(self):
Expand Down
2 changes: 1 addition & 1 deletion lumicks/pylake/force_calibration/detail/driving_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def estimate_driving_input_parameters(
class DrivenPower:
def __init__(self, psd_data, sample_rate, driving_frequency, num_windows, freq_window=50.0):
"""This class is used to determine power in the driven peak."""
self.ps = PowerSpectrum(
self.ps = PowerSpectrum.from_data(
psd_data, sample_rate, window_seconds=num_windows / driving_frequency
).in_range(max(1.0, driving_frequency - freq_window), driving_frequency + freq_window)

Expand Down
Loading