Ejemplo n.º 1
0
    def __init__(self,
                 filenames=[],
                 redshifts=[],
                 smooth=6,
                 minWave=3500,
                 maxWave=10000,
                 classifyHost=False,
                 knownZ=True,
                 rlapScores=True,
                 data_files='models_v06'):
        """ Takes a list of filenames and corresponding redshifts for supernovae.
        Files should contain a single spectrum, and redshifts should be a list of corresponding redshift floats
        """
        # download_all_files('v01')
        self.filenames = filenames
        self.redshifts = redshifts
        self.smooth = smooth
        self.minWave = minWave
        self.maxWave = maxWave
        self.classifyHost = classifyHost
        self.numSpectra = len(filenames)
        self.scriptDirectory = os.path.dirname(os.path.abspath(__file__))
        if knownZ and redshifts != []:
            self.knownZ = True
        else:
            self.knownZ = False
        if not self.redshifts:
            self.redshifts = [None] * len(filenames)
        self.rlapScores = rlapScores
        self.pars = get_training_parameters()
        self.nw, w0, w1 = self.pars['nw'], self.pars['w0'], self.pars['w1']
        self.dwlog = np.log(w1 / w0) / self.nw
        self.wave = w0 * np.exp(np.arange(0, self.nw) * self.dwlog)
        self.snTemplates, self.galTemplates = load_templates(
            os.path.join(self.scriptDirectory, data_files,
                         'models/sn_and_host_templates.npz'))

        if self.knownZ:
            if classifyHost:
                self.modelFilename = os.path.join(
                    self.scriptDirectory, data_files,
                    "models/zeroZ_classifyHost/tensorflow_model.ckpt")
            else:
                self.modelFilename = os.path.join(
                    self.scriptDirectory, data_files,
                    "models/zeroZ/tensorflow_model.ckpt")
        else:
            if self.classifyHost:
                raise ValueError(
                    "A model that classifies the host while simulatenously not knowing redshift does not "
                    "exist currently. Please try one of the other 3 models or check back at a later "
                    "date. Contact the author for support or further queries.")
                # self.modelFilename = os.path.join(self.scriptDirectory, data_files,
                #                                   "models/agnosticZ_classifyHost/tensorflow_model.ckpt")
            else:
                self.modelFilename = os.path.join(
                    self.scriptDirectory, data_files,
                    "models/agnosticZ/tensorflow_model.ckpt")
Ejemplo n.º 2
0
    def __init__(self, inputFlux, templateFluxes, templateNames, wave, inputMinMaxIndex, templateMinMaxIndexes):
        self.templateFluxes = templateFluxes
        self.templateNames = templateNames
        self.wave = wave
        pars = get_training_parameters()
        w0, w1, self.nw, = pars['w0'], pars['w1'], pars['nw']
        self.inputFlux = mean_zero_spectra(inputFlux, inputMinMaxIndex[0], inputMinMaxIndex[1], self.nw)
        self.templateMinMaxIndexes = templateMinMaxIndexes

        self.dwlog = np.log(w1 / w0) / self.nw
Ejemplo n.º 3
0
    def templates(self):
        pars = get_training_parameters()
        self.w0, self.w1, self.minAge, self.maxAge, self.ageBinSize, self.typeList, self.nTypes, self.nw, self.hostTypes \
            = pars['w0'], pars['w1'], pars['minAge'], pars['maxAge'], pars['ageBinSize'], pars['typeList'], pars['nTypes'], pars['nw'], pars['galTypeList']

        self.dwlog = np.log(self.w1 / self.w0) / self.nw
        self.wave = self.w0 * np.exp(np.arange(0, self.nw) * self.dwlog)

        self.snTemplates, self.galTemplates = load_templates(
            os.path.join(self.mainDirectory, self.data_files,
                         'models/sn_and_host_templates.npz'))
Ejemplo n.º 4
0
    def __init__(self,
                 filenames=[],
                 redshifts=[],
                 smooth=6,
                 minWave=3500,
                 maxWave=10000,
                 classifyHost=False,
                 knownZ=True,
                 rlapScores=True,
                 data_files='models_v04'):
        """ Takes a list of filenames and corresponding redshifts for supernovae.
        Files should contain a single spectrum, and redshifts should be a list of corresponding redshift floats
        """
        # download_all_files('v01')
        self.filenames = filenames
        self.redshifts = redshifts
        self.smooth = smooth
        self.minWave = minWave
        self.maxWave = maxWave
        self.classifyHost = classifyHost
        self.numSpectra = len(filenames)
        self.scriptDirectory = os.path.dirname(os.path.abspath(__file__))
        if knownZ and redshifts != []:
            self.knownZ = True
        else:
            self.knownZ = False
        self.rlapScores = rlapScores
        self.pars = get_training_parameters()
        self.nw, w0, w1 = self.pars['nw'], self.pars['w0'], self.pars['w1']
        self.dwlog = np.log(w1 / w0) / self.nw
        self.wave = w0 * np.exp(np.arange(0, self.nw) * self.dwlog)
        self.snTemplates, self.galTemplates = load_templates(
            os.path.join(self.scriptDirectory, data_files,
                         'models/sn_and_host_templates.npz'))

        if self.knownZ:
            if classifyHost:
                self.modelFilename = os.path.join(
                    self.scriptDirectory, data_files,
                    "models/zeroZ_classifyHost/tensorflow_model.ckpt")
            else:
                self.modelFilename = os.path.join(
                    self.scriptDirectory, data_files,
                    "models/zeroZ/tensorflow_model.ckpt")
        else:
            if self.classifyHost:
                self.modelFilename = os.path.join(
                    self.scriptDirectory, data_files,
                    "models/agnosticZ_classifyHost/tensorflow_model.ckpt")
            else:
                self.modelFilename = os.path.join(
                    self.scriptDirectory, data_files,
                    "models/agnosticZ/tensorflow_model.ckpt")
Ejemplo n.º 5
0
    def _input_spectrum_single_redshift(self):
        trainParams = get_training_parameters()
        loadInputSpectraUnRedshifted = LoadInputSpectra(self.inputFilename, 0, self.smooth, trainParams, self.minWave,
                                                        self.maxWave, self.classifyHost)
        inputImageUnRedshifted, inputRedshift, typeNamesList, nw, nBins, minMaxIndexUnRedshifted = loadInputSpectraUnRedshifted.input_spectra()

        loadInputSpectra = LoadInputSpectra(self.inputFilename, self.knownZ, self.smooth, trainParams, self.minWave,
                                            self.maxWave, self.classifyHost)
        inputImage, inputRedshift, typeNamesList, nw, nBins, minMaxIndex = loadInputSpectra.input_spectra()
        bestTypesList = BestTypesListSingleRedshift(self.modelFilename, inputImage, typeNamesList, nw, nBins)
        bestTypes = bestTypesList.bestTypes[0]
        softmax = bestTypesList.softmaxOrdered[0]
        idx = bestTypesList.idx[0]

        return bestTypes, softmax, idx, typeNamesList, inputImageUnRedshifted[0], minMaxIndexUnRedshifted[0]