add optional data sparsity

This commit is contained in:
Valentin Boettcher 2024-05-08 20:50:40 -04:00
parent 39d6e682e6
commit 9e4414b02a
11 changed files with 55 additions and 22 deletions

1
.gitignore vendored
View file

@ -9,3 +9,4 @@ devenv.local.nix
.pre-commit-config.yaml .pre-commit-config.yaml
data data
__pycache__

BIN
figures/non_steady.pdf Normal file

Binary file not shown.

BIN
figures/non_steady.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View file

@ -2,3 +2,9 @@
:ID: d7630955-6ca9-4de7-9770-2d50d4847bcd :ID: d7630955-6ca9-4de7-9770-2d50d4847bcd
:END: :END:
#+title: Fitting Ringdown #+title: Fitting Ringdown
* Failure of the steady state
On the right peak on can see that there might be something fish going
on. This is ~data/24_05_24/nice_transient2~.
[[file:figures/non_steady.png]]

View file

@ -9,7 +9,14 @@ from . import utils
class ScanData: class ScanData:
def __init__(self, laser: np.ndarray, output: np.ndarray, time: np.ndarray): def __init__(
self,
laser: np.ndarray,
output: np.ndarray,
time: np.ndarray,
truncation: [float, float] = [0, 100],
sparcity: float = 1,
):
""" """
A class to hold the data from an oscilloscope scan where the A class to hold the data from an oscilloscope scan where the
laser frequency is stepped as per the modulation ``laser``. laser frequency is stepped as per the modulation ``laser``.
@ -19,11 +26,40 @@ class ScanData:
:param laser: The laser modulation signal. :param laser: The laser modulation signal.
:param output: The output intensity signal. :param output: The output intensity signal.
:param time: The time axis for the signals. :param time: The time axis for the signals.
:param truncation: The fraction of the signals to truncate
from the beginning and end.
:param sparcity: The fraction of the signals to keep.
""" """
self._laser = laser if len(laser) != len(output) or len(laser) != len(time):
self._output = output raise ValueError("The signals must all be the same length.")
self._time = time
length = len(laser)
begin = int(truncation[0] * length / 100)
end = int(truncation[1] * length / 100)
every = int(1 / sparcity)
self._laser = laser[begin:end:every]
self._output = output[begin:end:every]
self._time = time[begin:end:every]
@classmethod
def from_dir(cls, directory: str | Path, **kwargs):
"""Load and parse the oscilloscope data from the
``directory``. The ``**kwargs`` are passed to the
constructor.
The directory should contain ``signal_laser.npy``,
``signal_outp.npy``, and ``time.npy``.
"""
directory = Path(directory)
laser = np.load(directory / "signal_laser.npy")
output = np.load(directory / "signal_outp.npy")
time = np.load(directory / "time.npy")
return cls(laser, output, time, **kwargs)
@property @property
def laser(self): def laser(self):
@ -81,17 +117,3 @@ class ScanData:
window = int(step_size * end_fraction) window = int(step_size * end_fraction)
return np.array([self._output[step - window : step].mean() for step in steps]) return np.array([self._output[step - window : step].mean() for step in steps])
def load_scan(directory: str | Path):
"""Load and parse the oscilloscope data from the ``directory``.
The directory should contain ``signal_laser.npy``, ``signal_outp.npy``, and ``time.npy``.
"""
directory = Path(directory)
laser = np.load(directory / "signal_laser.npy")
output = np.load(directory / "signal_outp.npy")
time = np.load(directory / "time.npy")
return ScanData(laser, output, time)

View file

@ -1,7 +1,7 @@
from . import data from . import data
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from scipy.ndimage import uniform_filter1d from scipy.ndimage import uniform_filter1d
from scipy.interpolate import make_interp_spline, BSpline from scipy.interpolate import make_interp_spline
import numpy as np import numpy as np

View file

@ -6,7 +6,11 @@ import matplotlib.pyplot as plt
from ringfit.data import * from ringfit.data import *
from ringfit.plotting import * from ringfit.plotting import *
path = "/home/hiro/Documents/org/roam/code/fitting_ringdown/data/24_05_24/characterization_first" path = (
scan = data.load_scan(path) "/home/hiro/Documents/org/roam/code/fitting_ringdown/data/24_05_24/nice_transient_2"
)
scan = ScanData.from_dir(path, truncation=[0, 50])
plot_scan(scan, steps=True) fig, ax = plot_scan(scan, steps=True, smoothe_output=1000)
plt.savefig("../figures/non_steady.png")