Commit 43fa1f24 authored by Ivo Peterek's avatar Ivo Peterek

ENH: user defines path to meric config

parent 39501434
This diff is collapsed.
......@@ -9,8 +9,9 @@ import h5py
class DataLoad:
def __init__(self, config_path):
def __init__(self, config_path, meric_config_path):
self.config_path = config_path
self.meric_config_path = meric_config_path
self.config_dic = run_path(config_path)
self.data_path = self.config_dic['root_folder'][0][0]
self.main_reg = self.config_dic['main_reg'][0].values()
......@@ -23,7 +24,7 @@ class DataLoad:
# self.regions.append(region)
# self.regions = sorted(self.regions, key=lambda s: s.lower())
meric_config_energy_file = open(self.data_path + "/" + 'meric_config_energy.opts')
meric_config_energy_file = open(meric_config_path)
meric_config_energy_str = meric_config_energy_file.read()
self.meric_config_energy_data = json.loads(meric_config_energy_str)
......
......@@ -31,12 +31,26 @@ class DataHandler:
return None
return DataHandler.__instance
def __init__(self, config_path):
def __init__(self, config_path, meric_config_path):
if DataHandler.__instance is not None:
DataHandler.__instance = DataHandler.getInstance(self)
else:
DataHandler.__instance = self
if meric_config_path:
try:
self.raw_data = data_load.DataLoad(config_path, meric_config_path).data
except Exception:
print("loading data directly from csv failed!!! using old radar get_data_for_gui.py !!!")
traceback.print_exc()
self.__run_old_radar(config_path)
else:
print("Data loaded directly from csv files.")
else:
print("No Meric config file. Using old version of radar!!!")
self.__run_old_radar(config_path)
def __run_old_radar(self, config_path):
path_to_radar = Path(os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '/pathToRadar.json')
if path_to_radar.exists():
with open(path_to_radar) as f:
......@@ -52,18 +66,13 @@ class DataHandler:
else:
self.__print_error_msg('pathToRadar.json not found')
class MainMenu(QtWidgets.QFrame, design_main_menu.Ui_MainMenu):
def __init__(self, config_path):
def __init__(self, config_path, meric_config_path):
super(self.__class__, self).__init__()
try:
self.data_no_radar = data_load.DataLoad(config_path)
except Exception:
print("loading data directly from csv failed!!! using old radar get_data_for_gui.py !!!")
traceback.print_exc()
self.data_no_radar = None
else:
print("Data loaded directly from csv files.")
self.config_path = config_path
self.meric_config_path = meric_config_path
self.config = run_path(config_path)
self.dictForTex = {'tree': None, 'plots': [], 'heatmaps': [], 'overall': False, 'regions': [], 'nested': []}
self.setupUi(self)
......@@ -81,7 +90,7 @@ class MainMenu(QtWidgets.QFrame, design_main_menu.Ui_MainMenu):
self.pushButton_generate_meric.clicked.connect(self.__meric_opt)
self.pushButton_restart.clicked.connect(self.restart)
self.radar_data = DataHandler(self.config_path)
self.radar_data = DataHandler(self.config_path, self.meric_config_path)
self.sub_windows = []
self.pushButton_samples.setEnabled(False)
......@@ -93,7 +102,7 @@ class MainMenu(QtWidgets.QFrame, design_main_menu.Ui_MainMenu):
self.__print_success_msg('Some analysis options were disabled because analyzed measurement contains only'
' main region.', 'Info')
root_folder = self.radar_data.raw_data['root_folder']
root_folder = self.config['root_folder'][0][0]
for region in os.listdir(root_folder):
if os.path.isdir(root_folder + "/" + region):
if glob.glob(glob.escape(root_folder) + '/' + glob.escape(region) + '/*.csv'):
......@@ -106,10 +115,7 @@ class MainMenu(QtWidgets.QFrame, design_main_menu.Ui_MainMenu):
break
def __plot(self):
if self.data_no_radar:
self.plot_window = data_plot.Window(ownData=self.data_no_radar.data,)
else:
self.plot_window = data_plot.Window(ownData=self.radar_data.raw_data)
self.plot_window = data_plot.Window(ownData=self.radar_data.raw_data)
self.plot_window.show()
self.plot_window.sendInfo.connect(partial(self.__getTeXInfo,'plots'))
self.sub_windows.append(self.plot_window)
......@@ -121,11 +127,7 @@ class MainMenu(QtWidgets.QFrame, design_main_menu.Ui_MainMenu):
self.sub_windows.append(self.samples_window)
def __heatmap(self):
#self.heatmap_window = heatmap.Window(self, ownData=self.radar_data.raw_data, radar_data=True)
if self.data_no_radar:
self.heatmap_window = heatmap.Window(self, ownData=self.data_no_radar.data, radar_data=True)
else:
self.heatmap_window = heatmap.Window(self, ownData=self.radar_data.raw_data, radar_data=True)
self.heatmap_window = heatmap.Window(self, ownData=self.radar_data.raw_data, radar_data=True)
self.heatmap_window.show()
self.heatmap_window.sendInfo.connect(partial(self.__getTeXInfo,'heatmaps'))
self.sub_windows.append(self.heatmap_window)
......@@ -137,37 +139,28 @@ class MainMenu(QtWidgets.QFrame, design_main_menu.Ui_MainMenu):
self.dictForTex[objType].append(entry)
def __tree(self):
self.tree_window = pydot_example.regionTree(pathToData = self.radar_data.raw_data['root_folder_lst'][0], ownData=self.radar_data.raw_data, defaultDPI='300')
self.tree_window.show()
self.tree_window.sendInfo.connect(partial(self.__getTeXInfo,'tree'))
#pydot_example.browse_dir(self.radar_data.raw_data['root_folder_lst'][0], ownData=self.radar_data.raw_data)
self.sub_windows.append(self.tree_window)
self.tree_window = pydot_example.regionTree(pathToData = self.radar_data.raw_data['root_folder_lst'][0], ownData=self.radar_data.raw_data, defaultDPI='300')
self.tree_window.show()
self.tree_window.sendInfo.connect(partial(self.__getTeXInfo,'tree'))
#pydot_example.browse_dir(self.radar_data.raw_data['root_folder_lst'][0], ownData=self.radar_data.raw_data)
self.sub_windows.append(self.tree_window)
def __average_start(self):
if self.data_no_radar:
self.average_start_window = all_tables.IndicSelectWindow(table="regions", ownData=self.data_no_radar.data)
else:
self.average_start_window = all_tables.IndicSelectWindow(table="regions", ownData=self.radar_data.raw_data)
self.average_start_window = all_tables.IndicSelectWindow(table="regions", ownData=self.radar_data.raw_data)
self.average_start_window.createTable()
self.average_start_window.show()
self.average_start_window.sendInfo.connect(partial(self.__getTeXInfo,'regions'))
self.sub_windows.append(self.average_start_window)
def __table_nested_region(self):
if self.data_no_radar:
self.nested_region_window = all_tables.IndicSelectWindow(table="onereg", ownData=self.data_no_radar.data)
else:
self.nested_region_window = all_tables.IndicSelectWindow(table="onereg", ownData=self.radar_data.raw_data)
self.nested_region_window = all_tables.IndicSelectWindow(table="onereg", ownData=self.radar_data.raw_data)
self.nested_region_window.createTable()
self.nested_region_window.show()
self.nested_region_window.sendInfo.connect(partial(self.__getTeXInfo,'nested'))
self.sub_windows.append(self.nested_region_window)
def __overall(self):
if self.data_no_radar:
self.overall_window = all_tables.IndicSelectWindow(table="overall", ownData=self.data_no_radar.data)
else:
self.overall_window = all_tables.IndicSelectWindow(table="overall", ownData=self.radar_data.raw_data)
self.overall_window = all_tables.IndicSelectWindow(table="overall", ownData=self.radar_data.raw_data)
self.overall_window.createTable()
self.overall_window.show()
self.overall_window.sendInfo.connect(partial(self.__getTeXInfo,'overall'))
......@@ -219,7 +212,8 @@ class MainMenu(QtWidgets.QFrame, design_main_menu.Ui_MainMenu):
self.hide()
self.close_sub_windows()
config_window = radarGUI_analyze.TabWidget('', os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +
'/.gui_tmp_config_{}.py'.format(os.getpid()), main_menu_instance=self)
'/.gui_tmp_config_{}.py'.format(os.getpid()), main_menu_instance=self,
meric_config_path=self.meric_config_path)
config_window.show()
def __meric_opt(self):
......
......@@ -34,7 +34,7 @@ class CustomStepSpinBox(QtWidgets.QDoubleSpinBox):
self.setValue(self.value()/10)
class TabWidget(QtWidgets.QTabWidget, design_radarGUI_analyze.Ui_TabWidget):
def __init__(self, DataPath, ConfigPath, runRadar = False, main_menu_instance = None):
def __init__(self, DataPath, ConfigPath, runRadar=False, main_menu_instance=None, meric_config_path=None):
super(self.__class__, self).__init__()
self.setupUi(self)
self.current_labels_dic = {'xLabel': None, 'funcLabel': None}
......@@ -64,6 +64,7 @@ class TabWidget(QtWidgets.QTabWidget, design_radarGUI_analyze.Ui_TabWidget):
self.data_path = DataPath
self.config_path = ConfigPath
self.main_menu_instance = main_menu_instance
self.meric_config_path = meric_config_path
if self.config_path:
self.config_dic = run_path(self.config_path)
......@@ -574,7 +575,7 @@ class TabWidget(QtWidgets.QTabWidget, design_radarGUI_analyze.Ui_TabWidget):
def __save_and_run(self):
if self.__generate():
self.main_menu = main_menu_analyze.MainMenu(self.save_file_path)
self.main_menu = main_menu_analyze.MainMenu(self.save_file_path, self.meric_config_path)
if self.main_menu_instance:
self.main_menu_instance.close()
self.main_menu_instance = self.main_menu
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment