From d7a1ea82c98b166d07f117a6bb4a9f03fff300d5 Mon Sep 17 00:00:00 2001 From: gnzng Date: Tue, 17 Jun 2025 15:50:51 -0700 Subject: [PATCH] adjusted warn msg based on Daynes suggestion --- src/cdtools/datasets/ptycho_2d_dataset.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cdtools/datasets/ptycho_2d_dataset.py b/src/cdtools/datasets/ptycho_2d_dataset.py index c653a25..3825d6d 100644 --- a/src/cdtools/datasets/ptycho_2d_dataset.py +++ b/src/cdtools/datasets/ptycho_2d_dataset.py @@ -125,9 +125,9 @@ class Ptycho2DDataset(CDataset): self.translations = self.translations.to(*args, **kwargs) self.patterns = self.patterns.to(*args, **kwargs) - # It sucks that I can't reuse the base factory method here, # perhaps there is a way but I couldn't figure it out. + @classmethod def from_cxi(cls, cxi_file, cut_zeros=True, load_patterns=True): """Generates a new Ptycho2DDataset from a .cxi file directly @@ -149,7 +149,7 @@ class Ptycho2DDataset(CDataset): """ # If a bare string is passed if isinstance(cxi_file, str) or isinstance(cxi_file, pathlib.Path): - with h5py.File(cxi_file,'r') as f: + with h5py.File(cxi_file, 'r') as f: return cls.from_cxi(f, cut_zeros=cut_zeros, load_patterns=load_patterns) # Generate a base dataset @@ -168,7 +168,10 @@ class Ptycho2DDataset(CDataset): # If the data is 64-bit, we need to convert it to 32-bit # because 64-bit floats are not supported in reconstructions dataset.patterns = dataset.patterns.to(dtype=t.float32) - warnings.warn('64-bit floats are not supported and precision will not be retained in reconstructions and were converted to t.float32! Please explicitly convert your data to 32-bit or submit a pull request') + warnings.warn( + "64-bit floats are not supported and precision will not be retained in reconstructions and were converted to t.float32! " + "If you would like to have 64-bit support, please open an issue or submit a pull request." + ) dataset.axes = axes if dataset.mask is None: @@ -179,9 +182,8 @@ class Ptycho2DDataset(CDataset): dataset.intensities = t.as_tensor(intensities, dtype=t.float32) except KeyError: dataset.intensities = None - - return dataset + return dataset def to_cxi(self, cxi_file): """Saves out a Ptycho2DDataset as a .cxi file