change scan nr for image in submultiimage, set level for reconstruction

This commit is contained in:
e20632
2023-05-03 15:46:48 +02:00
parent 4414202f92
commit 4f8d84c316
5 changed files with 65 additions and 36 deletions

View File

@ -26,7 +26,7 @@ class BECAdapter:
self.scan_nr = None self.scan_nr = None
self.scan_running = False self.scan_running = False
self.eaccount = "e20633" # for jeff: 20633 self.eaccount = "e20632" #change for each new beamtime
# To decide what should be plotted # To decide what should be plotted
self.monitor = monitor self.monitor = monitor
@ -131,15 +131,18 @@ class BECAdapter:
mypath = "/sls/X12SA/data/" + self.eaccount + "/Data10/analysis/" + ending_path mypath = "/sls/X12SA/data/" + self.eaccount + "/Data10/analysis/" + ending_path
recon_file = self.get_recon_file(mypath) recon_file = self.get_recon_file(mypath)
with h5py.File(mypath + '/' + recon_file, 'r') as hf: with h5py.File(mypath + '/' + recon_file, 'r') as hf:
recon_img_abs, recon_img_angle = self.get_recon_imgs(hf) recon_img_abs, recon_img_phase = self.get_recon_imgs(hf)
# PLOT # PLOT
print("max(recon_img_abs)", max(max(recon_img_abs)))
print("max(recon_img_phase)", max(max(recon_img_phase)))
print('plotting new image with scan_nr: ', self.latest_reconstructed) print('plotting new image with scan_nr: ', self.latest_reconstructed)
xlab = str(self.latest_reconstructed) xlab = str(self.latest_reconstructed)
if self.recon: if self.recon:
self.grum_client_recon_abs.new_image( "Absorption", {'image': recon_img_abs, "xlabel": xlab}) self.grum_client_recon_abs.new_image( "Absorption", {'image': recon_img_abs, "xlabel": xlab, "levels":[0.9, 1.1]})
# self.grum_client_recon_phase.new_image( f"Phase for scan_nr: {self.latest_reconstructed}", {'image': recon_img_angle, "xlabel": xlab}) #, "colormap":"CET-C1"}) # self.grum_client_recon_phase.new_image( f"Phase for scan_nr: {self.latest_reconstructed}", {'image': recon_img_angle, "xlabel": xlab}) #, "colormap":"CET-C1"})
self.grum_client_recon_phase.new_image( "Phase", {'image': recon_img_angle, "xlabel": xlab}) #, "colormap":"CET-C1"}) self.grum_client_recon_phase.new_image( "Phase", {'image': recon_img_phase, "xlabel": xlab, "levels": [-1,1]}) #, "colormap":"CET-C1"})
self.last_plotted_scan_nr = self.latest_reconstructed self.last_plotted_scan_nr = self.latest_reconstructed
time.sleep(10) time.sleep(10)
@ -162,14 +165,14 @@ class BECAdapter:
recon_object =np.array(recon_object) recon_object =np.array(recon_object)
recon_object_abs = np.abs(recon_object) recon_object_abs = np.abs(recon_object)
recon_object_angle = np.angle(recon_object) recon_object_phase = np.angle(recon_object)
recon_object_abs = np.rot90(recon_object_abs,3) recon_object_abs = np.rot90(recon_object_abs,3)
recon_object_angle = np.rot90(recon_object_angle, 3) recon_object_phase = np.rot90(recon_object_phase, 3)
recon_img_abs = recon_object_abs.tolist() recon_img_abs = recon_object_abs.tolist()
recon_img_angle = recon_object_angle.tolist() recon_img_phase = recon_object_phase.tolist()
return recon_img_abs, recon_img_angle return recon_img_abs, recon_img_phase
def update_latest_reconstructed(self): def update_latest_reconstructed(self):
mypath = '/sls/X12SA/Data10/' + self.eaccount + '/analysis/online/ptycho/gallery' mypath = '/sls/X12SA/Data10/' + self.eaccount + '/analysis/online/ptycho/gallery'

View File

@ -6,14 +6,14 @@ from .theme import pg_legend_style
class ImageDescription: class ImageDescription:
def __init__(self, name, title=None, xlabel=None, ylabel=None, image=None, colormap=None): def __init__(self, name, title=None, xlabel=None, ylabel=None, image=None, colormap=None, levels=None):
self.name = name self.name = name
self.title = title self.title = title
self.xlabel = xlabel self.xlabel = xlabel
self.ylabel = ylabel self.ylabel = ylabel
self.image = image self.image = image
self.colormap = colormap self.colormap = colormap
self.levels = levels
@property @property
def data(self): def data(self):
return np.asarray(self.image) return np.asarray(self.image)
@ -31,6 +31,9 @@ class ImageDescription:
def make_plot(self, plotwidget, style): def make_plot(self, plotwidget, style):
if self.levels:
res = plotwidget.setImage(self.data, levels = self.levels)
else:
res = plotwidget.setImage(self.data) res = plotwidget.setImage(self.data)
# plotwidget.colormap() # plotwidget.colormap()
if self.title: if self.title:

View File

