Skip to content
Snippets Groups Projects
Commit e91ec9ac authored by Chad Hanna's avatar Chad Hanna Committed by Cort Posnansky
Browse files

fix a sorting issue in the map between template ids and array index in the population file

parent fab69a52
No related branches found
No related tags found
1 merge request!399fix a sorting issue in the map between template ids and array index in the population file
Pipeline #498212 passed with warnings
......@@ -114,10 +114,11 @@ class SourcePopulationModel(object):
with h5py.File(filename, 'r') as model:
snr_bp = model['SNR'][()]
try:
template_indices = {x:n for n,x in enumerate(numpy.array(model['template_id']))}
template_ids = numpy.array(model['template_id'])
except KeyError:
# FIXME: assume sequential order if model['event_id'] doesn't exist
template_indices = {x:n for n,x in enumerate(numpy.array(model['event_id']))}
template_ids = numpy.array(model['event_id'])
template_id_to_index_map = {x:n for n,x in enumerate(template_ids)}
# PPoly can construct an array of polynomials by just
# feeding it the coefficients array all in one go, but then
# it insists on evaluating all of them at once. we don't
......@@ -126,13 +127,13 @@ class SourcePopulationModel(object):
# just one. since we have to do this anyway, we use a
# dictionary to also solve the problem of mapping
# template_id to a specific polynomial
template_ids = sorted(template_ids)
try:
these_template_id_indices = numpy.array([template_indices[t] for t in template_ids], dtype=numpy.int)
these_template_id_indices = numpy.array([template_id_to_index_map[t] for t in template_ids], dtype=numpy.int)
these_template_id_indices_sort_index = numpy.argsort(these_template_id_indices)
except KeyError:
raise KeyError("One or more template IDs are not in this model")
coefficients = model['coefficients'][:,:,these_template_id_indices]
self.polys = dict((template_id, PPoly(coefficients[:,:, n], snr_bp)) for n, template_id in enumerate(template_ids))
coefficients = model['coefficients'][:,:,these_template_id_indices[these_template_id_indices_sort_index]]
self.polys = {template_ids[these_template_id_indices_sort_index[n]]:PPoly(coefficients[:,:, n], snr_bp) for n in range(len(these_template_id_indices_sort_index))}
self.max_snr = snr_bp.max()
else:
self.polys = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment