def __init__(self, parameters=None, input_path=None, output_path=None):
        """

        :param parameters: Parameters of the calculation (not data).
        :type parameters: dict || AbstractCalculatorParameters

        :param input_path: Path to hdf5 file holding the input data.
        :type input_path: str

        :param output_path: Path to hdf5 file for output.
        :type output_path: str
        """

        # Check input path. Raises if none given.
        input_path = checkAndSetInstance(str, input_path, None)

        # Check output path. Set default if none given.
        output_path = checkAndSetInstance(str, output_path, 'source')

        # Init base class.
        super(AbstractPhotonSource, self).__init__(parameters, input_path, output_path)

        # Setup provided data groups and sets.
        self.__provided_data = ['/data/arrEhor',
                                '/data/arrEver',
                                '/params/Mesh/nSlices',
                                '/params/Mesh/nx',
                                '/params/Mesh/ny',
                                '/params/Mesh/sliceMax',
                                '/params/Mesh/sliceMin',
                                '/params/Mesh/xMax',
                                '/params/Mesh/xMin',
                                '/params/Mesh/yMax',
                                '/params/Mesh/yMin',
                                '/params/Mesh/zCoord',
                                '/params/Rx',
                                '/params/Ry',
                                '/params/dRx',
                                '/params/dRy',
                                '/params/nval',
                                '/params/photonEnergy',
                                '/params/wDomain',
                                '/params/wEFieldUnit',
                                '/params/wFloatType',
                                '/params/wSpace',
                                '/params/xCentre',
                                '/params/yCentre',
                                '/history/parent/info/data_description',
                                '/history/parent/info/package_version',
                                '/history/parent/misc/FAST2XY.DAT',
                                '/history/parent/misc/angular_distribution',
                                '/history/parent/misc/spot_size',
                                '/history/parent/misc/gain_curve',
                                '/history/parent/misc/nzc',
                                '/history/parent/misc/temporal_struct',
                                '/version',
                                ]

        # Setup expected data.
        self.__expected_data = [d for d in self.__provided_data]
    def testCheckAndSetInstanceDerived(self):
        """ Test the check and set utility works correctly also for abstract data and derived types. """

        # Check works for a derived type.
        class my_baseclass(object):
            def __init__(self, var1, var2):
                self.__var1 = var1
                self.__var2 = var2
        class my_derived_class(my_baseclass):
            def __init__(self, var1, var2, var3):
                super(my_derived_class, self).__init__(1.0, 2.0)
                self.__var3 = var3

        mc_base = my_baseclass(1.0, 2.0)
        mc_derived = my_derived_class(1.0, 2.0, 3.0)

        check_ok = True
        try:
            checked_base_class = checkAndSetInstance(my_baseclass, mc_base)
            checked_derived_class = checkAndSetInstance(my_derived_class, mc_derived)
            checked_derived_class2 = checkAndSetInstance(my_baseclass, mc_derived)
        except:
            check_ok = False

        self.assertTrue(check_ok)
    def __init__(self, parameters=None, input_path=None, output_path=None, tmp_files_path=None, run_files_path=None):
        """

        :param  parameters: Parameters for the EMC orientation calculator.
        :type parameters: EMCOrientationParameters instance

        :param input_path: Path to directory holding input data for EMC.
        :type input_path: str

        :param output_path: Path to file where output data will be stored.
        :type output_path: str

        :param tmp_files_path: Path to directory where temporary files will be stored.
        :type tmp_files_path: str

        :param run_files_path: Path to directory where run data will be stored, in particular the sparse photons file 'photons.dat' and 'detector.dat'.
        :type run_files_path: str

        :note: If 'run_files_path' is an existing directory that contains data from a previous EMC run, the current run will append to the
               existing data. A consistency check is performed.

        """

        # Check parameters.
        if isinstance( parameters, dict ):
            parameters = EMCOrientationParameters( parameters_dictionary = parameters )

        # Set default parameters is no parameters given.
        if parameters is None:
            parameters = checkAndSetInstance( EMCOrientationParameters, parameters, EMCOrientationParameters() )
        else:
            parameters = checkAndSetInstance( EMCOrientationParameters, parameters, None )


        # Initialize base class.
        super(EMCOrientation, self).__init__(parameters,input_path,output_path)


        self.__provided_data = ['data/data',
                                'data/angle',
                                'data/center',
                                'params/info',
                                'version',]

        self.__expected_data = ['/data/data',
                                '/data/diffr',
                                '/data/angle',
                                '/params/geom/detectorDist',
                                '/params/geom/pixelWidth',
                                '/params/geom/pixelHeight',
                                '/params/geom/mask',
                                '/params/beam/photonEnergy',
                                '/params/beam/photons',
                                '/params/beam/focusArea',
                                ]

        # Set run and tmp files paths.
        if _checkPaths( run_files_path, tmp_files_path ):
            self.run_files_path = run_files_path
            self.tmp_files_path = tmp_files_path
    def __init__(self, parameters=None, input_path=None, output_path=None):
        """
        Constructor for the Abstract Photon Detector.
        """

        # Check input path. Set to default if none given.
        input_path = checkAndSetInstance(str, input_path, 'diffr')
        # Check output path. Set default if none given.
        output_path = checkAndSetInstance(str, output_path, 'detector')


        # Initialize the base class.
        super(AbstractPhotonDetector, self).__init__(parameters, input_path, output_path)
def checkAndSetModelSee( model ):
    """
    Utility to check if the model is a valid model for the high frequency (dynamic) feature.

    @param model : The model to check.
    <br/><b>type</b> : str
    @return : The checked model
    @raise ValueError if not a string or not a valid See0 model ('RPA', 'BMA', 'BMA+sLFC', 'BMA+dLFC', 'LFC', 'Landen')
    """

    # Default handling.
    model = checkAndSetInstance( str, model, 'RPA')

    # Valid models.
    valid_models = ['RPA',
                    'Lindhard',
                    'static LFC',
                    'dynamic LFC',
                    'BMA',
                    'BMA+sLFC',
                    'BMA+dLFC',
                    ]

    if model not in valid_models:
        raise ValueError( "The See model must be a valid See0 model. Valid See0 models are %s." % (str(valid_models)) )

    # Return
    return model
 def pmi_stop_ID(self, value):
     """ Set the 'pmi_stop_ID' parameter to a given value.
     :param value: The value to set 'pmi_stop_ID' to.
     """
     pmi_stop_ID = checkAndSetInstance(int, value, 1)
     if pmi_stop_ID >= 0:
         self.__pmi_stop_ID = pmi_stop_ID
     else:
         raise ValueError("The parameters 'pmi_stop_ID' must be a positive integer.")
    def photon_response(self, val):
        """ Set the panel photon_response. """
        if val is not None:
            val = checkAndSetInstance(float, val, None)

        self.__photon_response = val

        # Invalidate energy response.
        if val is not None and self.__energy_response is not None:
            self.__energy_response = None
Exemple #8
0
 def pmi_stop_ID(self, value):
     """ Set the 'pmi_stop_ID' parameter to a given value.
     :param value: The value to set 'pmi_stop_ID' to.
     """
     pmi_stop_ID = checkAndSetInstance(int, value, 1)
     if pmi_stop_ID >= 0:
         self.__pmi_stop_ID = pmi_stop_ID
     else:
         raise ValueError(
             "The parameters 'pmi_stop_ID' must be a positive integer.")
    def min_error(self, value):
        """ Set the 'min_error' parameter to a given value.
        :param value: The value to set 'min_error' to.
        """
        min_error = checkAndSetInstance( float, value, 1.e-5 )

        if min_error > 0:
            self.__min_error = min_error
        else:
            raise ValueError( "The parameter 'min_error' must be a positive float.")
    def max_number_of_iterations(self, value):
        """ Set the 'max_number_of_iterations' parameter to a given value.
        :param value: The value to set 'max_number_of_iterations' to.
        """
        max_number_of_iterations = checkAndSetInstance( int, value, 100 )

        if max_number_of_iterations > 0:
            self.__max_number_of_iterations = max_number_of_iterations
        else:
            raise ValueError( "The parameter 'max_number_of_iterations' must be a positive integer.")
    def number_of_MPI_processes(self, value):
        """ Set the 'number_of_MPI_processes' parameter to a given value.
        :param value: The value to set 'number_of_MPI_processes' to.
        """
        number_of_MPI_processes = checkAndSetInstance(int, value, 2)

        if number_of_MPI_processes > 0:
            self.__number_of_MPI_processes = number_of_MPI_processes
        else:
            raise ValueError("The parameters 'number_of_MPI_processes' must be a positive integer.")
    def initial_number_of_quaternions(self, value):
        """ Set the 'initial_number_of_quaternions' parameter to a given value.
        :param value: The value to set 'initial_number_of_quaternions' to.
        """
        initial_number_of_quaternions = checkAndSetInstance( int, value, 1 )

        if all([initial_number_of_quaternions > 0, initial_number_of_quaternions < 10]):
            self.__initial_number_of_quaternions = initial_number_of_quaternions
        else:
            raise ValueError( "Parameter 'initial_number_of_quaternions' must be an integer (0 < n < 10)")
    def __init__(self, parameters=None, input_path=None, output_path=None):
        """

        :param parameters: Parameters of the calculation (not data).
        :type parameters: dict || AbstractCalculatorParameters

        :param input_path: Path to hdf5 file holding the input data.
        :type input_path: str

        :param output_path: Path to hdf5 file for output.
        :type output_path: str
        """

        # Check input path. Set to default if none given.
        input_path = checkAndSetInstance(str, input_path, 'prop')
        # Check output path. Set default if none given.
        output_path = checkAndSetInstance(str, output_path, 'pmi')

        super(AbstractPhotonInteractor, self).__init__(parameters, input_path, output_path)
