Skip to content

Commit cbf6686

Browse files
committed
added multifrequency blurring to image.py
1 parent 7762c81 commit cbf6686

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

ehtim/image.py

+41-20
Original file line numberDiff line numberDiff line change
@@ -3358,7 +3358,7 @@ def display(self, pol=None, cfun=False, interp='gaussian',
33583358
scale_lw=1, beam_lw=1, cbar_fontsize=12, axis=None,
33593359
scale_fontsize=12,
33603360
power=0,
3361-
beamcolor='w', scalecolor='w',dpi=500):
3361+
beamcolor='w', beampos='right', scalecolor='w',dpi=500):
33623362
"""Display the image.
33633363
33643364
Args:
@@ -3624,8 +3624,12 @@ def display(self, pol=None, cfun=False, interp='gaussian',
36243624
im = plt.imshow(imarr, alpha=alpha, cmap=cmap, interpolation=interp)
36253625

36263626
if not(beamparams is None or beamparams is False):
3627-
beamparams = [beamparams[0], beamparams[1], beamparams[2],
3628-
-.35 * self.fovx(), -.35 * self.fovy()]
3627+
if beampos=='left':
3628+
beamparams = [beamparams[0], beamparams[1], beamparams[2],
3629+
+.4 * self.fovx(), -.4 * self.fovy()]
3630+
else:
3631+
beamparams = [beamparams[0], beamparams[1], beamparams[2],
3632+
-.35 * self.fovx(), -.35 * self.fovy()]
36293633
beamimage = self.copy()
36303634
beamimage.imvec *= 0
36313635
beamimage = beamimage.add_gauss(1, beamparams)
@@ -4248,24 +4252,9 @@ def avg_imlist(imlist):
42484252

42494253

42504254
return imavg
4251-
4252-
def get_specim(imlist, reffreq, fit_order=1):
4253-
"""Fit the spectral index for a list of images and return a multifrequency image.
4254-
WARNING: does not correctly handle polarization!!
4255-
4256-
Args:
4257-
imlist (list): List of image objects at different frequencies
4258-
reffreq (float): Reference frequency of ouptut image in Hz
4259-
fit_order (int): How many terms to fit in spectrum (1 or 2).
4260-
42614255

4262-
Returns:
4263-
(Image): multifrequency image object
4264-
"""
4265-
4266-
if fit_order not in [1,2]:
4267-
raise Exception("get_specim only works with fit_order=1 or fit_order=2 currently!")
4268-
4256+
def get_specim(imlist, reffreq, fit_order=2):
4257+
"""get the spectral index/curvature from a list of images"""
42694258
freqs = [im.rf for im in imlist]
42704259

42714260
# remove any zeros in the images
@@ -4296,3 +4285,35 @@ def get_specim(imlist, reffreq, fit_order=1):
42964285
outim.curvvec = beta
42974286

42984287
return outim
4288+
4289+
4290+
def blur_mf(im,freqs,kernel,fit_order=2):
4291+
"""blur multifrequncy images with the same beam"""
4292+
reffreq = im.rf
4293+
4294+
# remove any zeros in the images
4295+
4296+
4297+
imlist = [im.get_image_mf(rf).blur_circ(kernel) for rf in freqs]
4298+
for image in imlist:
4299+
image.imvec[image.imvec<=0] = np.min(image.imvec[image.imvec!=0])
4300+
4301+
xfit = np.log(np.array(freqs)/reffreq)
4302+
yfit = np.log(np.array([im.imvec for im in imlist]))
4303+
4304+
if fit_order == 2:
4305+
coeffs = np.polyfit(xfit,yfit,2)
4306+
beta = coeffs[0]
4307+
alpha = coeffs[1]
4308+
elif fit_order == 1:
4309+
coeffs = np.polyfit(xfit,yfit,1)
4310+
alpha = coeffs[0]
4311+
beta = 0*alpha
4312+
else:
4313+
alpha = 0*yfit
4314+
beta = 0*yfit
4315+
4316+
outim = im.blur_circ(kernel)
4317+
outim.specvec = alpha
4318+
outim.curvvec = beta
4319+
return outim

ehtim/movie.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def offset_time(self, t_offset):
473473
return mov
474474

475475
def add_pol_movie(self, movie, pol):
476-
"""Add another movie polarization. f
476+
"""Add another movie polarization.
477477
478478
Args:
479479
movie (list): list of 2D frames (possibly complex) in a Jy/pixel array

0 commit comments

Comments
 (0)