コード例 #1
0
def main_process(sid, line):
    os.chdir("Fe2")
    try:
        os.mkdir(str(sid))
    except OSError:
        pass
    os.chdir("../Fe2-fig")
    try:
        os.mkdir(str(sid))
    except OSError:
        pass
    os.chdir("../")
    [wave, flux, fluxerr] = read_raw_data(sid)
    [wave, flux, fluxerr] = mask_points(wave, flux, fluxerr)
    # Extract the part of data for fitting
    [wave, flux, fluxerr] = extract_fit_part(wave, flux, fluxerr, line[0], line[2])
    os.chdir("Fe2-fig/" + str(sid))
    #try:
    [hbeta, bef, aft, o3sn, fesn] = compare_fe2(wave, flux, fluxerr)
    #except Exception as reason:
    #    print(str(reason))
    #    exception_logging(sid, "Fe2", reason)
    #    os.chdir("../../")
    #    return
    os.chdir("../../")
    output_fit(hbeta, sid, "Hbeta")
    output_fit(bef, sid, "bef")
    output_fit(aft, sid, "aft")
    os.chdir("Fe2/")
    sn_file = open(str(sid) + ".txt", "a")
    sn_file.write("%9.4f    %9.4f\n" % (o3sn, fesn))
    sn_file.close()
    os.chdir("../")
    print(o3sn, fesn)
    print("Process finished for " + str(sid))
コード例 #2
0
def mc_ee_single(rmid, mjd):
    print("    Begin for " + str(mjd))
    try:
        [wave, flux, error] = read_raw_data(rmid, mjd)
        # error = pickle.load(open(Location.project_loca + "data/raw/" +
        #                          str(rmid) + "/" + str(mjd) + "/" +
        #                          "error_scaled.pkl", "rb"))
        [wave, flux, error] = mask_points(wave, flux, error)
        [wave, flux, error] = extract_fit_part(wave, flux, error, 4000.0,
                                               5500.0)
    except Exception:
        print("        Unable to locate data file.")
        return [[], []]
    flux_with_noise = noise_gene(flux, error)
    error_with_noise = np.tile(error, [100, 1])
    num_list = list(range(100))
    m = Manager()
    p = Pool(processes=100)
    fit_res = m.list()
    func = partial(get_flux, wave, rmid, mjd, fit_res)
    args = list()
    for i in range(len(flux_with_noise)):
        args.append([flux_with_noise[i], error_with_noise[i], num_list[i]])
    p.map(func, args)
    p.close()
    res = np.transpose(np.array(list(fit_res)))
    std_res = list()
    mean_res = list()
    for each in res:
        std_res.append(np.std(each))
        mean_res.append(np.mean(each))
    return [std_res, mean_res]
コード例 #3
0
def rough_finder(sid, hbeta, o3, fe2):
    [wave, flux, ivar] = read_raw_data(sid)
    [wave, flux, ivar] = extract_fit_part(wave, flux, ivar, 4000, 5500)
    [wave, flux, ivar] = mask_points(wave, flux, ivar)
    try:
        [wave, flux, ivar, fig] = cont_handler(wave, flux, ivar)
    except Exception:
        fig.savefig("rough_finder/" + str(sid))
        plt.close()
        return [-1, -1]
    fig.savefig("rough_finder/" + str(sid))
    plt.close() 
    try:
        i_hbeta = find_i(wave, flux, ivar, hbeta[0], hbeta[1])
        i_o3 = find_i(wave, flux, ivar, o3[0], o3[1])
    except ValueError:
        return [0, 0]
    i_fe2 = 0
    for each in fe2:
        try:
            i_fe2 = i_fe2 + find_i(wave, flux, ivar, each[0], each[1])
        except ValueError:
            continue
    o3vshbeta = i_o3 / i_hbeta
    fe2vshbeta = i_fe2 / i_hbeta
    return [o3vshbeta, fe2vshbeta]
