def __init__(self,
                 y_obs_lower=-np.Inf,
                 y_obs_upper=np.Inf,
                 y_diff_upper=np.Inf,
                 y_diff_lower=-np.Inf,
                 x_calc=None,
                 y_calc=None):
        if y_calc is None:
            y_calc = [0.0]
        if x_calc is None:
            x_calc = [0.0]
        main = LoggedPathDict(
            x_min=np.amin(x_calc).item(),
            x_max=np.amax(x_calc).item(),
            y_min=(np.amin([np.amin(y_calc),
                            np.amin(y_obs_lower)]).item()),
            y_max=(np.amax([np.amax(y_calc),
                            np.amax(y_obs_upper)]).item()))

        difference = LoggedPathDict(y_min=np.amin(y_diff_lower).item(),
                                    y_max=np.amax(y_diff_upper).item())

        super().__init__(main=main, difference=difference)
        self._log = logging.getLogger(__class__.__module__)
        self._log.debug('Created limits %s', self['main'])
 def __init__(self, name: str, bragg_peaks: BraggPeaks,
              calculated_pattern: CalculatedPattern, limits: Limits):
     super().__init__(name=name,
                      bragg_peaks=bragg_peaks,
                      calculated_pattern=calculated_pattern,
                      limits=limits)
     self._log = logging.getLogger(__class__.__module__)
Example #3
0
 def __init__(self, experiments: Union[Experiment, dict, list]):
     """
     Constructor for holding multiple experiments
     :param experiments: A collection of experimental dicts
     """
     super().__init__(experiments, Experiment)
     self._log = logging.getLogger(__class__.__module__)
Example #4
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self._project_dict = None
     self._model = QStandardItemModel()
     # set roles
     self._label_role = Qt.UserRole + 1
     self._type_role = Qt.UserRole + 2
     self._chiiso_role = Qt.UserRole + 3
     self._chi11_role = Qt.UserRole + 4
     self._chi22_role = Qt.UserRole + 5
     self._chi33_role = Qt.UserRole + 6
     self._chi12_role = Qt.UserRole + 7
     self._chi13_role = Qt.UserRole + 8
     self._chi23_role = Qt.UserRole + 9
     self._model.setItemRoleNames({
         self._label_role: b'label',
         self._type_role: b'type',
         self._chiiso_role: b'chiiso',
         self._chi11_role: b'chi11',
         self._chi22_role: b'chi22',
         self._chi33_role: b'chi33',
         self._chi12_role: b'chi12',
         self._chi13_role: b'chi13',
         self._chi23_role: b'chi23'
     })
     self._log = logger.getLogger(self.__class__.__module__)
Example #5
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self._calculator = None

        # Create the status items
        chi_item = StatusItem('chiSq',
                              title='Current \u03c7\u00b2',
                              additionalData=1)
        chi_item.setReturn(True)
        chi_item.title = 'Previous \u03c7\u00b2'
        chi_item.setReturn(False)
        self._interestedList = StatusList([
            chi_item,
            StatusItem('numPars', title='Fit parameters', additionalData=1),
            StatusItem('numData', title='Experiments', additionalData=0),
            StatusItem('numPhases', title='Phases', additionalData=0)
        ])

        # minor properties
        self._first_role = Qt.UserRole + 1

        self._statusBarModel = QStandardItemModel()
        self._chartDisplayModel = QStandardItemModel()
        # set role names
        self._role_names_list = ['label', 'value']
        self._roles_list = []
        self._roles_dict = {'status': {}, 'plot': {}}
        self._setRolesListAndDict()
        self._statusBarModel.setItemRoleNames(self._roles_dict['status'])
        self._chartDisplayModel.setItemRoleNames(self._roles_dict['plot'])

        self._log = logger.getLogger(self.__class__.__module__)
