Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 7cedc9e

Browse files
author
LAKESIDE\LindaT18
committed
added pkl to h5 to flim and spec analyses
1 parent def6b76 commit 7cedc9e

4 files changed

Lines changed: 253 additions & 107 deletions

File tree

PythonGUI_apps/FLIM_analysis/FLIM_plot.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
import h5py
23
from pathlib import Path
34
import os.path
45
import pyqtgraph as pg
@@ -40,6 +41,9 @@ def __init__(self):
4041
self.ui.save_intensities_array_pushButton.clicked.connect(self.save_intensities_array)
4142
self.ui.compare_checkBox.stateChanged.connect(self.switch_compare)
4243
self.ui.intensity_sums_viewBox.roi.sigRegionChanged.connect(self.line_profile_update_plot)
44+
45+
self.ui.import_pkl_pushButton.clicked.connect(self.import_pkl_to_convert)
46+
self.ui.pkl_to_h5_pushButton.clicked.connect(self.pkl_to_h5)
4347
self.show()
4448

4549
"""Open Scan Files"""
@@ -50,6 +54,13 @@ def open_pkl_file(self):
5054
except Exception as err:
5155
print(format(err))
5256

57+
def import_pkl_to_convert(self):
58+
try:
59+
self.pkl_to_convert = QtWidgets.QFileDialog.getOpenFileName(self)
60+
self.ui.result_textBrowser.append("Done Loading - .pkl to convert")
61+
except:
62+
pass
63+
5364
def plot_intensity_sums(self):
5465
try:
5566
data = self.pkl_file
@@ -192,6 +203,32 @@ def save_intensities_array(self):
192203
except:
193204
pass
194205

