示例#1
0
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 = dash.Classify(filenames,
                                   knownRedshifts,
                                   classifyHost=False,
                                   rlapScores=True,
                                   smooth=6)
    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=0)
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 = dash.Classify(filenames,
                                   knownRedshifts,
                                   classifyHost=False,
                                   rlapScores=True,
                                   smooth=6,
                                   knownZ=True)
    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)
示例#3
0
import dash
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 = dash.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)
示例#4
0
import dash

directoryPath = '/Users/dmuthukrishna/Documents/OzDES_data/ATEL_9742_Run26'

atel9742 = [('DES16E1ciy_E1_combined_161101_v10_b00.dat', 0.174),
            ('DES16S1cps_S1_combined_161101_v10_b00.dat', 0.274),
            ('DES16E2crb_E2_combined_161102_v10_b00.dat', 0.229),
            ('DES16E2clk_E2_combined_161102_v10_b00.dat', 0.367),
            ('DES16E2cqq_E2_combined_161102_v10_b00.dat', 0.426),
            ('DES16X2ceg_X2_combined_161103_v10_b00.dat', 0.335),
            ('DES16X2bkr_X2_combined_161103_v10_b00.dat', 0.159),
            ('DES16X2crr_X2_combined_161103_v10_b00.dat', 0.312),
            ('DES16X2cpn_X2_combined_161103_v10_b00.dat', 0.28),
            ('DES16X2bvf_X2_combined_161103_v10_b00.dat', 0.135),
            ('DES16C1cbg_C1_combined_161103_v10_b00.dat', 0.111),
            ('DES16C2cbv_C2_combined_161103_v10_b00.dat', 0.109),
            ('DES16C1bnt_C1_combined_161103_v10_b00.dat', 0.351),
            ('DES16C3at_C3_combined_161031_v10_b00.dat', 0.217),
            ('DES16X3cpl_X3_combined_161031_v10_b00.dat', 0.205),
            ('DES16E2cjg_E2_combined_161102_v10_b00.dat', 0.48),
            ('DES16X2crt_X2_combined_161103_v10_b00.dat', 0.57)]

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

classification = dash.Classify(filenames, knownRedshifts)
bestFits, bestTypes = classification.list_best_matches(n=1)
print(bestFits)
np.savetxt('Run26_fits.txt', bestFits, fmt='%s')
# classification.plot_with_gui(indexToPlot=1)
示例#5
0
    # ('VLT/DES16S2bpf_all.txt', 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 = dash.Classify(filenames,
                               knownRedshifts,
                               classifyHost=False,
                               rlapScores=True)
bestFits, redshifts, bestTypes, rejectionLabels, reliableFlags = 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)
示例#6
0
knownRedshifts = []
for (snid, name, field, z, specType, filename) in ozdesList:
    if filename != 0:
        filenames.append(filename)
        if snid in cidNew:
            newListIndex = np.where(cidNew == snid)[0][0]
            # print(z-zNew[newListIndex])
            z = zNew[newListIndex]
        knownRedshifts.append(z)
        names.append(name)
        # shutil.copy2(directory+filename, './copiedFiles')
t1 = time.time()
print("Time spent reading files: {0:.2f}".format(t1 - t0))
classification = dash.Classify(filenames,
                               knownRedshifts,
                               classifyHost=False,
                               smooth=7,
                               knownZ=True)
bestFits, redshifts, bestTypes, rejectionLabels, reliableFlags = classification.list_best_matches(
    n=5)
t2 = time.time()
print("Time spent classifying: {0:.2f}".format(t2 - t1))
# 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" %
            (names[i], redshifts[i], bestTypes[i], reliableFlags[i],
             rejectionLabels[i], bestFits[i]))
f.close()
print("Finished classifying %d spectra!" % len(filenames))
    ('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 = dash.Classify(filenames, knownRedshifts, classifyHost=False)
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(atels)):
    f.write("%s   z=%s     %s     %s      %s\n %s\n\n" %
            (atels[i][0], atels[i][1], bestTypes[i], reliableFlags[i],
             rejectionLabels[i], bestFits[i]))
f.close()
print("Finished classifying %d spectra!" % len(atels))

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