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

Fix ordering issue in graphs #372

Merged
merged 2 commits into from
Oct 16, 2024
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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ChangeLog

## v24.1.1

Bug fixes:
* Fix abscissa order in graphs #372

## v24.1.0
Enhancements:
* Edit h text in viewer2D #354
Expand Down
3 changes: 1 addition & 2 deletions src/idvc/dvc_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3319,7 +3319,6 @@ def createSavePointCloudWindow(self, save_only):

def createPointCloud(self, **kwargs):
## Create the PointCloud
#print("Create point cloud")
filename = kwargs.get('filename', "latest_pointcloud.roi")
progress_callback = kwargs.get('progress_callback', PrintCallback())
message_callback = kwargs.get('message_callback', PrintCallback())
Expand Down Expand Up @@ -4644,7 +4643,7 @@ def create_run_config(self, **kwargs):
pointcloud_new_file = os.path.join(results_folder, folder_name, "_" + self.pointcloud_parameters['pointcloud_size_entry'].text() + ".roi")
shutil.copyfile(self.roi, pointcloud_new_file)

else:
elif setting == "bulk":
xmin = int(self.rdvc_widgets['points_in_subvol_range_min_value'].text())
xmax = int(self.rdvc_widgets['points_in_subvol_range_max_value'].text())
xstep = int(self.rdvc_widgets['points_in_subvol_range_step_value'].text())
Expand Down
44 changes: 24 additions & 20 deletions src/idvc/ui/graphs_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def __init__(self, parent, result_data_frame):
single_result = result_data_frame.iloc[0]['result']
self.run_name = single_result.run_name
self.data_label = single_result.data_label
self.subvol_sizes = result_data_frame['subvol_size'].unique()
self.subvol_points = result_data_frame['subvol_points'].unique()
self.subvol_sizes = result_data_frame['subvol_size'].unique().astype(str)
self.subvol_points = result_data_frame['subvol_points'].unique().astype(str)
self.color_list = [
'#1f77b4', # Blue
'#ff7f0e', # Orange
Expand Down Expand Up @@ -102,14 +102,14 @@ def _selectRow(self, result_data_frame, selected_subvol_points, selected_subvol_
----------
result_data_frame : pandas.DataFrame
Data frame containing the results. Includes the 'subvol_points' and 'subvol_size' columns.
selected_subvol_points : str of an integer
selected_subvol_points : int
Selected points in subvolume.
selected_subvol_size : str of an integer
selected_subvol_size : int
Selected subvolume size.
'''
df = result_data_frame
if len(df) > 1:
df = df[(df['subvol_points'].astype(str) == selected_subvol_points) & (df['subvol_size'].astype(str) == selected_subvol_size)]
df = df[(df['subvol_points'] == selected_subvol_points) & (df['subvol_size'] == selected_subvol_size)]
elif len(df) == 1:
df = self.result_data_frame
row = df.iloc[0]
Expand All @@ -125,11 +125,11 @@ def _selectOneParameter(self, result_data_frame, parameter, selected_parameter):
Data frame containing the results. Includes the 'subvol_points' and 'subvol_size' columns.
parameter : str
'subvol_points' or 'subvol_size'
selected_parameter : str of an integer
selected_parameter : int
Selected value of the parameter.
'''
df = result_data_frame
df = df[(df[parameter].astype(str) == selected_parameter)]
df = df[(df[parameter] == selected_parameter)]
return df

def _addHistogramSubplot(self, subplot, array, xlabel, mean, std):
Expand Down Expand Up @@ -204,6 +204,7 @@ def addWidgetsToGridLayout(self):

self.subvol_points_widget = QComboBox(self)
self.subvol_points_widget.addItems(self.subvol_points)
self.subvol_points_widget.setCurrentIndex(0)
self.grid_layout.addWidget(self.subvol_points_widget,widgetno,2)
widgetno+=1

Expand All @@ -213,6 +214,7 @@ def addWidgetsToGridLayout(self):

self.subvol_size_widget = QComboBox(self)
self.subvol_size_widget.addItems(self.subvol_sizes)
self.subvol_size_widget.setCurrentIndex(0)
self.grid_layout.addWidget(self.subvol_size_widget,widgetno,2)
widgetno+=1

Expand Down Expand Up @@ -254,8 +256,8 @@ def addSubplotsToFigure(self):
numRows = 2
numColumns = 2
if len(self.result_data_frame) > 1:
current_subvol_points = self.subvol_points_widget.currentText()
current_subvol_size = self.subvol_size_widget.currentText()
current_subvol_points = int(self.subvol_points_widget.currentText())
current_subvol_size = int(self.subvol_size_widget.currentText())
row = self._selectRow(self.result_data_frame, current_subvol_points, current_subvol_size)
elif len(self.result_data_frame) == 1:
row = self._selectRow(self.result_data_frame, None, None)
Expand Down Expand Up @@ -343,6 +345,7 @@ def addWidgetstoGridLayout(self, param_list, button_text):

self.subvol_size_value_widget = QComboBox(self)
self.subvol_size_value_widget.addItems(self.subvol_sizes)
self.subvol_size_value_widget.setCurrentIndex(0)
self.grid_layout.addWidget(self.subvol_size_value_widget,widgetno,2)

self.subvol_points_value_label = QLabel(self)
Expand All @@ -351,6 +354,7 @@ def addWidgetstoGridLayout(self, param_list, button_text):

self.subvol_points_value_widget = QComboBox(self)
self.subvol_points_value_widget.addItems(self.subvol_points)
self.subvol_points_value_widget.setCurrentIndex(0)
self.grid_layout.addWidget(self.subvol_points_value_widget,widgetno,2)

self.showParameterValues()
Expand Down Expand Up @@ -459,7 +463,7 @@ def addSubplotsToFigure(self):
plot_title = f"Bulk run '{self.run_name}': {data_label.lower()} distribution for all parameters"
else:
value_widget = self.parameter_value_widget_list[param_index]
parameter_value = value_widget.currentText()
parameter_value = int(value_widget.currentText())
param_text = self.parameter_fix_widget.currentText().lower()
plot_title = f"Bulk run '{self.run_name}': {data_label.lower()} distribution for {param_text} = {parameter_value}"
self.fig.suptitle(plot_title,fontsize=self.fontsizes['figure_title'])
Expand All @@ -475,17 +479,17 @@ def addSubplotsToFigure(self):
numRows = 1
self.canvas.setMinimumSize(300*numColumns, 400)
subplot_title = f"Points in subvolume = {result.subvol_points}"
if result.subvol_size != float(parameter_value):
if result.subvol_size != parameter_value:
continue
elif param_index == 1:
numColumns = 1
self.canvas.setMinimumSize(800, 300*numRows) #needed for scrollbar
self.canvas.setMinimumSize(800, 400*numRows) #needed for scrollbar
subplot_title = f"Subvolume size = {result.subvol_size}"
if result.subvol_points != float(parameter_value):
if result.subvol_points != parameter_value:
continue
elif param_index == 2:
subplot_title = f"Points in subvolume = {result.subvol_points}, subvolume size = {result.subvol_size}"
self.canvas.setMinimumSize(300*numColumns, 300*numRows)
self.canvas.setMinimumSize(300*numColumns, 400*numRows)
data_index = self.data_label_widget.currentIndex()
x_label = data_label
if 0<data_index<4:
Expand Down Expand Up @@ -565,7 +569,7 @@ def _meanStdPlots(self, subplot_mean, subplot_std, result_data_frame, data_index
Label for the data.
parameter : str
Parameter to filter the data frame.
selected_parameter : str
selected_parameter : int
Value of the parameter to filter.
x_parameter : str
Column name for x-axis values.
Expand Down Expand Up @@ -657,7 +661,7 @@ def addSubplotsToFigure(self):
numColumns = 2
subplot = self.fig.add_subplot(numRows, numColumns, plotNum)
subplot.set_title(f"{data_label}", pad=20, fontsize=self.fontsizes['subplot_title'])
value = value_widget.currentText()
value = int(value_widget.currentText())
plot_title = f"Bulk run '{self.run_name}': mean and standard deviation for {param_text} = {value}"
twin = subplot.twinx()
self._meanStdPlots(subplot, twin, df, data_index, "", label_list[param_index], value, label_list[1-param_index], x_label)
Expand All @@ -675,14 +679,14 @@ def addSubplotsToFigure(self):
plot_title = f"Bulk run '{self.run_name}': {data_label.lower()} mean and standard deviation for fixed {param_text}"
if not self.collapse_checkbox.isChecked():
numRows = len(self.value_list[param_index])
self.canvas.setMinimumSize(800, 300*numRows)
self.canvas.setMinimumSize(800, 400*numRows)
for value in self.value_list[param_index]:
subplot_mean = self.fig.add_subplot(numRows, numColumns, plotNum)
subplot_mean.set_title(f"Mean for {param_text} = {value}", fontsize=self.fontsizes['subplot_title'], pad=20)
subplot_std = self.fig.add_subplot(numRows, numColumns, plotNum +1)
subplot_std.set_title(f"Standard deviation for {param_text} = {value}", fontsize=self.fontsizes['subplot_title'], pad=20)
label = f"{param_text} = {value}"
self._meanStdPlots(subplot_mean, subplot_std, df, data_index, data_label+" ", label_list[param_index], value, label_list[1-param_index], x_label, label_mean = label, label_std = label)
self._meanStdPlots(subplot_mean, subplot_std, df, data_index, data_label+" ", label_list[param_index], int(value), label_list[1-param_index], x_label, label_mean = label, label_std = label)
plotNum = plotNum + 2
elif self.collapse_checkbox.isChecked():
numRows = 1
Expand All @@ -698,7 +702,7 @@ def addSubplotsToFigure(self):
else:
color = np.random.rand(3,)
label = f"{param_text} = {value}"
self._meanStdPlots(subplot_mean, subplot_std, df, data_index, data_label+" ", label_list[param_index], value, label_list[1-param_index], x_label, color, color, label, label, linestyle = linestyle)
self._meanStdPlots(subplot_mean, subplot_std, df, data_index, data_label+" ", label_list[param_index], int(value), label_list[1-param_index], x_label, color, color, label, label, linestyle = linestyle)
subplot_mean.legend(loc='upper right')
subplot_std.legend(loc='upper right')
else:
Expand All @@ -707,7 +711,7 @@ def addSubplotsToFigure(self):
subplot_mean.set_title("Mean", fontsize=self.fontsizes['subplot_title'], pad=20)
subplot_std = self.fig.add_subplot(numRows, numColumns, plotNum+1)
subplot_std.set_title("Standard deviation", fontsize=self.fontsizes['subplot_title'], pad=20)
value = value_widget.currentText()
value = int(value_widget.currentText())
plot_title = f"Bulk run '{self.run_name}': {data_label.lower()} mean and standard deviation for {param_text} = {value}"
self._meanStdPlots(subplot_mean, subplot_std, df, data_index, data_label+" ", label_list[param_index], value, label_list[1-param_index], x_label)

Expand Down
13 changes: 7 additions & 6 deletions src/idvc/utils/manipulate_result_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def _extractDataFromDispResultFile(result, displ_wrt_point0):
"""
Extracts objective minimum and displacement vectors from a result file.
Extracts objective minimum and displacement vectors from a result file in a numpy 2D array.
Optionally, adjusts the displacement vectors relative to the displacement of the first point.

The objective function minimum is located at index 5.
Expand All @@ -29,7 +29,7 @@ def _extractDataFromDispResultFile(result, displ_wrt_point0):
2D array where each row corresponds to a column of data from the file,
including the objective function minimum and displacement vectors.
"""
data = np.genfromtxt(result.disp_file, delimiter='\t', skip_header=1)
data = np.genfromtxt(result.disp_file, delimiter='\t', skip_header=1, ndmin=2)
data_shape = data.shape
index_objmin = 5
index_disp = [6, 9]
Expand All @@ -56,8 +56,8 @@ def createResultsDataFrame(results_folder, displ_wrt_point0):
Returns
-------
pd.DataFrame: A DataFrame with the following columns:
- 'subvol_size': List of subvolume sizes as strings.
- 'subvol_points': List of subvolume points as strings.
- 'subvol_size': List of subvolume sizes as int.
- 'subvol_points': List of subvolume points as int.
- 'result': List of RunResults objects.
- 'result_arrays': List of 4 arrays containing extracted data.
"""
Expand All @@ -69,8 +69,8 @@ def createResultsDataFrame(results_folder, displ_wrt_point0):
for folder in glob.glob(os.path.join(results_folder, "dvc_result_*")):
result = RunResults(folder)
result_arrays = _extractDataFromDispResultFile(result, displ_wrt_point0)
subvol_size_list.append(str(result.subvol_size))
subvol_points_list.append(str(result.subvol_points))
subvol_size_list.append(int(result.subvol_size))
subvol_points_list.append(int(result.subvol_points))
result_list.append(result)

result_arrays_list.append(result_arrays)
Expand All @@ -79,6 +79,7 @@ def createResultsDataFrame(results_folder, displ_wrt_point0):
'subvol_points': subvol_points_list,
'result': result_list,
'result_arrays': result_arrays_list})
result_data_frame = result_data_frame.sort_values(by=['subvol_size', 'subvol_points'], ascending=[True, True]).reset_index(drop=True)
return result_data_frame

def addMeanAndStdToResultDataFrame(result_data_frame):
Expand Down