Exemplo n.º 1
0
    def rlap_warning_label(self, bestType, inputImage, inputMinMaxIndex):
        host, name, age = classification_split(bestType)
        snInfos, snNames, hostInfos, hostNames = get_templates(
            name, age, host, self.snTemplates, self.galTemplates, self.nw)
        if snInfos != []:
            if self.rlapScores:
                templateImages = snInfos[:, 1]
                templateMinMaxIndexes = list(zip(snInfos[:, 2], snInfos[:, 3]))
                rlapCalc = RlapCalc(inputImage, templateImages, snNames,
                                    self.wave, inputMinMaxIndex,
                                    templateMinMaxIndexes)
                rlap, rlapWarningBool = rlapCalc.rlap_label()
                if rlapWarningBool:
                    rlapLabel = "Low rlap: {0}".format(rlap)
                else:
                    rlapLabel = "Good rlap: {0}".format(rlap)
            else:
                rlapLabel = "No rlap"
                rlapWarningBool = "None"
        else:
            rlapLabel = "(NO_TEMPLATES)"
            rlapWarningBool = "None"

        # import matplotlib
        # matplotlib.use('TkAgg')
        # import matplotlib.pyplot as plt
        # plt.plot(inputImage)
        # plt.plot(templateImage)
        # plt.show()

        return rlapLabel, rlapWarningBool
Exemplo n.º 2
0
    def plot_best_matches(self):
        if self.plotted:
            templateWave = self.wave * (1 + (self.plotZ))
            self.labelTemplateName.setText(self.templatePlotName)

            self.graphicsView.clear()
            inputPlotFlux = self.inputImageUnRedshifted
            self.graphicsView.plot(self.wave, inputPlotFlux, name='Input Spectrum', pen={'color': (0, 255, 0)})
            self.graphicsView.plot(templateWave, self.templatePlotFlux, name=self.templatePlotName,
                                   pen={'color': (255, 0, 0)})
            self.graphicsView.setXRange(int(self.w0), int(self.w1))
            self.graphicsView.setYRange(0, 1)
            self.graphicsView.plotItem.showGrid(x=True, y=True, alpha=0.95)
            self.graphicsView.plotItem.setLabels(bottom="Observed Wavelength (<font>&#8491;</font>)")

            try:
                self.cAxis.setScale(1 / (1 + self.plotZ))
            except ZeroDivisionError:
                print("Invalid redshift. Redshift cannot be -1.")
            self.cAxis.setGrid(False)
            self.cAxis.setLabel("Rest Wavelength (<font>&#8491;</font>)")

            if np.any(self.templatePlotFlux):
                rlapCalc = RlapCalc(self.inputImageUnRedshifted, [self.templatePlotFlux], [self.templatePlotName],
                                    self.wave, self.inputMinMaxIndex, [self.templateMinMaxIndex])
                rlap = rlapCalc.rlap_label()[0]
                self.labelRlapScore.setText("rlap: {0}".format(rlap))
Exemplo n.º 3
0
    def low_rlap_warning_label(self, bestName, bestAge, bestHost):
        fluxes, snNames, templateMinMaxIndexes = self.get_smoothed_templates(bestName, bestAge, bestHost)
        rlapCalc = RlapCalc(self.inputImageUnRedshifted, fluxes, snNames, self.wave, self.inputMinMaxIndex,
                            templateMinMaxIndexes)
        rlapLabel, rlapWarning = rlapCalc.rlap_label()

        return rlapLabel, rlapWarning
Exemplo n.º 4
0
    def list_best_matches_single_redshift(self):
        print("listing best matches...")
        redshifts, redshiftErrs = self.best_redshifts()
        self.listWidget.clear()

        header = ['No.', 'Type', 'Age', 'Softmax Prob.']
        if self.classifyHost:
            header.insert(1, 'Host')
        if not self.knownRedshift:
            header.insert(3, 'Redshift')
        if self.getRlapScores:
            header.insert(5, 'rlap')
        self.listWidget.addItem("".join(word.ljust(25) for word in header))

        for i in range(20):
            host, name, age = classification_split(self.bestTypes[i])
            prob = self.softmax[i]
            redshift = redshifts[i]

            line = [str(i + 1), name, age, str(prob)]
            if self.classifyHost:
                line.insert(1, host)
            if not self.knownRedshift:
                line.insert(3, str(redshift))
            if self.getRlapScores:
                fluxes, snNames, templateMinMaxIndexes = self.get_smoothed_templates(
                    name, age, host)
                rlapCalc = RlapCalc(self.inputImageUnRedshifted, fluxes,
                                    snNames, self.wave, self.inputMinMaxIndex,
                                    templateMinMaxIndexes)
                rlap = rlapCalc.rlap_label()[0]
                line.insert(5, str(rlap))
            self.listWidget.addItem("".join(word.ljust(25) for word in line))

            if i == 0:
                SNTypeComboBoxIndex = self.comboBoxSNType.findText(name)
                self.comboBoxSNType.setCurrentIndex(SNTypeComboBoxIndex)
                AgeComboBoxIndex = self.comboBoxAge.findText(age)
                self.comboBoxAge.setCurrentIndex(AgeComboBoxIndex)
                hostComboBoxIndex = self.comboBoxHost.findText(host)
                self.comboBoxHost.setCurrentIndex(hostComboBoxIndex)

                rlap, rlapWarning = self.low_rlap_warning_label(
                    name, age, host)
                if rlapWarning:
                    self.labelRlapWarning.setText("Low rlap: {0}".format(rlap))
                    self.labelRlapWarning.setStyleSheet('color: red')
                else:
                    self.labelRlapWarning.setText(
                        "Good rlap: {0}".format(rlap))
                    self.labelRlapWarning.setStyleSheet('color: green')

            if not self.knownRedshift:
                self.bestRedshift = redshifts[0]
                self.bestRedshiftErr = redshiftErrs[0]
        self.best_broad_type()