コード例 #1
0
ファイル: spectype_main_V1.py プロジェクト: georgezhou/hsfu23
def test_template(data_type,data_spectrum,teff,logg,feh,start_lambda,end_lambda,shift):
    ### Import a template spectrum - test
    template_spectrum = "template_" + str(teff) + "_" + str(logg) + "_" + str(feh) + ".dat"

    if data_type=="flux":
        template_spectrum = functions.read_ascii(model_path_flux + template_spectrum)
    if data_type=="norm":
        template_spectrum = functions.read_ascii(model_path_norm + template_spectrum)

    template_spectrum = functions.read_table(template_spectrum)
    template_spectrum = transpose(array(template_spectrum))

    if data_type=="flux":
        template_spectrum = spectype_functions.normalise(template_spectrum,flux_normalise_w1,flux_normalise_w2)

    ### Chop both spectra
    data_region = spectype_numerical_functions.chop_spectrum(data_spectrum,start_lambda,end_lambda)
    template_region = spectype_numerical_functions.chop_spectrum(template_spectrum,start_lambda,end_lambda)

    ### Conform template spectrum to data spectrum -> same wavelength scale
    template_region = spectype_numerical_functions.conform_spectrum(data_region,template_region)

    ### Find shift

    data_region_shifted,template_region_shifted = spectype_functions.shift_spectrum(data_region,template_region,shift)
    chisq = spectype_numerical_functions.chisq(data_region_shifted,template_region_shifted)

    # plt.clf()
    # plt.plot(data_region_shifted[0],data_region_shifted[1])
    # plt.plot(template_region_shifted[0],template_region_shifted[1])
    # plt.title(data_type + " " + str(teff) + " " + str(logg) + " " + str(feh) +" " + str(chisq))
    # plt.show()

    return chisq
コード例 #2
0
ファイル: spectype_main_V1.py プロジェクト: georgezhou/hsfu23
def find_shift(data_type,data_spectrum,teff,logg,feh,start_lambda,end_lambda):
    ### Import the template spectrum
    template_spectrum = "template_" + str(teff) + "_" + str(logg) + "_" + str(feh) + ".dat"

    if data_type=="flux":
        template_spectrum = functions.read_ascii(model_path_flux + template_spectrum)
    if data_type=="norm":
        template_spectrum = functions.read_ascii(model_path_norm + template_spectrum)

    template_spectrum = functions.read_table(template_spectrum)
    template_spectrum = transpose(array(template_spectrum))

    if data_type=="flux":
        template_spectrum =spectype_functions.normalise(template_spectrum,flux_normalise_w1,flux_normalise_w2)

    ### Chop both spectra
    data_region = spectype_numerical_functions.chop_spectrum(data_spectrum,start_lambda,end_lambda)
    template_region = spectype_numerical_functions.chop_spectrum(template_spectrum,start_lambda,end_lambda)

    ### Conform template spectrum to data spectrum -> same wavelength scale
    template_region = spectype_numerical_functions.conform_spectrum(data_region,template_region)

    ### Find shift
    chisq_shift = []

    shift_limit = 20
    shift  = -1*shift_limit
    while shift <= shift_limit:
        data_region_shifted,template_region_shifted = spectype_functions.shift_spectrum(data_region,template_region,shift)
        chisq_shift.append(spectype_numerical_functions.chisq(data_region_shifted,template_region_shifted))
        shift = shift + 1

    chisq_min = spectype_functions.find_min(chisq_shift)
    best_shift = chisq_min - shift_limit
    return best_shift