Ejemplo 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
Ejemplo n.º 2
0
 def best_redshifts(self):
     redshifts = []
     for i in range(20):
         host, name, age = classification_split(self.bestTypes[i])
         redshift, crossCorr, medianName = self.calc_redshift(name, age)
         redshifts.append(redshift)
     return redshifts
Ejemplo n.º 3
0
 def best_broad_type(self):
     bestMatchList = []
     for i in range(10):
         host, name, age = classification_split(self.bestTypes[i])
         bestMatchList.append([host, name, age, self.softmax[i]])
     host, prevName, bestAge, probTotal, reliableFlag = combined_prob(
         bestMatchList)
     self.labelBestSnType.setText(prevName)
     self.labelBestAgeRange.setText(bestAge)
     self.labelBestHostType.setText(host)
     if host == "":
         self.labelBestHostType.setFixedWidth(0)
     if self.bestRedshiftErr is None:
         self.labelBestRedshift.setText(str(self.bestRedshift))
     else:
         self.labelBestRedshift.setText("{} {} {}".format(
             str(self.bestRedshift), "±", self.bestRedshiftErr))
     self.labelBestRelProb.setText("%s%%" % str(round(100 * probTotal, 2)))
     if host == "":
         self.labelBestHostType.setFixedWidth(0)
     if reliableFlag:
         self.labelInconsistentWarning.setText("Reliable matches")
         self.labelInconsistentWarning.setStyleSheet('color: green')
     else:
         self.labelInconsistentWarning.setText("Unreliable matches")
         self.labelInconsistentWarning.setStyleSheet('color: red')
Ejemplo 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()
Ejemplo n.º 5
0
    def list_best_matches(self, n=5, saveFilename='DASH_matches.txt'):
        """Returns a list of lists of the the top n best matches for each spectrum"""
        bestTypes, softmaxes, bestLabels, inputImages, inputMinMaxIndexes = self._input_spectra_info(
        )
        bestMatchLists = []
        bestBroadTypes = []
        rlapLabels = []
        matchesReliableLabels = []
        redshifts = []
        redshiftErrs = []
        for specNum in range(self.numSpectra):
            bestMatchList = []
            for i in range(20):
                host, name, age = classification_split(bestTypes[specNum][i])
                if not self.knownZ:
                    redshift, _, redshiftErr = self.calc_redshift(
                        inputImages[specNum], name, age,
                        inputMinMaxIndexes[specNum])
                    redshifts.append(redshift)
                    redshiftErrs.append(redshiftErr)
                prob = softmaxes[specNum][i]
                bestMatchList.append((host, name, age, prob))
            bestMatchList = np.array(bestMatchList)
            bestMatchLists.append(bestMatchList[0:n])
            bestBroadType, matchesReliableFlag = self.best_broad_type(
                bestMatchList)
            bestBroadTypes.append(bestBroadType)
            rlapLabel, rlapWarningBool = self.rlap_warning_label(
                bestTypes[specNum][0], inputImages[specNum],
                inputMinMaxIndexes[specNum])

            rlapLabels.append(rlapLabel)
            if matchesReliableFlag:
                matchesReliableLabels.append("Reliable matches")
            else:
                matchesReliableLabels.append("Unreliable matches")

        bestMatchLists = np.array(bestMatchLists)

        if not redshifts:
            redshifts = self.redshifts
            redshiftErrs = [None] * len(self.redshifts)
        else:
            redshifts = np.array(redshifts)
            redshiftErrs = np.array(redshiftErrs)

        if saveFilename:
            self.save_best_matches(bestMatchLists, redshifts, bestBroadTypes,
                                   rlapLabels, matchesReliableLabels,
                                   saveFilename)

        return bestMatchLists, redshifts, bestBroadTypes, rlapLabels, matchesReliableLabels, redshiftErrs