changed default NoiseMeasurement.plottable

I added left/right arguments to the plottable method because after many attempts at finding a
solution to the Nyquist frequency problem, I resolved to simply dropping the Nyquist frquency
when plotting the PSD.
This commit is contained in:
Benoît Sierro
2023-12-12 12:27:33 +01:00
parent 3a16b87882
commit f33fbc4127

View File

@@ -104,7 +104,8 @@ class NoiseMeasurement:
dB: bool = True, dB: bool = True,
wavelength: float | None = None, wavelength: float | None = None,
power: float | None = None, power: float | None = None,
crop: int | float = 1, left: int = 1,
right: int = -1,
) -> tuple[np.ndarray, np.ndarray]: ) -> tuple[np.ndarray, np.ndarray]:
""" """
Transforms the PSD in a way that makes it easy to plot Transforms the PSD in a way that makes it easy to plot
@@ -116,9 +117,12 @@ class NoiseMeasurement:
wavelength, power : float | None, optional wavelength, power : float | None, optional
if both are provided, will be used to compute the quantum noise limit and the PSD will if both are provided, will be used to compute the quantum noise limit and the PSD will
be output relative to that amount be output relative to that amount
crop : int, optional left : int, optional
how many low frequency points to drop. The default (1) is to drop only the 0 frequency Index of the first frequency point. The default (1) is to drop only the 0 frequency
point, as it is outside the plot range when plotting the PSD on a log-log plot. point, as it is outside the plot range when plotting the PSD on a log-log plot.
right : int, optional
index of the last frequency point, non inclusive (i.e. like slices). The default (-1) is
to drop only the Nyquist frequency, as segmentation artificially reduces its value.
Returns Returns
------- -------
@@ -131,7 +135,7 @@ class NoiseMeasurement:
------- -------
>>> noise = NoiseMeasurement(*np.load("my_measurement.npy")) >>> noise = NoiseMeasurement(*np.load("my_measurement.npy"))
>>> plt.plot(*noise.plottable(wavelength=800e-9, power=0.3)) # dB above quantum limit >>> plt.plot(*noise.plottable(wavelength=800e-9, power=0.3)) # dB above quantum limit
>>> plt.xscale("log") >>> plt.xscale("log") # creates log-log plot is dB is already log scale for y axis
>>> plt.show() >>> plt.show()
""" """
psd = self.psd psd = self.psd
@@ -141,10 +145,7 @@ class NoiseMeasurement:
if dB: if dB:
psd = math.to_dB(psd, ref=1.0) psd = math.to_dB(psd, ref=1.0)
if isinstance(crop, (float, np.floating)): return self.freq[left:right], psd[left:right]
crop = math.argclosest(self.freq, crop)
return self.freq[crop:], psd[crop:]
def sample_spectrum( def sample_spectrum(
self, nf: int, dt: float | None = None, log_mode: bool = False self, nf: int, dt: float | None = None, log_mode: bool = False