def checkAndSetLFC(lfc):
    """ Utility to check if input is a valid local field correction factor.

    @param  lfc : The lfc to check.
    <br/><b>type</b> : double
    @return : The checked lfc.
    """
    lfc = checkAndSetInstance(float, lfc, 0.0)

    return lfc
Exemple #15
0
    def number_of_diffraction_patterns(self, value):
        """ Set the 'number_of_diffraction_patterns' parameter to a given value.
        :param value: The value to set 'number_of_diffraction_patterns' to.
        """
        number_of_diffraction_patterns = checkAndSetInstance( int, value, 1 )

        if number_of_diffraction_patterns > 0:
            self.__number_of_diffraction_patterns = number_of_diffraction_patterns
        else:
            raise ValueError("The parameters 'number_of_diffraction_patterns' must be a positive integer.")
    def slice_interval(self, value):
        """ Set the 'slice_interval' parameter to a given value.
        :param value: The value to set 'slice_interval' to.
        """
        slice_interval = checkAndSetInstance(int, value, 100)

        if slice_interval > 0:
            self.__slice_interval = slice_interval
        else:
            raise ValueError("The parameter 'slice_interval' must be a positive integer.")
    def number_of_diffraction_patterns(self, value):
        """ Set the 'number_of_diffraction_patterns' parameter to a given value.
        :param value: The value to set 'number_of_diffraction_patterns' to.
        """
        number_of_diffraction_patterns = checkAndSetInstance(int, value, 1)

        if number_of_diffraction_patterns > 0:
            self.__number_of_diffraction_patterns = number_of_diffraction_patterns
        else:
            raise ValueError("The parameters 'number_of_diffraction_patterns' must be a positive integer.")
 def number_of_shrink_cycles(self, value):
     """ Set the 'number_of_shrink_cycles' parameter to a given value.
     :param value : The value to set 'number_of_shrink_cycles' to.
     :type value: int
     """
     number_of_shrink_cycles = checkAndSetInstance(int, value, 10)
     if number_of_shrink_cycles > 0:
         self.__number_of_shrink_cycles = number_of_shrink_cycles
     else:
         raise ValueError("The parameter 'number_of_shrink_cycles' must be a positive integer.")
    def max_number_of_quaternions(self, value):
        """ Set the 'max_number_of_quaternions' parameter to a given value.
        :param value: The value to set 'max_number_of_quaternions' to.
        """
        max_number_of_quaternions = checkAndSetInstance( int, value, self.__initial_number_of_quaternions+1 )

        if all([ max_number_of_quaternions <= 10, max_number_of_quaternions > self.initial_number_of_quaternions]):
            self.__max_number_of_quaternions = max_number_of_quaternions
        else:
            raise ValueError( "Parameter 'max_number_of_quaternions' must be an integer (initial_number_of_quaternions < n <= 10)")
    def __init__(self, parameters=None, input_path=None, output_path=None):
        """

        :param parameters: Parameters of the calculation (not data).
        :type parameters: dict || AbstractCalculatorParameters

        :param input_path: Path to hdf5 file holding the input data.
        :type input_path: str

        :param output_path: Path to hdf5 file for output.
        :type output_path: str
        """

        # Check input path. Set to default if none given.
        input_path = checkAndSetInstance(str, input_path, 'prop')
        # Check output path. Set default if none given.
        output_path = checkAndSetInstance(str, output_path, 'pmi')

        super(AbstractPhotonInteractor, self).__init__(parameters, input_path, output_path)
