def with_added_column_from_file(self, name, file_name, multiplication_factor=1):
"""Create a copy of this protocol with the given column (loaded from a file) added to this protocol.
The given file can either contain a single value or one value per protocol line.
Args:
name (str): The name of the column to add.
file_name (str): The file to get the column from.
multiplication_factor (double): we might need to scale the data by a constant. For example,
if the data in the file is in ms we might need to scale it to seconds by multiplying with 1e-3
Returns:
self: for chaining
"""
columns = copy.copy(self._columns)
if name == 'g':
columns.update(get_g_columns(file_name))
for column_name in ('gx', 'gy', 'gz'):
columns[column_name] *= multiplication_factor
return Protocol(columns)
else:
data = np.genfromtxt(file_name)
data *= multiplication_factor
return self.with_new_column(name, data)
评论列表
文章目录