<s> from matplotlib . axes import Axes , subplot_class_factory <EOL> from matplotlib . transforms import Affine2D , Bbox , Transform <EOL> from astropy . wcs import WCS <EOL> from . transforms import ( WCSPixel2WorldTransform , WCSWorld2PixelTransform , <EOL> CoordinateTransform ) <EOL> from . coordinates_map import CoordinatesMap <EOL> from . utils import get_coord_meta <EOL> from . wcs_utils import wcs_to_celestial_frame <EOL> from . frame import RectangularFrame <EOL> import numpy as np <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> VISUAL_PROPERTIES = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> IDENTITY = WCS ( naxis = <NUM_LIT:2> ) <EOL> IDENTITY . wcs . ctype = [ "<STR_LIT:X>" , "<STR_LIT:Y>" ] <EOL> IDENTITY . wcs . crval = [ <NUM_LIT:1.> , <NUM_LIT:1.> ] <EOL> IDENTITY . wcs . crpix = [ <NUM_LIT:1.> , <NUM_LIT:1.> ] <EOL> IDENTITY . wcs . cdelt = [ <NUM_LIT:1.> , <NUM_LIT:1.> ] <EOL> class WCSAxes ( Axes ) : <EOL> def __init__ ( self , fig , rect , wcs = None , transform = None , coord_meta = None , <EOL> transData = None , slices = None , frame_class = RectangularFrame , <EOL> ** kwargs ) : <EOL> super ( WCSAxes , self ) . __init__ ( fig , rect , ** kwargs ) <EOL> self . _bboxes = [ ] <EOL> self . frame_class = frame_class <EOL> if not ( transData is None ) : <EOL> self . transData = transData <EOL> self . reset_wcs ( wcs = wcs , slices = slices , transform = transform , coord_meta = coord_meta ) <EOL> self . _hide_parent_artists ( ) <EOL> self . format_coord = self . _display_world_coords <EOL> self . _display_coords_index = <NUM_LIT:0> <EOL> fig . canvas . mpl_connect ( '<STR_LIT>' , self . _set_cursor_prefs ) <EOL> self . patch = self . coords . frame . patch <EOL> def _display_world_coords ( self , x , y ) : <EOL> if self . _display_coords_index == - <NUM_LIT:1> : <EOL> return "<STR_LIT>" % ( x , y ) <EOL> pixel = np . array ( [ x , y ] ) <EOL> coords = self . _all_coords [ self . _display_coords_index ] <EOL> world = coords . _transform . transform ( np . array ( [ pixel ] ) ) [ <NUM_LIT:0> ] <EOL> xw = coords [ self . _x_index ] . format_coord ( world [ self . _x_index ] ) <EOL> yw = coords [ self . _y_index ] . format_coord ( world [ self . _y_index ] ) <EOL> if self . _display_coords_index == <NUM_LIT:0> : <EOL> system = "<STR_LIT>" <EOL> else : <EOL> system = "<STR_LIT>" . format ( self . _display_coords_index ) <EOL> coord_string = "<STR_LIT>" % ( xw , yw , system ) <EOL> return coord_string <EOL> def _set_cursor_prefs ( self , event , ** kwargs ) : <EOL> if event . key == '<STR_LIT:w>' : <EOL> self . _display_coords_index += <NUM_LIT:1> <EOL> if self . _display_coords_index + <NUM_LIT:1> > len ( self . _all_coords ) : <EOL> self . _display_coords_index = - <NUM_LIT:1> <EOL> def _hide_parent_artists ( self ) : <EOL> for s in self . spines . values ( ) : <EOL> s . set_visible ( False ) <EOL> self . xaxis . set_visible ( False ) <EOL> self . yaxis . set_visible ( False ) <EOL> def reset_wcs ( self , wcs = None , slices = None , transform = None , coord_meta = None ) : <EOL> """<STR_LIT>""" <EOL> if wcs is None and transform is None : <EOL> self . wcs = IDENTITY <EOL> else : <EOL> self . wcs = wcs <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> previous_frame_path = self . coords . frame . _path <EOL> else : <EOL> previous_frame_path = None <EOL> self . coords = CoordinatesMap ( self , wcs = self . wcs , slice = slices , <EOL> transform = transform , coord_meta = coord_meta , <EOL> frame_class = self . frame_class , <EOL> previous_frame_path = previous_frame_path ) <EOL> self . _all_coords = [ self . coords ] <EOL> if slices is None : <EOL> self . slices = ( '<STR_LIT:x>' , '<STR_LIT:y>' ) <EOL> self . _x_index = <NUM_LIT:0> <EOL> self . _y_index = <NUM_LIT:1> <EOL> else : <EOL> self . slices = slices <EOL> self . _x_index = self . slices . index ( '<STR_LIT:x>' ) <EOL> self . _y_index = self . slices . index ( '<STR_LIT:y>' ) <EOL> if self . frame_class is RectangularFrame : <EOL> for coord_index in range ( len ( self . slices ) ) : <EOL> if self . slices [ coord_index ] == '<STR_LIT:x>' : <EOL> self . coords [ coord_index ] . set_axislabel_position ( '<STR_LIT:b>' ) <EOL> self . coords [ coord_index ] . set_ticklabel_position ( '<STR_LIT:b>' ) <EOL> elif self . slices [ coord_index ] == '<STR_LIT:y>' : <EOL> self . coords [ coord_index ] . set_axislabel_position ( '<STR_LIT:l>' ) <EOL> self . coords [ coord_index ] . set_ticklabel_position ( '<STR_LIT:l>' ) <EOL> else : <EOL> self . coords [ coord_index ] . set_axislabel_position ( '<STR_LIT>' ) <EOL> self . coords [ coord_index ] . set_ticklabel_position ( '<STR_LIT>' ) <EOL> self . coords [ coord_index ] . set_ticks_position ( '<STR_LIT>' ) <EOL> def draw ( self , renderer , inframe = False ) : <EOL> self . coords . frame . _update_patch_path ( ) <EOL> super ( WCSAxes , self ) . draw ( renderer , inframe ) <EOL> self . _bboxes = [ ] <EOL> self . _ticklabels_bbox = [ ] <EOL> visible_ticks = [ ] <EOL> for coords in self . _all_coords : <EOL> coords . frame . update ( ) <EOL> for coord in coords : <EOL> coord . _draw ( renderer , bboxes = self . _bboxes , <EOL> ticklabels_bbox = self . _ticklabels_bbox ) <EOL> visible_ticks . extend ( coord . ticklabels . get_visible_axes ( ) ) <EOL> for coords in self . _all_coords : <EOL> for coord in coords : <EOL> coord . _draw_axislabels ( renderer , bboxes = self . _bboxes , <EOL> ticklabels_bbox = self . _ticklabels_bbox , <EOL> visible_ticks = visible_ticks ) <EOL> self . coords . frame . draw ( renderer ) <EOL> def set_xlabel ( self , label ) : <EOL> self . coords [ self . _x_index ] . set_axislabel ( label ) <EOL> def set_ylabel ( self , label ) : <EOL> self . coords [ self . _y_index ] . set_axislabel ( label ) <EOL> def get_xlabel ( self ) : <EOL> return self . coords [ self . _x_index ] . get_axislabel ( ) <EOL> def get_ylabel ( self ) : <EOL> return self . coords [ self . _y_index ] . get_axislabel ( ) <EOL> def get_coords_overlay ( self , frame , equinox = None , obstime = None , coord_meta = None ) : <EOL> if isinstance ( frame , WCS ) : <EOL> coords = CoordinatesMap ( self , frame , frame_class = self . frame_class ) <EOL> else : <EOL> if coord_meta is None : <EOL> coord_meta = get_coord_meta ( frame ) <EOL> transform = self . _get_transform_no_transdata ( frame , equinox = equinox , obstime = obstime ) <EOL> coords = CoordinatesMap ( self , transform = transform , coord_meta = coord_meta , frame_class = self . frame_class ) <EOL> self . _all_coords . append ( coords ) <EOL> coords [ <NUM_LIT:0> ] . set_axislabel_position ( '<STR_LIT:t>' ) <EOL> coords [ <NUM_LIT:1> ] . set_axislabel_position ( '<STR_LIT:r>' ) <EOL> coords [ <NUM_LIT:0> ] . set_ticklabel_position ( '<STR_LIT:t>' ) <EOL> coords [ <NUM_LIT:1> ] . set_ticklabel_position ( '<STR_LIT:r>' ) <EOL> self . overlay_coords = coords <EOL> return coords <EOL> def get_transform ( self , frame , equinox = None , obstime = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_transform_no_transdata ( frame , equinox = equinox , obstime = obstime ) . inverted ( ) + self . transData <EOL> def _get_transform_no_transdata ( self , frame , equinox = None , obstime = None ) : <EOL> """<STR_LIT>""" <EOL> if self . wcs is None and frame != '<STR_LIT>' : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if isinstance ( frame , WCS ) : <EOL> coord_in = wcs_to_celestial_frame ( self . wcs ) <EOL> coord_out = wcs_to_celestial_frame ( frame ) <EOL> if coord_in == coord_out : <EOL> return ( WCSPixel2WorldTransform ( self . wcs ) <EOL> + WCSWorld2PixelTransform ( frame ) ) <EOL> else : <EOL> return ( WCSPixel2WorldTransform ( self . wcs ) <EOL> + CoordinateTransform ( self . wcs , frame ) <EOL> + WCSWorld2PixelTransform ( frame ) ) <EOL> elif frame == '<STR_LIT>' : <EOL> return Affine2D ( ) <EOL> elif isinstance ( frame , Transform ) : <EOL> pixel2world = WCSPixel2WorldTransform ( self . wcs ) <EOL> return pixel2world + frame <EOL> else : <EOL> pixel2world = WCSPixel2WorldTransform ( self . wcs ) <EOL> if frame == '<STR_LIT>' : <EOL> return pixel2world <EOL> else : <EOL> coordinate_transform = CoordinateTransform ( self . wcs , frame ) <EOL> if coordinate_transform . same_frames : <EOL> return pixel2world <EOL> else : <EOL> return pixel2world + CoordinateTransform ( self . wcs , frame ) <EOL> def get_tightbbox ( self , renderer ) : <EOL> if not self . get_visible ( ) : <EOL> return <EOL> bb = [ b for b in self . _bboxes if b and ( b . width != <NUM_LIT:0> or b . height != <NUM_LIT:0> ) ] <EOL> if bb : <EOL> _bbox = Bbox . union ( bb ) <EOL> return _bbox <EOL> else : <EOL> return self . get_window_extent ( renderer ) <EOL> def grid ( self , draw_grid = True , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if draw_grid : <EOL> self . coords . grid ( draw_grid = draw_grid , ** kwargs ) <EOL> class WCSAxesSubplot ( subplot_class_factory ( WCSAxes ) ) : <EOL> pass </s>