Exemple #21
0
    def __init__(self, parameters=None, input_path=None, output_path=None):
        """

        :param  parameters: Phasing parameters.
        :type parameters: DMPhasingParameters instance

        :param input_path: Path to input data (file or directory).
        :type input_path: str

        :param output_path: Path to output data (file or directory).
        :type output_path: str
        """

        # Check parameters.
        if isinstance(parameters, dict):
            parameters = DMPhasingParameters(parameters_dictionary=parameters)

        # Set default parameters is no parameters given.
        if parameters is None:
            parameters = checkAndSetInstance(DMPhasingParameters, parameters,
                                             DMPhasingParameters())
        else:
            parameters = checkAndSetInstance(DMPhasingParameters, parameters,
                                             None)

        super(DMPhasing, self).__init__(parameters, input_path, output_path)

        self.__expected_data = [
            '/data/data',
            '/data/angle',
            '/data/center',
            '/params/info',
            '/version',
        ]

        self.__provided_data = [
            '/data/electronDensity',
            '/params/info',
            '/history',
            '/info',
            '/misc',
            '/version',
        ]
def checkAndSetLFC(lfc):
    """ Utility to check if input is a valid local field correction factor.

    @param  lfc : The lfc to check.
    <br/><b>type</b> : double
    @return : The checked lfc.
    """
    lfc = checkAndSetInstance(float, lfc, 0.0)

    return lfc
def checkAndSetPhotonDetector(var=None, default=None):
    """
    Check if passed object is an AbstractPhotonDetector instance. If non is given, set to given default.

    :param var: The object to check.
    :param default: The default to use.
    :return: The checked photon source object.
    :raises RuntimeError:  if no valid PhotonDetector was given.
    """

    return checkAndSetInstance(AbstractPhotonDetector, var, default)
Exemple #24
0
    def min_error(self, value):
        """ Set the 'min_error' parameter to a given value.
        :param value: The value to set 'min_error' to.
        """
        min_error = checkAndSetInstance(float, value, 1.e-5)

        if min_error > 0:
            self.__min_error = min_error
        else:
            raise ValueError(
                "The parameter 'min_error' must be a positive float.")
Exemple #25
0
def checkAndSetPhotonDiffractor(var=None, default=None):
    """
    Check if passed object is an AbstractPhotonDiffractor instance. If non is given, set to given default.

    @param var : The object to check.
    @param default : The default to use.
    @return : The checked photon source object.
    @throw : RuntimeError if no valid PhotonDiffractor was given.
    """

    return checkAndSetInstance(AbstractPhotonDiffractor, var, default)
Exemple #26
0
    def __init__(self,  parameters=None, input_path=None, output_path=None):
        """

        :param parameters: Parameters of the calculation (not data).
        :type parameters:  CrystFELPhotonDiffractorParameters

        :param input_path: Path to hdf5 file holding the input data.
        :type input_path: str

        :param output_path: Path to hdf5 file for output.
        :type output_path: str
        """

        # Set default parameters if no parameters given.
        if parameters is None:
            raise ValueError( "Parameters must at least specify the sample structure, e.g. in pdb format.")
        else:
            self.__parameters = checkAndSetInstance( CrystFELPhotonDiffractorParameters, parameters, None )


        # Dummy input path since none required (we don't read from a beam propgation yet.)
        if input_path is None:
            input_path = os.path.dirname(__file__)
        else:
            if parameters.beam_parameters is not None:
                raise RuntimeError("Beam parameters can only be passed through the parameters object or via the input_path argument.")
            parameters.beam_parameters = propToBeamParameters( input_path )

        if output_path is None:
            output_path = os.path.join(os.path.dirname(__file__), "diffr")

        # Init base class.
        super(CrystFELPhotonDiffractor, self).__init__(parameters,input_path,output_path)

        ### FIXME
        self.__provided_data = [
                                '/data/data',
                                '/data/diffr',
                                '/data/angle',
                                '/history/parent/detail',
                                '/history/parent/parent',
                                '/info/package_version',
                                '/info/contact',
                                '/info/data_description',
                                '/info/method_description',
                                '/params/geom/detectorDist',
                                '/params/geom/pixelWidth',
                                '/params/geom/pixelHeight',
                                '/params/geom/mask',
                                '/params/beam/photonEnergy',
                                '/params/beam/photons',
                                '/params/beam/focusArea',
                                '/params/info',
                                ]
    def leash(self, value):
        """ Set the 'leash' parameter to a given value.
        :param value: The value to set 'leash' to.
        :type value: float
        """
        leash = checkAndSetInstance(float, value, 0.2)

        if leash > 0:
            self.__leash = leash
        else:
            raise ValueError("The parameter 'leash' must be a positive integer.")
    def number_of_trials(self, value):
        """ Set the 'number_of_trials' parameter to a given value.
        :param value: The value to set 'number_of_trials' to.
        :type value: int
        """
        number_of_trials = checkAndSetInstance(int, value, 500)

        if all([number_of_trials > 0]):
            self.__number_of_trials = number_of_trials
        else:
            raise ValueError("Parameter 'number_of_trials' must be an integer (n > 0)")
    def averaging_start(self, value):
        """ Set the 'averaging_start' parameter to a given value.
        :param value: The value to set 'averaging_start' to.
        :type value: int
        """
        averaging_start = checkAndSetInstance(int, value, 15)

        if averaging_start > 0:
            self.__averaging_start = averaging_start
        else:
            raise ValueError("The parameter 'averaging_start' must be a positive integer.")
