Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LISA Instrument
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Gitlab has been updated. More info
here
and
there
.
Show more breadcrumbs
LISA Simulation
LISA Instrument
Commits
898e15dd
Commit
898e15dd
authored
4 years ago
by
Jean-Baptiste Bayle
Browse files
Options
Downloads
Patches
Plain Diff
Add a method to plot a `ForEachObject`
parent
e3669fa8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4
Resolve "Add glitch"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lisainstrument/containers.py
+36
-0
36 additions, 0 deletions
lisainstrument/containers.py
with
36 additions
and
0 deletions
lisainstrument/containers.py
+
36
−
0
View file @
898e15dd
...
...
@@ -11,6 +11,7 @@ import abc
import
logging
import
numpy
import
h5py
import
matplotlib.pyplot
class
ForEachObject
(
abc
.
ABC
):
...
...
@@ -93,6 +94,41 @@ class ForEachObject(abc.ABC):
"""
Return dictionary items.
"""
return
self
.
dict
.
items
()
def
plot
(
self
,
output
=
None
,
dt
=
1
,
t0
=
0
,
size
=
'
auto
'
,
title
=
'
Signals
'
):
"""
Plot signals for each object.
Args:
output: output file, None to show the plots
dt: sampling period [s]
t0: initial time [s]
size: duration of time series, or
'
auto
'
[samples]
title: plot title
"""
if
size
==
'
auto
'
:
size
=
len
(
self
)
if
len
(
self
)
>
1
else
100
t
=
t0
+
numpy
.
arange
(
size
)
*
dt
# Plot signals
logging
.
info
(
"
Plotting signals for each object
"
)
matplotlib
.
pyplot
.
figure
(
figsize
=
(
12
,
4
))
for
key
,
signal
in
self
.
items
():
matplotlib
.
pyplot
.
plot
(
t
,
numpy
.
broadcast_to
(
signal
,
size
),
label
=
key
)
matplotlib
.
pyplot
.
grid
()
matplotlib
.
pyplot
.
legend
()
matplotlib
.
pyplot
.
xlabel
(
"
Time [s]
"
)
matplotlib
.
pyplot
.
ylabel
(
"
Signal
"
)
matplotlib
.
pyplot
.
title
(
title
)
# Save or show glitch
if
output
is
not
None
:
logging
.
info
(
"
Saving plot to %s
"
,
output
)
matplotlib
.
pyplot
.
savefig
(
output
,
bbox_inches
=
'
tight
'
)
else
:
matplotlib
.
pyplot
.
show
()
def
__len__
(
self
):
"""
Return maximum size of signals.
"""
sizes
=
[
1
if
numpy
.
isscalar
(
signal
)
else
len
(
signal
)
for
signal
in
self
.
values
()]
return
numpy
.
max
(
sizes
)
def
__eq__
(
self
,
other
):
if
isinstance
(
other
,
self
.
__class__
):
return
self
.
dict
==
other
.
dict
...
...
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