def __init__(self, project=None): """ Initializes the AppModel with the given Project. """ super(AppModel, self).__init__() self.needs_plot_update = Signal() self.current_project = project if project: project.parent = self
def __init__(self, *args, **kwargs): """ Constructor takes any of its properties as a keyword argument. It also support two UUID list keyword arguments: - phase_uuids: a list of UUID's for the phases in the mixture - specimen_uuids: a list of UUID's for the specimens in the mixture These should be *instead* of the phases and specimens keywords. In addition to the above, the constructor still supports the following deprecated keywords, mapping to a current keyword: - phase_indeces: a list of project indices for the phases in the mixture - specimen_indeces: a list of project indices for the specimens in the mixture Any other arguments or keywords are passed to the base class. """ my_kwargs = self.pop_kwargs( kwargs, "data_name", "phase_uuids", "phase_indeces", "specimen_uuids", "specimen_indeces", "data_phases", "data_scales", "data_bgshifts", "data_fractions", "refine_method", "data_refine_method", "fractions", "bgshifts", "scales", "phases", *[ names[0] for names in type(self).Meta.get_local_storable_properties() ]) super(Mixture, self).__init__(*args, **kwargs) kwargs = my_kwargs with self.data_changed.hold(): self._data_object = MixtureData() self.needs_reset = Signal() self.needs_update = HoldableSignal() self.name = self.get_kwarg(kwargs, "New Mixture", "name", "data_name") self.auto_run = self.get_kwarg(kwargs, False, "auto_run") self.auto_bg = self.get_kwarg(kwargs, True, "auto_bg") # 2D matrix, rows match specimens, columns match mixture 'phases'; contains the actual phase objects phase_uuids = self.get_kwarg(kwargs, None, "phase_uuids") phase_indeces = self.get_kwarg(kwargs, None, "phase_indeces") if phase_uuids is not None: self.phase_matrix = np.array([[ type(type(self)).object_pool.get_object(uuid) if uuid else None for uuid in row ] for row in phase_uuids], dtype=np.object_) elif phase_indeces and self.parent is not None: warn( "The use of object indices is deprecated since version 0.4. Please switch to using object UUIDs.", DeprecationWarning) self.phase_matrix = np.array([[ self.parent.phases.get_user_data_from_index(index) if index != -1 else None for index in row ] for row in phase_indeces], dtype=np.object_) else: self.phase_matrix = np.empty(shape=(0, 0), dtype=np.object_) # list with actual specimens, indexes match with rows in phase_matrix specimen_uuids = self.get_kwarg(kwargs, None, "specimen_uuids") specimen_indeces = self.get_kwarg(kwargs, None, "specimen_indeces") if specimen_uuids: self.specimens = [ type(type(self)).object_pool.get_object(uuid) if uuid else None for uuid in specimen_uuids ] elif specimen_indeces and self.parent is not None: warn( "The use of object indices is deprecated since version 0.4. Please switch to using object UUIDs.", DeprecationWarning) self.specimens = [ self.parent.specimens.get_user_data_from_index(index) if index != -1 else None for index in specimen_indeces ] else: self.specimens = list() # list with mixture phase names, indexes match with cols in phase_matrix self.phases = self.get_kwarg(kwargs, list(), "phases", "data_phases") # list with scale values, indexes match with rows in phase_matrix (= specimens) self.scales = np.asarray( self.get_kwarg(kwargs, [1.0] * len(self.specimens), "scales", "data_scales")) # list with specimen background shift values, indexes match with rows in phase_matrix (=specimens) self.bgshifts = np.asarray( self.get_kwarg(kwargs, [0.0] * len(self.specimens), "bgshifts", "data_bgshifts")) # list with phase fractions, indexes match with cols in phase_matrix (=phases) self.fractions = np.asarray( self.get_kwarg(kwargs, [0.0] * len(self.phases), "fractions", "data_fractions")) # sanity check: n, m = self.phase_matrix.shape if self.phase_matrix.ndim == 2 else ( 0, 0) if len(self.scales) != n or len(self.specimens) != n or len( self.bgshifts) != n: raise IndexError, "Shape mismatch: scales (%d), background shifts (%d) or specimens (%d) list lengths do not match with row count (%d) of phase matrix" % ( len(self.scales), len(self.specimens), len( self.bgshifts), n) if len(self.phases) != m or len(self.fractions) != m: raise IndexError, "Shape mismatch: fractions or phases lists do not match with column count of phase matrix" self._observe_specimens() self._observe_phases() self.optimizer = Optimizer(parent=self) self.refinement = Refinement( refine_method_index=self.get_kwarg(kwargs, 0, "refine_method_index", "refine_method", "data_refine_method"), refine_options=self.get_kwarg(kwargs, dict(), "refine_options"), parent=self) self.update() self.observe_model(self) pass # end hold data_changed
def __init__(self, parent=None, *args, **kwargs): super(ChildModel, self).__init__(*args, **kwargs) self.removed = Signal() self.added = Signal() self.parent = parent
def __init__(self, marker_peaks=[], *args, **kwargs): super(MineralScorer, self).__init__(*args, **kwargs) self._matches = [] self.matches_changed = Signal() self.marker_peaks = marker_peaks # position, intensity