Exemple #30
0
    def geometry(self, value):
        """ Set the 'geometry' parameter to a given value.
        :param value: The value to set 'geometry' to.
        """
        self.__geometry = checkAndSetInstance( str, value, None )

        if self.__geometry is not None:
            if not os.path.isfile( self.__geometry):
                raise IOError("The geometry %s is not a valid file or filename." % (self.__geometry) )
        else:
            print ("WARNING: Geometry file not set, calculation will most probably fail.")
Exemple #31
0
    def slice_interval(self, value):
        """ Set the 'slice_interval' parameter to a given value.
        :param value: The value to set 'slice_interval' to.
        """
        slice_interval = checkAndSetInstance(int, value, 100)

        if slice_interval > 0:
            self.__slice_interval = slice_interval
        else:
            raise ValueError(
                "The parameter 'slice_interval' must be a positive integer.")
Exemple #32
0
def checkAndSetPhotonPropagator(var=None, default=None):
    """
    Check if passed object is an AbstractPhotonPropagator instance. If non is given, set to given default.

    :param var: The object to check
    :param default: The default to use
    :return: The checked photon source object
    :raise RuntimeError: if no valid PhotonPropagator was given.
    """

    return checkAndSetInstance(AbstractPhotonPropagator, var, default)
def checkAndSetPhotonAnalyzer(var=None, default=None):
    """
    Check if passed object is an AbstractPhotonAnalyzer instance. If non is given, set to given default.

    @param var : The object to check.
    @param default : The default to use.
    @return : The checked photon source object.
    @throw : RuntimeError if no valid PhotonAnalyzer was given.
    """

    return checkAndSetInstance(AbstractPhotonAnalyzer, var, default)
Exemple #34
0
    def number_of_slices(self, value):
        """ Set the 'number_of_slices' parameter to a given value.
        :param value: The value to set 'number_of_slices' to.
        """
        number_of_slices = checkAndSetInstance(int, value, 1)

        if number_of_slices > 0:
            self.__number_of_slices = number_of_slices
        else:
            raise ValueError(
                "The parameter 'slice_interval' must be a positive integer.")
Exemple #35
0
    def number_of_trials(self, value):
        """ Set the 'number_of_trials' parameter to a given value.
        :param value: The value to set 'number_of_trials' to.
        :type value: int
        """
        number_of_trials = checkAndSetInstance(int, value, 500)

        if all([number_of_trials > 0]):
            self.__number_of_trials = number_of_trials
        else:
            raise ValueError(
                "Parameter 'number_of_trials' must be an integer (n > 0)")
Exemple #36
0
 def number_of_shrink_cycles(self, value):
     """ Set the 'number_of_shrink_cycles' parameter to a given value.
     :param value : The value to set 'number_of_shrink_cycles' to.
     :type value: int
     """
     number_of_shrink_cycles = checkAndSetInstance(int, value, 10)
     if number_of_shrink_cycles > 0:
         self.__number_of_shrink_cycles = number_of_shrink_cycles
     else:
         raise ValueError(
             "The parameter 'number_of_shrink_cycles' must be a positive integer."
         )
Exemple #37
0
    def averaging_start(self, value):
        """ Set the 'averaging_start' parameter to a given value.
        :param value: The value to set 'averaging_start' to.
        :type value: int
        """
        averaging_start = checkAndSetInstance(int, value, 15)

        if averaging_start > 0:
            self.__averaging_start = averaging_start
        else:
            raise ValueError(
                "The parameter 'averaging_start' must be a positive integer.")
