예제 #1
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
예제 #2
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"
        else:
            rlapLabel = "(NO_TEMPLATES)"

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

        return rlapLabel, rlapWarningBool
예제 #3
0
파일: classify.py 프로젝트: Python3pkg/DASH
    def list_best_matches(self, n=5):
        """Returns a list of lists of the the top n best matches for each spectrum"""
        bestTypes, softmaxes, bestLabels, inputImages = self._input_spectra_info(
        )
        bestMatchLists = []
        bestBroadTypes = []
        rejectionLabels = []
        reliableFlags = []
        redshifts = []
        for specNum in range(self.numSpectra):
            bestMatchList = []
            for i in range(20):
                host, name, age = classification_split(bestTypes[specNum][i])
                if not self.knownZ:
                    redshifts.append(
                        self.calc_redshift(inputImages[i], name, age)[0])
                prob = softmaxes[specNum][i]
                bestMatchList.append((host, name, age, prob))
            bestMatchList = np.array(bestMatchList)
            bestMatchLists.append(bestMatchList[0:n])
            bestBroadType, reliableFlag = self.best_broad_type(bestMatchList)
            bestBroadTypes.append(bestBroadType)
            reliableFlags.append(reliableFlag)
            rejectionLabels.append(
                self.false_positive_rejection(bestTypes[specNum][0],
                                              inputImages[specNum]))

        bestMatchLists = np.array(bestMatchLists)

        if not redshifts:
            redshifts = self.redshifts
        else:
            redshifts = np.array(redshifts)

        return bestMatchLists, redshifts, bestBroadTypes, rejectionLabels, reliableFlags
예제 #4
0
파일: gui_main.py 프로젝트: Python3pkg/DASH
    def list_best_matches_single_redshift(self):
        print("listing best matches...")
        redshifts = self.best_redshifts()
        self.listWidget.clear()
        if self.knownRedshift:
            self.listWidget.addItem("".join(word.ljust(25) for word in ['No.', 'Type', 'Age', 'Softmax Prob.']))
        else:
            self.listWidget.addItem("".join(word.ljust(25) for word in ['No.', 'Type', 'Age', 'Redshift', 'Softmax Prob.']))
        for i in range(20):
            host, name, age = classification_split(self.bestTypes[i])
            prob = self.softmax[i]
            redshift = redshifts[i]
            if self.classifyHost:
                if self.knownRedshift:
                    self.listWidget.addItem("".join(word.ljust(25) for word in [str(i + 1), host, name, age, str(prob)]))
                else:
                    self.listWidget.addItem("".join(word.ljust(25) for word in [str(i + 1), host, name, age, str(redshift), str(prob)]))
            else:
                if self.knownRedshift:
                    self.listWidget.addItem("".join(word.ljust(25) for word in [str(i + 1), name, age, str(prob)]))
                else:
                    self.listWidget.addItem("".join(word.ljust(25) for word in [str(i + 1), name, age, str(redshift), str(prob)]))


            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)
            if not self.knownRedshift:
                self.bestRedshift = redshifts[0]
        self.best_broad_type()
예제 #5
0
    def list_best_matches_single_redshift(self):
        print("listing best matches...")
        redshifts = 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.best_broad_type()
예제 #6
0
파일: gui_main.py 프로젝트: Python3pkg/DASH
 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)
     self.labelBestRedshift.setText(str(self.bestRedshift))
     self.labelBestRelProb.setText("%s%%" % str(round(100*probTotal, 2)))
     if reliableFlag:
         self.labelReliableFlag.setText("Reliable")
         self.labelReliableFlag.setStyleSheet('color: green')
     else:
         self.labelReliableFlag.setText("Unreliable")
         self.labelReliableFlag.setStyleSheet('color: red')
예제 #7
0
파일: classify.py 프로젝트: Python3pkg/DASH
    def false_positive_rejection(self, bestType, inputImage):
        host, name, age = classification_split(bestType)
        snInfos, snNames, hostInfos, hostNames = get_templates(
            name, age, host, self.snTemplates, self.galTemplates, self.nw)
        if snInfos != []:
            templateImages = snInfos[:, 1]
            falsePositiveRejection = FalsePositiveRejection(
                inputImage, templateImages)
            rejectionLabel = "NONE"  # "(chi2=%s, rlap=%s)" % (falsePositiveRejection.rejection_label(), falsePositiveRejection.rejection_label2())
        else:
            rejectionLabel = "(NO_TEMPLATES)"

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

        return rejectionLabel
예제 #8
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 = []
        for specNum in range(self.numSpectra):
            bestMatchList = []
            for i in range(20):
                host, name, age = classification_split(bestTypes[specNum][i])
                if not self.knownZ:
                    redshifts.append(self.calc_redshift(inputImages[i], name, age)[0], inputMinMaxIndexes[i])
                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
        else:
            redshifts = np.array(redshifts)

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

        return bestMatchLists, redshifts, bestBroadTypes, rlapLabels, matchesReliableLabels