time series assumes a mean of 0
This commit is contained in:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "scgenerator"
|
name = "scgenerator"
|
||||||
version = "0.4.2"
|
version = "0.4.3"
|
||||||
description = "Simulate nonlinear pulse propagation in optical fibers"
|
description = "Simulate nonlinear pulse propagation in optical fibers"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = [{ name = "Benoit Sierro", email = "benoit.sierro@iap.unibe.ch" }]
|
authors = [{ name = "Benoit Sierro", email = "benoit.sierro@iap.unibe.ch" }]
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ class NoiseMeasurement:
|
|||||||
return freq[left:], psd[left:]
|
return freq[left:], psd[left:]
|
||||||
|
|
||||||
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, left: float | None = None
|
||||||
) -> tuple[np.ndarray, np.ndarray]:
|
) -> tuple[np.ndarray, np.ndarray]:
|
||||||
"""
|
"""
|
||||||
sample an amplitude spectrum with nt points. The corresponding sample spacing in the time
|
sample an amplitude spectrum with nt points. The corresponding sample spacing in the time
|
||||||
@@ -156,6 +156,9 @@ class NoiseMeasurement:
|
|||||||
dt : float | None, optional
|
dt : float | None, optional
|
||||||
if given, freq will only be sampled up to 0.5/dt. if that value is higher than the
|
if given, freq will only be sampled up to 0.5/dt. if that value is higher than the
|
||||||
max of freq, an exception is raised.
|
max of freq, an exception is raised.
|
||||||
|
left : float | None, optional
|
||||||
|
extend current PSD to the lower frequency range by assuming a constant value of `left`.
|
||||||
|
if None (default), extends with the last value
|
||||||
log_mode : bool, optional
|
log_mode : bool, optional
|
||||||
sample on a log-log scale rather than on a linear scale, by default False
|
sample on a log-log scale rather than on a linear scale, by default False
|
||||||
"""
|
"""
|
||||||
@@ -171,19 +174,24 @@ class NoiseMeasurement:
|
|||||||
if log_mode:
|
if log_mode:
|
||||||
interp = np.zeros_like(f)
|
interp = np.zeros_like(f)
|
||||||
ind = self.freq > 0
|
ind = self.freq > 0
|
||||||
|
if left is not None and left <= 0:
|
||||||
|
raise ValueError(f"value {left!r} for `left` in log mode is invalid")
|
||||||
|
elif left is None:
|
||||||
|
left = self.psd[ind][0]
|
||||||
interp[1:] = np.exp(
|
interp[1:] = np.exp(
|
||||||
np.interp(
|
np.interp(
|
||||||
np.log(f[1:]),
|
np.log(f[1:]),
|
||||||
np.log(self.freq[ind]),
|
np.log(self.freq[ind]),
|
||||||
np.log(self.psd[ind]),
|
np.log(self.psd[ind]),
|
||||||
left=np.log(self.psd[ind][0]),
|
left=np.log(left),
|
||||||
right=np.log(self.psd[ind][-1]),
|
right=np.log(self.psd[ind][-1]),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if self.freq[0] == 0:
|
if self.freq[0] == 0:
|
||||||
interp[0] = self.psd[0]
|
interp[0] = self.psd[0]
|
||||||
else:
|
else:
|
||||||
interp = np.interp(f, self.freq, self.psd, left=self.psd[0], right=self.psd[-1])
|
left = left if left is not None else self.psd[0]
|
||||||
|
interp = np.interp(f, self.freq, self.psd, left=left, right=self.psd[-1])
|
||||||
return f, interp
|
return f, interp
|
||||||
|
|
||||||
def resampled(self, nf: int, dt: float | None = None, log_mode: bool = False) -> Self:
|
def resampled(self, nf: int, dt: float | None = None, log_mode: bool = False) -> Self:
|
||||||
@@ -211,7 +219,7 @@ class NoiseMeasurement:
|
|||||||
sample on a log-log scale rather than on a linear scale, by default False
|
sample on a log-log scale rather than on a linear scale, by default False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
freq, amp = self.sample_spectrum(nf, dt, log_mode)
|
freq, amp = self.sample_spectrum(nf, dt, log_mode, left=0)
|
||||||
fs = freq[-1] * 2
|
fs = freq[-1] * 2
|
||||||
|
|
||||||
if nf % 2:
|
if nf % 2:
|
||||||
|
|||||||
Reference in New Issue
Block a user