# Path: condor/utils/log.py
# def log(logger, message, lvl, exception=None, rollback=1):
# def log_execution_time(logger):
#     def st_time(func):
#         def st_func(*args, **keyArgs):
# 
# Path: condor/utils/pixelmask.py
# class PixelMask:
#     """
#     CXI bitmasks follow the formalism described in Maia (2012) [#Maia2012]_ (see also `www.cxidb.org <http://www.cxidb.org>`_) and encode the status of detector pixels. In *Condor* these bitmasks are represented by arrays of unsigned 16 bit integer values. 
# 
#     The status of a pixel is a combination of pixel properties represented by the bits of the bitmask value. A pixel with no bit set (all bits are 0) represents an \"perfect\" pixel. No property is set.
#     
#     ``PIXEL_IS_PERFECT`` = 0
#     
#     Each bit that is set to 1 indicates that the respective property is assigned to that pixel.
# 
#     **Bit code:**
# 
#     ========================================  ============  =============================
#     Name                                      Bit position  Bit in integer representation 
#     ========================================  ============  =============================
#     ``PIXEL_IS_INVALID``                      0th           0            
#     ``PIXEL_IS_SATURATED``                    1st           2            
#     ``PIXEL_IS_HOT``                          2nd           4            
#     ``PIXEL_IS_DEAD``                         3rd           8 
#     ``PIXEL_IS_SHADOWED``                     4th           16
#     ``PIXEL_IS_IN_PEAKMASK``                  5th           32
#     ``PIXEL_IS_TO_BE_IGNORED``                6th           64
#     ``PIXEL_IS_BAD``                          7th           128
#     ``PIXEL_IS_OUT_OF_RESOLUTION_LIMITS``     8th           256
#     ``PIXEL_IS_MISSING``                      9th           512
#     ``PIXEL_IS_NOISY``                        10th          1024
#     ``PIXEL_IS_ARTIFACT_CORRECTED``           11th          2048
#     ``PIXEL_FAILED_ARTIFACT_CORRECTION``      12th          4096
#     ``PIXEL_IS_PEAK_FOR_HITFINDER``           13th          8192
#     ``PIXEL_IS_PHOTON_BACKGROUND_CORRECTED``  14th          16384
#     (not used)                                15th          32768
#     ========================================  ============  =============================
# 
#     .. [#Maia2012] Filipe R. N. C. Maia, The Coherent X-ray Imaging Data Bank, Nature Methods 9, 854-855 (2012) `doi:10.1038/nmeth.2110 <http://dx.doi.org/doi:10.1038/nmeth.2110>`_.
# 
# 
#     """
#     # CXI pixelmask bits
#     PIXEL_IS_PERFECT = 0
#     PIXEL_IS_INVALID = 1
#     PIXEL_IS_SATURATED = 2
#     PIXEL_IS_HOT = 4
#     PIXEL_IS_DEAD = 8
#     PIXEL_IS_SHADOWED = 16
#     PIXEL_IS_IN_PEAKMASK = 32
#     PIXEL_IS_TO_BE_IGNORED = 64
#     PIXEL_IS_BAD = 128
#     PIXEL_IS_OUT_OF_RESOLUTION_LIMITS = 256
#     PIXEL_IS_MISSING = 512
#     PIXEL_IS_NOISY = 1024
#     PIXEL_IS_ARTIFACT_CORRECTED = 2048
#     PIXEL_FAILED_ARTIFACT_CORRECTION = 4096
#     PIXEL_IS_PEAK_FOR_HITFINDER = 8192
#     PIXEL_IS_PHOTON_BACKGROUND_CORRECTED = 16384
#     # Cummulative bit options
#     PIXEL_IS_IN_MASK = PIXEL_IS_INVALID |  PIXEL_IS_SATURATED | PIXEL_IS_HOT | PIXEL_IS_DEAD | PIXEL_IS_SHADOWED | PIXEL_IS_IN_PEAKMASK | PIXEL_IS_TO_BE_IGNORED | PIXEL_IS_BAD | PIXEL_IS_MISSING
# 
# Path: condor/utils/linalg.py
# def length(v):
#     return numpy.sqrt(dotproduct(v, v))