206+
def pkl_to_h5(self):
207+
try:
208+
folder = os.path.dirname(self.pkl_to_convert[0])
209+
filename_ext = os.path.basename(self.pkl_to_convert[0])
210+
filename = os.path.splitext(filename_ext)[0] #get filename without extension
211+
pkl_file = pickle.load(open(self.pkl_to_convert[0], 'rb'))
212+
213+
h5_filename = folder + "/" + filename + ".h5"
214+
h5_file = h5py.File(h5_filename, "w")
215+
self.traverse_dict(pkl_file, h5_file)
216+
except Exception as err:
217+
print(format(err))
218+
219+
def traverse_dict(self, dictionary, h5_output):
220+
for key in dictionary:
221+
if type(dictionary[key]) == dict:
222+
#print_string += key + "-->"
223+
group = h5_output.create_group(key)#print(print_string)
224+
previous_dict = dictionary[key]
225+
self.traverse_dict(dictionary[key], group)
226+
else:
227+
if key == "Histogram data" or key == "Time data":
228+
h5_output.create_dataset(key, data=dictionary[key])
229+
else:
230+
h5_output.attrs[key] = dictionary[key]
231+
195232
def close_application(self):
196233
choice = QtGui.QMessageBox.question(self, 'EXIT!',
197234
"Do you want to exit the app?",

PythonGUI_apps/FLIM_analysis/flim_plot_gui.ui

Lines changed: 132 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>706</width>
9+
<width>738</width>
1010
<height>876</height>
1111
</rect>
1212
</property>
@@ -15,102 +15,147 @@
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout_2">
1717
<item row="0" column="0">
18-
<layout class="QGridLayout" name="gridLayout">
19-
<item row="0" column="0" alignment="Qt::AlignLeft">
20-
<widget class="QPushButton" name="load_scan_pushButton">
21-
<property name="text">
22-
<string>Load Scan</string>
23-
</property>
24-
</widget>
25-
</item>
26-
<item row="4" column="1">
27-
<layout class="QVBoxLayout" name="verticalLayout_2">
28-
<item alignment="Qt::AlignLeft">
29-
<widget class="QPushButton" name="plot_intensity_sums_pushButton">
30-
<property name="text">
31-
<string>Plot</string>
32-
</property>
33-
</widget>
34-
</item>
35-
<item alignment="Qt::AlignLeft">
36-
<widget class="QPushButton" name="save_intensities_array_pushButton">
37-
<property name="text">
38-
<string>Save intensities array</string>
39-
</property>
40-
</widget>
41-
</item>
42-
<item alignment="Qt::AlignLeft">
43-
<widget class="QPushButton" name="save_intensities_image_pushButton">
44-
<property name="text">
45-
<string>Save intensities image</string>
46-
</property>
47-
</widget>
18+
<widget class="QTabWidget" name="tabWidget">
19+
<property name="currentIndex">
20+
<number>0</number>
21+
</property>
22+
<widget class="QWidget" name="analysis_tab">
23+
<attribute name="title">
24+
<string>Analysis</string>
25+
</attribute>
26+
<layout class="QGridLayout" name="gridLayout_3">
27+
<item row="0" column="0">
28+
<layout class="QGridLayout" name="gridLayout">
29+
<item row="0" column="0" alignment="Qt::AlignLeft">
30+
<widget class="QPushButton" name="load_scan_pushButton">
31+
<property name="text">
32+
<string>Load Scan</string>
33+
</property>
34+
</widget>
35+
</item>
36+
<item row="4" column="1">
37+
<layout class="QVBoxLayout" name="verticalLayout_2">
38+
<item alignment="Qt::AlignLeft">
39+
<widget class="QPushButton" name="plot_intensity_sums_pushButton">
40+
<property name="text">
41+
<string>Plot</string>
42+
</property>
43+
</widget>
44+
</item>
45+
<item alignment="Qt::AlignLeft">
46+
<widget class="QPushButton" name="save_intensities_array_pushButton">
47+
<property name="text">
48+
<string>Save intensities array</string>
49+
</property>
50+
</widget>
51+
</item>
52+
<item alignment="Qt::AlignLeft">
53+
<widget class="QPushButton" name="save_intensities_image_pushButton">
54+
<property name="text">
55+
<string>Save intensities image</string>
56+
</property>
57+
</widget>
58+
</item>
59+
</layout>
60+
</item>
61+
<item row="4" column="0">
62+
<widget class="ImageView" name="intensity_sums_viewBox">
63+
<property name="minimumSize">
64+
<size>
65+
<width>500</width>
66+
<height>300</height>
67+
</size>
68+
</property>
69+
</widget>
70+
</item>
71+
<item row="3" column="0">
72+
<widget class="QLabel" name="label">
73+
<property name="font">
74+
<font>
75+
<pointsize>12</pointsize>
76+
</font>
77+
</property>
78+
<property name="text">
79+
<string>Histogram Intensity Sums</string>
80+
</property>
81+
</widget>
82+
</item>
83+
<item row="9" column="0">
84+
<widget class="QLabel" name="label_2">
85+
<property name="font">
86+
<font>
87+
<pointsize>12</pointsize>
88+
</font>
89+
</property>
90+
<property name="text">
91+
<string>Raw Histogram Data</string>
92+
</property>
93+
</widget>
94+
</item>
95+
<item row="10" column="0">
96+
<widget class="ImageView" name="raw_hist_data_viewBox">
97+
<property name="minimumSize">
98+
<size>
99+
<width>500</width>
100+
<height>300</height>
101+
</size>
102+
</property>
103+
</widget>
104+
</item>
105+
<item row="10" column="1">
106+
<layout class="QVBoxLayout" name="verticalLayout">
107+
<item alignment="Qt::AlignLeft">
108+
<widget class="QPushButton" name="plot_raw_hist_data_pushButton">
109+
<property name="text">
110+
<string>Plot</string>
111+
</property>
112+
</widget>
113+
</item>
114+
<item alignment="Qt::AlignLeft">
115+
<widget class="QCheckBox" name="compare_checkBox">
116+
<property name="text">
117+
<string>Compare ROIs</string>
118+
</property>
119+
</widget>
120+
</item>
121+
</layout>
122+
</item>
123+
</layout>
48124
</item>
49125
</layout>
50-
</item>
51-
<item row="4" column="0">
52-
<widget class="ImageView" name="intensity_sums_viewBox">
53-
<property name="minimumSize">
54-
<size>
55-
<width>500</width>
56-
<height>300</height>
57-
</size>
58-
</property>
59-
</widget>
60-
</item>
61-
<item row="3" column="0">
62-
<widget class="QLabel" name="label">
63-
<property name="font">
64-
<font>
65-
<pointsize>12</pointsize>
66-
</font>
126+
</widget>
127+
<widget class="QWidget" name="pkl_to_h5">
128+
<attribute name="title">
129+
<string>.pkl to .h5</string>
130+
</attribute>
131+
<widget class="QPushButton" name="import_pkl_pushButton">
132+
<property name="geometry">
133+
<rect>
134+
<x>20</x>
135+
<y>20</y>
136+
<width>171</width>
137+
<height>34</height>
138+
</rect>
67139
</property>
68140
<property name="text">
69-
<string>Histogram Intensity Sums</string>
141+
<string>Import .pkl file</string>
70142
</property>
71143
</widget>
72-
</item>
73-
<item row="9" column="0">
74-
<widget class="QLabel" name="label_2">
75-
<property name="font">
76-
<font>
77-
<pointsize>12</pointsize>
78-
</font>
144+
<widget class="QPushButton" name="pkl_to_h5_pushButton">
145+
<property name="geometry">
146+
<rect>
147+
<x>20</x>
148+
<y>80</y>
149+
<width>171</width>
150+
<height>34</height>
151+
</rect>
79152
</property>
80153
<property name="text">
81-
<string>Raw Histogram Data</string>
82-
</property>
83-
</widget>
84-
</item>
85-
<item row="10" column="0">
86-
<widget class="ImageView" name="raw_hist_data_viewBox">
87-
<property name="minimumSize">
88-
<size>
89-
<width>500</width>
90-
<height>300</height>
91-
</size>
154+
<string>.pkl to .h5</string>
92155
</property>
93156
</widget>
94-
</item>
95-
<item row="10" column="1">
96-
<layout class="QVBoxLayout" name="verticalLayout">
97-
<item alignment="Qt::AlignLeft">
98-
<widget class="QPushButton" name="plot_raw_hist_data_pushButton">
99-
<property name="text">
100-
<string>Plot</string>
101-
</property>
102-
</widget>
103-
</item>
104-
<item alignment="Qt::AlignLeft">
105-
<widget class="QCheckBox" name="compare_checkBox">
106-
<property name="text">
107-
<string>Compare ROIs</string>
108-
</property>
109-
</widget>
110-
</item>
111-
</layout>
112-
</item>
113-
</layout>
157+
</widget>
158+
</widget>
114159
</item>
115160
</layout>
116161
</widget>

PythonGUI_apps/Spectrum_analysis/Spectra_plot_fit.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# system imports
99
import sys
10+
import h5py
1011
from pathlib import Path
1112
import os.path
1213
import pyqtgraph as pg
@@ -79,6 +80,8 @@ def __init__(self):
7980
self.ui.data_txt_pushButton.clicked.connect(self.pkl_data_to_txt)
8081
self.ui.scan_params_txt_pushButton.clicked.connect(self.pkl_params_to_txt)
8182

83+
self.ui.pkl_to_h5_pushButton.clicked.connect(self.pkl_to_h5)
84+
8285
self.ui.tabWidget.currentChanged.connect(self.switch_overall_tab)
8386
self.ui.fitFunc_comboBox.currentTextChanged.connect(self.switch_bounds_and_guess_tab)
8487
self.ui.adjust_param_checkBox.stateChanged.connect(self.switch_adjust_param)
@@ -605,6 +608,30 @@ def pkl_params_to_txt(self):
605608

606609
self.ui.result_textBrowser.append("Scan parameters from .pkl saved as .txt")
607610

611+
def pkl_to_h5(self):
612+
folder = os.path.dirname(self.pkl_to_convert[0])
613+
filename_ext = os.path.basename(self.pkl_to_convert[0])
614+
filename = os.path.splitext(filename_ext)[0] #get filename without extension
615+
pkl_file = pickle.load(open(self.pkl_to_convert[0], 'rb'))
616+
617+
h5_filename = folder + "/" + filename + ".h5"
618+
h5_file = h5py.File(h5_filename, "w")
619+
self.traverse_dict(pkl_file, h5_file)
620+
621+
def traverse_dict(self, dictionary, h5_output):
622+
for key in dictionary:
623+
if type(dictionary[key]) == dict:
624+
#print_string += key + "-->"
625+
group = h5_output.create_group(key)#print(print_string)
626+
previous_dict = dictionary[key]
627+
self.traverse_dict(dictionary[key], group)
628+
else:
629+
if key == "Wavelengths" or key == "Intensities":
630+
h5_output.create_dataset(key, data=dictionary[key])
631+
else:
632+
h5_output.attrs[key] = dictionary[key]
633+
634+
608635
def close_application(self):
609636
choice = QtGui.QMessageBox.question(self, 'EXIT!',
610637
"Do you want to exit the app?",

0 commit comments

Comments
 (0)