@@ -3358,7 +3358,7 @@ def display(self, pol=None, cfun=False, interp='gaussian',
3358
3358
scale_lw = 1 , beam_lw = 1 , cbar_fontsize = 12 , axis = None ,
3359
3359
scale_fontsize = 12 ,
3360
3360
power = 0 ,
3361
- beamcolor = 'w' , scalecolor = 'w' ,dpi = 500 ):
3361
+ beamcolor = 'w' , beampos = 'right' , scalecolor = 'w' ,dpi = 500 ):
3362
3362
"""Display the image.
3363
3363
3364
3364
Args:
@@ -3624,8 +3624,12 @@ def display(self, pol=None, cfun=False, interp='gaussian',
3624
3624
im = plt .imshow (imarr , alpha = alpha , cmap = cmap , interpolation = interp )
3625
3625
3626
3626
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 ()]
3629
3633
beamimage = self .copy ()
3630
3634
beamimage .imvec *= 0
3631
3635
beamimage = beamimage .add_gauss (1 , beamparams )
@@ -4248,24 +4252,9 @@ def avg_imlist(imlist):
4248
4252
4249
4253
4250
4254
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
-
4261
4255
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"""
4269
4258
freqs = [im .rf for im in imlist ]
4270
4259
4271
4260
# remove any zeros in the images
@@ -4296,3 +4285,35 @@ def get_specim(imlist, reffreq, fit_order=1):
4296
4285
outim .curvvec = beta
4297
4286
4298
4287
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
0 commit comments