import sys,os
import numpy
import logging
import condor.utils.log
import condor.utils.resample
import condor.utils.testing
import condor.utils.scattering_vector
                import h5py
            import h5py
    from collections.abc import Iterable ## Python >= 3.3
    from collections import Iterable  ## Python < 3.3
from condor.utils.log import log_and_raise_error,log_warning,log_info,log_debug
from condor.utils.variation import Variation
from condor.utils.pixelmask import PixelMask
from condor.utils.linalg import length
        # Mask out pixels in hole    
        if hole_diameter_in_pixel > 0:
            if cx_hole is None:
                cx_hole = (self._nx-1)/2.
            if cy_hole is None:
                cy_hole = (self._ny-1)/2.
            Y,X = numpy.indices((self._ny,self._nx), dtype=numpy.float64)
            X = X-cx_hole
            Y = Y-cy_hole
            R = numpy.sqrt(X**2 + Y**2)
            tmp = R<=hole_diameter_in_pixel/2.0
            if tmp.sum() > 0:
                self._mask[tmp] |= PixelMask.PIXEL_IS_MISSING

    def get_mask(self,intensities=None, boolmask=False):
        """
        Return mask. The mask has information about the status of each individual detector pixel. The output can be either a CXI bitmask (default) or a boolean mask
    
        For further information and the full bitcode go to :class:`condor.utils.pixelmask.PixelMask`
       
        Kwargs:
          :intensities: Numpy array of photon intensities for masking saturated pixels (default ``None``)

          :boolmask (bool): If ``True`` the output will be a boolean array. Mask values are converted to ``True`` if no bit is set and to ``False`` otherwise
        """
        if intensities is not None:
            if not condor.utils.testing.same_shape(intensities, self._mask):
                log_and_raise_error(logger, "Intensities and mask do not have the same shape")
        M = self._mask.copy()
        if self.saturation_level is not None and intensities is not None:

# Path: condor/utils/log.py
# def log(logger, message, lvl, exception=None, rollback=1):
# def log_execution_time(logger):
#     def st_time(func):
#         def st_func(*args, **keyArgs):
# 
# Path: condor/utils/pixelmask.py
# class PixelMask:
#     """
#     CXI bitmasks follow the formalism described in Maia (2012) [#Maia2012]_ (see also `www.cxidb.org <http://www.cxidb.org>`_) and encode the status of detector pixels. In *Condor* these bitmasks are represented by arrays of unsigned 16 bit integer values. 
# 
#     The status of a pixel is a combination of pixel properties represented by the bits of the bitmask value. A pixel with no bit set (all bits are 0) represents an \"perfect\" pixel. No property is set.
#     
#     ``PIXEL_IS_PERFECT`` = 0
#     
#     Each bit that is set to 1 indicates that the respective property is assigned to that pixel.
# 
#     **Bit code:**
# 
#     ========================================  ============  =============================
#     Name                                      Bit position  Bit in integer representation 
#     ========================================  ============  =============================
#     ``PIXEL_IS_INVALID``                      0th           0            
#     ``PIXEL_IS_SATURATED``                    1st           2            
#     ``PIXEL_IS_HOT``                          2nd           4            
#     ``PIXEL_IS_DEAD``                         3rd           8 
#     ``PIXEL_IS_SHADOWED``                     4th           16
#     ``PIXEL_IS_IN_PEAKMASK``                  5th           32
#     ``PIXEL_IS_TO_BE_IGNORED``                6th           64
#     ``PIXEL_IS_BAD``                          7th           128
#     ``PIXEL_IS_OUT_OF_RESOLUTION_LIMITS``     8th           256
#     ``PIXEL_IS_MISSING``                      9th           512
#     ``PIXEL_IS_NOISY``                        10th          1024
#     ``PIXEL_IS_ARTIFACT_CORRECTED``           11th          2048
#     ``PIXEL_FAILED_ARTIFACT_CORRECTION``      12th          4096
#     ``PIXEL_IS_PEAK_FOR_HITFINDER``           13th          8192
#     ``PIXEL_IS_PHOTON_BACKGROUND_CORRECTED``  14th          16384
#     (not used)                                15th          32768
#     ========================================  ============  =============================
# 
#     .. [#Maia2012] Filipe R. N. C. Maia, The Coherent X-ray Imaging Data Bank, Nature Methods 9, 854-855 (2012) `doi:10.1038/nmeth.2110 <http://dx.doi.org/doi:10.1038/nmeth.2110>`_.
# 
# 
#     """
#     # CXI pixelmask bits
#     PIXEL_IS_PERFECT = 0
#     PIXEL_IS_INVALID = 1
#     PIXEL_IS_SATURATED = 2
#     PIXEL_IS_HOT = 4
#     PIXEL_IS_DEAD = 8
#     PIXEL_IS_SHADOWED = 16
#     PIXEL_IS_IN_PEAKMASK = 32
#     PIXEL_IS_TO_BE_IGNORED = 64
#     PIXEL_IS_BAD = 128
#     PIXEL_IS_OUT_OF_RESOLUTION_LIMITS = 256
#     PIXEL_IS_MISSING = 512
#     PIXEL_IS_NOISY = 1024
#     PIXEL_IS_ARTIFACT_CORRECTED = 2048
#     PIXEL_FAILED_ARTIFACT_CORRECTION = 4096
#     PIXEL_IS_PEAK_FOR_HITFINDER = 8192
#     PIXEL_IS_PHOTON_BACKGROUND_CORRECTED = 16384
#     # Cummulative bit options
#     PIXEL_IS_IN_MASK = PIXEL_IS_INVALID |  PIXEL_IS_SATURATED | PIXEL_IS_HOT | PIXEL_IS_DEAD | PIXEL_IS_SHADOWED | PIXEL_IS_IN_PEAKMASK | PIXEL_IS_TO_BE_IGNORED | PIXEL_IS_BAD | PIXEL_IS_MISSING
# 
# Path: condor/utils/linalg.py
# def length(v):
#     return numpy.sqrt(dotproduct(v, v))


