From 53a71516f49e4ac9b48ce322fbb5406e6ef096b4 Mon Sep 17 00:00:00 2001 From: Benedikt Daurer Date: Thu, 23 May 2024 10:59:11 +0100 Subject: [PATCH 1/3] Only update views if strictly needed --- ptypy/core/classes.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ptypy/core/classes.py b/ptypy/core/classes.py index 622077a48..6c5c89585 100644 --- a/ptypy/core/classes.py +++ b/ptypy/core/classes.py @@ -629,6 +629,9 @@ def reformat(self, newID=None, update=True): if update: self.update() + # Keep track if we need to update views again at the end (which can be costly) + requires_update = False + # List of views on this storage views = self.views @@ -692,6 +695,7 @@ def reformat(self, newID=None, update=True): % (str(self.ID), str(self.owner.ID), _misfit_str)) if needtocrop_or_pad: + requires_update = True if self.padonly: misfit[negmisfit] = 0 @@ -729,6 +733,7 @@ def reformat(self, newID=None, update=True): # Deal with layermap if self.layermap != new_layermap: + requires_update = True relaid_data = [] for i in new_layermap: if i in self.layermap: @@ -755,6 +760,8 @@ def reformat(self, newID=None, update=True): self.data = new_data self.shape = new_shape self.center = new_center + if requires_update: + self.update() def _to_pix(self, coord): """ @@ -825,7 +832,7 @@ def center(self, v): """ self._center = u.expectN(v, self.ndim) self._origin = - self._center * self._psize - self.update() + #self.update() @property def views(self): @@ -1812,7 +1819,7 @@ def new_storage(self, ID=None, **kwargs): # Return new storage return s - def reformat(self, also_in_copies=False): + def reformat(self, also_in_copies=False, update=True): """ Reformats all storages in this container. @@ -1822,7 +1829,7 @@ def reformat(self, also_in_copies=False): If True, also reformat associated copies of this container """ for ID, s in self.storages.items(): - s.reformat() + s.reformat(update=update) if also_in_copies: for c in self.copies: c.S[ID].reformat() From 4eb943c96e0baba328047429e0f3f23540a23cb7 Mon Sep 17 00:00:00 2001 From: Benedikt Daurer Date: Thu, 23 May 2024 10:59:44 +0100 Subject: [PATCH 2/3] Moved reformat calls to outermost layer --- ptypy/core/manager.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ptypy/core/manager.py b/ptypy/core/manager.py index ec376c8ff..813c5f325 100644 --- a/ptypy/core/manager.py +++ b/ptypy/core/manager.py @@ -1673,12 +1673,13 @@ def new_data(self): # Attempt to get new data new_data = [] + prb_ids, obj_ids, pod_ids = dict(), dict(), set() for label, scan in self.scans.items(): if not scan.data_available: continue else: ilog_streamer('%s: loading data for scan %s' %(type(scan).__name__,label)) - prb_ids, obj_ids, pod_ids = dict(), dict(), set() + nd = scan.new_data(_nframes) while nd: new_data.append((label, nd[0])) @@ -1690,16 +1691,16 @@ def new_data(self): nd = scan.new_data(_nframes) ilog_newline() - # Reformatting - ilog_message('%s: loading data for scan %s (reformatting probe/obj/exit)' %(type(scan).__name__,label)) - self.ptycho.probe.reformat(True) - self.ptycho.obj.reformat(True) - self.ptycho.exit.reformat(True) - - # Initialize probe/object/exit - ilog_message('%s: loading data for scan %s (initializing probe/obj/exit)' %(type(scan).__name__,label)) - scan._initialize_probe(prb_ids) - scan._initialize_object(obj_ids) - scan._initialize_exit(list(pod_ids)) + # Reformatting + ilog_message('Reformatting probe/obj/exit)') + self.ptycho.probe.reformat(True, update=False) + self.ptycho.obj.reformat(True, update=False) + self.ptycho.exit.reformat(True, update=False) + + # Initialize probe/object/exit + ilog_message('%Initializing probe/obj/exit)') + scan._initialize_probe(prb_ids) + scan._initialize_object(obj_ids) + scan._initialize_exit(list(pod_ids)) return new_data From 1a3b1a87988a3c80ff0846b0cf84fa8c99951e2e Mon Sep 17 00:00:00 2001 From: Benedikt Daurer Date: Tue, 28 May 2024 16:06:00 +0100 Subject: [PATCH 3/3] not updating views at the start of reformat broke the bragg scan test --- ptypy/core/manager.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ptypy/core/manager.py b/ptypy/core/manager.py index 813c5f325..272862179 100644 --- a/ptypy/core/manager.py +++ b/ptypy/core/manager.py @@ -1693,9 +1693,9 @@ def new_data(self): # Reformatting ilog_message('Reformatting probe/obj/exit)') - self.ptycho.probe.reformat(True, update=False) - self.ptycho.obj.reformat(True, update=False) - self.ptycho.exit.reformat(True, update=False) + self.ptycho.probe.reformat(True, update=True) + self.ptycho.obj.reformat(True, update=True) + self.ptycho.exit.reformat(True, update=True) # Initialize probe/object/exit ilog_message('%Initializing probe/obj/exit)')