Ejemplo n.º 1
0
def rspec(path=None, local=False, filt=""):
    """Return a random spectra built from fits file in given path."""
    # Get path
    if path is None:
        path = loc.shortpath('All')
    if local:
        # path = '/home/extra/AstroFiles/fits/'
        path = loc.shortpath('local')
    fits = [x for x in os.listdir(path) if '.fits' in x]
    fits = [x for x in fits if filt in x.lower()]
    fname = path + rand.choice(fits)
    try:
        s = spectrum(fname)
        return s
    except:
        fname = path + rand.choice(fits)
        # try:
        s = spectrum(fname)
        return s
    # except Exception as e:
        print "ERROR MAKING SPECTRUM: ", e
        return None

    print len(fits)
    return path
def submit_button(self):
    pt_index = self.ui.tabWidget.currentIndex()
    if pt_index == 0:
        ct_index = self.ui.tabWidget_2.currentIndex()
        if ct_index == 0:
            extract_input(self, 0)
        if ct_index == 1:
            extract_input(self, 1)
        if ct_index == 2:
            rename_files(self)
        if ct_index == 3:
            determine_similarity(self)
    if pt_index == 1:
        ct_index = self.ui.tabWidget_3.currentIndex()
        if ct_index == 0:
            Extract_SPE(self)
        if ct_index == 1:
            Extract_Thermo(self)
        if ct_index == 2:
            spectrum(self)
        if ct_index == 3:
            rotate_gjf(self)
        if ct_index == 4:
            Mass_Props(self)
        if ct_index == 5:
            analyze_temperature(self)
    if pt_index == 2:
        preferences(self)
Ejemplo n.º 3
0
def all_specs(filt='', path=None, local=False, close=True):
    """Return all of the files in the path given as spectra."""
    # Get path
    if path is None:
        path = loc.shortpath('All')
        print 'got new path'
    if local:
        path = loc.shortpath('local')
    specs = []
    m.cd(path)
    m.pwd()
    print path
    files = m.ls(True, filt=filt, ext='.fits')
    ercounter = 0
    print 'There are {} files'.format(len(files))
    for f in files:
        try:
            s = spectrum(f)
            specs.append(s)
            if close:
                s.close()
        except:
            ercounter += 1
    print 'There were {0} errors'.format(ercounter)
    return specs
Ejemplo n.º 4
0
def rspecs(num=1, path=None, local=False, filt=''):
    """Allow for getting a list of multiple specs."""
    # Get path
    if path is None:
        path = loc.shortpath('All')
    if local:
        path = loc.shortpath('local')
    fits = [x for x in m.ls(True, path=path) if '.fits' in x]
    fnames = [x for x in fits if filt in x]
    assert len(fits) != 0, "There were no fit's files in the path"
    # print len(fnames)
    rand.shuffle(fnames)
    specs = []
    counter = 0
    while len(specs) < num:
        try:
            s = spectrum(fnames[counter])
            specs.append(s)
        except Exception as e:
            # print e
            pass
        counter += 1
        if counter > len(fnames):
            print 'Reached the end of available files'
            break
    return specs
Ejemplo n.º 5
0
def all_objs_info(path=None):
    """Return all spectra as well as the number of occs for each spectra."""
    # Get path
    if path is None:
        path = loc.shortpath('All')
        print 'got new path'
    specs = {}
    m.cd(path)
    m.pwd()
    print path
    files = m.ls(True, filt='.fits')
    ercounter = 0
    len_files = len(files)
    print 'There are {} files'.format(len_files)
    for i, f in enumerate(files):
        print '\rFilenumber: {0} \tPercentage Done: {1.4} \tNum Errors: {2}'\
                .format(i, float(i) / len_files * 100, ercounter),
        try:
            s = spectrum(f)
            specs[s.fname] = s.obj_name
            s.close()
        except:
            ercounter += 1
    print 'There were {0} errors'.format(ercounter)
    return specs
Ejemplo n.º 6
0
def all_objs(count=False, path=None):
    """Return all spectra as well as the number of occs for each spectra."""
    # Get path
    if path is None:
        path = loc.shortpath('All')
        print 'got new path'
    specs = {}
    specnum = {}
    m.cd(path)
    m.pwd()
    print path
    files = m.ls(True, filt='.fits')
    ercounter = 0
    len_files = len(files)
    print 'There are {} files'.format(len_files)
    for i, f in enumerate(files):
        print '\rFilenumber: {0}   \tPercentage Done: {1}'\
                .format(i, float(i) / len_files),
        try:
            s = spectrum(f)
            if count:
                num = specnum.get(s.obj_name, 0)
                num += 1
                specnum[s.obj_name] = num
            else:
                specs[s.fname] = s.obj_name
            s.close()
        except:
            ercounter += 1
    print 'There were {0} errors'.format(ercounter)
    if count:
        return specs, specnum
    return specs
Ejemplo n.º 7
0
def getSpecs(path=None, nots=False):
    if path is None:
        try:
            path = "/home/oort/Downloads/AstroFilesRaw/AstroFiles/"
            os.chdir(path)
        except:
            path = "/home/extra/Desktop/AllHA/t1/"
    specs = []
    errors = []
    nots_arr = []
    filenames = [path + x for x in os.listdir(path) if ".fits" in x]
    print "length filenames: ", len(filenames)
    for i, x in enumerate(filenames):
        print i, "\r",
        try:
            s = spectrum(x)
            specs.append(s)
            s.close()
        except Exception as e:
            errors.append(e)
            nots_arr.append(x)
    print "\nlength specs: ", len(specs), "\tlength errors: ", len(errors)
    if nots is True:
        return nots_arr
    return specs, errors
Ejemplo n.º 8
0
def getCors(path=None, nots=False):
    if path is None:
        try:
            path = "/home/oort/Downloads/AstroFilesRaw/AstroFiles/"
            os.chdir(path)
        except:
            # path = '/home/extra/AstroFiles/'
            path = "/home/extra/Desktop/AllHA/t12/"
    specs = []
    errors = []
    nots_arr = []
    dic = {}
    print path
    filenames = [path + x for x in os.listdir(path) if ".fits" in x]
    length = len(filenames)
    finished = 0
    print "length filenames: ", length
    csvfiles = [x for x in os.listdir(path) if ".csv" in x]
    print "Number of CSV files in directory originally: ", len(csvfiles)
    for i, x in enumerate(filenames):
        percent_done = float(i) / length * 100
        print "File Num: {1} \t % Done: {0:.3}".format(percent_done, i), "\r",
        try:
            # print i
            s = spectrum(x)
            specs.append(s)
            name = x.split("/")[-1]
            s.convertCSVNew()
            dic[name] = s.csv_name
            s.close()
            # print 'closed'
            finished += 1
        except Exception as e:
            errors.append([i, e])
            nots_arr.append(x)
    print "\nlength specs: ", len(specs), "\tlength finished: ", finished, "\tlength errors: ", len(errors)
    if nots:
        return nots_arr
    print ""
    csvfiles = [x for x in os.listdir(path) if ".csv" in x]
    print "Number of CSV files in directory: ", len(csvfiles)
    return dic, errors
Ejemplo n.º 9
0
os.chdir(path)
file_paths = [path + x for x in os.listdir(path) if ".fits" in x]

ans = raw_input("wanna check? y/n")
if ans == "y":

    for x in file_paths:
        print x

specs = []
nots = []

for f in file_paths:
    try:
        specs.append(spectrum(f))
    except:
        nots.append(f)

print ""
print "Number that worked: ", len(specs)
print "Number that didnt work: ", len(nots)
print ""

same = 0
fnames = []
for s in specs:
    name = ("").join(s.obj_name.split())
    fname = name + "_" + str(s.hjd).split(".")[0] + "_" + str(s.hjd).split(".")[1]
    if fname in fnames:
        same += 1