def test_beam_hatch(): data = np.zeros((16, 16)) f = FITSFigure(data) f.add_beam(major=0.1, minor=0.04, angle=10.) for hatch in ['/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*']: f.beam.set_hatch(hatch) f.close()
def test_beam_pad(): data = np.zeros((16, 16)) f = FITSFigure(data) f.add_beam(major=0.1, minor=0.04, angle=10.) f.beam.set_pad(0.1) f.beam.set_pad(0.3) f.close()
def test_beam_frame(): data = np.zeros((16, 16)) f = FITSFigure(data) f.add_beam(major=0.1, minor=0.04, angle=10.) f.beam.set_frame(True) f.beam.set_frame(False) f.close()
def test_beam_corner(): data = np.zeros((16, 16)) f = FITSFigure(data) f.add_beam(major=0.1, minor=0.04, angle=10.) for corner in ['top', 'bottom', 'left', 'right', 'top left', 'top right', 'bottom left', 'bottom right']: f.beam.set_corner(corner) f.close()
def test_beam_angle(): data = np.zeros((16, 16)) f = FITSFigure(data) f.show_grayscale() f.add_beam(major=0.1, minor=0.04, angle=10.) f.beam.set_angle(0.) f.beam.set_angle(55.) f.close()
def test_beam_linestyle(): data = np.zeros((16, 16)) f = FITSFigure(data) f.add_beam(major=0.1, minor=0.04, angle=10.) f.beam.set_linestyle('solid') f.beam.set_linestyle('dotted') f.beam.set_linestyle('dashed') f.close()
def test_beam_linewidth(): data = np.zeros((16, 16)) f = FITSFigure(data) f.add_beam(major=0.1, minor=0.04, angle=10.) f.beam.set_linewidth(0) f.beam.set_linewidth(1) f.beam.set_linewidth(5) f.close()
def test_beam_edgecolor(): data = np.zeros((16, 16)) f = FITSFigure(data) f.add_beam(major=0.1, minor=0.04, angle=10.) f.beam.set_edgecolor('black') f.beam.set_edgecolor('#003344') f.beam.set_edgecolor((1.0, 0.4, 0.3)) f.close()
def test_beam_addremove(): data = np.zeros((16, 16)) f = FITSFigure(data) f.show_grayscale() f.add_beam(major=0.1, minor=0.04, angle=10.) f.remove_beam() f.add_beam(major=0.1, minor=0.04, angle=10.) f.remove_beam() f.close()
def Bmap(self, idi=50.0, pdp=3.0, pmax=30.0, color='rainbow', scalevec=1.0, clevels=100, imin=0.0, imax=None, size_x=9.0, size_y=9.0, dpi=100.0): # Initialization # idi : Signal-to-noise ratio for Stokes I total intensity. Default is # idi = 50.0, which leads to an upper limit of at least dP = 5.0% # for the error on the polarization fraction P. # pdp : Signal-to-noise ratio for the de-biased polarization fraction P. # Default is pdp = 3.0, which is the commonly accepted detection # threshold in the litterature. # pmax : Maximum polarization fraction allowed. # color : Color scheme used for the plots. Default is rainbow. # scalevec : Length of the vectors plotted on the map. # clevels : Number of contours plotted on the contour plot. # imin : Minimum value plotted in the Stokes I intensity map. # Default is 0.0. # imax : Maximum value plotted in the Stokes I intensity map. # If no value is provided, maximum is automatically detected. print() print('=====================================') print('Plotting a lovable magnetic field map') print('=====================================') print() # Creating a new fits object for APLpy's FITSFigure method to recognize # for the Stokes I total intensity plot_hdu = fits.PrimaryHDU(data=self.I, header=self.header) # Loading the data in an APLpy figure Bmap = FITSFigure(plot_hdu, dpi=dpi, figsize=(size_x, size_y), slices=[0, 1]) print('Plotting the Stokes I total intensity map') print() # Showing the pixelated image and setting the aspect ratio Bmap.show_colorscale(cmap=color, vmin=imin, vmax=imax) # Plotting a filled contour plot of the data Bmap.show_contour(cmap=color, levels=clevels, filled=True, extend='both', vmin=imin, vmax=imax) # Inverting ticks #Bmap.ticks.set_tick_direction('in') # Not working in APLpy # Adding a colorbar to the plot Bmap.add_colorbar(pad=0.125) # Adding the units to the colorbar Bmap.colorbar.set_axis_label_text(self.units) # Moving the colorbar to be on top of the figure Bmap.colorbar.set_location('top') # Creating a new fits object for APLpy's FITSFigure method to recognize # for the polarization fraction P pref = fits.PrimaryHDU(data=self.P, header=self.header) pmap = pref.copy() # for the magnetic field angle B oref = fits.PrimaryHDU(data=self.B, header=self.header) omap = oref.copy() # A copy of the HDU is created before any masking is done. # This fixes an issue where modifying pmap was carried to other # instances of this method. Future fix should make sure pref is # closed/deleted at the end of this method. # Muting the numpy alerts triggered by nan values np.warnings.filterwarnings('ignore') print() print('Applying happy selection criteria on polarization vectors') print() # Creating a mask to hide polarization vectors with low signal-to-noise ratios imask_01 = np.where( self.I / self.dI < idi) # Total intensity SNR threshold imask_02 = np.where(self.I < 0) # Total intensity positive threshold pmask = np.where(self.P / self.dP < pdp) # Polarization SNR threshold pmaxmask = np.where(self.P > pmax) # Polarization SNR threshold # Forcing the polarization vectors to share the same amplitude pmap.data[np.where(self.P > 0.0)] = 1.0 # Masking all the indices for which the selection criteria failed pmap.data[imask_01] = np.nan pmap.data[imask_02] = np.nan pmap.data[pmask] = np.nan pmap.data[pmaxmask] = np.nan print('Plotting the magnetic field segments') print() # Plotting the polarization vectors Bmap.show_vectors(pmap, omap, scale=scalevec) # Adding the beam size Bmap.add_beam(facecolor='white', edgecolor='black', linewidth=2, pad=1, corner='bottom left') # Removing the pixelated structure under the figure Bmap.hide_colorscale( ) # Warning: You need to reopen it to create a new # colorbar, APLpy deals poorly with # contour maps by themselves print('Returning the APLpy figure as output, please feel free to' + ' improve it (see online APLpy.FITSFigure documentation)') print() print('Don\'t forget to save the results using the' + ' .savefig(\'name.png\') function') print() print('Have fun!') return Bmap
def make_polmap(filename, title=None, figure=None, subplot=(1, 1, 1)): hawc = fits.open(filename) p = hawc['DEBIASED PERCENT POL'] # % theta = hawc['ROTATED POL ANGLE'] # deg stokes_i = hawc['STOKES I'] # I error_i = hawc['ERROR I'] # error I # 1. plot Stokes I # convert from Jy/pix to Jy/sq. arcsec pxscale = stokes_i.header['CDELT2'] * 3600 # map scale in arcsec/pix stokes_i.data /= pxscale**2 error_i.data /= pxscale**2 fig = FITSFigure(stokes_i, figure=figure, subplot=subplot) # 2. perform S/N cut on I/\sigma_I err_lim = 100 mask = np.where(stokes_i.data / error_i.data < err_lim) # 3. mask out low S/N vectors by setting masked indices to NaN p.data[mask] = np.nan # 4. plot vectors scalevec = 0.4 # 1pix = scalevec * 1% pol # scale vectors to make it easier to see fig.show_vectors(p, theta, scale=scalevec, step=2) # step size = display every 'step' vectors # step size of 2 is effectively Nyquist sampling # --close to the beam size # 5. plot contours ncontours = 30 fig.show_contour(stokes_i, cmap=cmap, levels=ncontours, filled=True, smooth=1, kernel='box') fig.show_contour(stokes_i, colors='gray', levels=ncontours, smooth=1, kernel='box', linewidths=0.3) # Show image fig.show_colorscale(cmap=cmap) # If title, set it if title: fig.set_title(title) # Add colorbar fig.add_colorbar() fig.colorbar.set_axis_label_text('Flux (Jy/arcsec$^2$)') # Add beam indicator fig.add_beam(facecolor='red', edgecolor='black', linewidth=2, pad=1, corner='bottom left') fig.add_label(0.02, 0.02, 'Beam FWHM', horizontalalignment='left', weight='bold', relative=True, size='small') # Add vector scale # polarization vectors are displayed such that 'scalevec' * 1% pol is 1 pix long # must translate pixel size to angular degrees since the 'add_scalebar' function assumes a physical scale vectscale = scalevec * pxscale / 3600 fig.add_scalebar(5 * vectscale, "p = 5%", corner='top right', frame=True) return stokes_i, p, mask, fig
gc.add_colorbar() gc.colorbar.set_axis_label_text('I (mJy/sqarcsec)') gc.colorbar.set_axis_label_font(size=label_colorbar) gc.colorbar.set_font(size=tick_colorbar) #recenter gc.recenter(RA, DEC, width=width / 3600, height=height / 3600) #contours sigmaI = np.nanstd(stkIerr.data) levelsI = sigmaI * 1.8**(np.arange(2, 12, 0.5)) #levelsI = np.arange(3,155,3)*sigmaI gc.show_contour(colors='black',levels=levelsI,linewidth=0.1,\ filled=False,smooth=1,kernel='box',alpha=0.4) #gc.show_contour(levels=levelsI,\ # filled=True,smooth=1,kernel='box',cmap='viridis') #beam gc.add_beam(color='red') #title gc.set_title(title, fontsize=title_size) ##Pol map p = quality_cuts(stkI, stkIerr, p, perr, SNRp_cut, p_cut, SNRi_cut) #2. polmap gc.show_vectors(p,pa,scale=scalevec,\ step=2,color='black',linewidth=4.0) gc.show_vectors(p,pa,scale=scalevec,\ step=2,color='grey',linewidth=2.0) #show label gc.add_label(0.1,0.95,'Total Flux',fontsize=label_fontsize,\ color='white',weight='bold',relative=True)
def test_numpy_beam(): data = np.arange(256).reshape((16, 16)) f = FITSFigure(data) f.show_grayscale() f.add_beam(major=0.1, minor=0.04, angle=10.) f.close()