コード例 #4
0
def binning_single(rmid, lock, mjd):
    lock.acquire()
    print("Begin for " + str(mjd))
    lock.release()
    os.chdir(Location.project_loca + "data/binned/" + str(rmid))
    try:
        os.mkdir(str(mjd))
    except OSError:
        pass
    [wave, flux, error] = read_raw_data(rmid, mjd)
    [wave, flux, error] = mask_points(wave, flux, error)
    if len(wave) == 0:
        print("No valid data found for " + str(mjd))
        return
    num = math.ceil(len(wave) / 5.0)
    wave = np.array_split(wave, num)
    flux = np.array_split(flux, num)
    error = np.array_split(error, num)
    new_wave = []
    new_flux = []
    new_error = []
    for i in range(len(wave)):
        [temp1, temp2, temp3] = binning_point(wave[i], flux[i], error[i])
        new_wave.append(temp1)
        new_flux.append(temp2)
        new_error.append(temp3)
    output(rmid, mjd, new_wave, "wave")
    output(rmid, mjd, new_flux, "flux")
    output(rmid, mjd, new_error, "error")
    lock.acquire()
    print("Finished for " + str(mjd))
    lock.release()
コード例 #5
0
def mc_ee_single(rmid, mjd):
    print("    Begin for " + str(mjd))
    try:
        [wave, flux, error] = read_raw_data(rmid, mjd)
        # error = pickle.load(open(Location.project_loca + "data/raw/" +
        #                          str(rmid) + "/" + str(mjd) + "/" +
        #                          "error_scaled.pkl", "rb"))
        [wave, flux, error] = mask_points(wave, flux, error)
        [wave, flux, error] = extract_fit_part(wave, flux, error, 4000.0,
                                               5500.0)
    except Exception:
        print("        Unable to locate data file.")
        return [[], []]
    flux_with_noise = noise_gene(flux, error)
    error_with_noise = np.tile(error, [100, 1])
    num_list = list(range(100))
    m = Manager()
    p = Pool(processes=100)
    fit_res = m.list()
    func = partial(get_flux, wave, rmid, mjd, fit_res)
    args = list()
    for i in range(len(flux_with_noise)):
        args.append([flux_with_noise[i], error_with_noise[i], num_list[i]])
    p.map(func, args)
    p.close()
    res = np.transpose(np.array(list(fit_res)))
    std_res = list()
    mean_res = list()
    for each in res:
        std_res.append(np.std(each))
        mean_res.append(np.mean(each))
    return [std_res, mean_res]
コード例 #6
0
ファイル: line_profile.py プロジェクト: chengxinlun/se-finder
def main_process(sid):
    [wave, flux, error] = read_raw_data(str(sid))
    [wave, flux, error] = mask_points(wave, flux, error)
    fit_res = read_fit_res(sid)
    [wave, flux, error] = extract_fit_part(wave, flux, error, fit_res[7] - 2.0 * fit_res[8], fit_res[7] + 2.0 * fit_res[8])
    fwhm = calc_fwhm(wave, flux)
    std = fit_res[8]
    profile = fwhm / std
    print(sid + " " + str(profile))
    return profile
コード例 #7
0
def main_process(sid):
    print("Beginning process for " + str(sid))
    # Read data and preprocessing
    [wave, flux, error] = read_raw_data(sid)
    [wave, flux, error] = mask_points(wave, flux,  error)
    [wave, flux, error] = extract_fit_part(wave, flux, error, 4000.0, 5500.0)
    # Begin fitting and handling exception
    try:
        img_directory = "Fe2"
        [fit_res, cont_res, rcs] = template_fit(wave, flux, error,  img_directory, sid)
    except SpectraException as reason:
        exception_logging(sid, reason)
        print("Failed\n\n")
        return
    output_fit(fit_res, sid, "Fe2")
    output_fit(cont_res, sid, "cont")
    print("Finished\n\n")
