本文整理匯總了Python中pycbc.io.FieldArray.add_fields方法的典型用法代碼示例。如果您正苦於以下問題:Python FieldArray.add_fields方法的具體用法?Python FieldArray.add_fields怎麽用?Python FieldArray.add_fields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pycbc.io.FieldArray
的用法示例。
在下文中一共展示了FieldArray.add_fields方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TemplateBank
# 需要導入模塊: from pycbc.io import FieldArray [as 別名]
# 或者: from pycbc.io.FieldArray import add_fields [as 別名]
class TemplateBank(object):
""" Class to provide some basic helper functions and information
about elements of an xml template bank.
"""
def __init__(self, filename, approximant=None, **kwds):
ext = os.path.basename(filename)
if 'xml' in ext:
self.indoc = ligolw_utils.load_filename(
filename, False, contenthandler=LIGOLWContentHandler)
self.table = table.get_table(
self.indoc, lsctables.SnglInspiralTable.tableName)
self.table = FieldArray.from_ligolw_table(self.table)
# inclination stored in xml alpha3 column
names = list(self.table.dtype.names)
names = tuple([n if n != 'alpha3' else 'inclination' for n in names])
self.table.dtype.names = names
elif 'hdf' in ext:
f = h5py.File(filename, 'r')
dtype = []
data = {}
for key in f.keys():
try:
data[str(key)] = f[key][:]
dtype.append((str(key), data[key].dtype))
except:
pass
num = len(data[data.keys()[0]])
self.table = FieldArray(num, dtype=dtype)
for key in data:
self.table[key] = data[key]
else:
raise ValueError("Unsupported template bank file extension %s" % ext)
if not hasattr(self.table, 'template_duration'):
self.table = self.table.add_fields(numpy.zeros(len(self.table),
dtype=numpy.float32), 'template_duration')
self.extra_args = kwds
self.approximant_str = approximant
@staticmethod
def parse_option(row, arg):
safe_dict = {}
safe_dict.update(row.__dict__)
safe_dict.update(math.__dict__)
return eval(arg, {"__builtins__":None}, safe_dict)
def end_frequency(self, index):
""" Return the end frequency of the waveform at the given index value
"""
from pycbc.waveform.waveform import props
return pycbc.waveform.get_waveform_end_frequency(self.table[index],
approximant=self.approximant(index),
**self.extra_args)
def approximant(self, index):
""" Return the name of the approximant ot use at the given index
"""
if self.approximant_str is not None:
if 'params' in self.approximant_str:
t = type('t', (object,), {'params' : self.table[index]})
approximant = str(self.parse_option(t, self.approximant_str))
else:
approximant = self.approximant_str
else:
raise ValueError("Reading approximant from template bank not yet supported")
return approximant
def __len__(self):
return len(self.table)