Skip to content

Commit

Permalink
Merge pull request #357 from jonwright/master
Browse files Browse the repository at this point in the history
Allow to use another folder
  • Loading branch information
jonwright authored Dec 4, 2024
2 parents 1de0e7f + 8c9d16c commit 1858627
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions ImageD11/sinograms/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,22 @@ def __init__(
self._pk2d = None
self._pk4d = None

self.dsfile = None

# paths for processed data
self.analysispath = None # default
# Loaded
if filename is not None:
self.dsfile = filename
self.load(filename)
# paths for processed data

self.analysispath = analysispath
# Supplied overwrites
if analysispath is not None:
# Can be loaded with the dataset
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(
Expand All @@ -161,7 +168,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"),
Expand All @@ -181,6 +189,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 = []
Expand Down Expand Up @@ -802,6 +815,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
Expand Down Expand Up @@ -858,9 +874,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:
Expand Down

0 comments on commit 1858627

Please sign in to comment.