# Path: condor/detector.py
import sys,os
import numpy
import logging
import condor.utils.log
import condor.utils.resample
import condor.utils.testing
import condor.utils.scattering_vector
                import h5py
            import h5py
    from collections.abc import Iterable ## Python >= 3.3
    from collections import Iterable  ## Python < 3.3
from condor.utils.log import log_and_raise_error,log_warning,log_info,log_debug
from condor.utils.variation import Variation
from condor.utils.pixelmask import PixelMask
from condor.utils.linalg import length

        # Mask out pixels in hole    
        if hole_diameter_in_pixel > 0:
            if cx_hole is None:
                cx_hole = (self._nx-1)/2.
            if cy_hole is None:
                cy_hole = (self._ny-1)/2.
            Y,X = numpy.indices((self._ny,self._nx), dtype=numpy.float64)
            X = X-cx_hole
            Y = Y-cy_hole
            R = numpy.sqrt(X**2 + Y**2)
            tmp = R<=hole_diameter_in_pixel/2.0
            if tmp.sum() > 0:
                self._mask[tmp] |= PixelMask.PIXEL_IS_MISSING

    def get_mask(self,intensities=None, boolmask=False):
        """
        Return mask. The mask has information about the status of each individual detector pixel. The output can be either a CXI bitmask (default) or a boolean mask
    
        For further information and the full bitcode go to :class:`condor.utils.pixelmask.PixelMask`
       
        Kwargs:
          :intensities: Numpy array of photon intensities for masking saturated pixels (default ``None``)

          :boolmask (bool): If ``True`` the output will be a boolean array. Mask values are converted to ``True`` if no bit is set and to ``False`` otherwise
        """
        if intensities is not None:
            if not condor.utils.testing.same_shape(intensities, self._mask):
                log_and_raise_error(logger, "Intensities and mask do not have the same shape")
        M = self._mask.copy()
        if self.saturation_level is not None and intensities is not None:

            M[intensities >= self.saturation_level] |= PixelMask.PIXEL_IS_SATURATED