Example #6
0
    def __init__(self, u_11: Base, u_22: Base, u_33: Base, u_12: Base,
                 u_13: Base, u_23: Base):
        super().__init__(u_11=u_11,
                         u_22=u_22,
                         u_33=u_33,
                         u_12=u_12,
                         u_13=u_13,
                         u_23=u_23)
        self._log = logging.getLogger(__class__.__module__)
        self._log.debug('ADP created: %s', self)

        self.setItemByPath(['u_11', 'header'], 'U11')
        self.setItemByPath(['u_11', 'tooltip'], ATOM_DETAILS['ADP']['tooltip'])
        self.setItemByPath(['u_11', 'url'], ATOM_DETAILS['ADP']['url'])

        self.setItemByPath(['u_12', 'header'], 'U12')
        self.setItemByPath(['u_12', 'tooltip'], ATOM_DETAILS['ADP']['tooltip'])
        self.setItemByPath(['u_12', 'url'], ATOM_DETAILS['ADP']['url'])

        self.setItemByPath(['u_13', 'header'], 'U13')
        self.setItemByPath(['u_13', 'tooltip'], ATOM_DETAILS['ADP']['tooltip'])
        self.setItemByPath(['u_13', 'url'], ATOM_DETAILS['ADP']['url'])

        self.setItemByPath(['u_22', 'header'], 'U22')
        self.setItemByPath(['u_22', 'tooltip'], ATOM_DETAILS['ADP']['tooltip'])
        self.setItemByPath(['u_22', 'url'], ATOM_DETAILS['ADP']['url'])

        self.setItemByPath(['u_23', 'header'], 'U23')
        self.setItemByPath(['u_23', 'tooltip'], ATOM_DETAILS['ADP']['tooltip'])
        self.setItemByPath(['u_23', 'url'], ATOM_DETAILS['ADP']['url'])

        self.setItemByPath(['u_33', 'header'], 'U33')
        self.setItemByPath(['u_33', 'tooltip'], ATOM_DETAILS['ADP']['tooltip'])
        self.setItemByPath(['u_33', 'url'], ATOM_DETAILS['ADP']['url'])
Example #7
0
    def __init__(self,
                 x: list,
                 y_obs: list,
                 sy_obs: list,
                 y_obs_diff: Union[list, None] = None,
                 sy_obs_diff: Union[list, None] = None,
                 y_obs_up: Union[list, None] = None,
                 sy_obs_up: Union[list, None] = None,
                 y_obs_down: Union[list, None] = None,
                 sy_obs_down: Union[list, None] = None):
        """
        Constructor for a measured pattern

        :param x: Generally a two theta value
        :param y_obs: Observed intensity
        :param sy_obs: Observed Error
        :param y_obs_up: Polarised UP intensity. None if non-polarised
        :param sy_obs_up: Polarised UP intensity error. None if non-polarised
        :param y_obs_down: Polarised DOWN intensity. None if non-polarised
        :param sy_obs_down: Polarised DOWN intensity error. None if non-polarised
        """
        # 1d polarised powder diffraction data
        # if y_obs_up is not None and sy_obs_up is not None and y_obs_down is not None and sy_obs_down is not None:
        super().__init__(x=x,
                         y_obs=y_obs,
                         sy_obs=sy_obs,
                         y_obs_diff=y_obs_diff,
                         sy_obs_diff=sy_obs_diff,
                         y_obs_up=y_obs_up,
                         sy_obs_up=sy_obs_up,
                         y_obs_down=y_obs_down,
                         sy_obs_down=sy_obs_down)
        self._log = logging.getLogger(__class__.__module__)
Example #8
0
    def __init__(self, release_config_file_path, parent=None):
        self.__log = logger.getLogger(__name__)
        self.__log.info("")
        super().__init__(parent)

        self.info = Config(release_config_file_path)['release']

        self.projectChanged.connect(self.onProjectChanged)

        self._project_rcif_path = None
        self._samples_rcif_path = None
        self._experiment_rcif_path = None
        self._calculator_interface = QtCalculatorInterface(CryspyCalculator())
        self._project_dict_copy = {}

        self._project_control = ProjectControl()
        self._measured_data_model = MeasuredDataModel()
        self._calculated_data_model = CalculatedDataModel()
        self._bragg_peaks_model = BraggPeaksModel()
        self._cell_parameters_model = CellParametersModel()
        self._cell_box_model = CellBoxModel()
        self._atom_sites_model = AtomSitesModel()
        self._atom_adps_model = AtomAdpsModel()
        self._atom_msps_model = AtomMspsModel()
        self._fitables_model = FitablesModel()
        self._status_model = StatusModel()

        self._refine_thread = None
        self._refinement_running = False
        self._refinement_done = False
        self._refinement_result = {}

        self._calculator_interface.clearUndoStack()
        self._need_to_save = False
