Skip to content

Commit ece7604

Browse files
Túlio de CastroTúlio de Castro
authored andcommitted
I add a loading function for nexus files on Main.py
1 parent 9a5f4cd commit ece7604

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/mpes_tools/Main.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,38 @@ def __init__(self):
6969
self.show()
7070

7171

72+
7273
def open_file_phoibos(self):
73-
file_path, _ = QFileDialog.getOpenFileName(self, "Open Text File", "", "Text Files (*.npz)")
74-
if file_path:
75-
loaded_data = np.load(file_path)
76-
V1 = xr.DataArray(loaded_data['data_array'], dims=['Angle', 'Ekin','delay'], coords={'Angle': loaded_data['Angle'], 'Ekin': loaded_data['Ekin'],'delay': loaded_data['delay']})
74+
# ... existing code ...
75+
file_path, _ = QFileDialog.getOpenFileName(self, "Open File", "", "Data Files (*.npz *.nxs)")
76+
if file_path:
77+
if file_path.endswith('.npz'):
78+
loaded_data = np.load(file_path)
79+
V1 = xr.DataArray(loaded_data['data_array'],
80+
dims=['Angle', 'Ekin','delay'],
81+
coords={'Angle': loaded_data['Angle'],
82+
'Ekin': loaded_data['Ekin'],
83+
'delay': loaded_data['delay']})
84+
elif file_path.endswith('.nxs'):
85+
with h5py.File(file_path, 'r') as f:
86+
# Ajuste os caminhos dos dados de acordo com a estrutura do seu arquivo NeXus
87+
# Isso é um exemplo - você precisa adaptar para a estrutura específica do seu arquivo
88+
data_array = f['/entry/data/data'][:] # Ajuste o caminho conforme necessário
89+
angle = f['/entry/data/angular0'][:] # Ajuste o caminho conforme necessário
90+
energy = f['/entry/data/energy'][:] # Ajuste o caminho conforme necessário
91+
delay = f['/entry/data/delay'][:] # Ajuste o caminho conforme necessário
92+
93+
V1 = xr.DataArray(data_array,
94+
dims=['Angle', 'Ekin', 'delay'],
95+
coords={'Angle': angle,
96+
'Ekin': energy,
97+
'delay': delay})
98+
7799
axis=[V1['Angle'],V1['Ekin']-21.7,V1['delay']]
78-
# print(data.dims)
79100
graph_window= Gui_3d(V1,0,0,'Phoibos')
80-
81101
graph_window.show()
82102
self.graph_windows.append(graph_window)
83-
103+
84104
def open_file_dialoge(self):
85105
# Open file dialog to select a .h5 file
86106
file_path, _ = QFileDialog.getOpenFileName(self, "Open hdf5", "", "h5 Files (*.h5)")

0 commit comments

Comments
 (0)