idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
24,900 | def key_press_event ( self , widget , event ) : keyname = '' self . logger . debug ( "key press event, key=%s" % ( keyname ) ) return self . make_ui_callback ( 'key-press' , keyname ) | Called when a key is pressed and the window has the focus . Adjust method signature as appropriate for callback . |
24,901 | def key_release_event ( self , widget , event ) : keyname = '' self . logger . debug ( "key release event, key=%s" % ( keyname ) ) return self . make_ui_callback ( 'key-release' , keyname ) | Called when a key is released after being pressed . Adjust method signature as appropriate for callback . |
24,902 | def resizeEvent ( self , event ) : vp = self . viewport ( ) rect = vp . geometry ( ) x1 , y1 , x2 , y2 = rect . getCoords ( ) width = x2 - x1 + 1 height = y2 - y1 + 1 self . v_w . resize ( width , height ) | Override from QAbstractScrollArea . Resize the viewer widget when the viewport is resized . |
24,903 | def scrollContentsBy ( self , dx , dy ) : if self . _adjusting : return self . _scrolling = True try : bd = self . viewer . get_bindings ( ) res = bd . calc_pan_pct ( self . viewer , pad = self . pad ) if res is None : return pct_x , pct_y = res . pan_pct_x , res . pan_pct_y if dx != 0 : hsb = self . horizontalScrollBa... | Override from QAbstractScrollArea . Called when the scroll bars are adjusted by the user . |
24,904 | def get_catalog ( ) : tforms = { } for name , value in list ( globals ( ) . items ( ) ) : if name . endswith ( 'Transform' ) : tforms [ name ] = value return Bunch . Bunch ( tforms , caseless = True ) | Returns a catalog of available transforms . These are used to build chains for rendering with different back ends . |
24,905 | def masktorgb ( mask , color = 'lightgreen' , alpha = 1.0 ) : mask = np . asarray ( mask ) if mask . ndim != 2 : raise ValueError ( 'ndim={0} is not supported' . format ( mask . ndim ) ) ht , wd = mask . shape r , g , b = colors . lookup_color ( color ) rgbobj = RGBImage ( data_np = np . zeros ( ( ht , wd , 4 ) , dtype... | Convert boolean mask to RGB image object for canvas overlay . |
24,906 | def _find_rtd_version ( ) : vstr = 'latest' try : import ginga from bs4 import BeautifulSoup except ImportError : return vstr if not minversion ( ginga , '2.6.0' ) : return vstr url = 'https://readthedocs.org/projects/ginga/downloads/' with urllib . request . urlopen ( url ) as r : soup = BeautifulSoup ( r , 'html.pars... | Find closest RTD doc version . |
24,907 | def _download_rtd_zip ( rtd_version = None , ** kwargs ) : if not toolkit . family . startswith ( 'qt' ) : raise ValueError ( 'Downloaded documentation not compatible with {} ' 'UI toolkit browser' . format ( toolkit . family ) ) if rtd_version is None : rtd_version = _find_rtd_version ( ) data_path = os . path . dirna... | Download and extract HTML ZIP from RTD to installed doc data path . Download is skipped if content already exists . |
24,908 | def get_doc ( logger = None , plugin = None , reporthook = None ) : from ginga . GingaPlugin import GlobalPlugin , LocalPlugin if isinstance ( plugin , GlobalPlugin ) : plugin_page = 'plugins_global' plugin_name = str ( plugin ) elif isinstance ( plugin , LocalPlugin ) : plugin_page = 'plugins_local' plugin_name = str ... | Return URL to documentation . Attempt download if does not exist . |
24,909 | def redo ( self , * args ) : if not self . gui_up : return mod_only = self . w . modified_only . get_state ( ) treedict = Bunch . caselessDict ( ) self . treeview . clear ( ) self . w . status . set_text ( '' ) channel = self . fv . get_channel ( self . chname ) if channel is None : return if mod_only : all_keys = chan... | Generate listing of images that user can save . |
24,910 | def update_channels ( self ) : if not self . gui_up : return self . logger . debug ( "channel configuration has changed--updating gui" ) try : channel = self . fv . get_channel ( self . chname ) except KeyError : channel = self . fv . get_channel_info ( ) if channel is None : raise ValueError ( 'No channel available' )... | Update the GUI to reflect channels and image listing . |
24,911 | def _format_extname ( self , ext ) : if ext is None : outs = ext else : outs = '{0},{1}' . format ( ext [ 0 ] , ext [ 1 ] ) return outs | Pretty print given extension name and number tuple . |
24,912 | def browse_outdir ( self ) : self . dirsel . popup ( 'Select directory' , self . w . outdir . set_text , initialdir = self . outdir ) self . set_outdir ( ) | Browse for output directory . |
24,913 | def set_outdir ( self ) : dirname = self . w . outdir . get_text ( ) if os . path . isdir ( dirname ) : self . outdir = dirname self . logger . debug ( 'Output directory set to {0}' . format ( self . outdir ) ) else : self . w . outdir . set_text ( self . outdir ) self . logger . error ( '{0} is not a directory' . form... | Set output directory . |
24,914 | def set_suffix ( self ) : self . suffix = self . w . suffix . get_text ( ) self . logger . debug ( 'Output suffix set to {0}' . format ( self . suffix ) ) | Set output suffix . |
24,915 | def _write_history ( self , pfx , hdu , linechar = 60 , indentchar = 2 ) : channel = self . fv . get_channel ( self . chname ) if channel is None : return history_plgname = 'ChangeHistory' try : history_obj = self . fv . gpmon . getPlugin ( history_plgname ) except Exception : self . logger . error ( '{0} plugin is not... | Write change history to given HDU header . Limit each HISTORY line to given number of characters . Subsequent lines of the same history will be indented . |
24,916 | def _write_header ( self , image , hdu ) : hduhdr = hdu . header ghdr = image . metadata [ 'header' ] for key in ghdr : if key . upper ( ) == 'COMMENT' : continue bnch = ghdr . get_card ( key ) if key not in hduhdr : hduhdr [ key ] = ( bnch . value , bnch . comment ) elif hduhdr [ key ] != bnch . value : hduhdr [ key ]... | Write header from image object to given HDU . |
24,917 | def _write_mef ( self , key , extlist , outfile ) : channel = self . fv . get_channel ( self . chname ) with fits . open ( outfile , mode = 'update' ) as pf : for idx in extlist : k = '{0}[{1}]' . format ( key , self . _format_extname ( idx ) ) image = channel . datasrc [ k ] pf [ idx ] . data = image . get_data ( ) se... | Write out regular multi - extension FITS data . |
24,918 | def toggle_save_cb ( self , w , res_dict ) : if len ( res_dict ) > 0 : self . w . save . set_enabled ( True ) else : self . w . save . set_enabled ( False ) | Only enable saving if something is selected . |
24,919 | def save_images ( self ) : res_dict = self . treeview . get_selected ( ) clobber = self . settings . get ( 'clobber' , False ) self . treeview . clear_selection ( ) if self . suffix : sfx = '_' + self . suffix else : sfx = '' if self . settings . get ( 'include_chname' , True ) : sfx += '_' + self . chname for infile i... | Save selected images . |
24,920 | def font_info ( font_str ) : vals = font_str . split ( ';' ) point_size , style , weight = 8 , 'normal' , 'normal' family = vals [ 0 ] if len ( vals ) > 1 : style = vals [ 1 ] if len ( vals ) > 2 : weight = vals [ 2 ] match = font_regex . match ( family ) if match : family , point_size = match . groups ( ) point_size =... | Extract font information from a font string such as supplied to the font argument to a widget . |
24,921 | def get_points ( self ) : if hasattr ( self , 'points' ) : points = self . crdmap . to_data ( self . points ) else : points = [ ] return points | Get the set of points that is used to draw the object . |
24,922 | def get_data_points ( self , points = None ) : if points is None : points = self . points points = self . crdmap . to_data ( points ) return points | Points returned are in data coordinates . |
24,923 | def set_data_points ( self , points ) : self . points = np . asarray ( self . crdmap . data_to ( points ) ) | Input points must be in data coordinates will be converted to the coordinate space of the object and stored . |
24,924 | def convert_mapper ( self , tomap ) : frommap = self . crdmap if frommap == tomap : return if hasattr ( self , 'radius' ) : x0 , y0 = frommap . offset_pt ( ( self . x , self . y ) , ( self . radius , 0 ) ) pts = frommap . to_data ( ( ( self . x , self . y ) , ( x0 , y0 ) ) ) pts = tomap . data_to ( pts ) self . radius ... | Converts our object from using one coordinate map to another . |
24,925 | def point_within_radius ( self , points , pt , canvas_radius , scales = ( 1.0 , 1.0 ) ) : scale_x , scale_y = scales x , y = pt a_arr , b_arr = np . asarray ( points ) . T dx = np . fabs ( x - a_arr ) * scale_x dy = np . fabs ( y - b_arr ) * scale_y new_radius = np . sqrt ( dx ** 2 + dy ** 2 ) res = ( new_radius <= can... | Points points and point pt are in data coordinates . Return True for points within the circle defined by a center at point pt and within canvas_radius . |
24,926 | def within_radius ( self , viewer , points , pt , canvas_radius ) : scales = viewer . get_scale_xy ( ) return self . point_within_radius ( points , pt , canvas_radius , scales ) | Points points and point pt are in data coordinates . Return True for points within the circle defined by a center at point pt and within canvas_radius . The distance between points is scaled by the canvas scale . |
24,927 | def get_pt ( self , viewer , points , pt , canvas_radius = None ) : if canvas_radius is None : canvas_radius = self . cap_radius if hasattr ( self , 'rot_deg' ) : ctr_pt = self . get_center_pt ( ) pt = trcalc . rotate_coord ( pt , [ - self . rot_deg ] , ctr_pt ) res = self . within_radius ( viewer , points , pt , canva... | Takes an array of points points and a target point pt . Returns the first index of the point that is within the radius of the target point . If none of the points are within the radius returns None . |
24,928 | def within_line ( self , viewer , points , p_start , p_stop , canvas_radius ) : scale_x , scale_y = viewer . get_scale_xy ( ) new_radius = canvas_radius * 1.0 / min ( scale_x , scale_y ) return self . point_within_line ( points , p_start , p_stop , new_radius ) | Points points and line endpoints p_start p_stop are in data coordinates . Return True for points within the line defined by a line from p_start to p_end and within canvas_radius . The distance between points is scaled by the viewer s canvas scale . |
24,929 | def get_bbox ( self , points = None ) : if points is None : x1 , y1 , x2 , y2 = self . get_llur ( ) return ( ( x1 , y1 ) , ( x1 , y2 ) , ( x2 , y2 ) , ( x2 , y1 ) ) else : return trcalc . strip_z ( trcalc . get_bounds ( points ) ) | Get bounding box of this object . |
24,930 | def set ( self , time_sec , callback_fn , * args , ** kwdargs ) : timer = self . timer ( ) timer . set_callback ( 'expired' , callback_fn , * args , ** kwdargs ) timer . set ( time_sec ) return timer | Convenience function to create and set a timer . |
24,931 | def set_window_size ( self , width , height ) : self . _imgwin_wd = int ( width ) self . _imgwin_ht = int ( height ) self . _ctr_x = width // 2 self . _ctr_y = height // 2 self . logger . debug ( "widget resized to %dx%d" % ( width , height ) ) self . make_callback ( 'configure' , width , height ) self . redraw ( whenc... | Report the size of the window to display the image . |
24,932 | def set_renderer ( self , renderer ) : self . renderer = renderer width , height = self . get_window_size ( ) if width > 0 and height > 0 : renderer . resize ( ( width , height ) ) | Set and initialize the renderer used by this instance . |
24,933 | def set_canvas ( self , canvas , private_canvas = None ) : self . canvas = canvas canvas . initialize ( None , self , self . logger ) canvas . add_callback ( 'modified' , self . canvas_changed_cb ) canvas . set_surface ( self ) canvas . ui_set_active ( True ) self . _imgobj = None if private_canvas is not None : self .... | Set the canvas object . |
24,934 | def initialize_private_canvas ( self , private_canvas ) : if self . t_ . get ( 'show_pan_position' , False ) : self . show_pan_mark ( True ) if self . t_ . get ( 'show_focus_indicator' , False ) : self . show_focus_indicator ( True ) | Initialize the private canvas used by this instance . |
24,935 | def set_rgbmap ( self , rgbmap ) : self . rgbmap = rgbmap t_ = rgbmap . get_settings ( ) t_ . share_settings ( self . t_ , keylist = rgbmap . settings_keys ) rgbmap . add_callback ( 'changed' , self . rgbmap_cb ) self . redraw ( whence = 2 ) | Set RGB map object used by this instance . It controls how the values in the image are mapped to color . |
24,936 | def get_image ( self ) : if self . _imgobj is not None : return self . _imgobj . get_image ( ) canvas_img = self . get_canvas_image ( ) return canvas_img . get_image ( ) | Get the image currently being displayed . |
24,937 | def get_canvas_image ( self ) : if self . _imgobj is not None : return self . _imgobj try : self . _imgobj = self . canvas . get_object_by_tag ( self . _canvas_img_tag ) self . _imgobj . add_callback ( 'image-set' , self . _image_set_cb ) except KeyError : NormImage = self . canvas . getDrawClass ( 'normimage' ) interp... | Get canvas image object . |
24,938 | def set_image ( self , image , add_to_canvas = True ) : if not isinstance ( image , BaseImage . BaseImage ) : raise ValueError ( "Wrong type of object to load: %s" % ( str ( type ( image ) ) ) ) canvas_img = self . get_canvas_image ( ) old_image = canvas_img . get_image ( ) self . make_callback ( 'image-unset' , old_im... | Set an image to be displayed . |
24,939 | def save_profile ( self , ** params ) : image = self . get_image ( ) if ( image is None ) : return profile = image . get ( 'profile' , None ) if profile is None : profile = Settings . SettingGroup ( ) image . set ( profile = profile ) self . logger . debug ( "saving to image profile: params=%s" % ( str ( params ) ) ) p... | Save the given parameters into profile settings . |
24,940 | def set_data ( self , data , metadata = None ) : image = AstroImage . AstroImage ( data , metadata = metadata , logger = self . logger ) self . set_image ( image ) | Set an image to be displayed by providing raw data . |
24,941 | def clear ( self ) : self . _imgobj = None try : self . canvas . delete_object_by_tag ( self . _canvas_img_tag ) self . redraw ( ) except KeyError : pass | Clear the displayed image . |
24,942 | def redraw ( self , whence = 0 ) : with self . _defer_lock : whence = min ( self . _defer_whence , whence ) if not self . defer_redraw : if self . _hold_redraw_cnt == 0 : self . _defer_whence = self . _defer_whence_reset self . redraw_now ( whence = whence ) else : self . _defer_whence = whence return elapsed = time . ... | Redraw the canvas . |
24,943 | def canvas_changed_cb ( self , canvas , whence ) : self . logger . debug ( "root canvas changed, whence=%d" % ( whence ) ) try : canvas_img = self . canvas . get_object_by_tag ( self . _canvas_img_tag ) if self . _imgobj is not canvas_img : self . _imgobj = canvas_img self . _imgobj . add_callback ( 'image-set' , self ... | Handle callback for when canvas has changed . |
24,944 | def delayed_redraw ( self ) : with self . _defer_lock : whence = self . _defer_whence self . _defer_whence = self . _defer_whence_reset flag = self . _defer_flag self . _defer_flag = False if flag : self . redraw_now ( whence = whence ) | Handle delayed redrawing of the canvas . |
24,945 | def set_redraw_lag ( self , lag_sec ) : self . defer_redraw = ( lag_sec > 0.0 ) if self . defer_redraw : self . defer_lagtime = lag_sec | Set lag time for redrawing the canvas . |
24,946 | def set_refresh_rate ( self , fps ) : self . rf_fps = fps self . rf_rate = 1.0 / self . rf_fps self . logger . info ( "set a refresh rate of %.2f fps" % ( self . rf_fps ) ) | Set the refresh rate for redrawing the canvas at a timed interval . |
24,947 | def start_refresh ( self ) : self . logger . debug ( "starting timed refresh interval" ) self . rf_flags [ 'done' ] = False self . rf_draw_count = 0 self . rf_timer_count = 0 self . rf_late_count = 0 self . rf_late_total = 0.0 self . rf_early_count = 0 self . rf_early_total = 0.0 self . rf_delta_total = 0.0 self . rf_s... | Start redrawing the canvas at the previously set timed interval . |
24,948 | def stop_refresh ( self ) : self . logger . debug ( "stopping timed refresh" ) self . rf_flags [ 'done' ] = True self . rf_timer . clear ( ) | Stop redrawing the canvas at the previously set timed interval . |
24,949 | def get_refresh_stats ( self ) : if self . rf_draw_count == 0 : fps = 0.0 else : interval = time . time ( ) - self . rf_start_time fps = self . rf_draw_count / interval jitter = self . rf_delta_total / max ( 1 , self . rf_timer_count ) late_avg = self . rf_late_total / max ( 1 , self . rf_late_count ) late_pct = self .... | Return the measured statistics for timed refresh intervals . |
24,950 | def refresh_timer_cb ( self , timer , flags ) : start_time = time . time ( ) if flags . get ( 'done' , False ) : return deadline = self . rf_deadline self . rf_deadline += self . rf_rate self . rf_timer_count += 1 delta = abs ( start_time - deadline ) self . rf_delta_total += delta adjust = 0.0 if start_time > deadline... | Refresh timer callback . This callback will normally only be called internally . |
24,951 | def redraw_now ( self , whence = 0 ) : try : time_start = time . time ( ) self . redraw_data ( whence = whence ) self . update_image ( ) time_done = time . time ( ) time_delta = time_start - self . time_last_redraw time_elapsed = time_done - time_start self . time_last_redraw = time_done self . logger . debug ( "widget... | Redraw the displayed image . |
24,952 | def redraw_data ( self , whence = 0 ) : if not self . _imgwin_set : return if not self . _self_scaling : rgbobj = self . get_rgb_object ( whence = whence ) self . renderer . render_image ( rgbobj , self . _dst_x , self . _dst_y ) self . private_canvas . draw ( self ) self . make_callback ( 'redraw' , whence ) if whence... | Render image from RGB map and redraw private canvas . |
24,953 | def check_cursor_location ( self ) : data_x , data_y = self . get_data_xy ( self . last_win_x , self . last_win_y ) if ( data_x != self . last_data_x or data_y != self . last_data_y ) : self . last_data_x , self . last_data_y = data_x , data_y self . logger . debug ( "cursor location changed %.4f,%.4f => %.4f,%.4f" % (... | Check whether the data location of the last known position of the cursor has changed . If so issue a callback . |
24,954 | def getwin_array ( self , order = 'RGB' , alpha = 1.0 , dtype = None ) : order = order . upper ( ) depth = len ( order ) if dtype is None : rgbmap = self . get_rgbmap ( ) dtype = rgbmap . dtype data = self . _rgbobj . get_array ( order , dtype = dtype ) height , width , depth = data . shape imgwin_wd , imgwin_ht = self... | Get Numpy data array for display window . |
24,955 | def get_datarect ( self ) : x1 , y1 , x2 , y2 = self . _org_x1 , self . _org_y1 , self . _org_x2 , self . _org_y2 return ( x1 , y1 , x2 , y2 ) | Get the approximate bounding box of the displayed image . |
24,956 | def get_limits ( self , coord = 'data' ) : limits = self . t_ [ 'limits' ] if limits is None : image = self . get_image ( ) if image is not None : wd , ht = image . get_size ( ) limits = ( ( self . data_off , self . data_off ) , ( float ( wd - 1 + self . data_off ) , float ( ht - 1 + self . data_off ) ) ) else : canvas... | Get the bounding box of the viewer extents . |
24,957 | def set_limits ( self , limits , coord = 'data' ) : if limits is not None : if len ( limits ) != 2 : raise ValueError ( "limits takes a 2 tuple, or None" ) crdmap = self . get_coordmap ( coord ) limits = crdmap . to_data ( limits ) self . t_ . set ( limits = limits ) | Set the bounding box of the viewer extents . |
24,958 | def get_rgb_object ( self , whence = 0 ) : time_start = t2 = t3 = time . time ( ) win_wd , win_ht = self . get_window_size ( ) order = self . get_rgb_order ( ) if ( whence <= 0.0 ) or ( self . _rgbarr is None ) : pan_x , pan_y = self . get_pan ( coord = 'data' ) [ : 2 ] scale_x , scale_y = self . get_scale_xy ( ) wd , ... | Create and return RGB slices representing the data that should be rendered at the current zoom level and pan settings . |
24,959 | def _reset_bbox ( self ) : scale_x , scale_y = self . get_scale_xy ( ) pan_x , pan_y = self . get_pan ( coord = 'data' ) [ : 2 ] win_wd , win_ht = self . get_window_size ( ) win_wd , win_ht = max ( 1 , win_wd ) , max ( 1 , win_ht ) self . _calc_bg_dimensions ( scale_x , scale_y , pan_x , pan_y , win_wd , win_ht ) | This function should only be called internally . It resets the viewers bounding box based on changes to pan or scale . |
24,960 | def overlay_images ( self , canvas , data , whence = 0.0 ) : if not hasattr ( canvas , 'objects' ) : return for obj in canvas . get_objects ( ) : if hasattr ( obj , 'draw_image' ) : obj . draw_image ( self , data , whence = whence ) elif obj . is_compound ( ) and ( obj != canvas ) : self . overlay_images ( obj , data ,... | Overlay data from any canvas image objects . |
24,961 | def convert_via_profile ( self , data_np , order , inprof_name , outprof_name ) : to_intent = self . t_ . get ( 'icc_output_intent' , 'perceptual' ) proofprof_name = self . t_ . get ( 'icc_proof_profile' , None ) proof_intent = self . t_ . get ( 'icc_proof_intent' , 'perceptual' ) use_black_pt = self . t_ . get ( 'icc_... | Convert the given RGB data from the working ICC profile to the output profile in - place . |
24,962 | def get_data_xy ( self , win_x , win_y , center = None ) : if center is not None : self . logger . warning ( "`center` keyword is ignored and will be deprecated" ) arr_pts = np . asarray ( ( win_x , win_y ) ) . T return self . tform [ 'data_to_native' ] . from_ ( arr_pts ) . T [ : 2 ] | Get the closest coordinates in the data array to those reported on the window . |
24,963 | def offset_to_window ( self , off_x , off_y ) : arr_pts = np . asarray ( ( off_x , off_y ) ) . T return self . tform [ 'cartesian_to_native' ] . to_ ( arr_pts ) . T [ : 2 ] | Convert data offset to window coordinates . |
24,964 | def get_pan_rect ( self ) : wd , ht = self . get_window_size ( ) win_pts = np . asarray ( [ ( 0 , 0 ) , ( wd , 0 ) , ( wd , ht ) , ( 0 , ht ) ] ) arr_pts = self . tform [ 'data_to_window' ] . from_ ( win_pts ) return arr_pts | Get the coordinates in the actual data corresponding to the area shown in the display for the current zoom level and pan . |
24,965 | def get_data ( self , data_x , data_y ) : image = self . get_image ( ) if image is not None : return image . get_data_xy ( data_x , data_y ) raise ImageViewNoDataError ( "No image found" ) | Get the data value at the given position . Indices are zero - based as in Numpy . |
24,966 | def get_pixel_distance ( self , x1 , y1 , x2 , y2 ) : dx = abs ( x2 - x1 ) dy = abs ( y2 - y1 ) dist = np . sqrt ( dx * dx + dy * dy ) dist = np . round ( dist ) return dist | Calculate distance between the given pixel positions . |
24,967 | def _sanity_check_scale ( self , scale_x , scale_y ) : win_wd , win_ht = self . get_window_size ( ) if ( win_wd <= 0 ) or ( win_ht <= 0 ) : raise ImageViewError ( "window size undefined" ) if ( win_wd * scale_x < 1 ) or ( win_ht * scale_y < 1 ) : raise ValueError ( "resulting scale (%f, %f) would result in image size o... | Do a sanity check on the proposed scale vs . window size . Raises an exception if there will be a problem . |
24,968 | def scale_cb ( self , setting , value ) : zoomlevel = self . zoom . calc_level ( value ) self . t_ . set ( zoomlevel = zoomlevel ) self . redraw ( whence = 0 ) | Handle callback related to image scaling . |
24,969 | def set_scale_base_xy ( self , scale_x_base , scale_y_base ) : self . t_ . set ( scale_x_base = scale_x_base , scale_y_base = scale_y_base ) | Set stretch factors . |
24,970 | def get_scale_text ( self ) : scalefactor = self . get_scale_max ( ) if scalefactor >= 1.0 : text = '%.2fx' % ( scalefactor ) else : text = '1/%.2fx' % ( 1.0 / scalefactor ) return text | Report current scaling in human - readable format . |
24,971 | def set_zoom_algorithm ( self , name ) : name = name . lower ( ) alg_names = list ( zoom . get_zoom_alg_names ( ) ) if name not in alg_names : raise ImageViewError ( "Alg '%s' must be one of: %s" % ( name , ', ' . join ( alg_names ) ) ) self . t_ . set ( zoom_algorithm = name ) | Set zoom algorithm . |
24,972 | def zoomsetting_change_cb ( self , setting , value ) : alg_name = self . t_ [ 'zoom_algorithm' ] self . zoom = zoom . get_zoom_alg ( alg_name ) ( self ) self . zoom_to ( self . get_zoom ( ) ) | Handle callback related to changes in zoom . |
24,973 | def interpolation_change_cb ( self , setting , value ) : canvas_img = self . get_canvas_image ( ) canvas_img . interpolation = value canvas_img . reset_optimize ( ) self . redraw ( whence = 0 ) | Handle callback related to changes in interpolation . |
24,974 | def set_scale_limits ( self , scale_min , scale_max ) : self . t_ . set ( scale_min = scale_min , scale_max = scale_max ) | Set scale limits . |
24,975 | def enable_autozoom ( self , option ) : option = option . lower ( ) assert ( option in self . autozoom_options ) , ImageViewError ( "Bad autozoom option '%s': must be one of %s" % ( str ( self . autozoom_options ) ) ) self . t_ . set ( autozoom = option ) | Set autozoom behavior . |
24,976 | def set_pan ( self , pan_x , pan_y , coord = 'data' , no_reset = False ) : pan_pos = ( pan_x , pan_y ) with self . suppress_redraw : self . t_ . set ( pan = pan_pos , pan_coord = coord ) self . _reset_bbox ( ) if ( not no_reset ) and ( self . t_ [ 'autocenter' ] in ( 'override' , 'once' ) ) : self . t_ . set ( autocent... | Set pan position . |
24,977 | def pan_cb ( self , setting , value ) : pan_x , pan_y = value [ : 2 ] self . logger . debug ( "pan set to %.2f,%.2f" % ( pan_x , pan_y ) ) self . redraw ( whence = 0 ) | Handle callback related to changes in pan . |
24,978 | def get_pan ( self , coord = 'data' ) : pan_x , pan_y = self . t_ [ 'pan' ] [ : 2 ] if coord == 'wcs' : if self . t_ [ 'pan_coord' ] == 'data' : image = self . get_image ( ) if image is not None : try : return image . pixtoradec ( pan_x , pan_y ) except Exception as e : pass return ( pan_x , pan_y ) if self . t_ [ 'pan... | Get pan positions . |
24,979 | def center_image ( self , no_reset = True ) : try : xy_mn , xy_mx = self . get_limits ( ) data_x = float ( xy_mn [ 0 ] + xy_mx [ 0 ] ) / 2.0 data_y = float ( xy_mn [ 1 ] + xy_mx [ 1 ] ) / 2.0 except ImageViewNoDataError : canvas = self . get_canvas ( ) try : data_x , data_y = canvas . get_center_pt ( ) [ : 2 ] except E... | Pan to the center of the image . |
24,980 | def enable_autocenter ( self , option ) : option = option . lower ( ) assert ( option in self . autocenter_options ) , ImageViewError ( "Bad autocenter option '%s': must be one of %s" % ( str ( self . autocenter_options ) ) ) self . t_ . set ( autocenter = option ) | Set autocenter behavior . |
24,981 | def cut_levels ( self , loval , hival , no_reset = False ) : self . t_ . set ( cuts = ( loval , hival ) ) if ( not no_reset ) and ( self . t_ [ 'autocuts' ] in ( 'once' , 'override' ) ) : self . t_ . set ( autocuts = 'off' ) | Apply cut levels on the image view . |
24,982 | def auto_levels ( self , autocuts = None ) : if autocuts is None : autocuts = self . autocuts image = self . get_image ( ) if image is None : return loval , hival = autocuts . calc_cut_levels ( image ) self . t_ . set ( cuts = ( loval , hival ) ) if self . t_ [ 'autocuts' ] == 'once' : self . t_ . set ( autocuts = 'off... | Apply auto - cut levels on the image view . |
24,983 | def auto_levels_cb ( self , setting , value ) : method = self . t_ [ 'autocut_method' ] params = self . t_ . get ( 'autocut_params' , [ ] ) params = dict ( params ) if method != str ( self . autocuts ) : ac_class = AutoCuts . get_autocuts ( method ) self . autocuts = ac_class ( self . logger , ** params ) else : self .... | Handle callback related to changes in auto - cut levels . |
24,984 | def enable_autocuts ( self , option ) : option = option . lower ( ) assert ( option in self . autocuts_options ) , ImageViewError ( "Bad autocuts option '%s': must be one of %s" % ( str ( self . autocuts_options ) ) ) self . t_ . set ( autocuts = option ) | Set autocuts behavior . |
24,985 | def set_autocut_params ( self , method , ** params ) : self . logger . debug ( "Setting autocut params method=%s params=%s" % ( method , str ( params ) ) ) params = list ( params . items ( ) ) self . t_ . set ( autocut_method = method , autocut_params = params ) | Set auto - cut parameters . |
24,986 | def transform ( self , flip_x , flip_y , swap_xy ) : self . logger . debug ( "flip_x=%s flip_y=%s swap_xy=%s" % ( flip_x , flip_y , swap_xy ) ) with self . suppress_redraw : self . t_ . set ( flip_x = flip_x , flip_y = flip_y , swap_xy = swap_xy ) | Transform view of the image . |
24,987 | def transform_cb ( self , setting , value ) : self . make_callback ( 'transform' ) whence = 0 self . redraw ( whence = whence ) | Handle callback related to changes in transformations . |
24,988 | def copy_attributes ( self , dst_fi , attrlist , share = False ) : keylist = [ ] if 'transforms' in attrlist : keylist . extend ( [ 'flip_x' , 'flip_y' , 'swap_xy' ] ) if 'rotation' in attrlist : keylist . extend ( [ 'rot_deg' ] ) if 'autocuts' in attrlist : keylist . extend ( [ 'autocut_method' , 'autocut_params' ] ) ... | Copy interesting attributes of our configuration to another image view . |
24,989 | def auto_orient ( self ) : image = self . get_image ( ) if image is None : return invert_y = not isinstance ( image , AstroImage . AstroImage ) header = image . get_header ( ) if header : orient = header . get ( 'Orientation' , None ) if orient is None : orient = header . get ( 'Image Orientation' , None ) if orient is... | Set the orientation for the image to a reasonable default . |
24,990 | def get_image_as_buffer ( self , output = None ) : obuf = output if obuf is None : obuf = BytesIO ( ) arr8 = self . get_image_as_array ( ) if not hasattr ( arr8 , 'tobytes' ) : obuf . write ( arr8 . tostring ( order = 'C' ) ) else : obuf . write ( arr8 . tobytes ( order = 'C' ) ) return obuf | Get the current image shown in the viewer with any overlaid graphics in a IO buffer with channels as needed and ordered by the back end widget . |
24,991 | def get_rgb_image_as_bytes ( self , format = 'png' , quality = 90 ) : obuf = self . get_rgb_image_as_buffer ( format = format , quality = quality ) return bytes ( obuf . getvalue ( ) ) | Get the current image shown in the viewer with any overlaid graphics in the form of a buffer in the form of bytes . |
24,992 | def save_rgb_image_as_file ( self , filepath , format = 'png' , quality = 90 ) : with open ( filepath , 'wb' ) as out_f : self . get_rgb_image_as_buffer ( output = out_f , format = format , quality = quality ) self . logger . debug ( "wrote %s file '%s'" % ( format , filepath ) ) | Save the current image shown in the viewer with any overlaid graphics in a file with the specified format and quality . This can be overridden by subclasses . |
24,993 | def set_onscreen_message ( self , text , redraw = True ) : width , height = self . get_window_size ( ) font = self . t_ . get ( 'onscreen_font' , 'sans serif' ) font_size = self . t_ . get ( 'onscreen_font_size' , None ) if font_size is None : font_size = self . _calc_font_size ( width ) ht , wd = font_size , font_size... | Called by a subclass to update the onscreen message . |
24,994 | def _calc_font_size ( self , win_wd ) : font_size = 4 if win_wd >= 1600 : font_size = 24 elif win_wd >= 1000 : font_size = 18 elif win_wd >= 800 : font_size = 16 elif win_wd >= 600 : font_size = 14 elif win_wd >= 500 : font_size = 12 elif win_wd >= 400 : font_size = 11 elif win_wd >= 300 : font_size = 10 elif win_wd >=... | Heuristic to calculate an appropriate font size based on the width of the viewer window . |
24,995 | def popup ( self , title , callfn , initialdir = None , filename = None ) : self . cb = callfn self . filew . set_title ( title ) if initialdir : self . filew . set_current_folder ( initialdir ) if filename : self . filew . set_current_name ( filename ) self . filew . show ( ) | Let user select and load file . |
24,996 | def get_fileinfo ( self , filespec , dldir = None ) : if dldir is None : dldir = self . tmpdir info = iohelper . get_fileinfo ( filespec , cache_dir = dldir ) | Break down a file specification into its components . |
24,997 | def zoomset_cb ( self , setting , zoomlevel , fitsimage ) : if not self . gui_up : return fac_x , fac_y = fitsimage . get_scale_base_xy ( ) fac_x_me , fac_y_me = self . zoomimage . get_scale_base_xy ( ) if ( fac_x != fac_x_me ) or ( fac_y != fac_y_me ) : alg = fitsimage . get_zoom_algorithm ( ) self . zoomimage . set_z... | This method is called when a main FITS widget changes zoom level . |
24,998 | def set_amount_cb ( self , widget , val ) : self . zoom_amount = val zoomlevel = self . fitsimage_focus . get_zoom ( ) self . _zoomset ( self . fitsimage_focus , zoomlevel ) | This method is called when Zoom Amount control is adjusted . |
24,999 | def _slice ( self , view ) : if self . _data is not None : return self . _data [ view ] return self . _proxy . get_view ( self . id , view ) | Send view to remote server and do slicing there . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.