Example #9
0
    def __init__(self, backgrounds: Union[Background, dict, list]):
        """
        Constructor for Background data points

        :param backgrounds: Background parameters formed from Background dicts
        """
        super().__init__(backgrounds, Background)
        self._log = logging.getLogger(__class__.__module__)
Example #10
0
 def __init__(self, atoms: Union[Atom, dict, list]):
     """
     Constructor for multiple atoms
     :param atoms: Collection of atoms
     """
     super().__init__(atoms, Atom, 'atom_site_label')
     self._log = logging.getLogger(__class__.__module__)
     self._log.debug('Atoms created: %s', self)
Example #11
0
    def __init__(self, phases: Union[Phase, dict, list]):
        """
        Constructor for the phases dict

        :param phases: Collection of phases
        """
        super().__init__(phases, Phase, 'phasename')
        self._log = logging.getLogger(__class__.__module__)
        self._log.debug('Phases created: %s', self)
Example #12
0
 def __init__(self, value: Optional[Any] = None, unit: Optional[Union[str, Unit]] = ''):
     """
     Create a data class from a value with a unit. Can be left blank
     :param value: default value for the data
     :param unit: default unit for the data in the form of a easyInterface.Untils.unit
     """
     if not isinstance(unit, Unit):
         # Try to convert the unit to a string
         unit = Unit(unit)
     super().__init__(value=value, unit=unit, min=-np.Inf, max=np.Inf, error=0, constraint=None, hide=True, refine=False)
     self._log = logger.getLogger(__class__.__module__)
Example #13
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self._y_obs_column = 1
     self._sy_obs_column = 2
     self._y_max = 1
     self._y_min = 0
     self._upperSeriesRefs = [
     ]  # list of references to QML LineSeries (for 2 charts)
     self._lowerSeriesRefs = [
     ]  # list of references to QML LineSeries (for 2 charts)
     self._log = logger.getLogger(self.__class__.__module__)
Example #14
0
    def __init__(self, length_a: Base, length_b: Base, length_c: Base,
                 angle_alpha: Base, angle_beta: Base, angle_gamma: Base):
        """
        Constructor for the crystallographic unit cell

        :param length_a: Unit cell length a
        :param length_b: Unit cell length b
        :param length_c:  Unit cell length c
        :param angle_alpha: Unit cell angle alpha
        :param angle_beta:  Unit cell angle beta
        :param angle_gamma:  Unit cell angle gamma
        """

        super().__init__(length_a=length_a,
                         length_b=length_b,
                         length_c=length_c,
                         angle_alpha=angle_alpha,
                         angle_beta=angle_beta,
                         angle_gamma=angle_gamma)
        self._log = logging.getLogger(__class__.__module__)
        self._log.debug('Cell created: %s', self)

        self.setItemByPath(['length_a', 'header'], 'a (Ã…)')
        self.setItemByPath(['length_a', 'tooltip'],
                           CELL_DETAILS['length']['tooltip'])
        self.setItemByPath(['length_a', 'url'], CELL_DETAILS['length']['url'])

        self.setItemByPath(['length_b', 'header'], 'b (Ã…)')
        self.setItemByPath(['length_b', 'tooltip'],
                           CELL_DETAILS['length']['tooltip'])
        self.setItemByPath(['length_b', 'url'], CELL_DETAILS['length']['url'])

        self.setItemByPath(['length_c', 'header'], 'c (Ã…)')
        self.setItemByPath(['length_c', 'tooltip'],
                           CELL_DETAILS['length']['tooltip'])
        self.setItemByPath(['length_c', 'url'], CELL_DETAILS['length']['url'])

        self.setItemByPath(['angle_alpha', 'header'], 'alpha (°)')
        self.setItemByPath(['angle_alpha', 'tooltip'],
                           CELL_DETAILS['angle']['tooltip'])
        self.setItemByPath(['angle_alpha', 'url'],
                           CELL_DETAILS['angle']['url'])

        self.setItemByPath(['angle_beta', 'header'], 'beta (°)')
        self.setItemByPath(['angle_beta', 'tooltip'],
                           CELL_DETAILS['angle']['tooltip'])
        self.setItemByPath(['angle_beta', 'url'], CELL_DETAILS['angle']['url'])

        self.setItemByPath(['angle_gamma', 'header'], 'gamma (°)')
        self.setItemByPath(['angle_gamma', 'tooltip'],
                           CELL_DETAILS['angle']['tooltip'])
        self.setItemByPath(['angle_gamma', 'url'],
                           CELL_DETAILS['angle']['url'])
