diff --git a/format/FormatBruker.py b/format/FormatBruker.py index 4fd5ffc09..5e1f2a18b 100644 --- a/format/FormatBruker.py +++ b/format/FormatBruker.py @@ -2,6 +2,7 @@ from builtins import range from dxtbx.format.Format import Format +from dxtbx import IncorrectFormatError class FormatBruker(Format): @@ -92,12 +93,9 @@ def understand(image_file): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) - - Format.__init__(self, image_file, **kwargs) + super(FormatBruker, self).__init__(str(image_file), **kwargs) def detectorbase_start(self): pass diff --git a/format/FormatBrukerFixedChi.py b/format/FormatBrukerFixedChi.py index 98d0e93e9..c5b712167 100644 --- a/format/FormatBrukerFixedChi.py +++ b/format/FormatBrukerFixedChi.py @@ -26,18 +26,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment. Easy from Rigaku Saturn images as - they contain everything pretty much we need...""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - self._image_file = image_file - FormatBruker.__init__(self, image_file, **kwargs) - def _start(self): self.header_dict = {} header_text = open(self._image_file).read().split("......")[0] diff --git a/format/FormatBrukerPhotonII.py b/format/FormatBrukerPhotonII.py index d3dfad875..a7d40b7c2 100644 --- a/format/FormatBrukerPhotonII.py +++ b/format/FormatBrukerPhotonII.py @@ -46,17 +46,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment. Easy from Rigaku Saturn images as - they contain everything pretty much we need...""" - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - self._image_file = image_file - FormatBruker.__init__(self, image_file, **kwargs) - def _start(self): try: diff --git a/format/FormatCBF.py b/format/FormatCBF.py index fa00307b5..43e1710fa 100644 --- a/format/FormatCBF.py +++ b/format/FormatCBF.py @@ -12,6 +12,7 @@ import six from dxtbx.format.Format import Format +from dxtbx import IncorrectFormatError class FormatCBF(Format): @@ -58,12 +59,10 @@ def get_cbf_header(image_file): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) - Format.__init__(self, image_file, **kwargs) + super(FormatCBF, self).__init__(str(image_file), **kwargs) @staticmethod def _parse_cbf_header(cbf_header): @@ -97,8 +96,6 @@ def _start(self): """Open the image file, read the image header, copy it into memory for future inspection.""" - Format._start(self) - self._cif_header = FormatCBF.get_cbf_header(self._image_file) self._mime_header = "" diff --git a/format/FormatCBFFull.py b/format/FormatCBFFull.py index eb0bfdc6b..f1f247a64 100644 --- a/format/FormatCBFFull.py +++ b/format/FormatCBFFull.py @@ -36,24 +36,12 @@ def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" # It appears Pycbf can not handle unicode filenames (see dials/dials#256) - image_file = str(image_file) - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBF.__init__(self, image_file, **kwargs) self._raw_data = None + super(FormatCBFFull, self).__init__(str(image_file), **kwargs) def __del__(self): self._cbf_handle.__swig_destroy__(self._cbf_handle) - def _start(self): - """Open the image file as a cbf file handle, and keep this somewhere - safe.""" - - FormatCBF._start(self) - def _get_cbf_handle(self): try: return self._cbf_handle diff --git a/format/FormatCBFFullPilatus.py b/format/FormatCBFFullPilatus.py index ec3f9ba0e..662665d64 100644 --- a/format/FormatCBFFullPilatus.py +++ b/format/FormatCBFFullPilatus.py @@ -32,24 +32,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFFull.__init__(self, image_file, **kwargs) - - self._raw_data = None - - def _start(self): - """Open the image file as a cbf file handle, and keep this somewhere - safe.""" - - FormatCBFFull._start(self) - def _beam(self): """Return a working beam instance. Override polarization to be 0.999.""" diff --git a/format/FormatCBFFullPilatusDLS300KSN104.py b/format/FormatCBFFullPilatusDLS300KSN104.py index 853170a67..9ceb841ff 100644 --- a/format/FormatCBFFullPilatusDLS300KSN104.py +++ b/format/FormatCBFFullPilatusDLS300KSN104.py @@ -49,11 +49,8 @@ def has_dynamic_shadowing(**kwargs): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - - assert self.understand(image_file) - self._dynamic_shadowing = self.has_dynamic_shadowing(**kwargs) - FormatCBFFullPilatus.__init__(self, image_file, **kwargs) + super(FormatCBFFullPilatusDLS300KSN104, self).__init__(image_file, **kwargs) def get_mask(self, goniometer=None): mask = super(FormatCBFFullPilatusDLS300KSN104, self).get_mask() diff --git a/format/FormatCBFFullPilatusDLS6MSN100.py b/format/FormatCBFFullPilatusDLS6MSN100.py index 66246122e..01209286b 100644 --- a/format/FormatCBFFullPilatusDLS6MSN100.py +++ b/format/FormatCBFFullPilatusDLS6MSN100.py @@ -43,13 +43,9 @@ def has_dynamic_shadowing(**kwargs): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) self._dynamic_shadowing = self.has_dynamic_shadowing(**kwargs) - FormatCBFFullPilatus.__init__(self, image_file, **kwargs) + super(FormatCBFFullPilatusDLS6MSN100, self).__init__(image_file, **kwargs) def get_mask(self, goniometer=None): mask = super(FormatCBFFullPilatusDLS6MSN100, self).get_mask() diff --git a/format/FormatCBFFullPilatusDLS6MSN126.py b/format/FormatCBFFullPilatusDLS6MSN126.py index e630b486e..ede5f20a4 100644 --- a/format/FormatCBFFullPilatusDLS6MSN126.py +++ b/format/FormatCBFFullPilatusDLS6MSN126.py @@ -48,13 +48,9 @@ def has_dynamic_shadowing(**kwargs): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) self._dynamic_shadowing = self.has_dynamic_shadowing(**kwargs) - FormatCBFFullPilatus.__init__(self, image_file, **kwargs) + super(FormatCBFFullPilatusDLS6MSN126, self).__init__(image_file, **kwargs) def get_mask(self, goniometer=None): mask = super(FormatCBFFullPilatusDLS6MSN126, self).get_mask() diff --git a/format/FormatCBFMini.py b/format/FormatCBFMini.py index a921fbbc3..e27ff4eb5 100644 --- a/format/FormatCBFMini.py +++ b/format/FormatCBFMini.py @@ -62,21 +62,14 @@ def one_of_these_in(record): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBF.__init__(self, image_file, **kwargs) - self._raw_data = None + super(FormatCBFMini, self).__init__(image_file, **kwargs) def _start(self): """Open the image file, read the image header, copy it into a dictionary for future reference.""" - FormatCBF._start(self) - + super(FormatCBFMini, self)._start() cif_header = FormatCBF.get_cbf_header(self._image_file) self._cif_header_dictionary = {} diff --git a/format/FormatCBFMiniADSCHF4M.py b/format/FormatCBFMiniADSCHF4M.py index 4db0372ee..06e050234 100644 --- a/format/FormatCBFMiniADSCHF4M.py +++ b/format/FormatCBFMiniADSCHF4M.py @@ -51,22 +51,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMini.__init__(self, image_file, **kwargs) - - self._raw_data = None - - def _start(self): - FormatCBFMini._start(self) - def _detector(self): """Return a model for a simple detector, presuming no one has one of these on a two-theta stage. Assert that the beam centre is diff --git a/format/FormatCBFMiniEiger.py b/format/FormatCBFMiniEiger.py index ebe1b3729..d8d296a18 100644 --- a/format/FormatCBFMiniEiger.py +++ b/format/FormatCBFMiniEiger.py @@ -40,22 +40,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMini.__init__(self, image_file, **kwargs) - - self._raw_data = None - - def _start(self): - FormatCBFMini._start(self) - def _detector(self): distance = float(self._cif_header_dictionary["Detector_distance"].split()[0]) diff --git a/format/FormatCBFMiniEigerDLS16MSN160.py b/format/FormatCBFMiniEigerDLS16MSN160.py index bdf355f96..61eb3caa3 100644 --- a/format/FormatCBFMiniEigerDLS16MSN160.py +++ b/format/FormatCBFMiniEigerDLS16MSN160.py @@ -45,10 +45,6 @@ def has_dynamic_shadowing(**kwargs): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) self._dynamic_shadowing = self.has_dynamic_shadowing(**kwargs) super(FormatCBFMiniEigerDLS16MSN160, self).__init__(image_file, **kwargs) diff --git a/format/FormatCBFMiniEigerPetraP14.py b/format/FormatCBFMiniEigerPetraP14.py index 8a5f1578e..0dec9afdb 100644 --- a/format/FormatCBFMiniEigerPetraP14.py +++ b/format/FormatCBFMiniEigerPetraP14.py @@ -33,19 +33,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMiniEiger.__init__(self, image_file, **kwargs) - - self._raw_data = None - def _goniometer(self): return self._goniometer_factory.known_axis((0, 1, 0)) diff --git a/format/FormatCBFMiniEigerPhotonFactory.py b/format/FormatCBFMiniEigerPhotonFactory.py index 0ea5e16bb..df5c80722 100644 --- a/format/FormatCBFMiniEigerPhotonFactory.py +++ b/format/FormatCBFMiniEigerPhotonFactory.py @@ -37,22 +37,6 @@ def understand(image_file): return True return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMini.__init__(self, image_file, **kwargs) - - return - - def _start(self): - FormatCBFMini._start(self) - def _goniometer(self): return self._goniometer_factory.make_goniometer( (1, 0, 0), (1, 0, 0, 0, 1, 0, 0, 0, 1) diff --git a/format/FormatCBFMiniPilatus.py b/format/FormatCBFMiniPilatus.py index 9b47ca115..3d21a64aa 100644 --- a/format/FormatCBFMiniPilatus.py +++ b/format/FormatCBFMiniPilatus.py @@ -50,22 +50,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMini.__init__(self, image_file, **kwargs) - - return - - def _start(self): - FormatCBFMini._start(self) - def _detector(self): """Return a model for a simple detector, presuming no one has one of these on a two-theta stage. Assert that the beam centre is diff --git a/format/FormatCBFMiniPilatus3APS19ID6MSN132.py b/format/FormatCBFMiniPilatus3APS19ID6MSN132.py index bcb37e855..b63d19289 100644 --- a/format/FormatCBFMiniPilatus3APS19ID6MSN132.py +++ b/format/FormatCBFMiniPilatus3APS19ID6MSN132.py @@ -31,19 +31,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMiniPilatus.__init__(self, image_file, **kwargs) - - return - def _goniometer(self): """19ID has reversed goniometer""" diff --git a/format/FormatCBFMiniPilatusCHESS_6MSN127.py b/format/FormatCBFMiniPilatusCHESS_6MSN127.py index c4ee2d9b9..1501021ce 100644 --- a/format/FormatCBFMiniPilatusCHESS_6MSN127.py +++ b/format/FormatCBFMiniPilatusCHESS_6MSN127.py @@ -31,19 +31,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMiniPilatus.__init__(self, image_file, **kwargs) - - return - def _goniometer(self): """Return a model for a simple single-axis reversed direction goniometer.""" diff --git a/format/FormatCBFMiniPilatusDLS12M.py b/format/FormatCBFMiniPilatusDLS12M.py index 40d9dcd6b..762b48f92 100644 --- a/format/FormatCBFMiniPilatusDLS12M.py +++ b/format/FormatCBFMiniPilatusDLS12M.py @@ -49,20 +49,13 @@ def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file, including a proper model of the experiment.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - # if multi_panel == False, then interpret data as 24 panels, where each # row of 5 panels is grouped as one "panel" # elif multi_panel == True, then interpret data as 120 panels, # 24 rows * 5 columns self._dynamic_shadowing = self.has_dynamic_shadowing(**kwargs) self._multi_panel = kwargs.get("multi_panel", False) - FormatCBFMiniPilatus.__init__(self, image_file, **kwargs) - - self._raw_data = None + super(FormatCBFMiniPilatusDLS12M, self).__init__(image_file, **kwargs) def _detector(self): diff --git a/format/FormatCBFMiniPilatusDLS6MSN100.py b/format/FormatCBFMiniPilatusDLS6MSN100.py index 19d2c62f0..bb287f95a 100644 --- a/format/FormatCBFMiniPilatusDLS6MSN100.py +++ b/format/FormatCBFMiniPilatusDLS6MSN100.py @@ -181,16 +181,9 @@ def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file, including a proper model of the experiment.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - self._dynamic_shadowing = self.has_dynamic_shadowing(**kwargs) self._multi_panel = kwargs.get("multi_panel", False) - FormatCBFMiniPilatus.__init__(self, image_file, **kwargs) - - self._raw_data = None + super(FormatCBFMiniPilatusDLS6MSN100, self).__init__(image_file, **kwargs) def _goniometer(self): """Return a model for a simple single-axis goniometer. This should diff --git a/format/FormatCBFMiniPilatusDLS6MSN114.py b/format/FormatCBFMiniPilatusDLS6MSN114.py index 3278dfd6c..a388bff58 100644 --- a/format/FormatCBFMiniPilatusDLS6MSN114.py +++ b/format/FormatCBFMiniPilatusDLS6MSN114.py @@ -46,19 +46,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMiniPilatus.__init__(self, image_file, **kwargs) - - self._raw_data = None - def _goniometer(self): return self._goniometer_factory.known_axis((0, 1, 0)) diff --git a/format/FormatCBFMiniPilatusDLS6MSN114DMM.py b/format/FormatCBFMiniPilatusDLS6MSN114DMM.py index 9fa23cf83..0e2f6d037 100644 --- a/format/FormatCBFMiniPilatusDLS6MSN114DMM.py +++ b/format/FormatCBFMiniPilatusDLS6MSN114DMM.py @@ -41,11 +41,6 @@ def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file, including a proper model of the experiment.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - FormatCBFMiniPilatus.__init__(self, image_file, **kwargs) FormatStill.__init__(self, image_file, **kwargs) diff --git a/format/FormatCBFMiniPilatusDLS6MSN119.py b/format/FormatCBFMiniPilatusDLS6MSN119.py index f57a2e48c..001ceb036 100644 --- a/format/FormatCBFMiniPilatusDLS6MSN119.py +++ b/format/FormatCBFMiniPilatusDLS6MSN119.py @@ -46,19 +46,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMiniPilatus.__init__(self, image_file, **kwargs) - - self._raw_data = None - def _goniometer(self): """Return a model for a simple single-axis goniometer. This should probably be checked against the image header, though for miniCBF diff --git a/format/FormatCBFMiniPilatusDLS6MSN126.py b/format/FormatCBFMiniPilatusDLS6MSN126.py index 0527b047d..1d786ca99 100644 --- a/format/FormatCBFMiniPilatusDLS6MSN126.py +++ b/format/FormatCBFMiniPilatusDLS6MSN126.py @@ -169,14 +169,8 @@ def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file, including a proper model of the experiment.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - self._raw_data = None self._multi_panel = kwargs.get("multi_panel", False) - FormatCBFMiniPilatus.__init__(self, image_file, **kwargs) + super(FormatCBFMiniPilatusDLS6MSN126, self).__init__(image_file, **kwargs) def _goniometer(self): """Return a model for a simple single-axis goniometer. This should diff --git a/format/FormatCBFMiniPilatusSOLEILPX16MSN106.py b/format/FormatCBFMiniPilatusSOLEILPX16MSN106.py index 89ddd6e4d..1d5c1541c 100644 --- a/format/FormatCBFMiniPilatusSOLEILPX16MSN106.py +++ b/format/FormatCBFMiniPilatusSOLEILPX16MSN106.py @@ -36,19 +36,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMiniPilatus.__init__(self, image_file, **kwargs) - - self._raw_data = None - def _goniometer(self): """Construct a goniometer from the records in the mini CBF header.""" diff --git a/format/FormatCBFMiniPilatusSPring8_6MSN125.py b/format/FormatCBFMiniPilatusSPring8_6MSN125.py index 8024943d4..b92f5ef3c 100644 --- a/format/FormatCBFMiniPilatusSPring8_6MSN125.py +++ b/format/FormatCBFMiniPilatusSPring8_6MSN125.py @@ -38,19 +38,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMiniPilatus.__init__(self, image_file, **kwargs) - - return - def _goniometer(self): """Return a model for a simple single-axis reversed direction goniometer.""" diff --git a/format/FormatCBFMiniPilatusXXX.py b/format/FormatCBFMiniPilatusXXX.py index 10e642a2b..a36111fd5 100644 --- a/format/FormatCBFMiniPilatusXXX.py +++ b/format/FormatCBFMiniPilatusXXX.py @@ -31,17 +31,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMiniPilatus.__init__(self, image_file, **kwargs) - def _goniometer(self): """Return a model for a simple single-axis goniometer. This should probably be checked against the image header, though for miniCBF diff --git a/format/FormatCBFMultiTile.py b/format/FormatCBFMultiTile.py index 2267b7862..e5ac4b947 100644 --- a/format/FormatCBFMultiTile.py +++ b/format/FormatCBFMultiTile.py @@ -70,17 +70,6 @@ def understand(image_file): if "CBFlib Error" in str(e): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFFull.__init__(self, image_file, **kwargs) - - self._raw_data = None - def _start(self): """Open the image file as a cbf file handle, and keep this somewhere safe.""" diff --git a/format/FormatCBFMultiTileHierarchy.py b/format/FormatCBFMultiTileHierarchy.py index fca260b1f..cf1328082 100644 --- a/format/FormatCBFMultiTileHierarchy.py +++ b/format/FormatCBFMultiTileHierarchy.py @@ -46,20 +46,6 @@ def understand(image_file): raise e return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatCBFMultiTile.__init__(self, image_file, **kwargs) - - def _start(self): - """Parent class will open the image file as a cbf file handle, and keep - the handle somewhere safe.""" - FormatCBFMultiTile._start(self) - def _get_change_of_basis(self, axis_id): """Get the 4x4 homogenous coordinate matrix for a given axis. Assumes the cbf handle has been intialized diff --git a/format/FormatDIP2030b.py b/format/FormatDIP2030b.py index 4f8a00bcb..f497fa258 100644 --- a/format/FormatDIP2030b.py +++ b/format/FormatDIP2030b.py @@ -1,6 +1,7 @@ from __future__ import absolute_import, division, print_function from dxtbx.format.Format import Format +from dxtbx import IncorrectFormatError class FormatDIP2030b(Format): @@ -21,12 +22,9 @@ def understand(image_file): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) - - Format.__init__(self, image_file, **kwargs) + super(FormatDIP2030b, self).__init__(image_file, **kwargs) def detectorbase_start(self): pass diff --git a/format/FormatEDFALS733.py b/format/FormatEDFALS733.py index 3dbc89c02..85c99e0ee 100644 --- a/format/FormatEDFALS733.py +++ b/format/FormatEDFALS733.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, division, print_function from dxtbx.format.Format import Format +from dxtbx import IncorrectFormatError class FormatEDFALS733(Format): @@ -22,12 +23,10 @@ def understand(image_file): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError if not self.understand(image_file): raise IncorrectFormatError(self, image_file) - - Format.__init__(self, image_file, **kwargs) + super(FormatEDFALS733, self).__init__(image_file, **kwargs) def detectorbase_start(self): pass diff --git a/format/FormatEiger0MQDump.py b/format/FormatEiger0MQDump.py index d9acdd4b7..f543c46f7 100644 --- a/format/FormatEiger0MQDump.py +++ b/format/FormatEiger0MQDump.py @@ -14,9 +14,6 @@ class FormatEiger0MQDump(Format): - def __init__(self, image_file, **kwargs): - Format.__init__(self, image_file) - @staticmethod def understand(image_file): if os.path.exists(os.path.join(os.path.split(image_file)[0], "header")): diff --git a/format/FormatGatanDM4.py b/format/FormatGatanDM4.py index 9a669c07e..b82de09ee 100644 --- a/format/FormatGatanDM4.py +++ b/format/FormatGatanDM4.py @@ -9,6 +9,7 @@ from dxtbx.format.Format import Format from dxtbx.format.FormatMultiImage import FormatMultiImage +from dxtbx import IncorrectFormatError class FormatGatanDM4(FormatMultiImage, Format): @@ -58,8 +59,6 @@ class FormatGatanDM4(FormatMultiImage, Format): def __init__(self, image_file, **kwargs): - from dxtbx import IncorrectFormatError - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) FormatMultiImage.__init__(self, **kwargs) diff --git a/format/FormatHDF5.py b/format/FormatHDF5.py index 0c2adbf95..bdd8f7047 100644 --- a/format/FormatHDF5.py +++ b/format/FormatHDF5.py @@ -2,12 +2,11 @@ from dxtbx.format.Format import Format from dxtbx.format.FormatMultiImage import FormatMultiImage +from dxtbx import IncorrectFormatError class FormatHDF5(FormatMultiImage, Format): def __init__(self, image_file, **kwargs): - from dxtbx import IncorrectFormatError - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) FormatMultiImage.__init__(self, **kwargs) diff --git a/format/FormatHDF5Dectris.py b/format/FormatHDF5Dectris.py index 8ca6fac82..b3d59ede4 100644 --- a/format/FormatHDF5Dectris.py +++ b/format/FormatHDF5Dectris.py @@ -24,15 +24,6 @@ def understand(image_file): # # return tag == "\211HDF\r\n\032\n" - def __init__(self, image_file, **kwargs): - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatHDF5.__init__(self, image_file, **kwargs) - def _start(self): from iotbx.detectors.eiger import EIGERImage diff --git a/format/FormatHDF5EigerNearlyNexus.py b/format/FormatHDF5EigerNearlyNexus.py index 7a4f492d0..db5fe4e94 100644 --- a/format/FormatHDF5EigerNearlyNexus.py +++ b/format/FormatHDF5EigerNearlyNexus.py @@ -304,13 +304,6 @@ def create_scalar(handle, path, dtype, value): class FormatHDF5EigerNearlyNexus(FormatHDF5): - def __init__(self, image_file, **kwargs): - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - FormatHDF5.__init__(self, image_file, **kwargs) - @staticmethod def understand(image_file): try: diff --git a/format/FormatHDF5Lambda.py b/format/FormatHDF5Lambda.py index 3ea12ba2e..8642b0783 100644 --- a/format/FormatHDF5Lambda.py +++ b/format/FormatHDF5Lambda.py @@ -47,13 +47,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - FormatHDF5.__init__(self, image_file, **kwargs) - def _start(self): import h5py diff --git a/format/FormatHDF5PAL.py b/format/FormatHDF5PAL.py index 2a3b5fb0f..e69d9b54a 100644 --- a/format/FormatHDF5PAL.py +++ b/format/FormatHDF5PAL.py @@ -8,13 +8,6 @@ class FormatHDF5PAL(FormatHDF5): - def __init__(self, image_file, **kwargs): - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - FormatHDF5.__init__(self, image_file, **kwargs) - @staticmethod def understand(image_file): import h5py diff --git a/format/FormatHDF5RawData.py b/format/FormatHDF5RawData.py index 1a5769168..8d7cb1319 100644 --- a/format/FormatHDF5RawData.py +++ b/format/FormatHDF5RawData.py @@ -4,13 +4,6 @@ class FormatRawData(FormatHDF5): - def __init__(self, image_file, **kwargs): - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - FormatHDF5.__init__(self, image_file, **kwargs) - @staticmethod def understand(image_file): import h5py diff --git a/format/FormatHDF5Sacla.py b/format/FormatHDF5Sacla.py index 6d9c7af97..75a8d039c 100644 --- a/format/FormatHDF5Sacla.py +++ b/format/FormatHDF5Sacla.py @@ -27,13 +27,6 @@ def understand(image_file): understood = True return understood - def __init__(self, image_file, **kwargs): - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - FormatHDF5.__init__(self, image_file, **kwargs) - def _start(self): import h5py diff --git a/format/FormatHDF5SaclaMPCCD.py b/format/FormatHDF5SaclaMPCCD.py index 39fccfd48..da4404d66 100644 --- a/format/FormatHDF5SaclaMPCCD.py +++ b/format/FormatHDF5SaclaMPCCD.py @@ -46,14 +46,10 @@ def understand(image_file): return False def __init__(self, image_file, index=0, reconst_mode=False, **kwargs): - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) self._raw_data = None self.index = index self.image_filename = image_file - FormatHDF5.__init__(self, image_file, **kwargs) + super(FormatHDF5SaclaMPCCD, self).__init__(image_file, **kwargs) self.PIXEL_SIZE = 50 / 1000 # 50 um self.RECONST_SIZE = 2398 # compatible with DataConvert3 -reconst mode diff --git a/format/FormatHDF5SaclaRayonix.py b/format/FormatHDF5SaclaRayonix.py index e57da02e9..5186bd8ed 100644 --- a/format/FormatHDF5SaclaRayonix.py +++ b/format/FormatHDF5SaclaRayonix.py @@ -27,14 +27,10 @@ def understand(image_file): return False def __init__(self, image_file, index=0, reconst_mode=False, **kwargs): - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) self._raw_data = None self.index = index self.image_filename = image_file - FormatHDF5.__init__(self, image_file, **kwargs) + super(FormatHDF5SaclaRayonix, self).__init__(image_file, **kwargs) # This hard-coded value can be overwritten # by RAYONIX_DISTANCE diff --git a/format/FormatNexus.py b/format/FormatNexus.py index 557524c4c..8e3a29250 100644 --- a/format/FormatNexus.py +++ b/format/FormatNexus.py @@ -14,13 +14,6 @@ class FormatNexus(FormatHDF5): - def __init__(self, image_file, **kwargs): - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - FormatHDF5.__init__(self, image_file, **kwargs) - @staticmethod def understand(image_file): try: diff --git a/format/FormatNexusEigerDLS16M.py b/format/FormatNexusEigerDLS16M.py index 1a37f6b58..41d4812c4 100644 --- a/format/FormatNexusEigerDLS16M.py +++ b/format/FormatNexusEigerDLS16M.py @@ -48,10 +48,6 @@ def has_dynamic_shadowing(self, **kwargs): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) super(FormatNexusEigerDLS16M, self).__init__(image_file, **kwargs) self._dynamic_shadowing = self.has_dynamic_shadowing(**kwargs) diff --git a/format/FormatNexusExternalDataFile.py b/format/FormatNexusExternalDataFile.py index e4f9ac555..86c9095cb 100644 --- a/format/FormatNexusExternalDataFile.py +++ b/format/FormatNexusExternalDataFile.py @@ -47,13 +47,6 @@ def is_nexus_external_data_file(filename): class FormatNexusExternalDataFile(FormatHDF5): - def __init__(self, image_file, **kwargs): - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - FormatHDF5.__init__(self, image_file, **kwargs) - @staticmethod def understand(image_file): try: diff --git a/format/FormatPY.py b/format/FormatPY.py index 5fcc13e94..d3d935a4f 100644 --- a/format/FormatPY.py +++ b/format/FormatPY.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, division, print_function from dxtbx.format.Format import Format +from dxtbx import IncorrectFormatError class FormatPY(Format): @@ -24,11 +25,9 @@ def understand(image_file): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) - Format.__init__(self, image_file, **kwargs) + super(FormatPY, self).__init__(image_file, **kwargs) if __name__ == "__main__": diff --git a/format/FormatPYmultitile.py b/format/FormatPYmultitile.py index 27139b797..97d486f24 100644 --- a/format/FormatPYmultitile.py +++ b/format/FormatPYmultitile.py @@ -4,7 +4,6 @@ import six import six.moves.cPickle as pickle -from dxtbx import IncorrectFormatError from xfel.cftbx.detector.cspad_detector import CSPadDetector from dxtbx.model import Detector from calendar import timegm @@ -36,14 +35,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file.""" - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatPY.__init__(self, image_file, **kwargs) - def _start(self): # this Format class depends on stuff from detectorbase self.detectorbase_start() diff --git a/format/FormatPYunspecified.py b/format/FormatPYunspecified.py index 79c57089a..7bd800152 100644 --- a/format/FormatPYunspecified.py +++ b/format/FormatPYunspecified.py @@ -10,7 +10,6 @@ from past.builtins import basestring from iotbx.detectors.cspad_detector_formats import reverse_timestamp from iotbx.detectors.cspad_detector_formats import detector_format_version -from dxtbx import IncorrectFormatError from spotfinder.applications.xfel import cxi_phil from scitbx.array_family import flex from iotbx.detectors.npy import NpyImage @@ -39,14 +38,6 @@ def understand(image_file): return wanted_header_items.issubset(headers) - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file.""" - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatPY.__init__(self, image_file, **kwargs) - def detectorbase_start(self): pass @@ -231,8 +222,7 @@ def understand(image_file): def __init__(self, data, **kwargs): """ @param data In memory image dictionary, alredy initialized """ - FormatPYunspecified.__init__(self, data, **kwargs) - + super(FormatPYunspecifiedInMemory, self).__init__(data, **kwargs) self._image_file = copy.deepcopy(data) diff --git a/format/FormatPYunspecifiedStill.py b/format/FormatPYunspecifiedStill.py index 4599953e9..c9327ea74 100644 --- a/format/FormatPYunspecifiedStill.py +++ b/format/FormatPYunspecifiedStill.py @@ -1,7 +1,6 @@ from __future__ import absolute_import, division, print_function from future import standard_library -from dxtbx import IncorrectFormatError import sys standard_library.install_aliases() @@ -40,14 +39,6 @@ def understand(image_file): return data["OSC_RANGE"] <= 0 - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file.""" - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatPYunspecified.__init__(self, image_file, **kwargs) - class FormatPYunspecifiedStillInMemory(FormatStill, FormatPYunspecifiedInMemory): """Overrides the Format object's init method to accept an image dictionary @@ -70,8 +61,7 @@ def understand(image_file): def __init__(self, data, **kwargs): """ @param data In memory image dictionary, alredy initialized """ - FormatPYunspecifiedInMemory.__init__(self, data, **kwargs) - + super(FormatPYunspecifiedStillInMemory, self).__init__(data, **kwargs) self._image_file = copy.deepcopy(data) diff --git a/format/FormatSER.py b/format/FormatSER.py index 655dc48b4..56b026a4d 100644 --- a/format/FormatSER.py +++ b/format/FormatSER.py @@ -18,13 +18,12 @@ import dxtbx.ext from dxtbx.format.Format import Format from dxtbx.format.FormatMultiImage import FormatMultiImage +from dxtbx import IncorrectFormatError class FormatSER(FormatMultiImage, Format): def __init__(self, image_file, **kwargs): - from dxtbx import IncorrectFormatError - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) FormatMultiImage.__init__(self, **kwargs) diff --git a/format/FormatSEReBIC.py b/format/FormatSEReBIC.py index e6e8ae800..0660761cf 100644 --- a/format/FormatSEReBIC.py +++ b/format/FormatSEReBIC.py @@ -16,12 +16,6 @@ class FormatSEReBIC(FormatSER): - def __init__(self, image_file, **kwargs): - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - FormatSER.__init__(self, image_file, **kwargs) - @staticmethod def understand(image_file): diff --git a/format/FormatSMV.py b/format/FormatSMV.py index 7c710d2e8..0f559e938 100644 --- a/format/FormatSMV.py +++ b/format/FormatSMV.py @@ -13,6 +13,7 @@ from boost.python import streambuf from dxtbx.format.Format import Format +from dxtbx import IncorrectFormatError from dxtbx.ext import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex @@ -82,12 +83,9 @@ def _get_endianic_raw_data(self, size): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) - - Format.__init__(self, image_file, **kwargs) + super(FormatSMV, self).__init__(image_file, **kwargs) def _start(self): """Open the image file, read the image header, copy the key / value diff --git a/format/FormatSMVADSC.py b/format/FormatSMVADSC.py index 35ab4c718..939060739 100644 --- a/format/FormatSMVADSC.py +++ b/format/FormatSMVADSC.py @@ -59,21 +59,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMV.__init__(self, image_file, **kwargs) - - def _start(self): - - FormatSMV._start(self) - def detectorbase_start(self): if not hasattr(self, "detectorbase") or self.detectorbase is None: from iotbx.detectors import SMVImage diff --git a/format/FormatSMVADSCNoDateStamp.py b/format/FormatSMVADSCNoDateStamp.py index d79359639..3ff88c6d7 100644 --- a/format/FormatSMVADSCNoDateStamp.py +++ b/format/FormatSMVADSCNoDateStamp.py @@ -28,21 +28,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVADSC.__init__(self, image_file, **kwargs) - - def _start(self): - - FormatSMVADSC._start(self) - def _scan(self): """Return the scan information for this image, using the timestamp from the file rather than the header.""" diff --git a/format/FormatSMVADSCSN.py b/format/FormatSMVADSCSN.py index b09ecf7a3..07fcbb055 100644 --- a/format/FormatSMVADSCSN.py +++ b/format/FormatSMVADSCSN.py @@ -26,11 +26,6 @@ def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file, including a proper model of the experiment.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - # Mapping of serial numbers to models for known detectors self._sn_to_model = { 401: "Q4U", @@ -64,7 +59,7 @@ def __init__(self, image_file, **kwargs): 933: "Q315R", } - FormatSMVADSC.__init__(self, image_file, **kwargs) + super(FormatSMVADSCSN, self).__init__(image_file, **kwargs) def _adsc_module_gain(self, model=None): """Overload to look the model number up from the serial number table""" @@ -74,10 +69,6 @@ def _adsc_module_gain(self, model=None): model = self._sn_to_model.get(sn) return super(FormatSMVADSCSN, self)._adsc_module_gain(model=model) - def _start(self): - - FormatSMVADSC._start(self) - def detectorbase_start(self): from iotbx.detectors.adsc import ADSCImage diff --git a/format/FormatSMVADSCSN445.py b/format/FormatSMVADSCSN445.py index 1b519a1f0..d80d475ca 100644 --- a/format/FormatSMVADSCSN445.py +++ b/format/FormatSMVADSCSN445.py @@ -26,17 +26,6 @@ def understand(image_file): return int(header["DETECTOR_SN"]) == 445 - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVADSCSN.__init__(self, image_file, **kwargs) - def _detector(self): """Return a model for a simple detector, presuming no one has one of these on a two-theta stage. Assert that the beam centre is diff --git a/format/FormatSMVADSCSN457.py b/format/FormatSMVADSCSN457.py index c4fe17704..8f1a63c9f 100644 --- a/format/FormatSMVADSCSN457.py +++ b/format/FormatSMVADSCSN457.py @@ -26,17 +26,6 @@ def understand(image_file): return int(header["DETECTOR_SN"]) == 457 - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVADSCSN.__init__(self, image_file, **kwargs) - def _goniometer(self): """Return a model for a simple single-axis goniometer. This should probably be checked against the image header.""" diff --git a/format/FormatSMVADSCSN905.py b/format/FormatSMVADSCSN905.py index e167c7f13..7cdaed4f5 100644 --- a/format/FormatSMVADSCSN905.py +++ b/format/FormatSMVADSCSN905.py @@ -29,17 +29,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVADSCSN.__init__(self, image_file, **kwargs) - def _detector(self): """Return a model for a simple detector, presuming no one has one of these on a two-theta stage. Assert that the beam centre is diff --git a/format/FormatSMVADSCSN915.py b/format/FormatSMVADSCSN915.py index a26787ab8..5a908ea5b 100644 --- a/format/FormatSMVADSCSN915.py +++ b/format/FormatSMVADSCSN915.py @@ -27,17 +27,6 @@ def understand(image_file): return int(header["DETECTOR_SN"]) == 915 - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVADSCSN.__init__(self, image_file, **kwargs) - def get_raw_data(self): """Get the pixel intensities (i.e. read the image and return as a flex array of integers.)""" diff --git a/format/FormatSMVADSCSN920.py b/format/FormatSMVADSCSN920.py index 75011758b..6224d34e6 100644 --- a/format/FormatSMVADSCSN920.py +++ b/format/FormatSMVADSCSN920.py @@ -26,17 +26,6 @@ def understand(image_file): return int(header["DETECTOR_SN"]) == 920 - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVADSCSN.__init__(self, image_file, **kwargs) - def get_raw_data(self): """Get the pixel intensities (i.e. read the image and return as a flex array of integers.)""" diff --git a/format/FormatSMVADSCSN926.py b/format/FormatSMVADSCSN926.py index b8f9397be..9a117cd62 100644 --- a/format/FormatSMVADSCSN926.py +++ b/format/FormatSMVADSCSN926.py @@ -32,17 +32,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVADSCSN.__init__(self, image_file, **kwargs) - def _detector(self): """Return a model for a simple detector, allowing for the installation on on a two-theta stage. Assert that the beam centre is provided in diff --git a/format/FormatSMVADSCSN928.py b/format/FormatSMVADSCSN928.py index ced6cf955..1581b4ff6 100644 --- a/format/FormatSMVADSCSN928.py +++ b/format/FormatSMVADSCSN928.py @@ -23,17 +23,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVADSCSN.__init__(self, image_file, **kwargs) - def _goniometer(self): """Return a model for a simple single-axis goniometer. This should probably be checked against the image header.""" diff --git a/format/FormatSMVADSCSNAPSID19.py b/format/FormatSMVADSCSNAPSID19.py index e4471573f..4c1b93330 100644 --- a/format/FormatSMVADSCSNAPSID19.py +++ b/format/FormatSMVADSCSNAPSID19.py @@ -32,17 +32,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVADSCSN.__init__(self, image_file, **kwargs) - def _detector(self): """Return a model for a simple detector, presuming no one has one of these on a two-theta stage. Assert that the beam centre is diff --git a/format/FormatSMVADSCmlfsom.py b/format/FormatSMVADSCmlfsom.py index 7da2cb8fc..f051a1857 100644 --- a/format/FormatSMVADSCmlfsom.py +++ b/format/FormatSMVADSCmlfsom.py @@ -20,17 +20,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVADSC.__init__(self, image_file, **kwargs) - def _scan(self): """Return the scan information for this image.""" diff --git a/format/FormatSMVCMOS1.py b/format/FormatSMVCMOS1.py index a544fecac..356ac5a4a 100644 --- a/format/FormatSMVCMOS1.py +++ b/format/FormatSMVCMOS1.py @@ -74,18 +74,12 @@ def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file, including a proper model of the experiment.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMV.__init__(self, image_file, **kwargs) - + super(FormatSMVCMOS1, self).__init__(image_file, **kwargs) detector_prefixes = self._header_dictionary["DETECTOR_NAMES"].split() self._prefix = detector_prefixes[0] def _start(self): - FormatSMV._start(self) + super(FormatSMVCMOS1, self)._start() self._header_size = int(self._header_dictionary["HEADER_BYTES"]) def _goniometer(self): diff --git a/format/FormatSMVHamamatsu.py b/format/FormatSMVHamamatsu.py index c6f7f96b2..fd45ad4db 100644 --- a/format/FormatSMVHamamatsu.py +++ b/format/FormatSMVHamamatsu.py @@ -15,10 +15,6 @@ def understand(image_file): return "hamamatsu" in header["DETECTOR_NAME"].lower() - def _start(self): - - FormatSMVADSC._start(self) - def detectorbase_start(self): from iotbx.detectors.hamamatsu import HamamatsuImage diff --git a/format/FormatSMVJHSim.py b/format/FormatSMVJHSim.py index fe323f854..80028f839 100644 --- a/format/FormatSMVJHSim.py +++ b/format/FormatSMVJHSim.py @@ -39,23 +39,6 @@ def understand(image_file): else: return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMV.__init__(self, image_file, **kwargs) - - return - - def _start(self): - - FormatSMV._start(self) - def detectorbase_start(self): if not hasattr(self, "detectorbase") or self.detectorbase is None: from iotbx.detectors import SMVImage diff --git a/format/FormatSMVNOIR.py b/format/FormatSMVNOIR.py index de959e212..3fb7205bb 100644 --- a/format/FormatSMVNOIR.py +++ b/format/FormatSMVNOIR.py @@ -77,13 +77,7 @@ def __init__(self, image_file, **kwargs): proper model of the experiment. Easy from Rigaku Saturn images as they contain everything pretty much we need...""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVRigaku.__init__(self, image_file, **kwargs) - + super(FormatSMVNOIR, self).__init__(image_file, **kwargs) self.detector_class = "NOIR1" self.detector = "adsc" diff --git a/format/FormatSMVRigaku.py b/format/FormatSMVRigaku.py index 7a1290d4b..b7fd63c09 100644 --- a/format/FormatSMVRigaku.py +++ b/format/FormatSMVRigaku.py @@ -60,17 +60,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMV.__init__(self, image_file, **kwargs) - def _goniometer(self): """Overload this method to read the image file however you like so long as the result is an goniometer.""" diff --git a/format/FormatSMVRigakuA200.py b/format/FormatSMVRigakuA200.py index 79de9df4b..0652b0e9b 100644 --- a/format/FormatSMVRigakuA200.py +++ b/format/FormatSMVRigakuA200.py @@ -79,18 +79,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment. Easy from Rigaku A200 images as - they contain everything pretty much we need...""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVRigaku.__init__(self, image_file, **kwargs) - def detectorbase_start(self): from iotbx.detectors.dtrek import DTREKImage diff --git a/format/FormatSMVRigakuA200SPring8BL26B1.py b/format/FormatSMVRigakuA200SPring8BL26B1.py index 6c16db4c7..f50a6adcd 100644 --- a/format/FormatSMVRigakuA200SPring8BL26B1.py +++ b/format/FormatSMVRigakuA200SPring8BL26B1.py @@ -42,22 +42,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment. Easy from Rigaku A200 images as - they contain everything pretty much we need...""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVRigakuA200.__init__(self, image_file, **kwargs) - - def _start(self): - - FormatSMVRigakuA200._start(self) - def detectorbase_start(self): from iotbx.detectors.dtrek import DTREKImage diff --git a/format/FormatSMVRigakuEiger.py b/format/FormatSMVRigakuEiger.py index 2f2962a88..585d62d7b 100644 --- a/format/FormatSMVRigakuEiger.py +++ b/format/FormatSMVRigakuEiger.py @@ -40,17 +40,6 @@ def understand(image_file): return "Eiger" in header["%sDETECTOR_DESCRIPTION" % name] - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVRigaku.__init__(self, image_file, **kwargs) - def _goniometer(self): """Initialize the structure for the goniometer.""" diff --git a/format/FormatSMVRigakuPilatus.py b/format/FormatSMVRigakuPilatus.py index 9a48fcc02..0e8a9ff7d 100644 --- a/format/FormatSMVRigakuPilatus.py +++ b/format/FormatSMVRigakuPilatus.py @@ -36,17 +36,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVRigaku.__init__(self, image_file, **kwargs) - def _goniometer(self): """Initialize the structure for the goniometer - this will need to correctly compose the axes given in the image header. In this case diff --git a/format/FormatSMVRigakuSaturn.py b/format/FormatSMVRigakuSaturn.py index b480a8a5c..ad9da303f 100644 --- a/format/FormatSMVRigakuSaturn.py +++ b/format/FormatSMVRigakuSaturn.py @@ -78,18 +78,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment. Easy from Rigaku Saturn images as - they contain everything pretty much we need...""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVRigaku.__init__(self, image_file, **kwargs) - def detectorbase_start(self): from iotbx.detectors.saturn import SaturnImage diff --git a/format/FormatSMVRigakuSaturnNoTS.py b/format/FormatSMVRigakuSaturnNoTS.py index 6c5a6fe96..886c99917 100644 --- a/format/FormatSMVRigakuSaturnNoTS.py +++ b/format/FormatSMVRigakuSaturnNoTS.py @@ -79,18 +79,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment. Easy from Rigaku Saturn images as - they contain everything pretty much we need...""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMVRigaku.__init__(self, image_file, **kwargs) - def detectorbase_start(self): from iotbx.detectors.saturn import SaturnImage diff --git a/format/FormatSMVTimePix_SU.py b/format/FormatSMVTimePix_SU.py index 7087b90d2..deb4e1fe9 100644 --- a/format/FormatSMVTimePix_SU.py +++ b/format/FormatSMVTimePix_SU.py @@ -47,21 +47,6 @@ def understand(image_file): return True - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - - FormatSMV.__init__(self, image_file, **kwargs) - - def _start(self): - - FormatSMV._start(self) - def detectorbase_start(self): if not hasattr(self, "detectorbase") or self.detectorbase is None: from iotbx.detectors import SMVImage diff --git a/format/FormatTIFF.py b/format/FormatTIFF.py index 5e8884993..60c042ad7 100644 --- a/format/FormatTIFF.py +++ b/format/FormatTIFF.py @@ -10,6 +10,7 @@ from dxtbx.format.FormatTIFFHelpers import read_basic_tiff_header from dxtbx.format.FormatTIFFHelpers import LITTLE_ENDIAN from dxtbx.format.FormatTIFFHelpers import BIG_ENDIAN +from dxtbx import IncorrectFormatError class FormatTIFF(Format): @@ -41,12 +42,10 @@ def get_tiff_header(image_file): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - from dxtbx import IncorrectFormatError - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) - Format.__init__(self, image_file, **kwargs) + super(FormatTIFF, self).__init__(image_file, **kwargs) def _start(self): """Open the image file, read the image header, copy it into memory diff --git a/format/FormatTIFFBruker.py b/format/FormatTIFFBruker.py index 73b407543..f27533956 100644 --- a/format/FormatTIFFBruker.py +++ b/format/FormatTIFFBruker.py @@ -63,11 +63,6 @@ def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file, including a proper model of the experiment.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - width, height, depth, order, bytes = FormatTIFF.get_tiff_header(image_file) # comment block - where the detector serial number may (or may not) be stored @@ -84,13 +79,7 @@ def __init__(self, image_file, **kwargs): self._i = ">i" self._ii = ">ii" - FormatTIFF.__init__(self, image_file, **kwargs) - - return - - def _start(self): - - FormatTIFF._start(self) + super(FormatTIFFBruker, self).__init__(image_file, **kwargs) def detectorbase_start(self): from iotbx.detectors.mar import MARImage diff --git a/format/FormatTIFFRayonix.py b/format/FormatTIFFRayonix.py index 0848f488a..bb9fa9228 100644 --- a/format/FormatTIFFRayonix.py +++ b/format/FormatTIFFRayonix.py @@ -65,11 +65,6 @@ def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file, including a proper model of the experiment.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - width, height, depth, order, bytes = FormatTIFF.get_tiff_header(image_file) # comment block - where the detector serial number may (or may not) be stored @@ -86,11 +81,7 @@ def __init__(self, image_file, **kwargs): self._i = ">i" self._ii = ">ii" - FormatTIFF.__init__(self, image_file, **kwargs) - - def _start(self): - - FormatTIFF._start(self) + super(FormatTIFFRayonix, self).__init__(image_file, **kwargs) def detectorbase_start(self): from iotbx.detectors.mar import MARImage diff --git a/format/FormatTIFFRayonixESRF.py b/format/FormatTIFFRayonixESRF.py index 22fc165b3..c2c476cb8 100644 --- a/format/FormatTIFFRayonixESRF.py +++ b/format/FormatTIFFRayonixESRF.py @@ -57,18 +57,6 @@ def understand(image_file): ) # if header was in mm, disagreement should be # approximately the pixel size in mm - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - FormatTIFFRayonix.__init__(self, image_file, **kwargs) - - return - def _goniometer(self): """Return a model for goniometer corresponding to the values stored in the image header. In the first instance assume this is a single diff --git a/format/FormatTIFFRayonixSPring8.py b/format/FormatTIFFRayonixSPring8.py index c750c4813..9e3cfc902 100644 --- a/format/FormatTIFFRayonixSPring8.py +++ b/format/FormatTIFFRayonixSPring8.py @@ -77,16 +77,6 @@ def understand(image_file): return False - def __init__(self, image_file, **kwargs): - """Initialise the image structure from the given file, including a - proper model of the experiment.""" - - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - FormatTIFFRayonix.__init__(self, image_file, **kwargs) - def _detector(self): """Return a model for a simple detector, which at the moment insists that the offsets and rotations are all 0.0.""" diff --git a/format/FormatTIFFRayonixXPP.py b/format/FormatTIFFRayonixXPP.py index 0e52bc178..5eb641810 100644 --- a/format/FormatTIFFRayonixXPP.py +++ b/format/FormatTIFFRayonixXPP.py @@ -66,15 +66,10 @@ def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file, including a proper model of the experiment.""" - from dxtbx import IncorrectFormatError - - if not self.understand(image_file): - raise IncorrectFormatError(self, image_file) - from iotbx.detectors.mar import MARImage MARImage._read_header_asserts = lambda self: None - FormatTIFFRayonix.__init__(self, image_file, **kwargs) + super(FormatTIFFRayonixXPP, self).__init__(image_file, **kwargs) #################################################################### # # diff --git a/format/FormatXDS.py b/format/FormatXDS.py index a2d3a9313..edd90d6e8 100644 --- a/format/FormatXDS.py +++ b/format/FormatXDS.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function from dxtbx.format.Format import Format +from dxtbx import IncorrectFormatError class FormatXDS(Format): @@ -26,13 +27,9 @@ def understand(image_file): def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" - Format.__init__(self, image_file, **kwargs) - - from dxtbx import IncorrectFormatError - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) - return + super(FormatXDS, self).__init__(image_file, **kwargs) def _start(self): """Open the image file as a cbf file handle, and keep this somewhere diff --git a/format/FormatXTC.py b/format/FormatXTC.py index ef2e64b76..6a42c8193 100644 --- a/format/FormatXTC.py +++ b/format/FormatXTC.py @@ -4,6 +4,7 @@ from dxtbx.format.FormatStill import FormatStill from dxtbx.format.FormatMultiImage import Reader from dxtbx.format.FormatMultiImageLazy import FormatMultiImageLazy +from dxtbx import IncorrectFormatError from libtbx.phil import parse try: @@ -45,7 +46,6 @@ def nullify_format_instance(self): class FormatXTC(FormatMultiImageLazy, FormatStill, Format): def __init__(self, image_file, **kwargs): - from dxtbx import IncorrectFormatError if not self.understand(image_file): raise IncorrectFormatError(self, image_file) diff --git a/format/FormatXTCCspad.py b/format/FormatXTCCspad.py index 64cff0851..a5df65b21 100644 --- a/format/FormatXTCCspad.py +++ b/format/FormatXTCCspad.py @@ -39,8 +39,9 @@ class FormatXTCCspad(FormatXTC): def __init__(self, image_file, locator_scope=cspad_locator_scope, **kwargs): - assert self.understand(image_file) - FormatXTC.__init__(self, image_file, locator_scope=locator_scope, **kwargs) + super(FormatXTCCspad, self).__init__( + image_file, locator_scope=locator_scope, **kwargs + ) assert ( self.params.cspad.detz_offset is not None ), "Supply a detz_offset for the cspad" diff --git a/format/FormatXTCJungfrau.py b/format/FormatXTCJungfrau.py index 6ec907486..e3f2a9814 100644 --- a/format/FormatXTCJungfrau.py +++ b/format/FormatXTCJungfrau.py @@ -29,9 +29,8 @@ class FormatXTCJungfrau(FormatXTC): def __init__(self, image_file, **kwargs): - assert self.understand(image_file) - FormatXTC.__init__( - self, image_file, locator_scope=jungfrau_locator_scope, **kwargs + super(FormatXTCJungfrau, self).__init__( + image_file, locator_scope=jungfrau_locator_scope, **kwargs ) self._ds = FormatXTC._get_datasource(image_file, self.params) self._env = self._ds.env() diff --git a/format/FormatXTCMultipleDetectors.py b/format/FormatXTCMultipleDetectors.py index 3b43180dc..b1c4c710f 100644 --- a/format/FormatXTCMultipleDetectors.py +++ b/format/FormatXTCMultipleDetectors.py @@ -14,10 +14,6 @@ class FormatXTCMultipleDetectors(FormatXTCRayonix, FormatXTCCspad, FormatXTCJungfrau): def __init__(self, image_file, **kwargs): - assert self.understand(image_file) - FormatXTC.__init__( - self, image_file, locator_scope=multiple_locator_scope, **kwargs - ) self._ds = FormatXTCMultipleDetectors._get_datasource(image_file, self.params) self._env = self._ds.env() self.populate_events() diff --git a/format/FormatXTCRayonix.py b/format/FormatXTCRayonix.py index 5ba3d8492..cac23907d 100644 --- a/format/FormatXTCRayonix.py +++ b/format/FormatXTCRayonix.py @@ -24,9 +24,8 @@ class FormatXTCRayonix(FormatXTC): def __init__(self, image_file, **kwargs): import psana - assert self.understand(image_file) - FormatXTC.__init__( - self, image_file, locator_scope=rayonix_locator_scope, **kwargs + super(FormatXTCRayonix, self).__init__( + image_file, locator_scope=rayonix_locator_scope, **kwargs ) self._ds = FormatXTCRayonix._get_datasource(image_file, self.params) self._env = self._ds.env() diff --git a/newsfragments/76.misc b/newsfragments/76.misc new file mode 100644 index 000000000..51a40894c --- /dev/null +++ b/newsfragments/76.misc @@ -0,0 +1,9 @@ +Remove unnecessary `__init__` and `_start` methods from Format classes: + +- There is no need for every subclass to redefine the `__init__` method and +call its parent's `__init__` method. As well as a lot of unnecessary code +duplication, this also led to the subclass `self.understand()` method +being called once for every class in the format class hierarchy. +- There is no need for every subclass to redefine the `_start()` method and +call its parent's `_start()` method. +- Use `super()` where applicable. \ No newline at end of file