def draw_ellipse(ax): from mpl_toolkits.axes_grid.anchored_artists import AnchoredEllipse # draw an ellipse of width=0.1, height=0.15 in the data coordinate ae = AnchoredEllipse(ax.transData, width=0.1, height=0.15, angle=0., loc=3, pad=0.5, borderpad=0.4, frameon=True) ax.add_artist(ae)
def show(self, major='BMAJ', minor='BMIN', \ angle='BPA', corner='bottom left', frame=False, borderpad=0.4, pad=0.5, **kwargs): ''' Display the beam shape and size for the primary image. By default, this method will search for the BMAJ, BMIN, and BPA keywords in the FITS header to set the major and minor axes and the position angle on the sky. Parameters ---------- major : float, quantity or unit, optional Major axis of the beam in degrees or an angular quantity (overrides BMAJ if present) minor : float, quantity or unit, optional Minor axis of the beam in degrees or an angular quantity (overrides BMIN if present) angle : float, quantity or unit, optional Position angle of the beam on the sky in degrees or an angular quantity (overrides BPA if present) in the anticlockwise direction. corner : int, optional The beam location. Acceptable values are 'left', 'right', 'top', 'bottom', 'top left', 'top right', 'bottom left' (default), and 'bottom right'. frame : str, optional Whether to display a frame behind the beam (default is False) kwargs Additional arguments are passed to the matplotlib Ellipse class. See the matplotlib documentation for more details. ''' if isinstance(major, six.string_types): major = self._header[major] if isinstance(minor, six.string_types): minor = self._header[minor] if isinstance(angle, six.string_types): angle = self._header[angle] if isinstance(major, u.Quantity): major = major.to(u.degree).value elif isinstance(major, u.Unit): major = major.to(u.degree) if isinstance(minor, u.Quantity): minor = minor.to(u.degree).value elif isinstance(minor, u.Unit): minor = minor.to(u.degree) if isinstance(angle, u.Quantity): angle = angle.to(u.degree).value elif isinstance(angle, u.Unit): angle = angle.to(u.degree) degrees_per_pixel = wcs_util.celestial_pixel_scale(self._wcs) self._base_settings['minor'] = minor self._base_settings['major'] = major self._base_settings['angle'] = angle self._base_settings['corner'] = corner self._base_settings['frame'] = frame self._base_settings['borderpad'] = borderpad self._base_settings['pad'] = pad minor /= degrees_per_pixel major /= degrees_per_pixel try: self._beam.remove() except: pass if isinstance(corner, six.string_types): corner = corners[corner] self._beam = AnchoredEllipse(self._ax.transData, \ width=minor, height=major, angle=angle, \ loc=corner, pad=pad, borderpad=borderpad, frameon=frame) self._ax.add_artist(self._beam) self.set(**kwargs)
class Beam(object): def __init__(self, parent): # Retrieve info from parent figure self._figure = parent._figure self._header = parent._header self._ax = parent._ax1 self._wcs = parent._wcs # Save plotting parameters (required for @auto_refresh) self._parameters = parent._parameters # Initialize settings self._base_settings = {} self._beam_settings = {} # LAYOUT @auto_refresh def show(self, major='BMAJ', minor='BMIN', \ angle='BPA', corner='bottom left', frame=False, borderpad=0.4, pad=0.5, **kwargs): ''' Display the beam shape and size for the primary image. By default, this method will search for the BMAJ, BMIN, and BPA keywords in the FITS header to set the major and minor axes and the position angle on the sky. Parameters ---------- major : float, quantity or unit, optional Major axis of the beam in degrees or an angular quantity (overrides BMAJ if present) minor : float, quantity or unit, optional Minor axis of the beam in degrees or an angular quantity (overrides BMIN if present) angle : float, quantity or unit, optional Position angle of the beam on the sky in degrees or an angular quantity (overrides BPA if present) in the anticlockwise direction. corner : int, optional The beam location. Acceptable values are 'left', 'right', 'top', 'bottom', 'top left', 'top right', 'bottom left' (default), and 'bottom right'. frame : str, optional Whether to display a frame behind the beam (default is False) kwargs Additional arguments are passed to the matplotlib Ellipse class. See the matplotlib documentation for more details. ''' if isinstance(major, six.string_types): major = self._header[major] if isinstance(minor, six.string_types): minor = self._header[minor] if isinstance(angle, six.string_types): angle = self._header[angle] if isinstance(major, u.Quantity): major = major.to(u.degree).value elif isinstance(major, u.Unit): major = major.to(u.degree) if isinstance(minor, u.Quantity): minor = minor.to(u.degree).value elif isinstance(minor, u.Unit): minor = minor.to(u.degree) if isinstance(angle, u.Quantity): angle = angle.to(u.degree).value elif isinstance(angle, u.Unit): angle = angle.to(u.degree) degrees_per_pixel = wcs_util.celestial_pixel_scale(self._wcs) self._base_settings['minor'] = minor self._base_settings['major'] = major self._base_settings['angle'] = angle self._base_settings['corner'] = corner self._base_settings['frame'] = frame self._base_settings['borderpad'] = borderpad self._base_settings['pad'] = pad minor /= degrees_per_pixel major /= degrees_per_pixel try: self._beam.remove() except: pass if isinstance(corner, six.string_types): corner = corners[corner] self._beam = AnchoredEllipse(self._ax.transData, \ width=minor, height=major, angle=angle, \ loc=corner, pad=pad, borderpad=borderpad, frameon=frame) self._ax.add_artist(self._beam) self.set(**kwargs) @auto_refresh def _remove(self): self._beam.remove() @auto_refresh def hide(self): ''' Hide the beam ''' try: self._beam.remove() except: pass @auto_refresh def set_major(self, major): ''' Set the major axis of the beam, in degrees. ''' self._base_settings['major'] = major self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_minor(self, minor): ''' Set the minor axis of the beam, in degrees. ''' self._base_settings['minor'] = minor self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_angle(self, angle): ''' Set the position angle of the beam on the sky, in degrees. ''' self._base_settings['angle'] = angle self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_corner(self, corner): ''' Set the beam location. Acceptable values are 'left', 'right', 'top', 'bottom', 'top left', 'top right', 'bottom left' (default), and 'bottom right'. ''' self._base_settings['corner'] = corner self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_frame(self, frame): ''' Set whether to display a frame around the beam. ''' self._base_settings['frame'] = frame self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_borderpad(self, borderpad): ''' Set the amount of padding within the beam object, relative to the canvas size. ''' self._base_settings['borderpad'] = borderpad self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_pad(self, pad): ''' Set the amount of padding between the beam object and the image corner/edge, relative to the canvas size. ''' self._base_settings['pad'] = pad self.show(**self._base_settings) self.set(**self._beam_settings) # APPEARANCE @auto_refresh def set_alpha(self, alpha): ''' Set the alpha value (transparency). This should be a floating point value between 0 and 1. ''' self.set(alpha=alpha) @auto_refresh def set_color(self, color): ''' Set the beam color. ''' self.set(color=color) @auto_refresh def set_edgecolor(self, edgecolor): ''' Set the color for the edge of the beam. ''' self.set(edgecolor=edgecolor) @auto_refresh def set_facecolor(self, facecolor): ''' Set the color for the interior of the beam. ''' self.set(facecolor=facecolor) @auto_refresh def set_linestyle(self, linestyle): ''' Set the line style for the edge of the beam. This should be one of 'solid', 'dashed', 'dashdot', or 'dotted'. ''' self.set(linestyle=linestyle) @auto_refresh def set_linewidth(self, linewidth): ''' Set the line width for the edge of the beam, in points. ''' self.set(linewidth=linewidth) @auto_refresh def set_hatch(self, hatch): ''' Set the hatch pattern. This should be one of '/', '\', '|', '-', '+', 'x', 'o', 'O', '.', or '*'. ''' self.set(hatch=hatch) @auto_refresh def set(self, **kwargs): ''' Modify the beam properties. All arguments are passed to the matplotlib Ellipse class. See the matplotlib documentation for more details. ''' for kwarg in kwargs: self._beam_settings[kwarg] = kwargs[kwarg] self._beam.ellipse.set(**kwargs)
def show(self, major='BMAJ', minor='BMIN', \ angle='BPA', corner='bottom left', frame=False, borderpad=0.4, pad=0.5, **kwargs): ''' Display the beam shape and size for the primary image By default, this method will search for the BMAJ, BMIN, and BPA keywords in the FITS header to set the major and minor axes and the position angle on the sky. Optional Keyword Arguments: *major*: [ float ] Major axis of the beam in degrees (overrides BMAJ if present) *minor*: [ float ] Minor axis of the beam in degrees (overrides BMIN if present) *angle*: [ float ] Position angle of the beam on the sky in degrees (overrides BPA if present) in the anticlockwise direction. *corner*: [ integer ] The beam location. Acceptable values are 'left', 'right', 'top', 'bottom', 'top left', 'top right', 'bottom left' (default), and 'bottom right'. *frame*: [ True | False ] Whether to display a frame behind the beam (default is False) Advanced: Additional arguments are passed to the matplotlib Ellipse classe. See the matplotlib documentation for more details. ''' if isinstance(major, basestring): major = self._header[major] if isinstance(minor, basestring): minor = self._header[minor] if isinstance(angle, basestring): angle = self._header[angle] pixel_scale = wcs_util.pixel_scale(self._wcs) self._base_settings['minor'] = minor self._base_settings['major'] = major self._base_settings['angle'] = angle self._base_settings['corner'] = corner self._base_settings['frame'] = frame self._base_settings['borderpad'] = borderpad self._base_settings['pad'] = pad minor /= pixel_scale major /= pixel_scale try: self._beam.remove() except: pass if isinstance(corner, basestring): corner = corners[corner] self._beam = AnchoredEllipse(self._ax.transData, \ width=minor, height=major, angle=angle, \ loc=corner, pad=pad, borderpad=borderpad, frameon=frame) self._ax.add_artist(self._beam) self.set(**kwargs)
class Beam(object): def __init__(self, parent): # Retrieve info from parent figure self._figure = parent._figure self._hdu = parent._hdu self._ax = parent._ax1 self._wcs = parent._wcs # Initialize settings self._base_settings = {} self._beam_settings = {} # LAYOUT @auto_refresh def show(self, major='BMAJ', minor='BMIN', \ angle='BPA', corner='bottom left', frame=False, borderpad=0.4, pad=0.5, **kwargs): ''' Display the beam shape and size for the primary image By default, this method will search for the BMAJ, BMIN, and BPA keywords in the FITS header to set the major and minor axes and the position angle on the sky. Optional Keyword Arguments: *major*: [ float ] Major axis of the beam in degrees (overrides BMAJ if present) *minor*: [ float ] Minor axis of the beam in degrees (overrides BMIN if present) *angle*: [ float ] Position angle of the beam on the sky in degrees (overrides BPA if present) in the anticlockwise direction. *corner*: [ integer ] The beam location. Acceptable values are 'left','right', 'top', 'bottom', 'top left', 'top right', 'bottom left' (default), and 'bottom right'. *frame*: [ True | False ] Whether to display a frame behind the beam (default is False) Advanced: Additional arguments are passed to the matplotlib Ellipse classe. See the matplotlib documentation for more details. ''' if type(major) == str: major = self._hdu.header[major] if type(minor) == str: minor = self._hdu.header[minor] if type(angle) == str: angle = self._hdu.header[angle] degperpix = wcs_util.degperpix(self._wcs) self._base_settings['minor'] = minor self._base_settings['major'] = major self._base_settings['angle'] = angle self._base_settings['corner'] = corner self._base_settings['frame'] = frame self._base_settings['borderpad'] = borderpad self._base_settings['pad'] = pad minor /= degperpix major /= degperpix try: self._beam.remove() except: pass if type(corner) == str: corner = corners[corner] self._beam = AnchoredEllipse(self._ax.transData, \ width=minor, height=major, angle=angle, \ loc=corner, pad=pad, borderpad=borderpad, frameon=frame) self._ax.add_artist(self._beam) self.set(**kwargs) @auto_refresh def _remove(self): self._beam.remove() @auto_refresh def hide(self): ''' Hide the beam ''' try: self._beam.remove() except: pass @auto_refresh def set_major(self, major): ''' Set the major axis of the beam, in degrees. ''' self._base_settings['major'] = major self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_minor(self, minor): ''' Set the minor axis of the beam, in degrees. ''' self._base_settings['minor'] = minor self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_angle(self, angle): ''' Set the position angle of the beam on the sky in degrees. ''' self._base_settings['angle'] = angle self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_corner(self, corner): ''' Set the beam location. Acceptable values are 'left','right', 'top', 'bottom', 'top left', 'top right', 'bottom left' (default), and 'bottom right'. ''' self._base_settings['corner'] = corner self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_frame(self, frame): ''' Set whether to display a frame around the beam. ''' self._base_settings['frame'] = frame self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_borderpad(self, borderpad): ''' Set the amount of padding within the beam object, relative to the canvas size. ''' self._base_settings['borderpad'] = borderpad self.show(**self._base_settings) self.set(**self._beam_settings) @auto_refresh def set_pad(self, pad): ''' Set the amount of padding between the beam object and the image corner/edge, relative to the canvas size. ''' self._base_settings['pad'] = pad self.show(**self._base_settings) self.set(**self._beam_settings) # APPEARANCE @auto_refresh def set_alpha(self, alpha): ''' Set the alpha value (transparency). This should be a floating point value between 0 and 1. ''' self.set(alpha=alpha) @auto_refresh def set_color(self, color): ''' Set the beam color. ''' self.set(color=color) @auto_refresh def set_edgecolor(self, edgecolor): ''' Set the color for the edge of the beam. ''' self.set(edgecolor=edgecolor) @auto_refresh def set_facecolor(self, facecolor): ''' Set the color for the interior of the beam. ''' self.set(facecolor=facecolor) @auto_refresh def set_linestyle(self, linestyle): ''' Set the line style for the edge of the beam. This should be one of 'solid', 'dashed', 'dashdot', or 'dotted'. ''' self.set(linestyle=linestyle) @auto_refresh def set_linewidth(self, linewidth): ''' Set the line width for the edge of the beam, in points. ''' self.set(linewidth=linewidth) @auto_refresh def set_hatch(self, hatch): ''' Set the hatch pattern. This should be one of '/', '\', '|', '-', '+', 'x', 'o', 'O', '.', or '*'. ''' self.set(hatch=hatch) @auto_refresh def set(self, **kwargs): ''' Modify the beam properties. All arguments are passed to the matplotlib Ellipse classe. See the matplotlib documentation for more details. ''' for kwarg in kwargs: self._beam_settings[kwarg] = kwargs[kwarg] self._beam.ellipse.set(**kwargs)