Exemple #38
0
    def leash(self, value):
        """ Set the 'leash' parameter to a given value.
        :param value: The value to set 'leash' to.
        :type value: float
        """
        leash = checkAndSetInstance(float, value, 0.2)

        if leash > 0:
            self.__leash = leash
        else:
            raise ValueError(
                "The parameter 'leash' must be a positive integer.")
Exemple #39
0
    def max_number_of_iterations(self, value):
        """ Set the 'max_number_of_iterations' parameter to a given value.
        :param value: The value to set 'max_number_of_iterations' to.
        """
        max_number_of_iterations = checkAndSetInstance(int, value, 100)

        if max_number_of_iterations > 0:
            self.__max_number_of_iterations = max_number_of_iterations
        else:
            raise ValueError(
                "The parameter 'max_number_of_iterations' must be a positive integer."
            )
def checkAndSetIO(io):
    """ Check the passed io path/filenames and set appropriately. """

    # Check we have a tuple.
    io = checkAndSetInstance(tuple, io)
    if len(io) != 2:
        raise exceptions.RuntimeError("The parameter 'io' can only be a tuple of two strings.")

    # Check if input exists, if not, raise.
    i = checkAndSetInstance(str, io[0])
    if i is None:
        raise exceptions.IOError("The parameter 'input_path' must be a valid filename.")
    i = os.path.abspath(i)
#
    # Check if output file exists, otherwise attempt to create it.
    o = checkAndSetInstance(str, io[1])
    if o is None:
        raise exceptions.IOError("The parameter 'output_path' must be a valid filename.")
    o = os.path.abspath(o)

    return (i, o)
def checkAndSetIO(io):
    """ Check the passed io path/filenames and set appropriately. """

    # Check we have a tuple.
    io = checkAndSetInstance(tuple, io)
    if len(io) != 2:
        raise RuntimeError("The parameter 'io' can only be a tuple of two strings.")

    # Check if input exists, if not, raise.
    i = checkAndSetInstance(str, io[0])
    if i is None:
        raise IOError("The parameter 'input_path' must be a valid filename.")
    i = os.path.abspath(i)
#
    # Check if output file exists, otherwise attempt to create it.
    o = checkAndSetInstance(str, io[1])
    if o is None:
        raise IOError("The parameter 'output_path' must be a valid filename.")
    o = os.path.abspath(o)

    return (i, o)
Exemple #42
0
    def __init__(self, input_path=None):
        """

        :param input_path: Path to hdf5 file holding the data to analyze. Single file or directory.
        :type input_path: str

        """

        if input_path is None:
            raise ValueError("The parameter 'input_path' cannot be None.")

        self.__input_path = checkAndSetInstance(str, input_path, None)
Exemple #43
0
    def beam_parameters(self, value):
        """ Set the 'beam_parameters' parameter to a given value.
        :param value: The value to set 'beam_parameters' to.
        """
        if value is None:
            print ("WARNING: Beam parameters not set, will use crystFEL/pattern_sim defaults.")

        self.__beam_parameters = checkAndSetInstance( (str, PhotonBeamParameters), value, None )

        if isinstance(self.__beam_parameters, str):
            if not os.path.isfile( self.__beam_parameters):
                raise IOError("The beam_parameters %s is not a valid file or filename." % (self.__beam_parameters) )
    def __init__(self,  parameters=None, input_path=None, output_path=None):
        """
        Constructor for the phasing analyser.

        :param  parameters: Phasing parameters.
        :type parameters: DMPhasingParameters instance

        :param input_path: Path to input data (file or directory).
        :type input_path: str

        :param output_path: Path to output data (file or directory).
        :type output_path: str
        """

        # Check parameters.
        if isinstance( parameters, dict ):
            parameters = DMPhasingParameters( parameters_dictionary = parameters )

        # Set default parameters is no parameters given.
        if parameters is None:
            parameters = checkAndSetInstance( DMPhasingParameters, parameters, DMPhasingParameters() )
        else:
            parameters = checkAndSetInstance( DMPhasingParameters, parameters, None )

        super(DMPhasing, self).__init__(parameters,input_path,output_path)

        self.__expected_data = ['/data/data',
                                '/data/angle',
                                '/data/center',
                                '/params/info',
                                '/version',]

        self.__provided_data = ['/data/electronDensity',
                                '/params/info',
                                '/history',
                                '/info',
                                '/misc',
                                '/version',
                                ]
    def beam_geometry_file(self, value):
        """ Set the 'beam_geometry_file' parameter to a given value.
        :param value: The value to set 'beam_geometry_file' to.
        """
        self.__beam_geometry_file = checkAndSetInstance(str, value, None)

        if self.__beam_geometry_file is not None:
            if not os.path.isfile(self.__beam_geometry_file):
                raise IOError(
                    "The beam_parameter_file %s is not a valid file or filename." % (self.__beam_geometry_file)
                )
        else:
            print("WARNING: Geometry file not set, calculation will most probably fail.")