Example #15
0
    def __init__(self, name: str, wavelength: Base, offset: Base,
                 magnetic_field: Base, phase: ExperimentPhases,
                 background: Backgrounds, resolution: Resolution,
                 measured_pattern: MeasuredPattern):
        """
        Constructor for experimental data container

        :param name: The name of the experimental data
        :param wavelength: What wavelength was the experiment taken at
        :param offset: The experimental offset
        :param phase: The experimental phase scale
        :param background: Description of the background
        :param resolution: Description of the resolution
        :param measured_pattern: What was actually measured
        """

        refinement_type = RefinementType()
        refinement_type.sum = True

        super().__init__(name=name,
                         wavelength=wavelength,
                         offset=offset,
                         magnetic_field=magnetic_field,
                         phase=phase,
                         background=background,
                         resolution=resolution,
                         measured_pattern=measured_pattern,
                         refinement_type=refinement_type,
                         polarization=Polarization.default())
        self._log = logging.getLogger(__class__.__module__)

        self.setItemByPath(['wavelength', 'header'],
                           EXPERIMENT_DETAILS['wavelength']['header'])
        self.setItemByPath(['wavelength', 'tooltip'],
                           EXPERIMENT_DETAILS['wavelength']['tooltip'])
        self.setItemByPath(['wavelength', 'url'],
                           EXPERIMENT_DETAILS['wavelength']['url'])

        self.setItemByPath(['offset', 'header'],
                           EXPERIMENT_DETAILS['offset']['header'])
        self.setItemByPath(['offset', 'tooltip'],
                           EXPERIMENT_DETAILS['offset']['tooltip'])
        self.setItemByPath(['offset', 'url'],
                           EXPERIMENT_DETAILS['offset']['url'])

        self.setItemByPath(['magnetic_field', 'header'],
                           EXPERIMENT_DETAILS['magnetic_field']['header'])
        self.setItemByPath(['magnetic_field', 'tooltip'],
                           EXPERIMENT_DETAILS['magnetic_field']['tooltip'])
        self.setItemByPath(['magnetic_field', 'url'],
                           EXPERIMENT_DETAILS['magnetic_field']['url'])
Example #16
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self._project_dict = None
     self._model = QStandardItemModel()
     # set roles
     self._x_role, self._y_role, self._z_role = [
         Qt.UserRole + 1 + i for i in range(3)
     ]
     self._model.setItemRoleNames({
         self._x_role: b'xPos',
         self._y_role: b'yPos',
         self._z_role: b'zPos'
     })
     self._log = logger.getLogger(self.__class__.__module__)
 def __init__(self, parent=None):
     super().__init__(parent)
     self._y_calc_name = "y_calc_sum"
     self._y_obs_name = "y_obs"
     self._sy_obs_name = "sy_obs"
     self._y_max = 1
     self._y_min = 0
     self._y_diff_max = 1
     self._y_diff_min = 0
     self._calcSeriesRef = None
     self._calcBkgSeriesRef = None
     self._lowerDiffSeriesRef = None
     self._upperDiffSeriesRef = None
     self._log = logger.getLogger(self.__class__.__module__)
Example #18
0
 def __init__(self, parent=None):
     super().__init__(parent)
     # set roles
     self._phase_role = Qt.UserRole + 1
     self._experiment_role = Qt.UserRole + 2
     self._calculation_role = Qt.UserRole + 3
     self._model.setItemRoleNames({
         self._phase_role:
         b'phasesRole',
         self._experiment_role:
         b'experimentsRole',
         self._calculation_role:
         b'calculationsRole',
     })
     self._log = logger.getLogger(self.__class__.__module__)
Example #19
0
    def __init__(self, ttheta: float, intensity: Base):
        """
        Background dictionary

        :param ttheta: Two Theta angle in degrees
        :param intensity: Intensity data store
        :return: Background data object
        """
        super().__init__(name=str(ttheta), ttheta=ttheta, intensity=intensity)
        self._log = logging.getLogger(__class__.__module__)
        self.setItemByPath(['intensity', 'header'],
                           INTENSITY_DETAILS['intensity']['header'])
        self.setItemByPath(['intensity', 'tooltip'],
                           INTENSITY_DETAILS['intensity']['tooltip'])
        self.setItemByPath(['intensity', 'url'],
                           INTENSITY_DETAILS['intensity']['url'])
Example #20
0
    def __init__(self, name: str, scale: Base):
        """
        Constructor for the Experimental phase container

        :param scale: phase scale as data object
        """
        super().__init__(name=name, scale=scale)
        self._log = logging.getLogger(__class__.__module__)

        self.setItemByPath(['scale', 'header'],
                           SCALE_DETAILS['scale']['header'])
        self.setItemByPath(['scale', 'tooltip'],
                           SCALE_DETAILS['scale']['tooltip'])
        self.setItemByPath(['scale', 'url'], SCALE_DETAILS['scale']['url'])

        self._log.debug('Created phase: {}'.format(self))
 def __init__(self, bragg_peaks: Union[CrystalBraggPeaks, dict, list]):
     """
     Constructor for holding multiple bragg peaks
     :param bragg_peaks: A collection of bragg peak dicts
     """
     if isinstance(bragg_peaks, CrystalBraggPeaks):
         bragg_peaks = {
             bragg_peaks['name']: bragg_peaks,
         }
     if isinstance(bragg_peaks, list):
         theseCalculations = dict()
         for bragg_peak in bragg_peaks:
             theseCalculations[bragg_peak['name']] = bragg_peak
         bragg_peaks = theseCalculations
     super().__init__(**bragg_peaks)
     self._log = logging.getLogger(__class__.__module__)
    def __init__(self, calculations: Union[Calculation, dict, list]):
        """
        Constructor for holding multiple calculations

        :param calculations: A collection of calculation dicts
        """
        if isinstance(calculations, Calculation):
            calculations = {
                calculations['name']: calculations,
            }
        if isinstance(calculations, list):
            theseCalculations = dict()
            for calculation in calculations:
                theseCalculations[calculation['name']] = calculation
            calculations = theseCalculations
        super().__init__(**calculations)
        self._log = logging.getLogger(__class__.__module__)
Example #23
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self._project_dict = None
     self._model = QStandardItemModel()
     # set roles
     self._a_role, self._b_role, self._c_role, self._alpha_role, self._beta_role, self._gamma_role = [
         Qt.UserRole + 1 + i for i in range(6)
     ]
     self._model.setItemRoleNames({
         self._a_role: b'length_a',
         self._b_role: b'length_b',
         self._c_role: b'length_c',
         self._alpha_role: b'angle_alpha',
         self._beta_role: b'angle_beta',
         self._gamma_role: b'angle_gamma'
     })
     self._log = logger.getLogger(self.__class__.__module__)
Example #24
0
    def __init__(self, MSPtype: Base, chi_11: Base, chi_22: Base, chi_33: Base,
                 chi_12: Base, chi_13: Base, chi_23: Base):
        super().__init__(type=MSPtype,
                         chi_11=chi_11,
                         chi_22=chi_22,
                         chi_33=chi_33,
                         chi_12=chi_12,
                         chi_13=chi_13,
                         chi_23=chi_23)
        self._log = logging.getLogger(__class__.__module__)
        self._log.debug('MSP created: %s', self)

        self.setItemByPath(['type', 'header'], 'Type')

        self.setItemByPath(['chi_11', 'header'], 'U11')
        self.setItemByPath(['chi_11', 'tooltip'],
                           ATOM_DETAILS['MSP']['tooltip'])
        self.setItemByPath(['chi_11', 'url'], ATOM_DETAILS['MSP']['url'])

        self.setItemByPath(['chi_12', 'header'], 'U12')
        self.setItemByPath(['chi_12', 'tooltip'],
                           ATOM_DETAILS['MSP']['tooltip'])
        self.setItemByPath(['chi_12', 'url'], ATOM_DETAILS['MSP']['url'])

        self.setItemByPath(['chi_13', 'header'], 'U13')
        self.setItemByPath(['chi_13', 'tooltip'],
                           ATOM_DETAILS['MSP']['tooltip'])
        self.setItemByPath(['chi_13', 'url'], ATOM_DETAILS['MSP']['url'])

        self.setItemByPath(['chi_22', 'header'], 'U22')
        self.setItemByPath(['chi_22', 'tooltip'],
                           ATOM_DETAILS['MSP']['tooltip'])
        self.setItemByPath(['chi_22', 'url'], ATOM_DETAILS['MSP']['url'])

        self.setItemByPath(['chi_23', 'header'], 'U23')
        self.setItemByPath(['chi_23', 'tooltip'],
                           ATOM_DETAILS['MSP']['tooltip'])
        self.setItemByPath(['chi_23', 'url'], ATOM_DETAILS['MSP']['url'])

        self.setItemByPath(['chi_33', 'header'], 'U33')
        self.setItemByPath(['chi_33', 'tooltip'],
                           ATOM_DETAILS['MSP']['tooltip'])
        self.setItemByPath(['chi_33', 'url'], ATOM_DETAILS['MSP']['url'])
    def __init__(self,
                 calculator: 'easyInterface.Diffraction.Calculator') -> None:
        """
        Initialise an interface with a `calculator` of the `easyInterface.Diffraction.Calculator` class.

        :param calculator: Calculator of the `easyInterface.Diffraction.Calculator` class.
        """

        self._log: logging.logger = logging.getLogger(__class__.__module__)
        self.project_dict: ProjectDict = ProjectDict.default()
        self.calculator = calculator
        # Set the calculator info
        CALCULATOR_INFO = self.calculator.calculatorInfo()
        for key in CALCULATOR_INFO.keys():
            self.project_dict['calculator'][key] = CALCULATOR_INFO[key]
        self.__last_updated: datetime = datetime.max
        self.__last_calculated: datetime = datetime.min
        self.setProjectFromCalculator()
        self._log.info("Created: %s", self)
Example #26
0
    def __init__(self, u: Base, v: Base, w: Base, x: Base, y: Base):
        """
        Dictionary store for resolution parameters

        :param u: resolution parameter u
        :param v: resolution parameter v
        :param w:  resolution parameter w
        :param x:  resolution parameter x
        :param y:  resolution parameter y
        """
        super().__init__(u=u, v=v, w=w, x=x, y=y)
        self._log = logging.getLogger(__class__.__module__)

        self.setItemByPath(['u', 'header'],
                           RESOLUTION_DETAILS['UVWXY']['header'])
        self.setItemByPath(['u', 'tooltip'],
                           RESOLUTION_DETAILS['UVWXY']['tooltip'])
        self.setItemByPath(['u', 'url'], RESOLUTION_DETAILS['UVWXY']['url'])

        self.setItemByPath(['v', 'header'],
                           RESOLUTION_DETAILS['UVWXY']['header'])
        self.setItemByPath(['v', 'tooltip'],
                           RESOLUTION_DETAILS['UVWXY']['tooltip'])
        self.setItemByPath(['v', 'url'], RESOLUTION_DETAILS['UVWXY']['url'])

        self.setItemByPath(['w', 'header'],
                           RESOLUTION_DETAILS['UVWXY']['header'])
        self.setItemByPath(['w', 'tooltip'],
                           RESOLUTION_DETAILS['UVWXY']['tooltip'])
        self.setItemByPath(['w', 'url'], RESOLUTION_DETAILS['UVWXY']['url'])

        self.setItemByPath(['x', 'header'],
                           RESOLUTION_DETAILS['UVWXY']['header'])
        self.setItemByPath(['x', 'tooltip'],
                           RESOLUTION_DETAILS['UVWXY']['tooltip'])
        self.setItemByPath(['x', 'url'], RESOLUTION_DETAILS['UVWXY']['url'])

        self.setItemByPath(['y', 'header'],
                           RESOLUTION_DETAILS['UVWXY']['header'])
        self.setItemByPath(['y', 'tooltip'],
                           RESOLUTION_DETAILS['UVWXY']['tooltip'])
        self.setItemByPath(['y', 'url'], RESOLUTION_DETAILS['UVWXY']['url'])
Example #27
0
def time_it(func):
    """
    Times a function and reports the time either to the class' log or the base logger
    :param func: function to be timed
    :return: callable function with timer
    """
    name = func.__module__ + '.' + func.__name__
    time_logger = logger.getLogger('timer.' + name)

    @wraps(func)
    def _time_it(*args, **kwargs):
        start = int(round(time() * 1000))
        try:
            return func(*args, **kwargs)
        finally:
            end_ = int(round(time() * 1000)) - start
            time_logger.debug(
                f"\033[1;34;49mExecution time: {end_ if end_ > 0 else 0} ms\033[0m"
            )

    return _time_it
    def __init__(self,
                 x: list,
                 y_diff_lower: list,
                 y_diff_upper: list,
                 y_calc_up: list,
                 y_calc_down: list = [],
                 y_calc_bkg: list = []):
        y_calc_down_temp = y_calc_down
        if len(y_calc_down) == 0:
            y_calc_down_temp = [0] * len(y_calc_up)

        super().__init__(
            x=x,
            y_calc_sum=np.array(y_calc_up) + np.array(y_calc_down_temp),
            y_calc_diff=np.array(y_calc_up) - np.array(y_calc_down_temp),
            y_calc_up=y_calc_up,
            y_calc_down=y_calc_down,
            y_diff_lower=y_diff_lower,
            y_diff_upper=y_diff_upper,
            y_calc_bkg=y_calc_bkg)
        self._log = logging.getLogger(__class__.__module__)
Example #29
0
    def __init__(self, name: str, spacegroup: SpaceGroup, cell: Cell,
                 atoms: Union[Atom, dict, Atoms], sites: dict):
        """
        Constructor for a crystallographic phase

        :param name: The name of the crystallographic phase
        :param spacegroup: The phase spacegroup information
        :param cell: The unit cell parameters
        :param atoms: A collection of atoms for the unit cell
        """
        if isinstance(atoms, Atom):
            atoms = {
                atoms['atom_site_label']: atoms,
            }
        atoms = Atoms(atoms)
        super().__init__(phasename=name,
                         spacegroup=spacegroup,
                         cell=cell,
                         atoms=atoms,
                         sites=sites)
        self._log = logging.getLogger(__class__.__module__)
        self._log.debug('New phase created %s', name)
Example #30
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self._project_dict = None
     self._model = QStandardItemModel()
     # set roles
     self._label_role = Qt.UserRole + 1
     self._atom_role = Qt.UserRole + 2
     self._color_role = Qt.UserRole + 3
     self._x_role = Qt.UserRole + 4
     self._y_role = Qt.UserRole + 5
     self._z_role = Qt.UserRole + 6
     self._occupancy_role = Qt.UserRole + 7
     self._model.setItemRoleNames({
         self._label_role: b'label',
         self._atom_role: b'atom',
         self._color_role: b'colorStr',
         self._x_role: b'xPos',
         self._y_role: b'yPos',
         self._z_role: b'zPos',
         self._occupancy_role: b'occupancy'
     })
     self._log = logger.getLogger(self.__class__.__module__)