二维光谱银河数据的信噪比合并

发布于 2025-01-11 14:44:42 字数 2347 浏览 0 评论 0原文

我有长缝摄谱仪拍摄的椭圆星系 NGC 4697 的 2D 光谱。在此处输入图像描述x 方向(水平)对应于波长,y 方向对应于波长(垂直)对应于距星系中心的距离,而中间最亮的行是半径等于0的星系中心区域。由于我走得越远,信噪比就越差(增加y) ,我想将中心外信噪比较差的行合并在一起,以获得更好的信噪比,合并的一维光谱,我想稍后用于运动学光谱分析。

 def calc_signal_noise(lam, flux):
    '''calculate the signal to noise ratio of the galaxy spectra'''
    # cut out part of the spectrum without absorption features
    flux_section = flux[(lam >= 8.6075) & (lam <= 8.62)]
    lam_section = lam[(lam >= 8.6075) & (lam <= 8.62)]
    # fit polynom to the data in this part
    pol_coeff = np.polyfit(lam_section, flux_section, 5)
    pol_val = np.polyval(pol_coeff, lam_section)
    # calculate the rms error
    rms_error = np.std(pol_val-flux_section)
    signal_noise = np.median(flux_section/rms_error)
    return signal_noise

这是计算 S/N 比的函数,我现在想编写一个函数来对我的行进行装箱,直到获得所需的大约 50 的 S/N。

 def bin_spectra(data, cent_row, S_N_lim):
    """ bin spectra for different radii to achieve similar S/N for each binned spectra"""
    # variables:
    # data = 2 dimensional spectral data, where x-dir=wavelength and y-dir=distance from center, in our case data_gal
    # cent_row = int vor y-value (radius = 0 )
    # S_N_lim = minimal S/N ratio needed for spectral analysis
    # split data i
    data_upper = data()
    data_lower
    # Do I use the same wavelength array for all rows ?
    # extract 1D-spectrum for central row
    # take mean of more then 1 row to achieve better S/N ratio
    flux_gal_cent = data_gal[cent_row, :]  # first look on spectra in SAOImage ds9, row 597 corresponds to a central region
    w_gal = WCS(hdr_gal, naxis=1, relax=False, fix=False)
    loglam_gal = w_gal.wcs_pix2world(np.arange(len(flux_gal)), 0)[0]

    S_N = calc_signal_noise(loglam_gal, flux_gal_cent)

我不知道如何完成这个。我想从中心行开始,然后独立地从中心行向上和向下放置垃圾箱。如果我对行进行分箱/平均的信噪比达到约 50,我想将通量、波长、信噪比和距中心行的半径存储在 txt 文件中。

我有一个想法如何对多行进行平均:

flux_gal = np.mean(data_gal[n_row1:n_row2,:], 0) to get the mean of rows n_row1 through (n_row2 - 1)

并且我知道如何计算多行的半径:

radius = (n_row_center-np.mean(n_row1, n_row22))*0.2  #output in arcseconds

但我无法将其串成一个连贯的函数。关于编程方法或如何构造函数的任何提示都会对我有很大帮助。

I have the 2D spectrum of the ellipical galaxy NGC 4697 taken by a long slit spectrograph.enter image description hereThe x-direction (horizontal) corresponds to wavelength and the y-direction (vertical) corresponds to distance from the center of galaxy, while the brightest row in the middle, is the central region of the galaxy where the radius equals 0. Since the S/N ratio gets worse the further I go out (increase y), I want to bin rows with a worse S/N outside the center together to achieve a better S/N, the binned 1D spectra, I want to use for kinematical spectral analysis later.

 def calc_signal_noise(lam, flux):
    '''calculate the signal to noise ratio of the galaxy spectra'''
    # cut out part of the spectrum without absorption features
    flux_section = flux[(lam >= 8.6075) & (lam <= 8.62)]
    lam_section = lam[(lam >= 8.6075) & (lam <= 8.62)]
    # fit polynom to the data in this part
    pol_coeff = np.polyfit(lam_section, flux_section, 5)
    pol_val = np.polyval(pol_coeff, lam_section)
    # calculate the rms error
    rms_error = np.std(pol_val-flux_section)
    signal_noise = np.median(flux_section/rms_error)
    return signal_noise

This is the function that calculates the S/N ratio, I now want to write a function which bins my rows until I get the desired S/N of about 50.

 def bin_spectra(data, cent_row, S_N_lim):
    """ bin spectra for different radii to achieve similar S/N for each binned spectra"""
    # variables:
    # data = 2 dimensional spectral data, where x-dir=wavelength and y-dir=distance from center, in our case data_gal
    # cent_row = int vor y-value (radius = 0 )
    # S_N_lim = minimal S/N ratio needed for spectral analysis
    # split data i
    data_upper = data()
    data_lower
    # Do I use the same wavelength array for all rows ?
    # extract 1D-spectrum for central row
    # take mean of more then 1 row to achieve better S/N ratio
    flux_gal_cent = data_gal[cent_row, :]  # first look on spectra in SAOImage ds9, row 597 corresponds to a central region
    w_gal = WCS(hdr_gal, naxis=1, relax=False, fix=False)
    loglam_gal = w_gal.wcs_pix2world(np.arange(len(flux_gal)), 0)[0]

    S_N = calc_signal_noise(loglam_gal, flux_gal_cent)

I am not sure how to complete this. I wanted to start from the central row and then bin rows upper and lower from the central row independently. If my binned/averaged over rows achieve a S/N of about 50 I want to store the flux, the wavelength, the S/N and the radius from the central row in a txt file.

I have an idea how to average over multiple rows :

flux_gal = np.mean(data_gal[n_row1:n_row2,:], 0) to get the mean of rows n_row1 through (n_row2 - 1)

and I know how to calculate the radius for multiple rows:

radius = (n_row_center-np.mean(n_row1, n_row22))*0.2  #output in arcseconds

but I cant string it together into one coherent function. Any tips on the programming approach or how to structure the function would help me out a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文