def checkAndSetElectronTemperature(electron_temperature):
    """ Utility to check if input is a valid electron temperature.

    @param  electron_temperature : The electron temperature to check.
    <br/><b>type</b> : double
    @return : The checked electron temperature.
    """
    if electron_temperature is None:
        raise RuntimeError( "Electron temperature not specified.")
    electron_temperature = checkAndSetInstance( float, electron_temperature, None)
    if electron_temperature <= 0.0:
        raise ValueError( "Electron temperature must be positive.")

    return electron_temperature
    def testCheckAndSetInstanceDefault(self):
        """ Check that setting the default works correctly. """

        # Setup default, and class.
        default = 1.0
        tp = int

        # Check raises because default not of correct type.
        self.assertRaises(exceptions.TypeError, checkAndSetInstance, tp, None, default)

        default = 1
        # Use the utility to set the variable to the default.
        var = checkAndSetInstance(tp, None, default)

        self.assertEqual(var, default)
def checkAndSetElectronTemperature(electron_temperature):
    """ Utility to check if input is a valid electron temperature.

    @param  electron_temperature : The electron temperature to check.
    <br/><b>type</b> : double
    @return : The checked electron temperature.
    """
    if electron_temperature is None:
        raise RuntimeError("Electron temperature not specified.")
    electron_temperature = checkAndSetInstance(float, electron_temperature,
                                               None)
    if electron_temperature <= 0.0:
        raise ValueError("Electron temperature must be positive.")

    return electron_temperature
def checkAndSetElements(elements):
    """ Utility to check if input is a valid list of elements.

    @param  elements: The elements to check.
    <br/><b>type</b> elements: list
    @return: The checked list of elements.
    """

    if elements is None:
        raise RuntimeError( "No element(s) specified. Give at least one chemical element.")
    elements = checkAndSetInstance( list, elements, None )

    # Check each element.
    for element in elements:
        symbol, stoch, chrg = checkAndSetInstance( list, element, None )
        if symbol not in ALL_ELEMENTS:
            raise ValueError( '%s is not a valid chemical element symbol.' % (symbol) )
        stoch = checkAndSetPositiveInteger(stoch)
        chrg = checkAndSetInteger(chrg)
        if chrg < -1:
            raise ValueError( "Charge must be >= -1.")

        element = [symbol, stoch, chrg]
    return elements
Exemple #50
0
    def __init__(self, parameters=None, input_path=None, output_path=None):
        """

        :param parameters: Parameters of the calculation (not data).
        :type parameters: dict || AbstractCalculatorParameters

        :param input_path: Path to hdf5 file holding the input data.
        :type input_path: str

        :param output_path: Path to hdf5 file for output.
        :type output_path: str
        """

        # Check input path. Set to default if none given.
        input_path = checkAndSetInstance(str, input_path, 'detector')
        # Check output path. Set default if none given.
        o_path = checkAndSetInstance(str, output_path, 'analysis')

        if output_path is None:
            os.makedirs( os.path.abspath( o_path) )
        output_path = o_path

        # Initialize the base class.
        super(AbstractPhotonAnalyzer, self).__init__(parameters, input_path, output_path)
    def __init__(self, parameters=None, input_path=None, output_path=None):
        """

        :param parameters: Parameters of the calculation (not data).
        :type parameters: dict || AbstractCalculatorParameters

        :param input_path: Path to hdf5 file holding the input data.
        :type input_path: str

        :param output_path: Path to hdf5 file for output.
        :type output_path: str
        """

        # Check input path. Set to default if none given.
        input_path = checkAndSetInstance(str, input_path, 'detector')
        # Check output path. Set default if none given.
        o_path = checkAndSetInstance(str, output_path, 'analysis')

        if output_path is None:
            os.makedirs( os.path.abspath( o_path) )
        output_path = o_path

        # Initialize the base class.
        super(AbstractPhotonAnalyzer, self).__init__(parameters, input_path, output_path)
Exemple #52
0
    def testCheckAndSetInstanceDefault(self):
        """ Check that setting the default works correctly. """

        # Setup default, and class.
        default = 1.0
        tp = int

        # Check raises because default not of correct type.
        self.assertRaises(TypeError, checkAndSetInstance, tp, None, default)

        default = 1
        # Use the utility to set the variable to the default.
        var = checkAndSetInstance(tp, None, default)

        self.assertEqual(var, default)
Exemple #53
0
    def initial_number_of_quaternions(self, value):
        """ Set the 'initial_number_of_quaternions' parameter to a given value.
        :param value: The value to set 'initial_number_of_quaternions' to.
        """
        initial_number_of_quaternions = checkAndSetInstance(int, value, 1)

        if all([
                initial_number_of_quaternions > 0,
                initial_number_of_quaternions < 10
        ]):
            self.__initial_number_of_quaternions = initial_number_of_quaternions
        else:
            raise ValueError(
                "Parameter 'initial_number_of_quaternions' must be an integer (0 < n < 10)"
            )
Exemple #54
0
def checkAndSetBaseCalculator(var=None, default=None):
    """
    Check if passed object is an AbstractAnalysis instance. If non is given, set to given default.

    :param var: The object to check.

    :param default: The default to use.

    :return: The checked object.

    :raises RuntimeError: if no valid Analysis object was given.

    """

    return checkAndSetInstance(AbstractAnalysis, var, default)
def checkAndSetBandGap(band_gap):
    """ Utility to check if input is a valid bandgap.

    @param  band_gap: The bandgap to check.
    <br/><b>type</b> : double
    <br/><b>default</b> 0.0.
    @return : The checked bandgap.
    """
    if band_gap is None:
        return None

    band_gap = checkAndSetInstance( float, band_gap, 0.0)
    if band_gap < 0.0:
        raise ValueError( "Debye temperature must be positive.")

    return band_gap
def checkAndSetDebyeTemperature(debye_temperature):
    """ Utility to check if input is a valid Debye temperature.

    @param  debye_temperature : The Debye temperature to check.
    <br/><b>type</b> : double
    <br/><b>default</b> : 0.0
    @return : The checked Debye temperature.
    """
    if debye_temperature is None:
        return None

    debye_temperature = checkAndSetInstance(float, debye_temperature, 0.0)
    if debye_temperature < 0.0:
        raise ValueError("Debye temperature must be non-negative.")

    return debye_temperature
Exemple #57
0
    def beam_parameters(self, value):
        """ Set the 'beam_parameters' parameter to a given value.
        :param value: The value to set 'beam_parameters' to.
        """
        value = checkAndSetInstance((str, PhotonBeamParameters), value, None)

        if isinstance(value, str):
            if not os.path.isfile(value):
                raise IOError(
                    "The beam_parameters %s is not a valid file or filename." %
                    (value))
            raise TypeError(
                "Passing beam parameters as a file is currently unsupported. Please use the PhotonBeamParameters class."
            )

        self.__beam_parameters = value
def checkAndSetDebyeTemperature(debye_temperature):
    """ Utility to check if input is a valid Debye temperature.

    @param  debye_temperature : The Debye temperature to check.
    <br/><b>type</b> : double
    <br/><b>default</b> : 0.0
    @return : The checked Debye temperature.
    """
    if debye_temperature is None:
        return None

    debye_temperature = checkAndSetInstance( float, debye_temperature, 0.0)
    if debye_temperature < 0.0:
        raise ValueError( "Debye temperature must be non-negative.")

    return debye_temperature
def checkAndSetBandGap(band_gap):
    """ Utility to check if input is a valid bandgap.

    @param  band_gap: The bandgap to check.
    <br/><b>type</b> : double
    <br/><b>default</b> 0.0.
    @return : The checked bandgap.
    """
    if band_gap is None:
        return None

    band_gap = checkAndSetInstance(float, band_gap, 0.0)
    if band_gap < 0.0:
        raise ValueError("Debye temperature must be positive.")

    return band_gap
Exemple #60
0
    def max_number_of_quaternions(self, value):
        """ Set the 'max_number_of_quaternions' parameter to a given value.
        :param value: The value to set 'max_number_of_quaternions' to.
        """
        max_number_of_quaternions = checkAndSetInstance(
            int, value, self.__initial_number_of_quaternions + 1)

        if all([
                max_number_of_quaternions <= 10,
                max_number_of_quaternions > self.initial_number_of_quaternions
        ]):
            self.__max_number_of_quaternions = max_number_of_quaternions
        else:
            raise ValueError(
                "Parameter 'max_number_of_quaternions' must be an integer (initial_number_of_quaternions < n <= 10)"
            )