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,
wavelength: float | None = None,
power: float | None = None,
crop: int | float = 1,
left: int = 1,
right: int = -1,
) -> tuple[np.ndarray, np.ndarray]:
"""
Transforms the PSD in a way that makes it easy to plot
@@ -116,9 +117,12 @@ class NoiseMeasurement:
wavelength, power : float | None, optional
if both are provided, will be used to compute the quantum noise limit and the PSD will
be output relative to that amount
crop : int, optional
how many low frequency points to drop. The default (1) is to drop only the 0 frequency
left : int, optional
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.
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
-------
@@ -131,7 +135,7 @@ class NoiseMeasurement:
-------
>>> noise = NoiseMeasurement(*np.load("my_measurement.npy"))
>>> 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()
"""
psd = self.psd
@@ -141,10 +145,7 @@ class NoiseMeasurement:
if dB:
psd = math.to_dB(psd, ref=1.0)
if isinstance(crop, (float, np.floating)):
crop = math.argclosest(self.freq, crop)
return self.freq[crop:], psd[crop:]
return self.freq[left:right], psd[left:right]
def sample_spectrum(
self, nf: int, dt: float | None = None, log_mode: bool = False