Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fresnel-cavity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Mielec
fresnel-cavity
Commits
c3244df4
Commit
c3244df4
authored
7 years ago
by
Nicolas Mielec
Browse files
Options
Downloads
Patches
Plain Diff
Adds a few docstrings
parent
20c79260
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
spectrum.py
+18
-10
18 additions, 10 deletions
spectrum.py
with
18 additions
and
10 deletions
spectrum.py
+
18
−
10
View file @
c3244df4
...
...
@@ -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
])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment