# 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
          :cy (float): *y*-coordinate of the center position in unit pixel
        """
        Y, X = numpy.meshgrid(numpy.float64(numpy.arange(self._ny))-cy,
                              numpy.float64(numpy.arange(self._nx))-cx,
                              indexing="ij")
        return self.get_pixel_solid_angle(X, Y)
    
    def _get_xy_max_dist(self, cx = None, cy = None, center_variation = False):
        dist_max = []
        for c,dc,n in [[(cx if cx is not None else self.get_cx_mean_value()),self._center_variation.get_spread()[0],self._nx],
                       [(cy if cy is not None else self.get_cy_mean_value()),self._center_variation.get_spread()[1],self._ny]]:
            lim = 0
            if center_variation:
                lim = dc 
                lim = lim*0.5 if lim is not None else 0.
                cv_mode = self._center_variation.get_mode()
                if cv_mode is not None:
                    if "normal" in cv_mode:
                        lim *= 3
            c_min = c - lim/2.
            c_max = c + lim/2.
            res1 = n-1-c_min
            res2 = -c_max
            dist_max.append(res1 if abs(res1) > abs(res2) else res2)
        return dist_max

    def get_p_max_dist(self, cx = None, cy = None, pos = "corner", center_variation = False):
        r"""
        Return 3D position vector of the pixel furthest away from the beam center. If each of the given center position coordinates (``cx``, ``cy``) is ``None`` the beam center is assumed to be located at its mean position
        

# 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

          :cy (float): *y*-coordinate of the center position in unit pixel
        """
        Y, X = numpy.meshgrid(numpy.float64(numpy.arange(self._ny))-cy,
                              numpy.float64(numpy.arange(self._nx))-cx,
                              indexing="ij")
        return self.get_pixel_solid_angle(X, Y)
    
    def _get_xy_max_dist(self, cx = None, cy = None, center_variation = False):
        dist_max = []
        for c,dc,n in [[(cx if cx is not None else self.get_cx_mean_value()),self._center_variation.get_spread()[0],self._nx],
                       [(cy if cy is not None else self.get_cy_mean_value()),self._center_variation.get_spread()[1],self._ny]]:
            lim = 0
            if center_variation:
                lim = dc 
                lim = lim*0.5 if lim is not None else 0.
                cv_mode = self._center_variation.get_mode()
                if cv_mode is not None:
                    if "normal" in cv_mode:
                        lim *= 3
            c_min = c - lim/2.
            c_max = c + lim/2.
            res1 = n-1-c_min
            res2 = -c_max
            dist_max.append(res1 if abs(res1) > abs(res2) else res2)
        return dist_max

    def get_p_max_dist(self, cx = None, cy = None, pos = "corner", center_variation = False):
        r"""
        Return 3D position vector of the pixel furthest away from the beam center. If each of the given center position coordinates (``cx``, ``cy``) is ``None`` the beam center is assumed to be located at its mean position
        

        Kwargs: