Skip to content
Snippets Groups Projects
Commit c3244df4 authored by Nicolas Mielec's avatar Nicolas Mielec
Browse files

Adds a few docstrings

parent 20c79260
Branches
No related tags found
No related merge requests found
......@@ -6,15 +6,23 @@ from .functions import focused_linspace
class Spectrum(object):
def __init__(self, power_fun, shift=0.0):
'''
Spectrum created with a power function which should have resonances.
It allows for simple resonance finding and refining.
'''
def __init__(self, power_fun):
self.power = power_fun
self.resonance_phases = None
self.shift = shift
def compute_resonances(self, n_init=300, n_res=None, gain_thres=None):
"""Finds the resonance phases of the power_fun over 0 2pi"""
phases = np.linspace(0, 2 * np.pi, n_init) - self.shift
spectrum_log = np.log10(self.calculate_spectrum(phases - self.shift))
'''
Finds `n_res` highest resonances with a gain threshold `gain_thres` in the power_fun.
If n_res is None, gets all resonances.
If `gain_thres` is None, takes no condition on the resonances.
Returns the resonance phases, stores them in self.resonance_phases.
'''
phases = np.linspace(0, 2 * np.pi, n_init)
spectrum_log = np.log10(self(phases))
m, M = spectrum_log.min(), spectrum_log.max()
thres = (0.01 if gain_thres is None
......@@ -41,9 +49,6 @@ class Spectrum(object):
self.resonance_phases = resonance_phases
return resonance_phases
def calculate_spectrum(self, phases):
return np.array([self.power(phase - self.shift) for phase in phases])
def phase_linspace(self, limits=(0, 2 * np.pi),
num_focused=100, num_unfocused=100):
if self.resonance_phases is None:
......@@ -60,10 +65,13 @@ class Spectrum(object):
num_unfocused=num_unfocused)
def __call__(self, phases=None):
if phases is None:
return self.spectrum(phases)
else:
return self.spectrum(phases)[1]
def spectrum(self, phases=None):
if phases is None:
phases = self.phase_linspace()
return phases, np.array([self.power(phase - self.shift)
return phases, np.array([self.power(phase)
for phase in phases])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment