nfft无法与奇数图像尺寸一起使用!在ehtim

发布于 2025-01-26 01:48:14 字数 7168 浏览 4 评论 0原文

我正在尝试使用Python软件包EHTIM获取合成VLBI图像(使用了事件地平线望远镜的数据)。示例符合文件,一切正常。但是,当我尝试添加一个黑洞时,借助射线追踪(使用WCS坐标网格)生成的图像时,


from __future__ import division
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import ehtim as eh
from   ehtim.calibrating import self_cal as sc
import time
#from  ehtim.plotting import self_cal as sc
plt.close('all')

ttype = 'direct'

# Load the image and the array
im = eh.image.load_fits('disk_SchildWH.fits')
eht = eh.array.load_txt('EHT2017.txt')

# Look at the image
im.display()

# Observe the image
# tint_sec is the integration time in seconds, and tadv_sec is the advance time between scans
# tstart_hr is the GMST time of the start of the observation and tstop_hr is the GMST time of the end
# bw_hz is the  bandwidth in Hz
# sgrscat=True blurs the visibilities with the Sgr A* scattering kernel for the appropriate image frequency
# ampcal and phasecal determine if gain variations and phase errors are included
tint_sec = 5
tadv_sec = 600
tstart_hr = 0
tstop_hr = 24
bw_hz = 4e9
obs = im.observe(eht, tint_sec, tadv_sec, tstart_hr, tstop_hr, bw_hz,
                 sgrscat=False, ampcal=True, phasecal=False)

npix = 32
fov = 1.5*im.xdim * im.psize # slightly enlarge the field of view


# Resolution
beamparams = obs.fit_beam() # fitted beam parameters (fwhm_maj, fwhm_min, theta) in radians
res = obs.res() # nominal array resolution, 1/longest baseline
print("Clean beam parameters: " , beamparams)
print("Nominal Resolution: " ,res)

# Export the visibility data to uvfits/text
#obs.save_txt('obs.txt') # exports a text file with the visibilities
#obs.save_uvfits('obs.uvp') # exports a UVFITS file modeled on template.UVP

# Generate an image prior
npix = 128
fov = 1*im.fovx()
zbl = im.total_flux() # total flux
prior_fwhm = 200*eh.RADPERUAS # Gaussian size in microarcssec
emptyprior = eh.image.make_square(obs, npix, fov)
flatprior = emptyprior.add_flat(zbl)
gaussprior = emptyprior.add_gauss(zbl, (prior_fwhm, prior_fwhm, 0, 0, 0))

# Image total flux with bispectrum
flux = zbl
tt = time.time()
out  = eh.imager_func(obs, gaussprior, gaussprior, flux,
                      d1='bs', s1='simple',
                      alpha_s1=1, alpha_d1=100,
                      alpha_flux=100, alpha_cm=50,
                      maxit=100, ttype=ttype, show_updates=False)

# Blur the image with a circular beam and image again to help convergance
out = out.blur_circ(res)
out = eh.imager_func(obs, out, out, flux,
                d1='bs', s1='tv',
                alpha_s1=1, alpha_d1=50,
                alpha_flux=100, alpha_cm=50,
                maxit=100,ttype=ttype, show_updates=False)

out = out.blur_circ(res/2.0)
out = eh.imager_func(obs, out, out, flux,
                d1='bs', s1='tv',
                alpha_s1=1, alpha_d1=10,
                alpha_flux=100, alpha_cm=50,
                maxit=100,ttype=ttype, show_updates=False)

print ("total time: ", time.time() - tt)

outblur = out.blur_gauss(beamparams, 0.5)
out.display()

我遇到了一个错误,

Generating empty observation file . . . 
Producing clean visibilities from image with nfft FT . . . 

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
/tmp/ipykernel_196400/2864228422.py in <module>
     32 tstop_hr = 24
     33 bw_hz = 4e9
---> 34 obs = im.observe(eht, tint_sec, tadv_sec, tstart_hr, tstop_hr, bw_hz,
     35                  sgrscat=False, ampcal=True, phasecal=False)
     36 

~/.local/lib/python3.10/site-packages/ehtim/image.py in observe(self, array, tint, tadv, tstart, tstop, bw, mjd, timetype, polrep_obs, elevmin, elevmax, ttype, fft_pad_factor, fix_theta_GMST, sgrscat, add_th_noise, jones, inv_jones, opacitycal, ampcal, phasecal, frcal, dcal, rlgaincal, stabilize_scan_phase, stabilize_scan_amp, neggains, tau, taup, gain_offset, gainp, dterm_offset, caltable_path, seed, sigmat, verbose)
   2497 
   2498         # Observe on the same baselines as the empty observation and add noise
-> 2499         obs = self.observe_same(obs, ttype=ttype, fft_pad_factor=fft_pad_factor,
   2500                                 sgrscat=sgrscat, add_th_noise=add_th_noise,
   2501                                 jones=jones, inv_jones=inv_jones,

~/.local/lib/python3.10/site-packages/ehtim/image.py in observe_same(self, obs_in, ttype, fft_pad_factor, sgrscat, add_th_noise, jones, inv_jones, opacitycal, ampcal, phasecal, frcal, dcal, rlgaincal, stabilize_scan_phase, stabilize_scan_amp, neggains, taup, gain_offset, gainp, dterm_offset, caltable_path, seed, sigmat, verbose)
   2353             np.random.seed(seed=seed)
   2354 
-> 2355         obs = self.observe_same_nonoise(obs_in, sgrscat=sgrscat,ttype=ttype, 
   2356                                         cache=False, fft_pad_factor=fft_pad_factor,
   2357                                         zero_empty_pol=True, verbose=verbose)

~/.local/lib/python3.10/site-packages/ehtim/image.py in observe_same_nonoise(self, obs, sgrscat, ttype, cache, fft_pad_factor, zero_empty_pol, verbose)
   2270         # Extract uv datasample
   2271         uv = obsh.recarr_to_ndarr(obsdata[['u', 'v']], 'f8')
-> 2272         data = simobs.sample_vis(self, uv, sgrscat=sgrscat, polrep_obs=obs.polrep,
   2273                                  ttype=ttype, cache=cache, fft_pad_factor=fft_pad_factor,
   2274                                  zero_empty_pol=zero_empty_pol, verbose=verbose)

~/.local/lib/python3.10/site-packages/ehtim/observing/obs_simulate.py in sample_vis(im_org, uv, sgrscat, polrep_obs, ttype, cache, fft_pad_factor, zero_empty_pol, verbose)
    299         uvdim = len(uv)
    300         if (im.xdim % 2 or im.ydim % 2):
--> 301             raise Exception("NFFT doesn't work with odd image dimensions!")
    302 
    303         npad = fft_pad_factor * np.max((im.xdim, im.ydim))

Exception: NFFT doesn't work with odd image dimensions!

似乎NFFT与.fits不起作用,具有奇数图像尺寸。但是,我的.fit image只有二维形状(63,63),可以通过使用Astropy来显示:

import matplotlib.pyplot as plt
from astropy.utils.data import get_pkg_data_filename
from astropy.io import fits

image_file = get_pkg_data_filename('disk_SchildWH.fits')


fits.info(image_file)

这给出了

Filename: disk_SchildWH.fits
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU       8   (63, 63)   float64   

此拟合文件的尺寸均匀,并且所有内容都可以正常工作,但是> > EHTIM无法产生图像。也许有人知道为什么会发生?在这里,我添加了代码中使用的文件(eht txt array and .fits file):

https://drive.google.com/file/d/1bhpj52w4qhs5pv--xd7_sjrnkb_yr4or/view?usp = sharing?usp = sharing

? /file/d/d/1fpqesn0aigila5ey1hgptdhlzhhixh2_/view?usp =共享“ rel =” nofollow noreferrer“> https://drive.google.com/file.com/file.com/file/file/d/1fpqesn0aigila5ey1 ey1hgptdhlzhlzhh2_h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2h2spr.shring us

I'm trying to obtain the synthetic VLBI image using the python package ehtim (data of the Event Horizon Telescope is being used). Everything works fine with the example .fits files. However, when I'm trying to add a black hole .fits image generated with the help of ray-tracing (with the WCS coordinate grid) with the code


from __future__ import division
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import ehtim as eh
from   ehtim.calibrating import self_cal as sc
import time
#from  ehtim.plotting import self_cal as sc
plt.close('all')

ttype = 'direct'

# Load the image and the array
im = eh.image.load_fits('disk_SchildWH.fits')
eht = eh.array.load_txt('EHT2017.txt')

# Look at the image
im.display()

# Observe the image
# tint_sec is the integration time in seconds, and tadv_sec is the advance time between scans
# tstart_hr is the GMST time of the start of the observation and tstop_hr is the GMST time of the end
# bw_hz is the  bandwidth in Hz
# sgrscat=True blurs the visibilities with the Sgr A* scattering kernel for the appropriate image frequency
# ampcal and phasecal determine if gain variations and phase errors are included
tint_sec = 5
tadv_sec = 600
tstart_hr = 0
tstop_hr = 24
bw_hz = 4e9
obs = im.observe(eht, tint_sec, tadv_sec, tstart_hr, tstop_hr, bw_hz,
                 sgrscat=False, ampcal=True, phasecal=False)

npix = 32
fov = 1.5*im.xdim * im.psize # slightly enlarge the field of view


# Resolution
beamparams = obs.fit_beam() # fitted beam parameters (fwhm_maj, fwhm_min, theta) in radians
res = obs.res() # nominal array resolution, 1/longest baseline
print("Clean beam parameters: " , beamparams)
print("Nominal Resolution: " ,res)

# Export the visibility data to uvfits/text
#obs.save_txt('obs.txt') # exports a text file with the visibilities
#obs.save_uvfits('obs.uvp') # exports a UVFITS file modeled on template.UVP

# Generate an image prior
npix = 128
fov = 1*im.fovx()
zbl = im.total_flux() # total flux
prior_fwhm = 200*eh.RADPERUAS # Gaussian size in microarcssec
emptyprior = eh.image.make_square(obs, npix, fov)
flatprior = emptyprior.add_flat(zbl)
gaussprior = emptyprior.add_gauss(zbl, (prior_fwhm, prior_fwhm, 0, 0, 0))

# Image total flux with bispectrum
flux = zbl
tt = time.time()
out  = eh.imager_func(obs, gaussprior, gaussprior, flux,
                      d1='bs', s1='simple',
                      alpha_s1=1, alpha_d1=100,
                      alpha_flux=100, alpha_cm=50,
                      maxit=100, ttype=ttype, show_updates=False)

# Blur the image with a circular beam and image again to help convergance
out = out.blur_circ(res)
out = eh.imager_func(obs, out, out, flux,
                d1='bs', s1='tv',
                alpha_s1=1, alpha_d1=50,
                alpha_flux=100, alpha_cm=50,
                maxit=100,ttype=ttype, show_updates=False)

out = out.blur_circ(res/2.0)
out = eh.imager_func(obs, out, out, flux,
                d1='bs', s1='tv',
                alpha_s1=1, alpha_d1=10,
                alpha_flux=100, alpha_cm=50,
                maxit=100,ttype=ttype, show_updates=False)

print ("total time: ", time.time() - tt)

outblur = out.blur_gauss(beamparams, 0.5)
out.display()

I get an error

Generating empty observation file . . . 
Producing clean visibilities from image with nfft FT . . . 

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
/tmp/ipykernel_196400/2864228422.py in <module>
     32 tstop_hr = 24
     33 bw_hz = 4e9
---> 34 obs = im.observe(eht, tint_sec, tadv_sec, tstart_hr, tstop_hr, bw_hz,
     35                  sgrscat=False, ampcal=True, phasecal=False)
     36 

~/.local/lib/python3.10/site-packages/ehtim/image.py in observe(self, array, tint, tadv, tstart, tstop, bw, mjd, timetype, polrep_obs, elevmin, elevmax, ttype, fft_pad_factor, fix_theta_GMST, sgrscat, add_th_noise, jones, inv_jones, opacitycal, ampcal, phasecal, frcal, dcal, rlgaincal, stabilize_scan_phase, stabilize_scan_amp, neggains, tau, taup, gain_offset, gainp, dterm_offset, caltable_path, seed, sigmat, verbose)
   2497 
   2498         # Observe on the same baselines as the empty observation and add noise
-> 2499         obs = self.observe_same(obs, ttype=ttype, fft_pad_factor=fft_pad_factor,
   2500                                 sgrscat=sgrscat, add_th_noise=add_th_noise,
   2501                                 jones=jones, inv_jones=inv_jones,

~/.local/lib/python3.10/site-packages/ehtim/image.py in observe_same(self, obs_in, ttype, fft_pad_factor, sgrscat, add_th_noise, jones, inv_jones, opacitycal, ampcal, phasecal, frcal, dcal, rlgaincal, stabilize_scan_phase, stabilize_scan_amp, neggains, taup, gain_offset, gainp, dterm_offset, caltable_path, seed, sigmat, verbose)
   2353             np.random.seed(seed=seed)
   2354 
-> 2355         obs = self.observe_same_nonoise(obs_in, sgrscat=sgrscat,ttype=ttype, 
   2356                                         cache=False, fft_pad_factor=fft_pad_factor,
   2357                                         zero_empty_pol=True, verbose=verbose)

~/.local/lib/python3.10/site-packages/ehtim/image.py in observe_same_nonoise(self, obs, sgrscat, ttype, cache, fft_pad_factor, zero_empty_pol, verbose)
   2270         # Extract uv datasample
   2271         uv = obsh.recarr_to_ndarr(obsdata[['u', 'v']], 'f8')
-> 2272         data = simobs.sample_vis(self, uv, sgrscat=sgrscat, polrep_obs=obs.polrep,
   2273                                  ttype=ttype, cache=cache, fft_pad_factor=fft_pad_factor,
   2274                                  zero_empty_pol=zero_empty_pol, verbose=verbose)

~/.local/lib/python3.10/site-packages/ehtim/observing/obs_simulate.py in sample_vis(im_org, uv, sgrscat, polrep_obs, ttype, cache, fft_pad_factor, zero_empty_pol, verbose)
    299         uvdim = len(uv)
    300         if (im.xdim % 2 or im.ydim % 2):
--> 301             raise Exception("NFFT doesn't work with odd image dimensions!")
    302 
    303         npad = fft_pad_factor * np.max((im.xdim, im.ydim))

Exception: NFFT doesn't work with odd image dimensions!

It seems that nfft does not work with the .fits, that have odd image dimensions. But, my .fits image is only two-dimensional with shape (63,63), which could be shown with the use of astropy:

import matplotlib.pyplot as plt
from astropy.utils.data import get_pkg_data_filename
from astropy.io import fits

image_file = get_pkg_data_filename('disk_SchildWH.fits')


fits.info(image_file)

This gives

Filename: disk_SchildWH.fits
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU       8   (63, 63)   float64   

So the dimension of this fits file is even and everything shold work fine, but ehtim fails to produce an image. Maybe someone has a clue why does it happens? Here I add the files that was used in the code (EHT txt array and .fits file):

https://drive.google.com/file/d/1bhpJ52W4QHS5Pv--Xd7_SjrNKb_yR4oR/view?usp=sharing

https://drive.google.com/file/d/1FpQEsN0AIGiLa5EY1HGpTdhLZHHIXh2_/view?usp=sharing

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

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

发布评论

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