Skip to content

Commit

Permalink
Merge 3188a31 into 105cbf1
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLP committed Apr 24, 2018
2 parents 105cbf1 + 3188a31 commit a6be641
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions testbeam_analysis/examples/telescope_time_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def run_analysis():
# Merge the cluster tables to one merged table aligned at the event number
dut_alignment.merge_cluster_data(input_cluster_files=input_cluster_files,
output_merged_file=os.path.join(output_folder, 'Merged.h5'),
n_pixels=n_pixels,
pixel_size=pixel_size)

# Apply the prealignment to the merged cluster table to create tracklets
Expand Down
6 changes: 4 additions & 2 deletions testbeam_analysis/gui/tab_widgets/files_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,12 @@ def check_data(self):
else:
missing.append(req)
if len(missing) != 0:
self.incompatible_data[i] = 'Error! Data does not contain field(s):\n' + ', '.join(missing)
self.incompatible_data[i] = 'Data does not contain field(s):\n' + ', '.join(missing)
if f.root.Hits.shape[0] == 0:
self.incompatible_data[i] = 'Hit data is empty!'

except tb.exceptions.NoSuchNodeError:
self.incompatible_data[i] = 'No Hits! Existing nodes:\n' + ', '.join([node.name for node in f.root])
self.incompatible_data[i] = 'No Hits node! Found nodes:\n' + ', '.join([node.name for node in f.root])

font = QtGui.QFont()
font.setBold(True)
Expand Down
19 changes: 11 additions & 8 deletions testbeam_analysis/tools/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,10 @@ def fit_data():
global offset
global fit
global fit_fn
fit, _ = curve_fit(testbeam_analysis.tools.analysis_utils.linear, x[selected_data], mean_fitted[selected_data]) # Fit straight line
try:
fit, _ = curve_fit(testbeam_analysis.tools.analysis_utils.linear, x[selected_data], mean_fitted[selected_data]) # Fit straight line
except TypeError: # if number of points < 2
raise RuntimeError('Cannot find any correlation, please check data!')
fit_fn = np.poly1d(fit[::-1])
offset = fit_fn(x) - mean_fitted # Calculate straight line fit offset

Expand Down Expand Up @@ -592,13 +595,13 @@ def fit_data():
ax2.legend(lines + lines2, labels + labels2, loc=0)
ax.grid()
# Setup interactive sliders/buttons
ax_offset = plt.axes([0.410, 0.04, 0.2, 0.02], axisbg='white')
ax_error = plt.axes([0.410, 0.01, 0.2, 0.02], axisbg='white')
ax_left_limit = plt.axes([0.125, 0.04, 0.2, 0.02], axisbg='white')
ax_right_limit = plt.axes([0.125, 0.01, 0.2, 0.02], axisbg='white')
ax_button_auto = plt.axes([0.670, 0.01, 0.06, 0.05], axisbg='black')
ax_button_refit = plt.axes([0.735, 0.01, 0.08, 0.05], axisbg='black')
ax_button_ok = plt.axes([0.82, 0.01, 0.08, 0.05], axisbg='black')
ax_offset = plt.axes([0.410, 0.04, 0.2, 0.02], facecolor='white')
ax_error = plt.axes([0.410, 0.01, 0.2, 0.02], facecolor='white')
ax_left_limit = plt.axes([0.125, 0.04, 0.2, 0.02], facecolor='white')
ax_right_limit = plt.axes([0.125, 0.01, 0.2, 0.02], facecolor='white')
ax_button_auto = plt.axes([0.670, 0.01, 0.06, 0.05], facecolor='black')
ax_button_refit = plt.axes([0.735, 0.01, 0.08, 0.05], facecolor='black')
ax_button_ok = plt.axes([0.82, 0.01, 0.08, 0.05], facecolor='black')
# Create widgets
offset_slider = Slider(ax=ax_offset, label='Offset limit', valmin=0.0, valmax=offset_limit, valinit=offset_limit, closedmin=True, closedmax=True)
error_slider = Slider(ax=ax_error, label='Error limit', valmin=0.0, valmax=error_limit * 10.0, valinit=error_limit * 10.0, closedmin=True, closedmax=True)
Expand Down
23 changes: 10 additions & 13 deletions testbeam_analysis/tools/smc.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,15 @@ def __init__(self, table_file_in, file_out,
raise NotImplementedError('Data alignment is only supported '
'on event_number')



# Get the table node name
with tb.open_file(table_file_in) as in_file:
if not table: # Find the table node
tables = in_file.list_nodes('/',classname='Table') # get all nodes of type 'table'
if len(tables) == 1: # if there is only one table, take this one
tables = in_file.list_nodes('/', classname='Table') # get all nodes of type 'table'
if len(tables) == 1: # if there is only one table, take this one
self.node_name = tables[0].name
else: # Multiple tables
raise RuntimeError('No table node defined and '
'multiple table nodes found in file')
elif isinstance(table,(list,tuple,set)): # possible names
else: # Multiple tables
raise RuntimeError('No table node defined and multiple table nodes found in file')
elif isinstance(table, (list, tuple, set)): # possible names
self.node_name = None
for node_cand in table:
try:
Expand All @@ -123,8 +120,7 @@ def __init__(self, table_file_in, file_out,
except tb.NoSuchNodeError:
pass
if not self.node_name:
raise RuntimeError(
'No table nodes with names %s found', str(table))
raise RuntimeError('No table nodes with names %s found', str(table))
else: # string
self.node_name = table

Expand Down Expand Up @@ -155,6 +151,7 @@ def _split(self):
assert len(self.start_i) == len(self.stop_i)

def _map(self):
chunk_size_per_core = int(self.chunk_size / self.n_cores)
if self.n_cores == 1:
self.tmp_files = [self._work(self.table_file_in,
self.node_name,
Expand All @@ -163,7 +160,7 @@ def _map(self):
self.node_desc,
self.start_i[0],
self.stop_i[0],
self.chunk_size)]
chunk_size_per_core)]
else:
# Run function in parallel
pool = Pool(self.n_cores)
Expand All @@ -179,7 +176,7 @@ def _map(self):
node_desc=self.node_desc,
start_i=self.start_i[i],
stop_i=self.stop_i[i],
chunk_size=self.chunk_size
chunk_size=chunk_size_per_core
)
jobs.append(job)

Expand All @@ -204,7 +201,7 @@ def _work(self, table_file_in, node_name, func, func_kwargs,
with tb.open_file(table_file_in, 'r') as in_file:
node = in_file.get_node(in_file.root, node_name)

output_file = tempfile.NamedTemporaryFile(delete=False)
output_file = tempfile.NamedTemporaryFile(delete=False, dir=os.getcwd())
with tb.open_file(output_file.name, 'w') as out_file:
# Create result table with specified data format
# From given pytables tables description
Expand Down

0 comments on commit a6be641

Please sign in to comment.