diff --git a/.gitignore b/.gitignore index d1502f5..5b9c50c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ devenv.local.nix .pre-commit-config.yaml data +__pycache__ diff --git a/figures/non_steady.pdf b/figures/non_steady.pdf new file mode 100644 index 0000000..4d61518 Binary files /dev/null and b/figures/non_steady.pdf differ diff --git a/figures/non_steady.png b/figures/non_steady.png new file mode 100644 index 0000000..69bcd94 Binary files /dev/null and b/figures/non_steady.png differ diff --git a/fitting_ringdown.org b/fitting_ringdown.org index a986624..13644f0 100644 --- a/fitting_ringdown.org +++ b/fitting_ringdown.org @@ -2,3 +2,9 @@ :ID: d7630955-6ca9-4de7-9770-2d50d4847bcd :END: #+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]] diff --git a/ringfit/__pycache__/__init__.cpython-311.pyc b/ringfit/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index 77a5638..0000000 Binary files a/ringfit/__pycache__/__init__.cpython-311.pyc and /dev/null differ diff --git a/ringfit/__pycache__/data.cpython-311.pyc b/ringfit/__pycache__/data.cpython-311.pyc deleted file mode 100644 index 3f23ec7..0000000 Binary files a/ringfit/__pycache__/data.cpython-311.pyc and /dev/null differ diff --git a/ringfit/__pycache__/plotting.cpython-311.pyc b/ringfit/__pycache__/plotting.cpython-311.pyc deleted file mode 100644 index acbd614..0000000 Binary files a/ringfit/__pycache__/plotting.cpython-311.pyc and /dev/null differ diff --git a/ringfit/__pycache__/utils.cpython-311.pyc b/ringfit/__pycache__/utils.cpython-311.pyc deleted file mode 100644 index de9aad7..0000000 Binary files a/ringfit/__pycache__/utils.cpython-311.pyc and /dev/null differ diff --git a/ringfit/data.py b/ringfit/data.py index 655610c..2b5d435 100644 --- a/ringfit/data.py +++ b/ringfit/data.py @@ -9,7 +9,14 @@ from . import utils 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 laser frequency is stepped as per the modulation ``laser``. @@ -19,11 +26,40 @@ class ScanData: :param laser: The laser modulation signal. :param output: The output intensity signal. :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 - self._output = output - self._time = time + if len(laser) != len(output) or len(laser) != len(time): + raise ValueError("The signals must all be the same length.") + + 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 def laser(self): @@ -81,17 +117,3 @@ class ScanData: window = int(step_size * end_fraction) 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) diff --git a/ringfit/plotting.py b/ringfit/plotting.py index a093ae5..2ae3ec4 100644 --- a/ringfit/plotting.py +++ b/ringfit/plotting.py @@ -1,7 +1,7 @@ from . import data import matplotlib.pyplot as plt 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 diff --git a/scripts/first_test.py b/scripts/first_test.py index 354c563..58db471 100644 --- a/scripts/first_test.py +++ b/scripts/first_test.py @@ -6,7 +6,11 @@ import matplotlib.pyplot as plt from ringfit.data import * from ringfit.plotting import * -path = "/home/hiro/Documents/org/roam/code/fitting_ringdown/data/24_05_24/characterization_first" -scan = data.load_scan(path) +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")