def main(spectraDir, atelTextFile, saveMatchesFilename):
    filenames, knownRedshifts, wikiClassifications = [], [], []

    # Store all the file paths to the objects in this directory
    allFilePaths = glob.glob('%s/*.dat' % spectraDir)

    # Get filenames and corresponding redshifts
    atels = read_all_atels(atelTextFile)
    for i, row in atels.iterrows():
        count = 0
        for filePath in allFilePaths:
            name = os.path.basename(filePath).replace('.dat', '').split('_')[0]
            if row.Name == name:
                filenames.append(filePath)
                knownRedshifts.append(row.Redshift)
                wikiClassifications.append("{} {}".format(row.Type, row.Phase))
                count += 1
                # break  # Uncomment the break to only classify the last dated spectrum for each object instead of classifying all dates.
        print(count)
        if count == 0:
            print(row.Name)

    # Classify and print the best matches
    classification = astrodash.Classify(filenames, knownRedshifts, classifyHost=False, rlapScores=True, smooth=6, knownZ=True, data_files='models_v04')
    bestFits, redshifts, bestTypes, rlapFlag, matchesFlag = classification.list_best_matches(n=5, saveFilename=saveMatchesFilename)

    print("{0:17} | {1:5} | {2:8} | {3:10} | {4:6} | {5:10} | {6:10}".format("Name", "  z  ", "DASH_Fit", "  Age ", "Prob.", "Flag", "Wiki Fit"))
    for i in range(len(filenames)):
        print("{0:17} | {1:5} | {2:8} | {3:10} | {4:6} | {5:10} | {6:10}".format('_'.join([filenames[i].split('/')[-1].split('_')[0], filenames[i].split('/')[-1].split('_')[3]]) , redshifts[i], bestTypes[i][0], bestTypes[i][1], bestTypes[i][2], matchesFlag[i].replace(' matches',''), wikiClassifications[i]))

    # Plot one of the matches
    classification.plot_with_gui(indexToPlot=7)
def main(runDirectory, atelTextFile, saveMatchesFilename):

    # Store all the file paths to the objects in this run
    directoryPath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                 runDirectory)
    allFilePaths = []
    for dirpath, dirnames, filenames in os.walk(directoryPath):
        for filename in [f for f in filenames if f.endswith(".dat")]:
            allFilePaths.append(os.path.join(dirpath, filename))
    allFilePaths.reverse()

    # Get filenames and corresponding redshifts
    names, knownRedshifts, wikiClassifications = read_ozdes_wiki_atel(
        atelTextFile)
    run = []
    for i in range(len(names)):
        for filePath in allFilePaths:
            if names[i] == filePath.split('/')[-1].split('_')[0]:
                run.append(
                    (filePath, knownRedshifts[i], wikiClassifications[i]))
                #break  # Uncomment the break to only classify the last dated spectrum for each object instead of classifying all dates.
    filenames = [i[0] for i in run]
    knownRedshifts = [i[1] for i in run]
    wikiClassifications = [i[2] for i in run]

    # Classify and print the best matches
    classification = astrodash.Classify(filenames,
                                        knownRedshifts,
                                        classifyHost=False,
                                        rlapScores=True,
                                        smooth=6)
    bestFits, redshifts, bestTypes, rlapFlag, matchesFlag, redshiftErrs = classification.list_best_matches(
        n=5, saveFilename=saveMatchesFilename)
    print("{0:17} | {1:5} | {2:8} | {3:10} | {4:6} | {5:10} | {6:10}".format(
        "Name", "  z  ", "DASH_Fit", "  Age ", "Prob.", "Flag", "Wiki Fit"))
    for i in range(len(filenames)):
        print(
            "{0:17} | {1:5} | {2:8} | {3:10} | {4:6} | {5:10} | {6:10}".format(
                '_'.join([
                    filenames[i].split('/')[-1].split('_')[0],
                    filenames[i].split('/')[-1].split('_')[3]
                ]), redshifts[i], bestTypes[i][0], bestTypes[i][1],
                bestTypes[i][2], matchesFlag[i].replace(' matches', ''),
                wikiClassifications[i]))

    # Plot one of the matches
    classification.plot_with_gui(indexToPlot=0)
# for path, subdirs, files in os.walk(directory):
#     for name in files:
#         if name.lower().endswith(extensions):
#             filenames.append(os.path.join(path, name).replace(directory, ''))
# filenames.sort()
# for f in filenames:
#     print("('%s', 0)," % f)

#Convert files to fits

#Get redshifts from MARZ

filenames = [os.path.join(directory, i[0]) for i in atels]
knownRedshifts = [i[1] for i in atels]

classification = astrodash.Classify(filenames, knownRedshifts)
bestFits, bestTypes, rejectionLabels = classification.list_best_matches(n=5)

# SAVE BEST MATCHES
print bestFits
f = open('classification_results.txt', 'w')
for i in range(len(atels)):
    f.write("%s   %s     %s      %s\n %s\n\n" %
            (atels[i][0], atels[i][1], bestTypes[i], rejectionLabels[i],
             bestFits[i]))
f.close()
print("Finished classifying %d spectra!" % len(atels))

# PLOT SPECTRUM ON GUI
# classification.plot_with_gui(indexToPlot=0)
    ('ATEL_9961_Run28/DES16C3elb_C3_combined_161225_v10_b00.dat', 0.429),
    ('ATEL_9961_Run28/DES16X3dvb_X3_combined_161225_v10_b00.dat', 0.329),
    ('ATEL_9961_Run28/DES16C2ege_C2_combined_161225_v10_b00.dat', 0.348),
    ('ATEL_9961_Run28/DES16X3eww_X3_combined_161225_v10_b00.dat', 0.445),
    ('ATEL_9961_Run28/DES16X3enk_X3_combined_161225_v10_b00.dat', 0.331),
    ('ATEL_9961_Run28/DES16S1ffb_S1_combined_161226_v10_b00.dat', 0.164),
    ('ATEL_9961_Run28/DES16C1fgm_C1_combined_161226_v10_b00.dat', 0.361),
    ('ATEL_9961_Run28/DES16X2dzz_X2_combined_161226_v10_b00.dat', 0.325),
    ('ATEL_9961_Run28/DES16X1few_X1_combined_161227_v10_b00.dat', 0.311),
    ('ATEL_9961_Run28/DES16X1chc_X1_combined_161227_v10_b00.dat', 0.043),
    ('ATEL_9961_Run28/DES16S2ffk_S2_combined_161227_v10_b00.dat', 0.373)]

filenames = [os.path.join(directoryPath, i[0]) for i in atels]
knownRedshifts = [i[1] for i in atels]

classification = astrodash.Classify(filenames, knownRedshifts, classifyHost=False, smooth=5, knownZ=True)
bestFits, redshifts, bestTypes, rejectionLabels, reliableFlags = classification.list_best_matches(n=5)

# SAVE BEST MATCHES
print(bestFits)
f = open('classification_results.txt', 'w')
for i in range(len(filenames)):
    f.write("%s   z=%s     %s      %s     %s\n %s\n\n" % (filenames[i].strip(directoryPath), redshifts[i], bestTypes[i], reliableFlags[i], rejectionLabels[i], bestFits[i]))
f.close()
print("Finished classifying %d spectra!" % len(filenames))

# PLOT SPECTRUM ON GUI
classification.plot_with_gui(indexToPlot=18)

Exemple #5
0
import astrodash
import numpy as np

wave = np.arange(2500, 10000, 2)
flux = np.ones(len(wave))
filename = np.array([wave, flux])
# filename = open('/Users/danmuth/PycharmProjects/DASH/templates/superfit_templates/sne/Ib/sn1983N.p12.dat', 'r')
# filename = 'osc-SN2002er-10'
redshift = 0

classification = astrodash.Classify([filename], [redshift],
                                    classifyHost=False,
                                    knownZ=True,
                                    smooth=6,
                                    rlapScores=True)
bestFits, redshifts, bestTypes, rlapFlag, matchesFlag = classification.list_best_matches(
    n=5)

print(bestFits)

classification.plot_with_gui(indexToPlot=0)
Exemple #6
0
    ('VLT/DES16S2dgb_all.txt', 0.57),
    ('VLT/DES16S2ejs_all.txt', 0.38),
    # ('VLT/DES16X1ept_all.txt', 0.),
    ('VLT/DES16X2aey_all.txt', 0.210),
    # ('VLT/DES16X2afc_all.txt', 0.),
    ('VLT/DES16X3bdj_all.txt', 0.200),
    ('VLT/DES16X3bfv_all.txt', 0.60),
    ('VLT/DES16X3cdv_all.txt', 0.824),
    ('VLT/DES16X3cer_all.txt', 1.16),
    ('VLT/DES16X3cxy_all.txt', 0.688),  #0.50
    # ('VLT/DES16X3eyo_all.txt', 0.)
]

filenames = [os.path.join(directory, i[0]) for i in atels]
knownRedshifts = [i[1] for i in atels]

classification = astrodash.Classify(filenames,
                                    knownRedshifts,
                                    classifyHost=True,
                                    rlapScores=True,
                                    knownZ=True)
bestFits, redshifts, bestTypes, rejectionLabels, reliableFlags, redshiftErrs = classification.list_best_matches(
    n=5)

# SAVE BEST MATCHES
print(bestFits)
print("Finished classifying %d spectra!" % len(atels))

# PLOT SPECTRUM ON GUI
classification.plot_with_gui(indexToPlot=1)
Exemple #7
0
#ZTF18aajnqmp

# In[19]:

output_list = []
counter = 0
for i in np.unique(SEDM_ML_sample["ZTF_Name"]):
    try:
        filenames = []
        for j in (SEDM_ML_sample[np.where(
                i == SEDM_ML_sample["ZTF_Name"])]["Version"]):
            filenames.append(sample_location + str(j))

        classification = astrodash.Classify(filenames,
                                            classifyHost=False,
                                            knownZ=False,
                                            smooth=6,
                                            rlapScores=True)
        output = classification.list_best_matches(n=15,
                                                  saveFilename=dash + i +
                                                  '.txt')
        output_name = np.append(np.asarray(output), i)
        output_list.append(output_name)
        if (counter % 100 == 0):
            print(counter)
        counter += 1
    except:
        print(i)
output_list = np.asarray(output_list)

# In[40]: