Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend source classification to all kinds of GraceDB uploads #3149

Merged
merged 7 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bin/pycbc_live
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ from pycbc.events.ranking import newsnr
from pycbc.events.coinc import LiveCoincTimeslideBackgroundEstimator as Coincer
from pycbc.events.single import LiveSingle
from pycbc.io.live import SingleCoincForGraceDB
from pycbc.io.hdf import recursively_save_dict_contents_to_group
import pycbc.waveform.bank
from pycbc.vetoes.sgchisq import SingleDetSGChisq
from pycbc.waveform.waveform import props
Expand Down Expand Up @@ -331,6 +332,10 @@ class LiveEventManager(object):
hdfp['channel_names/{}'.format(ifo)] = \
args.channel_name[ifo]

recursively_save_dict_contents_to_group(hdfp,
'mc_area_args/',
self.mc_area_args)

cmd += '--params-file {} '.format(curr_fname)
cmd += '--approximant {} '.format(apr)
cmd += '--gracedb-server {} '.format(args.gracedb_server)
Expand Down Expand Up @@ -371,7 +376,8 @@ class LiveEventManager(object):
event = SingleCoincForGraceDB([ifo], single, bank=bank,
psds=psds, followup_data=fud,
low_frequency_cutoff=f_low,
channel_names=args.channel_name)
channel_names=args.channel_name,
mc_area_args=self.mc_area_args)

end_time = int(single['foreground/%s/end_time' % ifo])
fname = 'single-%s-%s.xml.gz' % (ifo, end_time)
Expand Down
6 changes: 5 additions & 1 deletion bin/pycbc_optimize_snr
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ from pycbc.conversions import (
)
from scipy.optimize import differential_evolution
from pycbc.io import live
from pycbc.io.hdf import load_hdf5_to_dict
from pycbc.detector import Detector
from pycbc.psd import interpolate

Expand Down Expand Up @@ -316,10 +317,13 @@ channel_names = {}
for ifo in fp['channel_names'].keys():
channel_names[ifo] = fp['channel_names'][ifo][()]

mc_area_args = load_hdf5_to_dict(fp, 'mc_area_args/')

kwargs = {'psds': {ifo: followup_data[ifo]['psd'] for ifo in ifos},
'low_frequency_cutoff': flow,
'followup_data': followup_data,
'channel_names': channel_names}
'channel_names': channel_names,
'mc_area_args': mc_area_args}

doc = live.SingleCoincForGraceDB(ifos, coinc_results,
upload_snr_series=True, **kwargs)
Expand Down
27 changes: 26 additions & 1 deletion pycbc/io/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,13 +960,38 @@ def recursively_save_dict_contents_to_group(h5file, path, dic):
python dictionary to be converted to hdf5 format
"""
for key, item in dic.items():
if isinstance(item, (np.ndarray, np.int64, np.float64, str, bytes, tuple, list)):
if isinstance(item, (np.ndarray, np.int64, np.float64, str, int, float,
bytes, tuple, list)):
h5file[path + str(key)] = item
elif isinstance(item, dict):
recursively_save_dict_contents_to_group(h5file, path + key + '/', item)
else:
raise ValueError('Cannot save %s type' % type(item))

def load_hdf5_to_dict(h5file, path):
"""
Parameters
----------
h5file:
h5py file to be loaded as a dictionary
path:
path within h5py file to load: '/' for the whole h5py file

Returns
-------
dic:
dictionary with hdf5 file group content
"""
dic = {}
for key, item in h5file[path].items():
if isinstance(item, h5py.Dataset):
dic[key] = item[()]
elif isinstance(item, h5py.Group):
dic[key] = load_hdf5_to_dict(h5file, path + key + '/')
else:
raise ValueError('Cannot load %s type' % type(item))
return dic

def combine_and_copy(f, files, group):
""" Combine the same column from multiple files and save to a third"""
# ensure that the files input is stable for iteration order
Expand Down
2 changes: 1 addition & 1 deletion pycbc/mchirp_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def calc_probabilities(mchirp, snr, eff_distance, src_args):
# equal to the maximum mass, the probability for BBH is 100%
mc_max = mass_limits['max_m1'] / (2 ** 0.2)
if trig_mc_det['central'] > mc_max * (1 + z['central']):
if mass_gap is not False:
if mass_gap:
veronica-villa marked this conversation as resolved.
Show resolved Hide resolved
probabilities = {"BNS": 0.0, "GNS": 0.0, "NSBH": 0.0, "GG": 0.0,
"BHG": 0.0, "BBH": 1.0}
else:
Expand Down