Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OrcaSong
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Machine Learning
OrcaSong
Commits
fd12fd58
Commit
fd12fd58
authored
5 years ago
by
Stefan Reck
Browse files
Options
Downloads
Patches
Plain Diff
Parser and some printing.
parent
34ee2fea
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
orcasong_plag/util/bin_stats_plot.py
+43
-18
43 additions, 18 deletions
orcasong_plag/util/bin_stats_plot.py
with
43 additions
and
18 deletions
orcasong_plag/util/bin_stats_plot.py
+
43
−
18
View file @
fd12fd58
...
...
@@ -4,9 +4,9 @@ Functions for plotting the bin stats made by the BinningStatsMaker module.
import
matplotlib.pyplot
as
plt
from
matplotlib.backends.backend_pdf
import
PdfPages
import
matplotlib.ticker
as
ticker
import
h5py
import
numpy
as
np
import
argparse
def
plot_hists
(
hists
,
save_to
,
plot_bin_edges
=
True
):
...
...
@@ -37,16 +37,15 @@ def plot_hists(hists, save_to, plot_bin_edges=True):
cut_off
=
hists_data
[
"
cut_off
"
]
total_hits
=
np
.
sum
(
hist
)
+
np
.
sum
(
cut_off
)
hist_frac
=
hist
/
total_hits
bin_widths
=
np
.
diff
(
hist_bin_edges
)
hist_prob
=
hist
/
bin_widths
/
np
.
sum
(
hist
)
bin_spacing
=
hist_bin_edges
[
1
]
-
hist_bin_edges
[
0
]
fig
,
ax
=
plt
.
subplots
()
plt
.
bar
(
hist_bin_edges
[:
-
1
],
hist_
frac
,
hist_
prob
,
align
=
"
edge
"
,
width
=
0.9
*
bin_spacing
,
width
=
bin_widths
)
ax
.
yaxis
.
set_major_formatter
(
ticker
.
PercentFormatter
(
xmax
=
1
))
if
plot_bin_edges
and
bin_name
!=
"
time
"
:
for
bin_edge
in
bin_edges
:
...
...
@@ -56,14 +55,19 @@ def plot_hists(hists, save_to, plot_bin_edges=True):
# place a text box in upper left in axes coords
out_neg_rel
=
cut_off
[
0
]
/
total_hits
out_pos_rel
=
cut_off
[
1
]
/
total_hits
textstr
=
"
Hits cut off:
\n
Left: {:.1%}
\n
"
\
"
Right: {:.1%}
"
.
format
(
out_neg_rel
,
out_pos_rel
)
textstr
=
"
Hits cut off:
\n
Left: {:.1%}
\n
"
\
"
Right: {:.1%}
"
.
format
(
out_neg_rel
,
out_pos_rel
)
props
=
dict
(
boxstyle
=
'
round
'
,
facecolor
=
'
white
'
,
alpha
=
0.9
)
ax
.
text
(
0.05
,
0.95
,
textstr
,
transform
=
ax
.
transAxes
,
verticalalignment
=
'
top
'
,
bbox
=
props
)
ax
.
text
(
0.95
,
0.95
,
textstr
,
transform
=
ax
.
transAxes
,
verticalalignment
=
'
top
'
,
bbox
=
props
,
horizontalalignment
=
"
right
"
)
# the auto ticks are nice even numbers
ylims
=
[
0
,
ax
.
get_yticks
().
max
()]
ax
.
set_ylim
(
ylims
)
plt
.
xlabel
(
bin_name
)
plt
.
ylabel
(
"
Fraction
of hits
"
)
plt
.
ylabel
(
"
Density
of hits
"
)
pdf_file
.
savefig
(
fig
)
...
...
@@ -161,12 +165,33 @@ def plot_hist_of_files(files, save_as):
"""
hists_list
=
[]
opened_files
=
[]
for
file
in
files
:
f
=
h5py
.
File
(
file
,
"
r
"
)
hists_list
.
append
(
f
[
"
bin_stats/
"
])
opened_files
.
append
(
f
)
plot_hists
(
hists_list
,
save_as
)
try
:
for
i
,
file
in
enumerate
(
files
):
if
i
%
100
==
0
:
print
(
"
File {} of {}...
"
.
format
(
i
,
len
(
files
)))
f
=
h5py
.
File
(
file
,
"
r
"
)
if
"
bin_stats/
"
not
in
f
:
raise
ValueError
(
"
Can not plot: File does not have bin_stats
"
)
hists_list
.
append
(
f
[
"
bin_stats/
"
])
opened_files
.
append
(
f
)
print
(
"
Plotting...
"
)
plot_hists
(
hists_list
,
save_as
)
finally
:
print
(
"
Closing files...
"
)
for
file
in
opened_files
:
file
.
close
()
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
(
description
=
'
Plot the bin stats in h5 files
'
)
parser
.
add_argument
(
'
save_as
'
,
metavar
=
'
S
'
,
type
=
str
,
help
=
'
Where to save the plot to.
'
)
parser
.
add_argument
(
'
files
'
,
metavar
=
'
F
'
,
type
=
str
,
nargs
=
'
+
'
,
help
=
'
The files
'
)
for
file
in
opened_files
:
file
.
close
(
)
args
=
parser
.
parse_args
()
plot_hist_of_files
(
args
.
files
,
args
.
save_as
)
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