Commit 134bef39 authored by Félix Hartmann's avatar Félix Hartmann
Browse files

The steady state is now saved in the hdf5 file.

parent 10e41d78
......@@ -490,6 +490,12 @@ def load_hdf5_file(hdf5file):
if dtphoto == []:
interekt.get_photo_datetime.set(False)
# Retrieve the data on the steady state from the h5 file
steady_state, exclude_steady_state = h5store.get_steady_state(hdf5file)
print("Steady state: ", steady_state, exclude_steady_state)
interekt.steady_state_image = steady_state
interekt.exclude_steady_state_from_time_series.set(exclude_steady_state)
######################### HANDLING OF THE IMAGE LIST ##########################
......@@ -3487,33 +3493,14 @@ def detection_step_setting():
step_frame.pack()
def onSelectSteadyStateImage(event):
"""Called when an image has been selected from the list as the steady-state image."""
sender = event.widget
try:
idx = sender.curselection()[0]
except:
idx = sender.curselection()
print(idx)
if idx == interekt.steady_state_image:
sender.selection_clear(idx)
interekt.steady_state_image = None
else:
interekt.steady_state_image = idx
try:
interekt.plot_image(interekt.steady_state_image, keep_zoom=True)
except Exception as e:
print("Image loading error!!!")
print(e)
def select_steady_state_image():
"""Top window for selecting the steady-state image.
The steady-state image is selected from the image liste.
In addition, there is a checkbox for removing this image from times series, which can
be useful when the steady-state image has been taken a long time after other images.
In addition, there is a checkbox for removing this image from times
series, which can be useful when the steady-state image has been taken
a long time after other images.
"""
# Create Tkinter top window
top_steadystate = Tk.Toplevel(master=root)
......@@ -3535,7 +3522,7 @@ def select_steady_state_image():
listb.see(interekt.steady_state_image)
# Function to call when an image has been selected
listb.bind("<<ListboxSelect>>", onSelectSteadyStateImage)
listb.bind("<<ListboxSelect>>", on_select_steady_state_image)
listb.pack(side=Tk.LEFT, fill=Tk.BOTH, expand=1)
list_frame.pack(fill=Tk.BOTH, expand=1)
......@@ -3552,6 +3539,43 @@ def select_steady_state_image():
rm_from_time_series_checkbox.pack()
check_frame.pack(fill=Tk.X, side=Tk.BOTTOM)
Tk.Button(check_frame, text=_("Save"),
command=save_steady_state).pack(fill=Tk.X, side=Tk.BOTTOM, expand=True)
def on_select_steady_state_image(event):
"""Called when an image has been selected from the list as the
steady-state image."""
sender = event.widget
try:
idx = sender.curselection()[0]
except:
idx = sender.curselection()
if idx == interekt.steady_state_image:
sender.selection_clear(idx)
interekt.steady_state_image = None
else:
interekt.steady_state_image = idx
try:
interekt.plot_image(interekt.steady_state_image, keep_zoom=True)
except Exception as e:
print("Image loading error!!!")
print(e)
def save_steady_state():
"""Save the selected steady-state image in the h5 file.
Save also whether the steady-state image has to be excluded from
time series.
"""
print("Save ss image ", interekt.steady_state_image, \
interekt.exclude_steady_state_from_time_series)
h5store.save_steady_state(
hdf5file,
interekt.steady_state_image,
interekt.exclude_steady_state_from_time_series)
def find_dict_subkeys(input_dict):
""""Find keys of a dictionary nested in another dictionary.
......
......@@ -602,6 +602,44 @@ def get_pixelscale(hdf5file):
return scaleout
def save_steady_state(hdf5file, steady_state, exclude_steady_state_from_time_series):
"""
Save the steady state image, and whether it should be excluded from time series.
"""
if steady_state is None:
steady_state_good = None
else:
steady_state_good = int(steady_state)
if exclude_steady_state_from_time_series is None:
exclude = False
else:
exclude = bool(exclude_steady_state_from_time_series)
dict_data = {'steady_state': steady_state_good, 'exclude_steady_state': exclude}
dicttoh5(treedict=dict_data, hdf5file=hdf5file, h5path='/', mode='a')
def get_steady_state(hdf5file):
"""
Return
- steady_state (int): the number of the steady state image
- exclude_steady_state (bool): whether it should be excluded from time series
"""
steady_state = None
exclude_steady_state = False
with h5py.File(hdf5file, 'r') as f:
if 'steady_state' in f:
steady_state = h5todict(hdf5file, path='steady_state')
if steady_state == {}:
steady_state = None
if 'exclude_steady_state' in f:
exclude_steady_state = h5todict(hdf5file, path='exclude_steady_state')
if exclude_steady_state == {}:
exclude_steady_state = False
return steady_state, exclude_steady_state
def save_detection_step(hdf5file, step):
"""
Fonction pour sauvegarder le pas d'espace pour la détection des squelettes.
......
Supports Markdown
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