From 1125a52d9fbb4ae1bdfcf1ce17439d06e2f1790d Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 4 Dec 2024 08:39:59 +0100 Subject: [PATCH 1/3] allow to use another folder (ds.analysispath=x; ds.update_paths(force=True) --- ImageD11/sinograms/dataset.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/ImageD11/sinograms/dataset.py b/ImageD11/sinograms/dataset.py index 9844fc4d..d08477af 100644 --- a/ImageD11/sinograms/dataset.py +++ b/ImageD11/sinograms/dataset.py @@ -139,15 +139,19 @@ def __init__( self._pk2d = None self._pk4d = None + self.dsfile = None if filename is not None: + self.dsfile = filename self.load(filename) - # paths for processed data - self.analysispath = analysispath + # paths for processed data + if analysispath is not None: + # Can be loaded with the dataset or supplied + self.analysispath = analysispath self.update_paths() - def update_paths(self, force=False): + def update_paths(self, force=False, verbose = False): # paths for processed data # root of analysis for this dataset for this sample: self.analysispath_default = os.path.join( @@ -161,7 +165,8 @@ def update_paths(self, force=False): ) # at the moment, set self.dsfile to be the default # if save or load is ever called, this will be replaced - self.dsfile = self.dsfile_default + if self.dsfile is None: + self.dsfile = self.dsfile_default # They should be saved / loaded with the dataset. for name, extn in [ ("pksfile", "_peaks_table.h5"), @@ -181,6 +186,11 @@ def update_paths(self, force=False): if (getattr(self, name, None) is None) or force: # Otherwise, these are the defaults. setattr(self, name, os.path.join(self.analysispath, self.dsname + extn)) + if verbose: + print('updated', getattr( self, name, None ) ) + else: + if verbose: + print('not updated', getattr( self, name, None ) ) def __repr__(self): r = [] @@ -436,6 +446,10 @@ def guess_shape(self): elif len(self.scans) > 1: s0 = len(self.scans) s1 = npts // s0 + else: + # no scans + s0 = 0 + s1 = 0 self.shape = s0, s1 if np.prod(self.shape) != npts: print("Warning: irregular scan - might be bugs in here") @@ -798,6 +812,9 @@ def check_sparse(self): def save(self, h5name=None, h5group="/"): if h5name is None: + if os.path.exists( self.dsfile ): + h5name = self.dsfile + # none supplied, so use default path h5name = self.dsfile_default # make sure parent directories exist @@ -854,9 +871,15 @@ def save(self, h5name=None, h5group="/"): self.dsfile = h5name def load(self, h5name=None, h5group="/"): + if h5name is None: - # none supplied, so use default path - h5name = self.dsfile_default + if os.path.exists( self.dsfile ): + h5name = self.dsfile + elif os.path.exists( self.dsfile_default ): + # none supplied, so use default path + h5name = self.dsfile_default + else: + raise Exception( "Filename for dataset not found") """ Recover this from a hdf5 file """ with h5py.File(h5name, "r") as hin: From 7628f1f0e581d8431ca1955f9ae18543be25de8e Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 4 Dec 2024 08:46:46 +0100 Subject: [PATCH 2/3] guessing at the logic now :-( --- ImageD11/sinograms/dataset.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ImageD11/sinograms/dataset.py b/ImageD11/sinograms/dataset.py index d08477af..7756417d 100644 --- a/ImageD11/sinograms/dataset.py +++ b/ImageD11/sinograms/dataset.py @@ -140,15 +140,16 @@ def __init__( self._pk4d = None self.dsfile = None - if filename is not None: - self.dsfile = filename - self.load(filename) # paths for processed data if analysispath is not None: # Can be loaded with the dataset or supplied self.analysispath = analysispath + if filename is not None: + self.dsfile = filename + self.load(filename) + self.update_paths() def update_paths(self, force=False, verbose = False): From 8c9d16cfac741a03b2271f932662d724600e3094 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 4 Dec 2024 08:53:47 +0100 Subject: [PATCH 3/3] Test ought to pass --- ImageD11/sinograms/dataset.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ImageD11/sinograms/dataset.py b/ImageD11/sinograms/dataset.py index 7756417d..c6927398 100644 --- a/ImageD11/sinograms/dataset.py +++ b/ImageD11/sinograms/dataset.py @@ -142,13 +142,15 @@ def __init__( self.dsfile = None # paths for processed data - if analysispath is not None: - # Can be loaded with the dataset or supplied - self.analysispath = analysispath - + self.analysispath = None # default + # Loaded if filename is not None: self.dsfile = filename self.load(filename) + # Supplied overwrites + if analysispath is not None: + # Can be loaded with the dataset + self.analysispath = analysispath self.update_paths()