Пример #1
0
    def OnAmplitudeCheck(self, event=None):
        """ Enable/Disable BG rate text line.
            New feature introduced in 0.7.8
        """
        modelid = self.corr.fit_model.id
        # Normalization to a certain parameter in plots
        # Find all parameters that start with an "N"
        # ? and "C" ?
        # Create List
        normlist = list()
        normlist.append("None")
        # Add parameters
        parameterlist = list()
        for i in np.arange(len(self.active_parms[0])):
            label = self.active_parms[0][i]
            if label[0].lower() == "n":
                normlist.append("*" + label)
                parameterlist.append(i)
        # Add supplementary parameters
        # Get them from models
        supplement = mdls.GetMoreInfo(modelid, self)
        if supplement is not None:
            for i in np.arange(len(supplement)):
                label = supplement[i][0]
                if label[0].lower() == "n":
                    normlist.append("*" + label)
                    # Add the id of the supplement starting at the
                    # number of fitting parameters of current page.
                    parameterlist.append(i + len(self.active_parms[0]))
        normsel = self.AmplitudeInfo[2].GetSelection()
        if normsel in [0, -1]:
            # init or no normalization selected
            self.corr.normparm = None
            normsel = 0
        else:
            self.corr.normparm = parameterlist[normsel - 1]

        if len(parameterlist) > 0:
            self.AmplitudeInfo[2].Enable()
            self.AmplitudeInfo[3].Enable()
        else:
            self.AmplitudeInfo[2].Disable()
            self.AmplitudeInfo[3].Disable()
        # Set dropdown values
        self.AmplitudeInfo[2].SetItems(normlist)
        self.AmplitudeInfo[2].SetSelection(normsel)
        # Plot intensities
        # Quick reminder:
        # self.AmplitudeInfo = [ [intlabel1, intlabel2],
        #                       [bgspin1, bgspin2],
        #                       normtoNDropdown, textnor]
        # Signal
        self.AmplitudeInfo[0][0].SetValue("{:.4f}".format(0))
        self.AmplitudeInfo[0][1].SetValue("{:.4f}".format(0))
        for i in range(len(self.corr.traces)):
            S = self.corr.traces[i].countrate
            self.AmplitudeInfo[0][i].SetValue("{:.4f}".format(S))
        if self.corr.is_cc:
            self.AmplitudeInfo[0][1].Enable()
        else:
            self.AmplitudeInfo[0][1].Disable()
        # Background
        # self.parent.Background[self.bgselected][i]
        # [0] average signal [kHz]
        # [1] signal name (edited by user)
        # [2] signal trace (tuple) ([ms], [kHz])
        if len(self.corr.backgrounds) >= 1:
            self.AmplitudeInfo[1][0].SetValue(
                self.corr.backgrounds[0].countrate)
        else:
            self.AmplitudeInfo[1][0].SetValue(0)
            self.AmplitudeInfo[1][1].SetValue(0)

        if len(self.corr.backgrounds) == 2:
            self.AmplitudeInfo[1][1].SetValue(
                self.corr.backgrounds[1].countrate)
        else:
            self.AmplitudeInfo[1][1].SetValue(0)
        # Disable the second line in amplitude correction, if we have
        # autocorrelation only.
        boolval = self.corr.is_cc
        for item in self.WXAmplitudeCCOnlyStuff:
            item.Enable(boolval)
