<s> import sys , os <EOL> import re <EOL> import math <EOL> import logging <EOL> import time <EOL> import traceback <EOL> import numpy , numpy . ma <EOL> from ginga . util import wcsmod , io_fits , iohelper <EOL> from ginga . util import wcs , iqcalc <EOL> from ginga . BaseImage import BaseImage , ImageError , Header <EOL> from ginga . misc import Bunch <EOL> from ginga import trcalc <EOL> import ginga . util . six as six <EOL> from ginga . util . six . moves import map , zip <EOL> class AstroHeader ( Header ) : <EOL> pass <EOL> class AstroImage ( BaseImage ) : <EOL> """<STR_LIT>""" <EOL> wcsClass = None <EOL> ioClass = None <EOL> @ classmethod <EOL> def set_wcsClass ( cls , klass ) : <EOL> cls . wcsClass = klass <EOL> @ classmethod <EOL> def set_ioClass ( cls , klass ) : <EOL> cls . ioClass = klass <EOL> def __init__ ( self , data_np = None , metadata = None , logger = None , <EOL> name = None , wcsclass = wcsClass , ioclass = ioClass , <EOL> inherit_primary_header = False ) : <EOL> BaseImage . __init__ ( self , data_np = data_np , metadata = metadata , <EOL> logger = logger , name = name ) <EOL> if wcsclass is None : <EOL> wcsclass = wcsmod . WCS <EOL> self . wcs = wcsclass ( self . logger ) <EOL> if ioclass is None : <EOL> ioclass = io_fits . fitsLoaderClass <EOL> self . io = ioclass ( self . logger ) <EOL> self . inherit_primary_header = inherit_primary_header <EOL> if self . inherit_primary_header : <EOL> self . _primary_hdr = AstroHeader ( ) <EOL> else : <EOL> self . _primary_hdr = None <EOL> if metadata is not None : <EOL> header = self . get_header ( ) <EOL> self . wcs . load_header ( header ) <EOL> self . naxispath = [ ] <EOL> self . revnaxis = [ ] <EOL> self . _md_data = None <EOL> def load_hdu ( self , hdu , fobj = None , naxispath = None ) : <EOL> self . clear_metadata ( ) <EOL> ahdr = self . get_header ( ) <EOL> loader = io_fits . PyFitsFileHandler ( self . logger ) <EOL> _data , naxispath = loader . load_hdu ( hdu , ahdr , naxispath = naxispath ) <EOL> self . _md_data = _data <EOL> if naxispath is None : <EOL> naxispath = [ ] <EOL> if len ( naxispath ) == <NUM_LIT:0> : <EOL> naxispath = ( [ <NUM_LIT:0> ] * ( len ( _data . shape ) - <NUM_LIT:2> ) ) <EOL> self . set_naxispath ( naxispath ) <EOL> if self . inherit_primary_header and fobj is not None : <EOL> self . io . fromHDU ( fobj [ <NUM_LIT:0> ] , self . _primary_hdr ) <EOL> self . wcs . load_header ( hdu . header , fobj = fobj ) <EOL> def load_file ( self , filepath , numhdu = None , naxispath = None , <EOL> allow_numhdu_override = True ) : <EOL> self . logger . debug ( "<STR_LIT>" % ( filepath ) ) <EOL> self . clear_metadata ( ) <EOL> ahdr = self . get_header ( ) <EOL> info = iohelper . get_fileinfo ( filepath ) <EOL> if numhdu is None : <EOL> numhdu = info . numhdu <EOL> _data , numhdu_ , naxispath = self . io . load_file ( info . filepath , ahdr , <EOL> numhdu = numhdu , <EOL> naxispath = naxispath , <EOL> phdr = self . _primary_hdr ) <EOL> self . _md_data = _data <EOL> if naxispath is None : <EOL> naxispath = [ ] <EOL> if len ( naxispath ) == <NUM_LIT:0> : <EOL> naxispath = ( [ <NUM_LIT:0> ] * ( len ( _data . shape ) - <NUM_LIT:2> ) ) <EOL> if not ( self . name is None ) : <EOL> self . set ( name = self . name ) <EOL> else : <EOL> name = self . get ( '<STR_LIT:name>' , None ) <EOL> if name is None : <EOL> name = info . name <EOL> if ( '<STR_LIT:[>' not in name ) : <EOL> if ( numhdu is None ) or allow_numhdu_override : <EOL> numhdu = numhdu_ <EOL> name += iohelper . get_hdu_suffix ( numhdu ) <EOL> self . set ( name = name ) <EOL> self . set ( path = filepath , idx = numhdu ) <EOL> self . set_naxispath ( naxispath ) <EOL> self . wcs . load_header ( ahdr ) <EOL> def load_buffer ( self , data , dims , dtype , byteswap = False , <EOL> metadata = None ) : <EOL> data = numpy . fromstring ( data , dtype = dtype ) <EOL> if byteswap : <EOL> data . byteswap ( True ) <EOL> data = data . reshape ( dims ) <EOL> self . set_data ( data , metadata = metadata ) <EOL> def get_mddata ( self ) : <EOL> return self . _md_data <EOL> def set_naxispath ( self , naxispath ) : <EOL> """<STR_LIT>""" <EOL> revnaxis = list ( naxispath ) <EOL> revnaxis . reverse ( ) <EOL> view = revnaxis + [ slice ( None ) , slice ( None ) ] <EOL> data = self . get_mddata ( ) [ view ] <EOL> assert len ( data . shape ) == <NUM_LIT:2> , ImageError ( "<STR_LIT>" % ( <EOL> str ( naxispath ) ) ) <EOL> self . naxispath = naxispath <EOL> self . revnaxis = revnaxis <EOL> self . set_data ( data ) <EOL> def set_wcs ( self , wcs ) : <EOL> self . wcs = wcs <EOL> def set_io ( self , io ) : <EOL> self . io = io <EOL> def get_data_size ( self ) : <EOL> return self . get_size ( ) <EOL> def get_header ( self , create = True ) : <EOL> try : <EOL> hdr = self . metadata [ '<STR_LIT>' ] <EOL> if self . inherit_primary_header and self . _primary_hdr is not None : <EOL> displayhdr = AstroHeader ( ) <EOL> for key in hdr . keyorder : <EOL> card = hdr . get_card ( key ) <EOL> bnch = displayhdr . __setitem__ ( card . key , card . value ) <EOL> bnch . comment = card . comment <EOL> for key in self . _primary_hdr . keyorder : <EOL> if key not in hdr : <EOL> card = self . _primary_hdr . get_card ( key ) <EOL> bnch = displayhdr . __setitem__ ( card . key , card . value ) <EOL> bnch . comment = card . comment <EOL> else : <EOL> displayhdr = hdr <EOL> except KeyError as e : <EOL> if not create : <EOL> raise e <EOL> hdr = AstroHeader ( ) <EOL> self . metadata [ '<STR_LIT>' ] = hdr <EOL> displayhdr = hdr <EOL> return displayhdr <EOL> def get_keyword ( self , kwd , * args ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> kwds = self . get_header ( ) <EOL> return kwds [ kwd ] <EOL> except KeyError : <EOL> if len ( args ) > <NUM_LIT:0> : <EOL> return args [ <NUM_LIT:0> ] <EOL> raise KeyError ( kwd ) <EOL> def get_keywords_list ( self , * args ) : <EOL> return list ( map ( self . get_keyword , args ) ) <EOL> def set_keyword ( self , kwd , value , create = True ) : <EOL> kwds = self . get_header ( create = create ) <EOL> kwd = kwd . upper ( ) <EOL> if not create : <EOL> prev = kwds [ kwd ] <EOL> kwds [ kwd ] = value <EOL> def update_keywords ( self , keyDict ) : <EOL> hdr = self . get_header ( ) <EOL> for kwd , val in keyDict . items ( ) : <EOL> hdr [ kwd . upper ( ) ] = val <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> self . wcs . load_header ( hdr ) <EOL> def set_keywords ( self , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> return self . update_keywords ( kwds ) <EOL> def update_data ( self , data_np , metadata = None , astype = None ) : <EOL> """<STR_LIT>""" <EOL> self . set_data ( data_np . copy ( ) , metadata = metadata , <EOL> astype = astype ) <EOL> def update_metadata ( self , keyDict ) : <EOL> for key , val in keyDict . items ( ) : <EOL> self . metadata [ key ] = val <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> header = self . get_header ( ) <EOL> self . wcs . load_header ( header ) <EOL> def clear_metadata ( self ) : <EOL> self . metadata = { } <EOL> def transfer ( self , other , astype = None ) : <EOL> data = self . _get_data ( ) <EOL> other . update_data ( data , astype = astype ) <EOL> other . update_metadata ( self . metadata ) <EOL> def copy ( self , astype = None ) : <EOL> data = self . _get_data ( ) <EOL> other = AstroImage ( data , logger = self . logger ) <EOL> self . transfer ( other , astype = astype ) <EOL> return other <EOL> def save_as_file ( self , filepath , ** kwdargs ) : <EOL> data = self . _get_data ( ) <EOL> header = self . get_header ( ) <EOL> self . io . save_as_file ( filepath , data , header , ** kwdargs ) <EOL> def pixtocoords ( self , x , y , system = None , coords = '<STR_LIT:data>' ) : <EOL> args = [ x , y ] + self . revnaxis <EOL> return self . wcs . pixtocoords ( args , system = system , coords = coords ) <EOL> def spectral_coord ( self , coords = '<STR_LIT:data>' ) : <EOL> args = [ <NUM_LIT:0> , <NUM_LIT:0> ] + self . revnaxis <EOL> return self . wcs . spectral_coord ( args , coords = coords ) <EOL> def pixtoradec ( self , x , y , format = '<STR_LIT>' , coords = '<STR_LIT:data>' ) : <EOL> args = [ x , y ] + self . revnaxis <EOL> ra_deg , dec_deg = self . wcs . pixtoradec ( args , coords = coords ) <EOL> if format == '<STR_LIT>' : <EOL> return ra_deg , dec_deg <EOL> return wcs . deg2fmt ( ra_deg , dec_deg , format ) <EOL> def radectopix ( self , ra_deg , dec_deg , format = '<STR_LIT>' , coords = '<STR_LIT:data>' ) : <EOL> if format != '<STR_LIT>' : <EOL> ra_deg = wcs . lon_to_deg ( ra_deg ) <EOL> dec_deg = wcs . lat_to_deg ( dec_deg ) <EOL> return self . wcs . radectopix ( ra_deg , dec_deg , coords = coords , <EOL> naxispath = self . revnaxis ) <EOL> def get_starsep_XY ( self , x1 , y1 , x2 , y2 ) : <EOL> ra_org , dec_org = self . pixtoradec ( x1 , y1 ) <EOL> ra_dst , dec_dst = self . pixtoradec ( x2 , y2 ) <EOL> return wcs . get_starsep_RaDecDeg ( ra_org , dec_org , ra_dst , dec_dst ) <EOL> def calc_radius_xy ( self , x , y , radius_deg ) : <EOL> """<STR_LIT>""" <EOL> ra_deg , dec_deg = self . pixtoradec ( x , y ) <EOL> ra2_deg , dec2_deg = wcs . add_offset_radec ( ra_deg , dec_deg , <EOL> <NUM_LIT:0.0> , <NUM_LIT:1.0> ) <EOL> x2 , y2 = self . radectopix ( ra2_deg , dec2_deg ) <EOL> px_per_deg_e = math . sqrt ( math . fabs ( x2 - x ) ** <NUM_LIT:2> + math . fabs ( y2 - y ) ** <NUM_LIT:2> ) <EOL> radius_px = px_per_deg_e * radius_deg <EOL> return radius_px <EOL> def calc_radius_deg2pix ( self , ra_deg , dec_deg , delta_deg , <EOL> equinox = None ) : <EOL> x , y = self . radectopix ( ra_deg , dec_deg , equinox = equinox ) <EOL> return self . calc_radius_xy ( x , y , delta_deg ) <EOL> def add_offset_xy ( self , x , y , delta_deg_x , delta_deg_y ) : <EOL> ra_deg , dec_deg = self . pixtoradec ( x , y ) <EOL> ra2_deg , dec2_deg = wcs . add_offset_radec ( ra_deg , dec_deg , <EOL> delta_deg_x , delta_deg_y ) <EOL> x2 , y2 = self . radectopix ( ra2_deg , dec2_deg ) <EOL> return ( x2 , y2 ) <EOL> def calc_radius_center ( self , delta_deg ) : <EOL> return self . calc_radius_xy ( float ( self . width / <NUM_LIT> ) , <EOL> float ( self . height / <NUM_LIT> ) , <EOL> delta_deg ) <EOL> def calc_compass ( self , x , y , len_deg_e , len_deg_n ) : <EOL> xe , ye = self . add_offset_xy ( x , y , len_deg_e , <NUM_LIT:0.0> ) <EOL> xe = int ( round ( xe ) ) <EOL> ye = int ( round ( ye ) ) <EOL> xn , yn = self . add_offset_xy ( x , y , <NUM_LIT:0.0> , len_deg_n ) <EOL> xn = int ( round ( xn ) ) <EOL> yn = int ( round ( yn ) ) <EOL> return ( x , y , xn , yn , xe , ye ) <EOL> def calc_compass_radius ( self , x , y , radius_px ) : <EOL> xe , ye = self . add_offset_xy ( x , y , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) <EOL> xn , yn = self . add_offset_xy ( x , y , <NUM_LIT:0.0> , <NUM_LIT:1.0> ) <EOL> px_per_deg_e = math . sqrt ( math . fabs ( ye - y ) ** <NUM_LIT:2> + math . fabs ( xe - x ) ** <NUM_LIT:2> ) <EOL> px_per_deg_n = math . sqrt ( math . fabs ( yn - y ) ** <NUM_LIT:2> + math . fabs ( xn - x ) ** <NUM_LIT:2> ) <EOL> len_deg_e = radius_px / px_per_deg_e <EOL> len_deg_n = radius_px / px_per_deg_n <EOL> return self . calc_compass ( x , y , len_deg_e , len_deg_n ) <EOL> def calc_compass_center ( self ) : <EOL> x = float ( self . width ) / <NUM_LIT> <EOL> y = float ( self . height ) / <NUM_LIT> <EOL> radius_px = float ( min ( self . width , self . height ) ) / <NUM_LIT> <EOL> return self . calc_compass_radius ( x , y , radius_px ) <EOL> def get_wcs_rotation_deg ( self ) : <EOL> header = self . get_header ( ) <EOL> ( rot , cdelt1 , cdelt2 ) = wcs . get_rotation_and_scale ( header ) <EOL> return rot <EOL> def rotate ( self , deg , update_wcs = False ) : <EOL> super ( AstroImage , self ) . rotate ( deg ) <EOL> def mosaic_inline ( self , imagelist , bg_ref = None , trim_px = None , <EOL> merge = False , allow_expand = True , expand_pad_deg = <NUM_LIT> , <EOL> max_expand_pct = None , <EOL> update_minmax = True , suppress_callback = False ) : <EOL> """<STR_LIT>""" <EOL> header = self . get_header ( ) <EOL> ( ( xrot_ref , yrot_ref ) , <EOL> ( cdelt1_ref , cdelt2_ref ) ) = wcs . get_xy_rotation_and_scale ( header ) <EOL> ref_rot = yrot_ref <EOL> scale_x , scale_y = math . fabs ( cdelt1_ref ) , math . fabs ( cdelt2_ref ) <EOL> mydata = self . _get_data ( ) <EOL> count = <NUM_LIT:1> <EOL> for image in imagelist : <EOL> name = image . get ( '<STR_LIT:name>' , '<STR_LIT>' % ( count ) ) <EOL> count += <NUM_LIT:1> <EOL> data_np = image . _get_data ( ) <EOL> ctr_x , ctr_y = trcalc . get_center ( data_np ) <EOL> ra , dec = image . pixtoradec ( ctr_x , ctr_y ) <EOL> ht , wd = data_np . shape [ : <NUM_LIT:2> ] <EOL> if trim_px : <EOL> xlo , xhi = trim_px , wd - trim_px <EOL> ylo , yhi = trim_px , ht - trim_px <EOL> data_np = data_np [ ylo : yhi , xlo : xhi , ... ] <EOL> ht , wd = data_np . shape [ : <NUM_LIT:2> ] <EOL> if bg_ref is not None : <EOL> bg = iqcalc . get_median ( data_np ) <EOL> bg_inc = bg_ref - bg <EOL> data_np = data_np + bg_inc <EOL> if update_minmax : <EOL> maxval = numpy . nanmax ( data_np ) <EOL> minval = numpy . nanmin ( data_np ) <EOL> self . maxval = max ( self . maxval , maxval ) <EOL> self . minval = min ( self . minval , minval ) <EOL> header = image . get_header ( ) <EOL> ( ( xrot , yrot ) , <EOL> ( cdelt1 , cdelt2 ) ) = wcs . get_xy_rotation_and_scale ( header ) <EOL> self . logger . debug ( "<STR_LIT>" % ( <EOL> name , xrot , yrot , cdelt1 , cdelt2 ) ) <EOL> if ( not numpy . isclose ( math . fabs ( cdelt1 ) , scale_x ) or <EOL> not numpy . isclose ( math . fabs ( cdelt2 ) , scale_y ) ) : <EOL> nscale_x = math . fabs ( cdelt1 ) / scale_x <EOL> nscale_y = math . fabs ( cdelt2 ) / scale_y <EOL> self . logger . debug ( "<STR_LIT>" % ( <EOL> nscale_x , nscale_y ) ) <EOL> data_np , ( ascale_x , ascale_y ) = trcalc . get_scaled_cutout_basic ( <EOL> data_np , <NUM_LIT:0> , <NUM_LIT:0> , wd - <NUM_LIT:1> , ht - <NUM_LIT:1> , nscale_x , nscale_y ) <EOL> rot_dx , rot_dy = xrot - xrot_ref , yrot - yrot_ref <EOL> flip_x = False <EOL> flip_y = False <EOL> if numpy . isclose ( math . fabs ( rot_dx ) , <NUM_LIT> ) : <EOL> flip_x = not flip_x <EOL> rot_dx = <NUM_LIT:0.0> <EOL> if numpy . isclose ( math . fabs ( rot_dy ) , <NUM_LIT> ) : <EOL> flip_y = not flip_y <EOL> rot_dy = <NUM_LIT:0.0> <EOL> self . logger . debug ( "<STR_LIT>" % ( flip_x , flip_y ) ) <EOL> if flip_x or flip_y : <EOL> rotdata = trcalc . transform ( data_np , <EOL> flip_x = flip_x , flip_y = flip_y ) <EOL> else : <EOL> rotdata = data_np <EOL> if not numpy . isclose ( rot_dy , <NUM_LIT:0.0> ) : <EOL> rot_deg = rot_dy <EOL> self . logger . debug ( "<STR_LIT>" % ( name , rot_deg ) ) <EOL> rotdata = trcalc . rotate ( rotdata , rot_deg , <EOL> ) <EOL> ht , wd = rotdata . shape [ : <NUM_LIT:2> ] <EOL> ctr_x , ctr_y = trcalc . get_center ( rotdata ) <EOL> x0 , y0 = self . radectopix ( ra , dec ) <EOL> x0 , y0 = int ( round ( x0 ) ) , int ( round ( y0 ) ) <EOL> self . logger . debug ( "<STR_LIT>" % ( <EOL> name , x0 , y0 ) ) <EOL> my_ctr_x , my_ctr_y = trcalc . get_center ( mydata ) <EOL> off_x , off_y = x0 - my_ctr_x , y0 - my_ctr_y <EOL> self . logger . debug ( "<STR_LIT>" % ( off_x , off_y ) ) <EOL> xlo , xhi = x0 - ctr_x , x0 + wd - ctr_x <EOL> ylo , yhi = y0 - ctr_y , y0 + ht - ctr_y <EOL> assert ( xhi - xlo == wd ) , Exception ( "<STR_LIT>" % ( xhi - xlo , wd ) ) <EOL> assert ( yhi - ylo == ht ) , Exception ( "<STR_LIT>" % ( yhi - ylo , ht ) ) <EOL> mywd , myht = self . get_size ( ) <EOL> if xlo < <NUM_LIT:0> or xhi > mywd or ylo < <NUM_LIT:0> or yhi > myht : <EOL> if not allow_expand : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> expand_x = max ( int ( expand_pad_deg / scale_x ) , <NUM_LIT:0> ) <EOL> expand_y = max ( int ( expand_pad_deg / scale_y ) , <NUM_LIT:0> ) <EOL> nx1_off , nx2_off = <NUM_LIT:0> , <NUM_LIT:0> <EOL> if xlo < <NUM_LIT:0> : <EOL> nx1_off = abs ( xlo ) + expand_x <EOL> if xhi > mywd : <EOL> nx2_off = ( xhi - mywd ) + expand_x <EOL> xlo , xhi = xlo + nx1_off , xhi + nx1_off <EOL> ny1_off , ny2_off = <NUM_LIT:0> , <NUM_LIT:0> <EOL> if ylo < <NUM_LIT:0> : <EOL> ny1_off = abs ( ylo ) + expand_y <EOL> if yhi > myht : <EOL> ny2_off = ( yhi - myht ) + expand_y <EOL> ylo , yhi = ylo + ny1_off , yhi + ny1_off <EOL> new_wd = mywd + nx1_off + nx2_off <EOL> new_ht = myht + ny1_off + ny2_off <EOL> old_area = mywd * myht <EOL> new_area = new_wd * new_ht <EOL> expand_pct = new_area / old_area <EOL> if ( ( max_expand_pct is not None ) and <EOL> ( expand_pct > max_expand_pct ) ) : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( expand_pct * <NUM_LIT:100> , max_expand_pct ) ) <EOL> new_data = numpy . zeros ( ( new_ht , new_wd ) ) <EOL> new_data [ ny1_off : ny1_off + myht , nx1_off : nx1_off + mywd ] = mydata <EOL> self . _data = new_data <EOL> mydata = new_data <EOL> if ( nx1_off > <NUM_LIT:0> ) or ( ny1_off > <NUM_LIT:0> ) : <EOL> crpix1 , crpix2 = self . get_keywords_list ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwds = dict ( CRPIX1 = crpix1 + nx1_off , <EOL> CRPIX2 = crpix2 + ny1_off ) <EOL> self . update_keywords ( kwds ) <EOL> try : <EOL> if merge : <EOL> mydata [ ylo : yhi , xlo : xhi , ... ] += rotdata [ <NUM_LIT:0> : ht , <NUM_LIT:0> : wd , ... ] <EOL> else : <EOL> idx = ( mydata [ ylo : yhi , xlo : xhi , ... ] == <NUM_LIT:0.0> ) <EOL> mydata [ ylo : yhi , xlo : xhi , ... ] [ idx ] = rotdata [ <NUM_LIT:0> : ht , <NUM_LIT:0> : wd , ... ] [ idx ] <EOL> except Exception as e : <EOL> self . logger . error ( "<STR_LIT>" % ( str ( e ) ) ) <EOL> raise <EOL> if not suppress_callback : <EOL> self . make_callback ( '<STR_LIT>' ) <EOL> return ( xlo , ylo , xhi , yhi ) <EOL> def info_xy ( self , data_x , data_y , settings ) : <EOL> try : <EOL> value = self . get_data_xy ( int ( data_x + <NUM_LIT:0.5> ) , int ( data_y + <NUM_LIT:0.5> ) ) <EOL> except Exception as e : <EOL> value = None <EOL> system = settings . get ( '<STR_LIT>' , None ) <EOL> format = settings . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ra_lbl , dec_lbl = six . unichr ( <NUM_LIT> ) , six . unichr ( <NUM_LIT> ) <EOL> ts = time . time ( ) <EOL> try : <EOL> if self . wcs is None : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> ra_txt = dec_txt = '<STR_LIT>' <EOL> elif self . wcs . coordsys == '<STR_LIT>' : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> ra_txt = dec_txt = '<STR_LIT>' <EOL> elif self . wcs . coordsys == '<STR_LIT>' : <EOL> args = [ data_x , data_y ] + self . revnaxis <EOL> x , y = self . wcs . pixtosystem ( <EOL> args , system = system , coords = '<STR_LIT:data>' ) <EOL> ra_txt = "<STR_LIT>" % ( x ) <EOL> dec_txt = "<STR_LIT>" % ( y ) <EOL> ra_lbl , dec_lbl = "<STR_LIT:X>" , "<STR_LIT:Y>" <EOL> else : <EOL> args = [ data_x , data_y ] + self . revnaxis <EOL> lon_deg , lat_deg = self . wcs . pixtosystem ( <EOL> args , system = system , coords = '<STR_LIT:data>' ) <EOL> if format == '<STR_LIT>' : <EOL> if system in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> sign , deg , min , sec = wcs . degToDms ( lon_deg , <EOL> isLatitude = False ) <EOL> ra_txt = '<STR_LIT>' % ( deg , min , sec ) <EOL> else : <EOL> deg , min , sec = wcs . degToHms ( lon_deg ) <EOL> ra_txt = '<STR_LIT>' % ( deg , min , sec ) <EOL> sign , deg , min , sec = wcs . degToDms ( lat_deg ) <EOL> if sign < <NUM_LIT:0> : <EOL> sign = '<STR_LIT:->' <EOL> else : <EOL> sign = '<STR_LIT:+>' <EOL> dec_txt = '<STR_LIT>' % ( sign , deg , min , sec ) <EOL> else : <EOL> ra_txt = '<STR_LIT>' % ( lon_deg ) <EOL> dec_txt = '<STR_LIT>' % ( lat_deg ) <EOL> if system == '<STR_LIT>' : <EOL> ra_lbl , dec_lbl = "<STR_LIT:l>" , "<STR_LIT:b>" <EOL> elif system == '<STR_LIT>' : <EOL> ra_lbl , dec_lbl = six . unichr ( <NUM_LIT> ) , six . unichr ( <NUM_LIT> ) <EOL> elif system == '<STR_LIT>' : <EOL> ra_txt = "<STR_LIT>" % ( lon_deg * <NUM_LIT> ) <EOL> dec_txt = "<STR_LIT>" % ( lat_deg * <NUM_LIT> ) <EOL> ra_lbl , dec_lbl = "<STR_LIT>" , "<STR_LIT>" <EOL> except Exception as e : <EOL> self . logger . warning ( "<STR_LIT>" % ( <EOL> str ( e ) ) ) <EOL> ra_txt = '<STR_LIT>' <EOL> dec_txt = '<STR_LIT>' <EOL> try : <EOL> ( type_ , value_ , tb ) = sys . exc_info ( ) <EOL> tb_str = "<STR_LIT>" . join ( traceback . format_tb ( tb ) ) <EOL> self . logger . error ( "<STR_LIT>" % ( tb_str ) ) <EOL> except Exception : <EOL> tb_str = "<STR_LIT>" <EOL> self . logger . error ( tb_str ) <EOL> te = time . time ( ) - ts <EOL> info = Bunch . Bunch ( itype = '<STR_LIT>' , data_x = data_x , data_y = data_y , <EOL> x = data_x , y = data_y , <EOL> ra_txt = ra_txt , dec_txt = dec_txt , <EOL> ra_lbl = ra_lbl , dec_lbl = dec_lbl , <EOL> value = value ) <EOL> return info </s>