@ -173,17 +173,23 @@ class MainWindow(QMainWindow):
""" """
Plot images from list Plot images from list
""" """
images = [] # images = []
i =1 # selected_items = []
# i =1
for img in image_desc_list: for img in image_desc_list:
self.new_image(img[0], img[1]) print("new image, ", img[0])
# desc = ImageDescription(img[0], **img[1]) desc = self.add_new_desc_to_list(img[0], img[1], Desc=ImageDescription) # best solution for now
# item = self.lst.get(img[0]) # this is also a neew window
# selected_items.append(item)
# self.new_image(img[0], img[1])
# desc = ImageDescription(img[0], **img[1]) #TODO: this pops up in new window, no images
# dlistitem = DictListItem(f"Phase: {i}", desc) # dlistitem = DictListItem(f"Phase: {i}", desc)
# images.append(dlistitem) # images.append(dlistitem)
# i+=1 # i+=1
# self.plot_multiple_images(images) # self.plot_multiple_images(selected_items)
# self.plot_multiple_images(images) # new window
# Signal callbacks # Signal callbacks
@ -289,10 +295,7 @@ class MainWindow(QMainWindow):
self.activate_or_make_subwin(MDISubMultiPlot, name, descs) self.activate_or_make_subwin(MDISubMultiPlot, name, descs)
def plot_multiple_images(self, images): def plot_multiple_images(self, images):
if type(images[0]) == list:
print('it is a list')
else:
print("this is imgdesc now: ", images) print("this is imgdesc now: ", images)
for i in images: for i in images:
i.timestamps.access.update() i.timestamps.access.update()

View File

@ -15,6 +15,8 @@ class MDISubImage(MDISubImageBase):
super().__init__(name, *args, **kwargs) super().__init__(name, *args, **kwargs)
self.pw = pw = pg.ImageView() self.pw = pw = pg.ImageView()
# self.pw.setLevels(1,2) # changing levels for histogram levels colors
# self.pw.getHistogramWidget().setLevels(500, 501)
self.setWidget(pw) self.setWidget(pw)
# connect to plot mouse-over event # connect to plot mouse-over event
@ -56,6 +58,8 @@ class MDISubMultiImage(MDISubImageBase):
self.pw = pw = pg.ImageView() self.pw = pw = pg.ImageView()
self.slider = QSlider(Qt.Horizontal) self.slider = QSlider(Qt.Horizontal)
self.slider.setRange(0,len(descs)-1) self.slider.setRange(0,len(descs)-1)
style = pg_plot_style()
self.layout = QGridLayout(self.central_widget) self.layout = QGridLayout(self.central_widget)
self.layout.addWidget(self.button_next,1,2) self.layout.addWidget(self.button_next,1,2)
@ -73,7 +77,6 @@ class MDISubMultiImage(MDISubImageBase):
desc = self.descriptions[0] desc = self.descriptions[0]
style = pg_plot_style()
plot = desc.make_plot(self.pw, style) plot = desc.make_plot(self.pw, style)
self.plots = {name: plot} self.plots = {name: plot}
self.image = desc.data self.image = desc.data
@ -83,12 +86,29 @@ class MDISubMultiImage(MDISubImageBase):
# self.update_timer.timeout.connect(self.update_movie) # self.update_timer.timeout.connect(self.update_movie)
def update_img_next(self): def update_img_next(self):
self.pw.setImage(self.descriptions[1].data)
self.slider.setValue(self.slider.value()+1) self.slider.setValue(self.slider.value()+1)
self.pw.setImage(self.descriptions[self.slider.value()].data)
self.set_title()
def update_img_previous(self): def update_img_previous(self):
self.pw.setImage(self.descriptions[0].data)
self.slider.setValue(self.slider.value()-1) self.slider.setValue(self.slider.value()-1)
self.pw.setImage(self.descriptions[self.slider.value()].data)
self.set_title()
def update_img(self, value): def update_img(self, value):
self.pw.setImage(self.descriptions[value].data) self.pw.setImage(self.descriptions[value].data)
self.set_title()
def set_title(self):
print("setting title")
vbox = self.pw.getView()
allchildren = vbox.allChildren()
for child in allchildren:
if isinstance(child, pg.LabelItem):
vbox.removeItem(child)
vbox.addItem(pg.LabelItem(self.descriptions[self.slider.value()].xlabel, size='50pt'))
print("changed title")

View File

@ -9,7 +9,7 @@ class plotPhases:
self.start = start self.start = start
self.end = end self.end = end
self.step =step self.step =step
self.eaccount = "e20633" # for jeff: 20633 self.eaccount = "e20632" # for jeff: 20633
self.grum_client = RPCClient("localhost", 8000) # this is outgoing self.grum_client = RPCClient("localhost", 8000) # this is outgoing
self.image_description_list = [] self.image_description_list = []
@ -25,7 +25,7 @@ class plotPhases:
recon_img_phase = self.get_recon_phase(hf) recon_img_phase = self.get_recon_phase(hf)
xlab = str(scan_nr) xlab = str(scan_nr)
self.image_description_list.append([f"Phase: {scan_nr}", {'image': recon_img_phase, "xlabel": xlab}]) self.image_description_list.append([f"{scan_nr} Phase", {'image': recon_img_phase, "xlabel": xlab}])
print("calling plot images from list") print("calling plot images from list")
self.grum_client.plot_images_from_list(self.image_description_list) self.grum_client.plot_images_from_list(self.image_description_list)