Пример #2
0
    def GetPageInfo(self, Page):
        """ Needs a Page and gets all information from it """
        Page.PlotAll("init")
        # A dictionary with headings as keys and lists of singletts/tuples as
        # values. If it is a tuple, it might me interesting for a table.
        InfoDict = dict()
        # Get Correlation
        corr = Page.corr

        # Get model information
        model = corr.fit_model
        parms = corr.fit_parameters
        fct = corr.fit_model.function.__name__
        InfoDict["version"] = [Page.parent.version]
        Title = list()
        # The tool statistics relys on the string "filename/title".
        # Do not change it!
        if len(model[1]) == 0:
            # Prevent saving no title
            model[1] = "NoName"
        Title.append(["filename/title", Page.title])
        Title.append(["Model species", model.components])
        Title.append(["Model name", model.name])
        Title.append(["Model ID", str(model.id)])
        Title.append(["Model function", fct])
        Title.append(["Page number", Page.counter[1:-2]])
        ## Parameters
        Parameters = list()
        # Use this function to determine human readable parameters, if possible
        Units, Newparameters = mdls.GetHumanReadableParms(model.id, parms)
        # Add Parameters
        for i in np.arange(len(parms)):
            Parameters.append([Units[i], Newparameters[i]])
        InfoDict["parameters"] = Parameters
        # Add some more information if available
        # Info is a dictionary or None
        MoreInfo = mdls.GetMoreInfo(model.id, Page)
        if MoreInfo is not None:
            InfoDict["supplement"] = MoreInfo
            # Try to get the dictionary entry of a model
            try:
                # This function should return all important information
                # that can be calculated from the given parameters.
                func_info = mdls.supplement[model.id]
            except KeyError:
                # No information available
                pass
            else:
                InfoDict["modelsupdoc"] = [func_info.func_doc]
        ## Fitting

        if hasattr(corr, "fit_results"):
            Fitting = list()
            weightedfit = corr.fit_results["weighted fit"]
            if corr.correlation is not None:
                # Mode AC vs CC
                if corr.is_cc:
                    Title.append(["Type AC/CC", "Cross-correlation"])
                else:
                    Title.append(["Type AC/CC", "Autocorrelation"])
                if "chi2" in corr.fit_results:
                    Fitting.append([u"χ²", corr.fit_results["chi2"]])
                if weightedfit:
                    try:
                        Fitting.append([
                            "Weighted fit",
                            corr.fit_results["weighted fit type"]
                        ])
                    except KeyError:
                        Fitting.append(
                            ["Weighted fit", u"" + Page.Fitbox[1].GetValue()])
                if corr.fit_results.has_key("chi2 type"):
                    ChiSqType = corr.fit_results["chi2 type"]
                else:
                    ChiSqType = "unknown"
                Fitting.append([u"χ²-type", ChiSqType])
                Fitting.append(
                    ["Algorithm", fit.Algorithms[corr.fit_algorithm][1]])
                if len(Page.GlobalParameterShare) != 0:
                    shared = str(Page.GlobalParameterShare[0])
                    for item in Page.GlobalParameterShare[1:]:
                        shared += ", " + str(item)
                    Fitting.append(["Shared parameters with Pages", shared])
                if corr.fit_results.has_key("weighted fit bins"):
                    Fitting.append([
                        "Std. channels",
                        2 * corr.fit_results["weighted fit bins"] + 1
                    ])
                # Fitting range:
                t1 = 1. * corr.lag_time[corr.fit_ival[0]]
                t2 = 1. * corr.lag_time[corr.fit_ival[1] - 1]
                Fitting.append(["Ival start [ms]", "%.4e" % t1])
                Fitting.append(["Ival end [ms]", "%.4e" % t2])
                # Fittet parameters
                try:
                    fitparmsid = corr.fit_results["fit parameters"]
                except:
                    fitparmsid = corr.fit_parameters_variable
                fitparms = np.array(corr.fit_model.parameters[0])[fitparmsid]
                fitparms_short = [f.split()[0] for f in fitparms]
                fitparms_short = u", ".join(fitparms_short)
                Fitting.append(["Fit parm.", fitparms_short])
                # global fitting
                for key in corr.fit_results.keys():
                    if key.startswith("global"):
                        Fitting.append(
                            [key.capitalize(), corr.fit_results[key]])
                # Fit errors
                if corr.fit_results.has_key("fit error estimation"):
                    errors = corr.fit_results["fit error estimation"]
                    for err, par in zip(errors, fitparms):
                        nam, val = mdls.GetHumanReadableParameterDict(
                            model.id, [par], [err])
                        Fitting.append(["Err " + nam[0], val[0]])

                InfoDict["fitting"] = Fitting

        ## Normalization parameter id to name
        if corr.normparm is None:
            normparmtext = "None"
        elif corr.normparm < len(corr.fit_parameters):
            normparmtext = corr.fit_model.parameters[0][corr.normparm]
        else:
            # supplementary parameters
            supnum = corr.normparm - len(corr.fit_parameters)
            normparmtext = MoreInfo[supnum][0]
        Title.append(["Normalization", normparmtext])

        ## Background
        Background = list()
        if corr.is_cc:
            if len(corr.backgrounds) == 2:
                # Channel 1
                Background.append(["bg name Ch1", corr.backgrounds[0].name])
                Background.append(
                    ["bg rate Ch1 [kHz]", corr.backgrounds[0].countrate])
                # Channel 2
                Background.append(["bg name Ch2", corr.backgrounds[1].name])
                Background.append(
                    ["bg rate Ch2 [kHz]", corr.backgrounds[1].countrate])
                InfoDict["background"] = Background
        else:
            if len(corr.backgrounds) == 1:
                Background.append(["bg name", corr.backgrounds[0].name])
                Background.append(
                    ["bg rate [kHz]", corr.backgrounds[0].countrate])
                InfoDict["background"] = Background
        ## Function doc string
        InfoDict["modeldoc"] = [corr.fit_model.description_long]
        InfoDict["title"] = Title

        return InfoDict