コード例 #8
0
def fe_fitter_single(rmid, lock, rcs_dict, mjd):
    # Read data and preprocessing
    try:
        [wave, flux, error] = read_raw_data(rmid, mjd)
        [wave, flux, error] = mask_points(wave, flux, error)
        [wave, flux, error] = extract_fit_part(wave, flux, error, 4000.0,
                                               5500.0)
    except Exception as reason:
        lock.acquire()
        exception_logging(rmid, mjd, reason)
        print("Failed for " + str(mjd))
        lock.release()
        return
    os.chdir(Location.project_loca + "result/fit_with_temp/data")
    try:
        os.mkdir(str(rmid))
    except OSError:
        pass
    os.chdir(Location.project_loca + "result/fit_with_temp/fig")
    try:
        os.mkdir(str(rmid))
    except OSError:
        pass
    # Begin fitting and handling exception
    try:
        [fit_res, cont_res, rcs, numcont,
         numfit] = template_fit(wave, flux, error, True, [], rmid, mjd)
    except Exception as reason:
        lock.acquire()
        exception_logging(rmid, mjd, reason)
        print("Failed for " + str(mjd))
        lock.release()
        return
    output_fit(fit_res, rmid, mjd, "Fe2")
    output_fit(cont_res, rmid, mjd, "cont")
    lock.acquire()
    rcs_dict[mjd] = rcs
    print("Finished for " + str(mjd))
    lock.release()
コード例 #9
0
def get_fwhm_hb(rmid, mjd):
    day_dir = Location.project_loca + "result/fit_with_temp/data/" + \
        str(rmid) + "/" + str(mjd) + "-"
    hb_file = open(day_dir + "Fe2.pkl", "rb")
    hb = pickle.load(hb_file)[10:12]
    hb_file.close()
    cont_file = open(day_dir + "cont.pkl", "rb")
    cont = pickle.load(cont_file)
    cont_file.close()
    cont_func = models.PowerLaw1D(cont[0], cont[1], cont[2])
    [wave, flux, error] = read_raw_data(rmid, mjd)
    [wave, flux,
     error] = extract_fit_part(wave, flux, error, hb[0] - 2.0 * hb[1],
                               hb[0] + 2.0 * hb[1])
    [wave, flux, error] = mask_points(wave, flux, error)
    flux = flux - cont_func(wave)
    up_wave = wave[0:flux.argmax()]
    up_flux = flux[0:flux.argmax()]
    down_flux = flux[flux.argmax():-1]
    down_wave = wave[flux.argmax():-1]
    wave_min = find_wave(up_wave, up_flux, 0.5 * np.amax(flux))
    wave_max = find_wave(down_wave, down_flux, 0.5 * np.amax(flux))
    return (wave_max - wave_min) / hb[1]
コード例 #10
0
def fe_fitter_single(rmid, lock, rcs_dict, mjd):
    # Read data and preprocessing
    try:
        [wave, flux, error] = read_raw_data(rmid, mjd)
        [wave, flux, error] = mask_points(wave, flux,  error)
        [wave, flux, error] = extract_fit_part(wave, flux, error, 4000.0, 5500.0)
    except Exception as reason:
        lock.acquire()
        exception_logging(rmid, mjd, reason)
        print("Failed for " + str(mjd))
        lock.release()
        return
    os.chdir(Location.project_loca + "result/fit_with_temp/data")
    try:
        os.mkdir(str(rmid))
    except OSError:
        pass
    os.chdir(Location.project_loca + "result/fit_with_temp/fig")
    try:
        os.mkdir(str(rmid))
    except OSError:
        pass
    # Begin fitting and handling exception
    try:
        [fit_res, cont_res, rcs, numcont, numfit] = template_fit(wave, flux, error, True, [], rmid, mjd)
    except Exception as reason:
        lock.acquire()
        exception_logging(rmid, mjd, reason)
        print("Failed for " + str(mjd))
        lock.release()
        return
    output_fit(fit_res, rmid, mjd, "Fe2")
    output_fit(cont_res, rmid, mjd, "cont")
    lock.acquire()
    rcs_dict[mjd] = rcs
    print("Finished for " + str(mjd))
    lock.release()