Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
lscsoft
bilby
Commits
b3ec4358
Commit
b3ec4358
authored
May 02, 2019
by
Gregory Ashton
Committed by
Colm Talbot
May 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds option to merge runs from the command line
Also resolves minor bug with likelihood meta data
parent
03219f50
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
17 deletions
+31
-17
bilby/core/likelihood.py
bilby/core/likelihood.py
+1
-1
bilby/core/result.py
bilby/core/result.py
+17
-13
cli_bilby/bilby_result.py
cli_bilby/bilby_result.py
+13
-3
No files found.
bilby/core/likelihood.py
View file @
b3ec4358
...
...
@@ -52,7 +52,7 @@ class Likelihood(object):
@
property
def
meta_data
(
self
):
return
self
.
_meta_data
return
getattr
(
self
,
'
_meta_data
'
,
None
)
@
meta_data
.
setter
def
meta_data
(
self
,
meta_data
):
...
...
bilby/core/result.py
View file @
b3ec4358
...
...
@@ -408,12 +408,15 @@ class Result(object):
pass
return
dictionary
def
save_to_file
(
self
,
overwrite
=
False
,
outdir
=
None
,
extension
=
'json'
,
gzip
=
False
):
def
save_to_file
(
self
,
filename
=
None
,
overwrite
=
False
,
outdir
=
None
,
extension
=
'json'
,
gzip
=
False
):
"""
Writes the Result to a json or deepdish h5 file
Parameters
----------
filename: optional,
Filename to write to (overwrites the default)
overwrite: bool, optional
Whether or not to overwrite an existing result file.
default=False
...
...
@@ -431,19 +434,20 @@ class Result(object):
extension
=
"json"
outdir
=
self
.
_safe_outdir_creation
(
outdir
,
self
.
save_to_file
)
file_name
=
result_file_name
(
outdir
,
self
.
label
,
extension
,
gzip
)
if
filename
is
None
:
filename
=
result_file_name
(
outdir
,
self
.
label
,
extension
,
gzip
)
if
os
.
path
.
isfile
(
file
_
name
):
if
os
.
path
.
isfile
(
filename
):
if
overwrite
:
logger
.
debug
(
'Removing existing file {}'
.
format
(
file
_
name
))
os
.
remove
(
file
_
name
)
logger
.
debug
(
'Removing existing file {}'
.
format
(
filename
))
os
.
remove
(
filename
)
else
:
logger
.
debug
(
'Renaming existing file {} to {}.old'
.
format
(
file
_
name
,
file
_
name
))
os
.
rename
(
file
_
name
,
file
_
name
+
'.old'
)
'Renaming existing file {} to {}.old'
.
format
(
filename
,
filename
))
os
.
rename
(
filename
,
filename
+
'.old'
)
logger
.
debug
(
"Saving result to {}"
.
format
(
file
_
name
))
logger
.
debug
(
"Saving result to {}"
.
format
(
filename
))
# Convert the prior to a string representation for saving on disk
dictionary
=
self
.
_get_save_data_dictionary
()
...
...
@@ -462,17 +466,17 @@ class Result(object):
import
gzip
# encode to a string
json_str
=
json
.
dumps
(
dictionary
,
cls
=
BilbyJsonEncoder
).
encode
(
'utf-8'
)
with
gzip
.
GzipFile
(
file
_
name
,
'w'
)
as
file
:
with
gzip
.
GzipFile
(
filename
,
'w'
)
as
file
:
file
.
write
(
json_str
)
else
:
with
open
(
file
_
name
,
'w'
)
as
file
:
with
open
(
filename
,
'w'
)
as
file
:
json
.
dump
(
dictionary
,
file
,
indent
=
2
,
cls
=
BilbyJsonEncoder
)
elif
extension
==
'hdf5'
:
import
deepdish
for
key
in
dictionary
:
if
isinstance
(
dictionary
[
key
],
pd
.
DataFrame
):
dictionary
[
key
]
=
dictionary
[
key
].
to_dict
()
deepdish
.
io
.
save
(
file
_
name
,
dictionary
)
deepdish
.
io
.
save
(
filename
,
dictionary
)
else
:
raise
ValueError
(
"Extension type {} not understood"
.
format
(
extension
))
except
Exception
as
e
:
...
...
@@ -1293,7 +1297,7 @@ class ResultList(list):
result
=
copy
(
self
[
0
])
if
result
.
label
is
not
None
:
result
.
label
+=
'combined'
result
.
label
+=
'
_
combined'
self
.
_check_consistent_sampler
()
self
.
_check_consistent_data
()
...
...
cli_bilby/bilby_result.py
View file @
b3ec4358
...
...
@@ -29,14 +29,17 @@ import bilby
def
setup_command_line_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
"Helper tool for bilby result files"
,
epilog
=
print
(
__doc__
))
description
=
"Helper tool for bilby result files"
)
parser
.
add_argument
(
"-r"
,
"--results"
,
nargs
=
'+'
,
required
=
True
,
help
=
"List of results files."
)
parser
.
add_argument
(
"-c"
,
"--convert"
,
type
=
str
,
choices
=
[
'json'
,
'hdf5'
],
help
=
"Convert all results."
,
default
=
False
)
parser
.
add_argument
(
"-m"
,
"--merge"
,
action
=
'store_true'
,
help
=
"Merge the set of runs, output saved using the outdir and label"
)
parser
.
add_argument
(
"-o"
,
"--outdir"
,
type
=
str
,
default
=
None
,
help
=
"Output directory."
)
parser
.
add_argument
(
"-l"
,
"--label"
,
type
=
str
,
default
=
None
,
help
=
"New label for output result object"
)
parser
.
add_argument
(
"-b"
,
"--bayes"
,
action
=
'store_true'
,
help
=
"Print all Bayes factors."
)
parser
.
add_argument
(
"-p"
,
"--print"
,
nargs
=
'+'
,
default
=
None
,
...
...
@@ -55,7 +58,7 @@ def read_in_results(filename_list):
results_list
=
[]
for
filename
in
filename_list
:
results_list
.
append
(
bilby
.
core
.
result
.
read_in_result
(
filename
=
filename
))
return
results_list
return
bilby
.
core
.
result
.
ResultList
(
results_list
)
def
print_bayes_factors
(
results_list
):
...
...
@@ -97,3 +100,10 @@ def main():
print_bayes_factors
(
results_list
)
if
args
.
ipython
:
drop_to_ipython
(
results_list
)
if
args
.
merge
:
result
=
results_list
.
combine
()
if
args
.
label
is
not
None
:
result
.
label
=
args
.
label
if
args
.
outdir
is
not
None
:
result
.
outdir
=
args
.
outdir
result
.
save_to_file
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment