idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
24,800 | def set_naxispath ( self , naxispath ) : revnaxis = list ( naxispath ) revnaxis . reverse ( ) view = tuple ( revnaxis + [ slice ( None ) , slice ( None ) ] ) data = self . get_mddata ( ) [ view ] if len ( data . shape ) != 2 : raise ImageError ( "naxispath does not lead to a 2D slice: {}" . format ( naxispath ) ) self . naxispath = naxispath self . revnaxis = revnaxis self . set_data ( data ) | Choose a slice out of multidimensional data . |
24,801 | def get_keyword ( self , kwd , * args ) : try : kwds = self . get_header ( ) return kwds [ kwd ] except KeyError : if len ( args ) > 0 : return args [ 0 ] raise KeyError ( kwd ) | Get an item from the fits header if any . |
24,802 | def as_nddata ( self , nddata_class = None ) : "Return a version of ourself as an astropy.nddata.NDData object" if nddata_class is None : from astropy . nddata import NDData nddata_class = NDData ahdr = self . get_header ( ) header = OrderedDict ( ahdr . items ( ) ) data = self . get_mddata ( ) wcs = None if hasattr ( self , 'wcs' ) and self . wcs is not None : wcs = self . wcs . wcs ndd = nddata_class ( data , wcs = wcs , meta = header ) return ndd | Return a version of ourself as an astropy . nddata . NDData object |
24,803 | def as_hdu ( self ) : "Return a version of ourself as an astropy.io.fits.PrimaryHDU object" from astropy . io import fits ahdr = self . get_header ( ) header = fits . Header ( ahdr . items ( ) ) data = self . get_mddata ( ) hdu = fits . PrimaryHDU ( data = data , header = header ) return hdu | Return a version of ourself as an astropy . io . fits . PrimaryHDU object |
24,804 | def astype ( self , type_name ) : if type_name == 'nddata' : return self . as_nddata ( ) if type_name == 'hdu' : return self . as_hdu ( ) raise ValueError ( "Unrecognized conversion type '%s'" % ( type_name ) ) | Convert AstroImage object to some other kind of object . |
24,805 | def hmsToDeg ( h , m , s ) : return h * degPerHMSHour + m * degPerHMSMin + s * degPerHMSSec | Convert RA hours minutes seconds into an angle in degrees . |
24,806 | def hmsStrToDeg ( ra ) : hour , min , sec = ra . split ( ':' ) ra_deg = hmsToDeg ( int ( hour ) , int ( min ) , float ( sec ) ) return ra_deg | Convert a string representation of RA into a float in degrees . |
24,807 | def dmsStrToDeg ( dec ) : sign_deg , min , sec = dec . split ( ':' ) sign = sign_deg [ 0 : 1 ] if sign not in ( '+' , '-' ) : sign = '+' deg = sign_deg else : deg = sign_deg [ 1 : ] dec_deg = decTimeToDeg ( sign , int ( deg ) , int ( min ) , float ( sec ) ) return dec_deg | Convert a string representation of DEC into a float in degrees . |
24,808 | def eqToEq2000 ( ra_deg , dec_deg , eq ) : ra_rad = math . radians ( ra_deg ) dec_rad = math . radians ( dec_deg ) x = math . cos ( dec_rad ) * math . cos ( ra_rad ) y = math . cos ( dec_rad ) * math . sin ( ra_rad ) z = math . sin ( dec_rad ) p11 , p12 , p13 , p21 , p22 , p23 , p31 , p32 , p33 = trans_coeff ( eq , x , y , z ) x0 = p11 * x + p21 * y + p31 * z y0 = p12 * x + p22 * y + p32 * z z0 = p13 * x + p23 * y + p33 * z new_dec = math . asin ( z0 ) if x0 == 0.0 : new_ra = math . pi / 2.0 else : new_ra = math . atan ( y0 / x0 ) if ( ( y0 * math . cos ( new_dec ) > 0.0 and x0 * math . cos ( new_dec ) <= 0.0 ) or ( y0 * math . cos ( new_dec ) <= 0.0 and x0 * math . cos ( new_dec ) < 0.0 ) ) : new_ra += math . pi elif new_ra < 0.0 : new_ra += 2.0 * math . pi new_ra_deg = new_ra * 12.0 / math . pi * 15.0 new_dec_deg = new_dec * 180.0 / math . pi return ( new_ra_deg , new_dec_deg ) | Convert Eq to Eq 2000 . |
24,809 | def get_rotation_and_scale ( header , skew_threshold = 0.001 ) : ( ( xrot , yrot ) , ( cdelt1 , cdelt2 ) ) = get_xy_rotation_and_scale ( header ) if math . fabs ( xrot ) - math . fabs ( yrot ) > skew_threshold : raise ValueError ( "Skew detected: xrot=%.4f yrot=%.4f" % ( xrot , yrot ) ) rot = yrot lonpole = float ( header . get ( 'LONPOLE' , 180.0 ) ) if lonpole != 180.0 : rot += 180.0 - lonpole return ( rot , cdelt1 , cdelt2 ) | Calculate rotation and CDELT . |
24,810 | def get_relative_orientation ( image , ref_image ) : header = ref_image . get_header ( ) ( ( xrot_ref , yrot_ref ) , ( cdelt1_ref , cdelt2_ref ) ) = get_xy_rotation_and_scale ( header ) scale_x , scale_y = math . fabs ( cdelt1_ref ) , math . fabs ( cdelt2_ref ) header = image . get_header ( ) ( ( xrot , yrot ) , ( cdelt1 , cdelt2 ) ) = get_xy_rotation_and_scale ( header ) rscale_x = math . fabs ( cdelt1 ) / scale_x rscale_y = math . fabs ( cdelt2 ) / scale_y rrot_dx , rrot_dy = xrot - xrot_ref , yrot - yrot_ref rrot_deg = max ( rrot_dx , rrot_dy ) res = Bunch . Bunch ( rscale_x = rscale_x , rscale_y = rscale_y , rrot_deg = rrot_deg ) return res | Computes the relative orientation and scale of an image to a reference image . |
24,811 | def deg2fmt ( ra_deg , dec_deg , format ) : rhr , rmn , rsec = degToHms ( ra_deg ) dsgn , ddeg , dmn , dsec = degToDms ( dec_deg ) if format == 'hms' : return rhr , rmn , rsec , dsgn , ddeg , dmn , dsec elif format == 'str' : ra_txt = '%d:%02d:%06.3f' % ( rhr , rmn , rsec ) if dsgn < 0 : dsgn = '-' else : dsgn = '+' dec_txt = '%s%d:%02d:%05.2f' % ( dsgn , ddeg , dmn , dsec ) return ra_txt , dec_txt | Format coordinates . |
24,812 | def deltaStarsRaDecDeg1 ( ra1_deg , dec1_deg , ra2_deg , dec2_deg ) : phi , dist = dispos ( ra1_deg , dec1_deg , ra2_deg , dec2_deg ) return arcsecToDeg ( dist * 60.0 ) | Spherical triangulation . |
24,813 | def get_starsep_RaDecDeg ( ra1_deg , dec1_deg , ra2_deg , dec2_deg ) : sep = deltaStarsRaDecDeg ( ra1_deg , dec1_deg , ra2_deg , dec2_deg ) sgn , deg , mn , sec = degToDms ( sep ) if deg != 0 : txt = '%02d:%02d:%06.3f' % ( deg , mn , sec ) else : txt = '%02d:%06.3f' % ( mn , sec ) return txt | Calculate separation . |
24,814 | def get_RaDecOffsets ( ra1_deg , dec1_deg , ra2_deg , dec2_deg ) : delta_ra_deg = ra1_deg - ra2_deg adj = math . cos ( math . radians ( dec2_deg ) ) if delta_ra_deg > 180.0 : delta_ra_deg = ( delta_ra_deg - 360.0 ) * adj elif delta_ra_deg < - 180.0 : delta_ra_deg = ( delta_ra_deg + 360.0 ) * adj else : delta_ra_deg *= adj delta_dec_deg = dec1_deg - dec2_deg return ( delta_ra_deg , delta_dec_deg ) | Calculate offset . |
24,815 | def lon_to_deg ( lon ) : if isinstance ( lon , str ) and ( ':' in lon ) : lon_deg = hmsStrToDeg ( lon ) else : lon_deg = float ( lon ) return lon_deg | Convert longitude to degrees . |
24,816 | def lat_to_deg ( lat ) : if isinstance ( lat , str ) and ( ':' in lat ) : lat_deg = dmsStrToDeg ( lat ) else : lat_deg = float ( lat ) return lat_deg | Convert latitude to degrees . |
24,817 | def get_ruler_distances ( image , p1 , p2 ) : x1 , y1 = p1 [ : 2 ] x2 , y2 = p2 [ : 2 ] dx , dy = x2 - x1 , y2 - y1 res = Bunch . Bunch ( x1 = x1 , y1 = y1 , x2 = x2 , y2 = y2 , theta = np . arctan2 ( y2 - y1 , x2 - x1 ) , dx_pix = dx , dy_pix = dy , dh_pix = np . sqrt ( dx ** 2 + dy ** 2 ) , ra_org = None , dec_org = None , ra_dst = None , dec_dst = None , ra_heel = None , dec_heel = None , dx_deg = None , dy_deg = None , dh_deg = None ) if image is not None and hasattr ( image , 'wcs' ) and image . wcs is not None : try : ra_org , dec_org = image . pixtoradec ( x1 , y1 ) res . ra_org , res . dec_org = ra_org , dec_org ra_dst , dec_dst = image . pixtoradec ( x2 , y2 ) res . ra_dst , res . dec_dst = ra_dst , dec_dst ra_heel , dec_heel = image . pixtoradec ( x2 , y1 ) res . ra_heel , res . dec_heel = ra_heel , dec_heel res . dh_deg = deltaStarsRaDecDeg ( ra_org , dec_org , ra_dst , dec_dst ) res . dx_deg = deltaStarsRaDecDeg ( ra_org , dec_org , ra_heel , dec_heel ) res . dy_deg = deltaStarsRaDecDeg ( ra_heel , dec_heel , ra_dst , dec_dst ) except Exception as e : pass return res | Get the distance calculated between two points . A Bunch of results is returned containing pixel values and distance values if the image contains a valid WCS . |
24,818 | def add_font ( font_file , font_name = None ) : global font_dir if font_name is None : dirname , filename = os . path . split ( font_file ) font_name , ext = os . path . splitext ( filename ) font_dir [ font_name ] = Bunch . Bunch ( name = font_name , font_path = font_file ) return font_name | Add a font description to our directory of externally loadable fonts . font_file is the path to the font and optional font_name is the name to register it under . |
24,819 | def have_font ( font_name ) : if font_name in font_dir : return True font_name = resolve_alias ( font_name , font_name ) return font_name in font_dir | Return True if the given font name is registered as one of our externally loadable fonts . If font_name is not found it will try to look it up as an alias and report if that is found . |
24,820 | def toggle_create_button ( self ) : if len ( self . _drawn_tags ) > 0 : self . w . create_mask . set_enabled ( True ) else : self . w . create_mask . set_enabled ( False ) | Enable or disable Create Mask button based on drawn objects . |
24,821 | def create_mask ( self ) : ntags = len ( self . _drawn_tags ) if ntags == 0 : return old_image = self . fitsimage . get_image ( ) if old_image is None : return mask = None obj_kinds = set ( ) for tag in self . _drawn_tags : obj = self . canvas . get_object_by_tag ( tag ) try : cur_mask = old_image . get_shape_mask ( obj ) except Exception as e : self . logger . error ( 'Cannot create mask: {0}' . format ( str ( e ) ) ) continue if mask is not None : mask |= cur_mask else : mask = cur_mask obj_kinds . add ( obj . kind ) image = dp . make_image ( mask . astype ( 'int16' ) , old_image , { } , pfx = self . _mask_prefix ) imname = image . get ( 'name' ) self . fv . gui_call ( self . fv . add_image , imname , image , chname = self . chname ) s = 'Mask created from {0} drawings ({1})' . format ( ntags , ',' . join ( sorted ( obj_kinds ) ) ) info = dict ( time_modified = datetime . utcnow ( ) , reason_modified = s ) self . fv . update_image_info ( image , info ) self . logger . info ( s ) | Create boolean mask from drawing . |
24,822 | def cmd_load ( self , * args , ** kwargs ) : ch = kwargs . get ( 'ch' , None ) for item in args : files = glob . glob ( item ) self . fv . gui_do ( self . fv . open_uris , files , chname = ch ) | load file ... ch = chname |
24,823 | def cmd_cuts ( self , lo = None , hi = None , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return loval , hival = viewer . get_cut_levels ( ) if ( lo is None ) and ( hi is None ) : self . log ( "lo=%f hi=%f" % ( loval , hival ) ) else : if lo is not None : loval = lo if hi is not None : hival = hi viewer . cut_levels ( loval , hival ) self . log ( "lo=%f hi=%f" % ( loval , hival ) ) | cuts lo = val hi = val ch = chname |
24,824 | def cmd_ac ( self , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return viewer . auto_levels ( ) self . cmd_cuts ( ch = ch ) | ac ch = chname |
24,825 | def cmd_cm ( self , nm = None , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return if nm is None : rgbmap = viewer . get_rgbmap ( ) cmap = rgbmap . get_cmap ( ) self . log ( cmap . name ) else : viewer . set_color_map ( nm ) | cm nm = color_map_name ch = chname |
24,826 | def cmd_cminv ( self , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return viewer . invert_cmap ( ) | cminv ch = chname |
24,827 | def cmd_dist ( self , nm = None , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return if nm is None : rgbmap = viewer . get_rgbmap ( ) dist = rgbmap . get_dist ( ) self . log ( str ( dist ) ) else : viewer . set_color_algorithm ( nm ) | dist nm = dist_name ch = chname |
24,828 | def cmd_imap ( self , nm = None , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return if nm is None : rgbmap = viewer . get_rgbmap ( ) imap = rgbmap . get_imap ( ) self . log ( imap . name ) else : viewer . set_intensity_map ( nm ) | imap nm = intensity_map_name ch = chname |
24,829 | def cmd_rot ( self , deg = None , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return if deg is None : self . log ( "%f deg" % ( viewer . get_rotation ( ) ) ) else : viewer . rotate ( deg ) | rot deg = num_deg ch = chname |
24,830 | def cmd_tr ( self , x = None , y = None , xy = None , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return fx , fy , sxy = viewer . get_transforms ( ) if x is None and y is None and xy is None : self . log ( "x=%s y=%s xy=%s" % ( fx , fy , sxy ) ) else : if x is None : x = fx else : x = ( x != 0 ) if y is None : y = fy else : y = ( y != 0 ) if xy is None : xy = sxy else : xy = ( xy != 0 ) viewer . transform ( x , y , xy ) | tr x = 0|1 y = 0|1 xy = 0|1 ch = chname |
24,831 | def cmd_scale ( self , x = None , y = None , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return scale_x , scale_y = viewer . get_scale_xy ( ) if x is None and y is None : self . log ( "x=%f y=%f" % ( scale_x , scale_y ) ) else : if x is not None : if y is None : y = x if y is not None : if x is None : x = y viewer . scale_to ( x , y ) | scale x = scale_x y = scale_y ch = chname |
24,832 | def cmd_z ( self , lvl = None , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return cur_lvl = viewer . get_zoom ( ) if lvl is None : self . log ( "zoom=%f" % ( cur_lvl ) ) else : viewer . zoom_to ( lvl ) | z lvl = level ch = chname |
24,833 | def cmd_zf ( self , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return viewer . zoom_fit ( ) cur_lvl = viewer . get_zoom ( ) self . log ( "zoom=%f" % ( cur_lvl ) ) | zf ch = chname |
24,834 | def cmd_c ( self , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return viewer . center_image ( ) | c ch = chname |
24,835 | def cmd_pan ( self , x = None , y = None , ch = None ) : viewer = self . get_viewer ( ch ) if viewer is None : self . log ( "No current viewer/channel." ) return pan_x , pan_y = viewer . get_pan ( ) if x is None and y is None : self . log ( "x=%f y=%f" % ( pan_x , pan_y ) ) else : if x is not None : if y is None : y = pan_y if y is not None : if x is None : x = pan_x viewer . set_pan ( x , y ) | scale ch = chname x = pan_x y = pan_y |
24,836 | def timer ( self , jitter , action , * args , ** kwargs ) : return Timer ( self , jitter , action , * args , ** kwargs ) | Convenience method to create a Timer from the heap |
24,837 | def add ( self , timer ) : with self . lock : if self . heap : top = self . heap [ 0 ] else : top = None assert timer not in self . timers self . timers [ timer ] = timer heapq . heappush ( self . heap , timer ) if self . heap [ 0 ] != top and not self . expiring : if self . rtimer is not None : self . rtimer . cancel ( ) self . rtimer = None if self . rtimer is None and not self . expiring : top = self . heap [ 0 ] ival = top . expire - time . time ( ) if ival < 0 : ival = 0 self . rtimer = threading . Timer ( ival , self . expire ) self . rtimer . start ( ) | Add a timer to the heap |
24,838 | def _remove ( self , timer ) : assert timer . timer_heap == self del self . timers [ timer ] assert timer in self . heap self . heap . remove ( timer ) heapq . heapify ( self . heap ) | Remove timer from heap lock and presence are assumed |
24,839 | def remove ( self , timer ) : with self . lock : if timer in self . timers : self . _remove ( timer ) return False else : return True | Remove a timer from the heap return True if already run |
24,840 | def remove_all_timers ( self ) : with self . lock : if self . rtimer is not None : self . rtimer . cancel ( ) self . timers = { } self . heap = [ ] self . rtimer = None self . expiring = False | Remove all waiting timers and terminate any blocking threads . |
24,841 | def get_llur ( self ) : points = np . array ( [ obj . get_llur ( ) for obj in self . objects ] ) t_ = points . T x1 , y1 = t_ [ 0 ] . min ( ) , t_ [ 1 ] . min ( ) x2 , y2 = t_ [ 2 ] . max ( ) , t_ [ 3 ] . max ( ) return ( x1 , y1 , x2 , y2 ) | Get lower - left and upper - right coordinates of the bounding box of this compound object . |
24,842 | def build_gui ( self , container ) : vbox = Widgets . VBox ( ) vbox . set_border_width ( 0 ) w = Viewers . GingaViewerWidget ( viewer = self ) vbox . add_widget ( w , stretch = 1 ) hbox = Widgets . HBox ( ) hbox . add_widget ( vbox , stretch = 0 ) hbox . add_widget ( Widgets . Label ( '' ) , stretch = 1 ) container . set_widget ( hbox ) | This is responsible for building the viewer s UI . It should place the UI in container . Override this to make a custom UI . |
24,843 | def embed ( self , width = 600 , height = 650 ) : from IPython . display import IFrame return IFrame ( self . url , width , height ) | Embed a viewer into a Jupyter notebook . |
24,844 | def load_fits ( self , filepath ) : image = AstroImage . AstroImage ( logger = self . logger ) image . load_file ( filepath ) self . set_image ( image ) | Load a FITS file into the viewer . |
24,845 | def load_hdu ( self , hdu ) : image = AstroImage . AstroImage ( logger = self . logger ) image . load_hdu ( hdu ) self . set_image ( image ) | Load an HDU into the viewer . |
24,846 | def load_data ( self , data_np ) : image = AstroImage . AstroImage ( logger = self . logger ) image . set_data ( data_np ) self . set_image ( image ) | Load raw numpy data into the viewer . |
24,847 | def set_html5_canvas_format ( self , fmt ) : fmt = fmt . lower ( ) if fmt not in ( 'jpeg' , 'png' ) : raise ValueError ( "Format must be one of {jpeg|png} not '%s'" % ( fmt ) ) settings = self . get_settings ( ) settings . set ( html5_canvas_format = fmt ) | Sets the format used for rendering to the HTML5 canvas . png offers greater clarity especially for small text but does not have as good of performance as jpeg . |
24,848 | def build_gui ( self , container ) : vbox = Widgets . VBox ( ) vbox . set_border_width ( 2 ) vbox . set_spacing ( 1 ) w = Viewers . GingaViewerWidget ( viewer = self ) vbox . add_widget ( w , stretch = 1 ) self . pixel_base = 1.0 self . readout = Widgets . Label ( "" ) vbox . add_widget ( self . readout , stretch = 0 ) self . set_callback ( 'cursor-changed' , self . motion_cb ) hbox = Widgets . HBox ( ) hbox . add_widget ( vbox , stretch = 0 ) hbox . add_widget ( Widgets . Label ( '' ) , stretch = 1 ) container . set_widget ( hbox ) | This is responsible for building the viewer s UI . It should place the UI in container . |
24,849 | def get_viewer ( self , v_id , viewer_class = None , width = 512 , height = 512 , force_new = False ) : if not force_new : try : return self . viewers [ v_id ] except KeyError : pass window = self . app . make_window ( "Viewer %s" % v_id , wid = v_id ) v_info = self . make_viewer ( window , viewer_class = viewer_class , width = width , height = height ) self . viewers [ v_id ] = v_info return v_info | Get an existing viewer by viewer id . If the viewer does not yet exist make a new one . |
24,850 | def detailxy ( self , canvas , button , data_x , data_y ) : if button == 0 : chviewer = self . fv . getfocus_viewer ( ) if chviewer != self . fitsimage : return True data_x = data_x + self . pick_x1 data_y = data_y + self . pick_y1 return self . fv . showxy ( chviewer , data_x , data_y ) | Motion event in the pick fits window . Show the pointing information under the cursor . |
24,851 | def reference_viewer ( sys_argv ) : viewer = ReferenceViewer ( layout = default_layout ) viewer . add_default_plugins ( ) viewer . add_separately_distributed_plugins ( ) from optparse import OptionParser usage = "usage: %prog [options] cmd [args]" optprs = OptionParser ( usage = usage , version = ( '%%prog %s' % version . version ) ) viewer . add_default_options ( optprs ) ( options , args ) = optprs . parse_args ( sys_argv [ 1 : ] ) if options . display : os . environ [ 'DISPLAY' ] = options . display if options . debug : import pdb pdb . run ( 'viewer.main(options, args)' ) elif options . profile : import profile print ( ( "%s profile:" % sys_argv [ 0 ] ) ) profile . run ( 'viewer.main(options, args)' ) else : viewer . main ( options , args ) | Create reference viewer from command line . |
24,852 | def add_default_plugins ( self , except_global = [ ] , except_local = [ ] ) : for spec in plugins : ptype = spec . get ( 'ptype' , 'local' ) if ptype == 'global' and spec . module not in except_global : self . add_plugin_spec ( spec ) if ptype == 'local' and spec . module not in except_local : self . add_plugin_spec ( spec ) | Add the ginga - distributed default set of plugins to the reference viewer . |
24,853 | def add_default_options ( self , optprs ) : optprs . add_option ( "--bufsize" , dest = "bufsize" , metavar = "NUM" , type = "int" , default = 10 , help = "Buffer length to NUM" ) optprs . add_option ( '-c' , "--channels" , dest = "channels" , help = "Specify list of channels to create" ) optprs . add_option ( "--debug" , dest = "debug" , default = False , action = "store_true" , help = "Enter the pdb debugger on main()" ) optprs . add_option ( "--disable-plugins" , dest = "disable_plugins" , metavar = "NAMES" , help = "Specify plugins that should be disabled" ) optprs . add_option ( "--display" , dest = "display" , metavar = "HOST:N" , help = "Use X display on HOST:N" ) optprs . add_option ( "--fitspkg" , dest = "fitspkg" , metavar = "NAME" , default = None , help = "Prefer FITS I/O module NAME" ) optprs . add_option ( "-g" , "--geometry" , dest = "geometry" , default = None , metavar = "GEOM" , help = "X geometry for initial size and placement" ) optprs . add_option ( "--modules" , dest = "modules" , metavar = "NAMES" , help = "Specify additional modules to load" ) optprs . add_option ( "--norestore" , dest = "norestore" , default = False , action = "store_true" , help = "Don't restore the GUI from a saved layout" ) optprs . add_option ( "--nosplash" , dest = "nosplash" , default = False , action = "store_true" , help = "Don't display the splash screen" ) optprs . add_option ( "--numthreads" , dest = "numthreads" , type = "int" , default = 30 , metavar = "NUM" , help = "Start NUM threads in thread pool" ) optprs . add_option ( "--opencv" , dest = "opencv" , default = False , action = "store_true" , help = "Use OpenCv acceleration" ) optprs . add_option ( "--opencl" , dest = "opencl" , default = False , action = "store_true" , help = "Use OpenCL acceleration" ) optprs . add_option ( "--plugins" , dest = "plugins" , metavar = "NAMES" , help = "Specify additional plugins to load" ) optprs . add_option ( "--profile" , dest = "profile" , action = "store_true" , default = False , help = "Run the profiler on main()" ) optprs . add_option ( "--sep" , dest = "separate_channels" , default = False , action = "store_true" , help = "Load files in separate channels" ) optprs . add_option ( "-t" , "--toolkit" , dest = "toolkit" , metavar = "NAME" , default = None , help = "Prefer GUI toolkit (gtk|qt)" ) optprs . add_option ( "--wcspkg" , dest = "wcspkg" , metavar = "NAME" , default = None , help = "Prefer WCS module NAME" ) log . addlogopts ( optprs ) | Adds the default reference viewer startup options to an OptionParser instance optprs . |
24,854 | def gui_call ( self , method , * args , ** kwdargs ) : my_id = thread . get_ident ( ) if my_id == self . gui_thread_id : return method ( * args , ** kwdargs ) else : future = self . gui_do ( method , * args , ** kwdargs ) return future . wait ( ) | General method for synchronously calling into the GUI . This waits until the method has completed before returning . |
24,855 | def show_help ( self , plugin = None , no_url_callback = None ) : if not Widgets . has_webkit : return self . fv . nongui_do ( self . _download_doc , plugin = plugin , no_url_callback = no_url_callback ) | See ~ginga . GingaPlugin for usage of optional keywords . |
24,856 | def get_mean ( data_np ) : i = np . isfinite ( data_np ) if not np . any ( i ) : return np . nan return np . mean ( data_np [ i ] ) | Calculate mean for valid values . |
24,857 | def calc_fwhm_gaussian ( self , arr1d , medv = None , gauss_fn = None ) : if gauss_fn is None : gauss_fn = self . gaussian N = len ( arr1d ) X = np . array ( list ( range ( N ) ) ) Y = arr1d if medv is None : medv = get_median ( Y ) Y = Y - medv maxv = Y . max ( ) Y = Y . clip ( 0 , maxv ) p0 = [ 0 , N - 1 , maxv ] errfunc = lambda p , x , y : gauss_fn ( x , p ) - y with self . lock : p1 , success = optimize . leastsq ( errfunc , p0 [ : ] , args = ( X , Y ) ) if not success : raise IQCalcError ( "FWHM gaussian fitting failed" ) mu , sdev , maxv = p1 self . logger . debug ( "mu=%f sdev=%f maxv=%f" % ( mu , sdev , maxv ) ) fwhm = 2.0 * np . sqrt ( 2.0 * np . log ( 2.0 ) ) * sdev fwhm = float ( fwhm ) mu = float ( mu ) sdev = float ( sdev ) maxv = float ( maxv ) res = Bunch . Bunch ( fwhm = fwhm , mu = mu , sdev = sdev , maxv = maxv , fit_fn = gauss_fn , fit_args = [ mu , sdev , maxv ] ) return res | FWHM calculation on a 1D array by using least square fitting of a gaussian function on the data . arr1d is a 1D array cut in either X or Y direction on the object . |
24,858 | def calc_fwhm_moffat ( self , arr1d , medv = None , moffat_fn = None ) : if moffat_fn is None : moffat_fn = self . moffat N = len ( arr1d ) X = np . array ( list ( range ( N ) ) ) Y = arr1d if medv is None : medv = get_median ( Y ) Y = Y - medv maxv = Y . max ( ) Y = Y . clip ( 0 , maxv ) p0 = [ 0 , N - 1 , 2 , maxv ] errfunc = lambda p , x , y : moffat_fn ( x , p ) - y with self . lock : p1 , success = optimize . leastsq ( errfunc , p0 [ : ] , args = ( X , Y ) ) if not success : raise IQCalcError ( "FWHM moffat fitting failed" ) mu , width , power , maxv = p1 width = np . abs ( width ) self . logger . debug ( "mu=%f width=%f power=%f maxv=%f" % ( mu , width , power , maxv ) ) fwhm = 2.0 * width * np . sqrt ( 2.0 ** ( 1.0 / power ) - 1.0 ) fwhm = float ( fwhm ) mu = float ( mu ) width = float ( width ) power = float ( power ) maxv = float ( maxv ) res = Bunch . Bunch ( fwhm = fwhm , mu = mu , width = width , power = power , maxv = maxv , fit_fn = moffat_fn , fit_args = [ mu , width , power , maxv ] ) return res | FWHM calculation on a 1D array by using least square fitting of a Moffat function on the data . arr1d is a 1D array cut in either X or Y direction on the object . |
24,859 | def my_import ( name , path = None ) : if hasattr ( importlib , 'invalidate_caches' ) : importlib . invalidate_caches ( ) if path is not None : directory , src_file = os . path . split ( path ) sys . path . insert ( 0 , directory ) try : mod = importlib . import_module ( name ) finally : sys . path . pop ( 0 ) else : mod = importlib . import_module ( name ) return mod | Return imported module for the given name . |
24,860 | def get_module ( self , module_name ) : try : return self . module [ module_name ] except KeyError : return sys . modules [ module_name ] | Return loaded module from the given name . |
24,861 | def parse_combo ( self , combo , modes_set , modifiers_set , pfx ) : mode , mods , trigger = None , set ( [ ] ) , combo if '+' in combo : if combo . endswith ( '+' ) : trigger , combo = '+' , combo [ : - 1 ] if '+' in combo : items = set ( combo . split ( '+' ) ) else : items = set ( combo ) else : items = combo . split ( '+' ) trigger , items = items [ - 1 ] , set ( items [ : - 1 ] ) if '*' in items : items . remove ( '*' ) mods = '*' else : mods = items . intersection ( modifiers_set ) mode = items . intersection ( modes_set ) if len ( mode ) == 0 : mode = None else : mode = mode . pop ( ) if pfx is not None : trigger = pfx + trigger return ( mode , mods , trigger ) | Parse a string into a mode a set of modifiers and a trigger . |
24,862 | def get_direction ( self , direction , rev = False ) : if ( direction < 90.0 ) or ( direction >= 270.0 ) : if not rev : return 'up' else : return 'down' elif ( 90.0 <= direction < 270.0 ) : if not rev : return 'down' else : return 'up' else : return 'none' | Translate a direction in compass degrees into up or down . |
24,863 | def kp_pan_px_center ( self , viewer , event , data_x , data_y , msg = True ) : if not self . canpan : return False self . pan_center_px ( viewer ) return True | This pans so that the cursor is over the center of the current pixel . |
24,864 | def ms_zoom ( self , viewer , event , data_x , data_y , msg = True ) : if not self . canzoom : return True msg = self . settings . get ( 'msg_zoom' , msg ) x , y = self . get_win_xy ( viewer ) if event . state == 'move' : self . _zoom_xy ( viewer , x , y ) elif event . state == 'down' : if msg : viewer . onscreen_message ( "Zoom (drag mouse L-R)" , delay = 1.0 ) self . _start_x , self . _start_y = x , y else : viewer . onscreen_message ( None ) return True | Zoom the image by dragging the cursor left or right . |
24,865 | def ms_zoom_in ( self , viewer , event , data_x , data_y , msg = False ) : if not self . canzoom : return True if not ( event . state == 'down' ) : return True with viewer . suppress_redraw : viewer . panset_xy ( data_x , data_y ) if self . settings . get ( 'scroll_zoom_direct_scale' , True ) : zoom_accel = self . settings . get ( 'scroll_zoom_acceleration' , 1.0 ) amount = self . _scale_adjust ( 2.0 , 15.0 , zoom_accel , max_limit = 4.0 ) self . _scale_image ( viewer , 0.0 , amount , msg = msg ) else : viewer . zoom_in ( ) if hasattr ( viewer , 'center_cursor' ) : viewer . center_cursor ( ) if msg : viewer . onscreen_message ( viewer . get_scale_text ( ) , delay = 1.0 ) return True | Zoom in one level by a mouse click . |
24,866 | def ms_rotate ( self , viewer , event , data_x , data_y , msg = True ) : if not self . canrotate : return True msg = self . settings . get ( 'msg_rotate' , msg ) x , y = self . get_win_xy ( viewer ) if event . state == 'move' : self . _rotate_xy ( viewer , x , y ) elif event . state == 'down' : if msg : viewer . onscreen_message ( "Rotate (drag around center)" , delay = 1.0 ) self . _start_x , self . _start_y = x , y self . _start_rot = viewer . get_rotation ( ) else : viewer . onscreen_message ( None ) return True | Rotate the image by dragging the cursor left or right . |
24,867 | def ms_contrast ( self , viewer , event , data_x , data_y , msg = True ) : if not self . cancmap : return True msg = self . settings . get ( 'msg_contrast' , msg ) x , y = self . get_win_xy ( viewer ) if event . state == 'move' : self . _tweak_colormap ( viewer , x , y , 'preview' ) elif event . state == 'down' : self . _start_x , self . _start_y = x , y if msg : viewer . onscreen_message ( "Shift and stretch colormap (drag mouse)" , delay = 1.0 ) else : viewer . onscreen_message ( None ) return True | Shift the colormap by dragging the cursor left or right . Stretch the colormap by dragging the cursor up or down . |
24,868 | def ms_contrast_restore ( self , viewer , event , data_x , data_y , msg = True ) : if self . cancmap and ( event . state == 'down' ) : self . restore_contrast ( viewer , msg = msg ) return True | An interactive way to restore the colormap contrast settings after a warp operation . |
24,869 | def ms_cmap_restore ( self , viewer , event , data_x , data_y , msg = True ) : if self . cancmap and ( event . state == 'down' ) : self . restore_colormap ( viewer , msg ) return True | An interactive way to restore the colormap settings after a rotate or invert operation . |
24,870 | def ms_pan ( self , viewer , event , data_x , data_y ) : if not self . canpan : return True x , y = viewer . get_last_win_xy ( ) if event . state == 'move' : data_x , data_y = self . get_new_pan ( viewer , x , y , ptype = self . _pantype ) viewer . panset_xy ( data_x , data_y ) elif event . state == 'down' : self . pan_set_origin ( viewer , x , y , data_x , data_y ) self . pan_start ( viewer , ptype = 2 ) else : self . pan_stop ( viewer ) return True | A drag or proportional pan where the image is panned by dragging the canvas up or down . The amount of the pan is proportionate to the length of the drag . |
24,871 | def ms_cutlo ( self , viewer , event , data_x , data_y ) : if not self . cancut : return True x , y = self . get_win_xy ( viewer ) if event . state == 'move' : self . _cutlow_xy ( viewer , x , y ) elif event . state == 'down' : self . _start_x , self . _start_y = x , y self . _loval , self . _hival = viewer . get_cut_levels ( ) else : viewer . onscreen_message ( None ) return True | An interactive way to set the low cut level . |
24,872 | def ms_cutall ( self , viewer , event , data_x , data_y ) : if not self . cancut : return True x , y = self . get_win_xy ( viewer ) if event . state == 'move' : self . _cutboth_xy ( viewer , x , y ) elif event . state == 'down' : self . _start_x , self . _start_y = x , y image = viewer . get_image ( ) self . _loval , self . _hival = viewer . autocuts . calc_cut_levels ( image ) else : viewer . onscreen_message ( None ) return True | An interactive way to set the low AND high cut levels . |
24,873 | def sc_cuts_coarse ( self , viewer , event , msg = True ) : if self . cancut : self . _adjust_cuts ( viewer , event . direction , 0.1 , msg = msg ) return True | Adjust cuts interactively by setting the low AND high cut levels . This function adjusts it coarsely . |
24,874 | def sc_cuts_alg ( self , viewer , event , msg = True ) : if self . cancut : direction = self . get_direction ( event . direction ) self . _cycle_cuts_alg ( viewer , msg , direction = direction ) return True | Adjust cuts algorithm interactively . |
24,875 | def sc_zoom ( self , viewer , event , msg = True ) : self . _sc_zoom ( viewer , event , msg = msg , origin = None ) return True | Interactively zoom the image by scrolling motion . This zooms by the zoom steps configured under Preferences . |
24,876 | def sc_zoom_coarse ( self , viewer , event , msg = True ) : if not self . canzoom : return True zoom_accel = self . settings . get ( 'scroll_zoom_acceleration' , 1.0 ) amount = self . _scale_adjust ( 1.2 , event . amount , zoom_accel , max_limit = 4.0 ) self . _scale_image ( viewer , event . direction , amount , msg = msg ) return True | Interactively zoom the image by scrolling motion . This zooms by adjusting the scale in x and y coarsely . |
24,877 | def sc_pan ( self , viewer , event , msg = True ) : if not self . canpan : return True rev = self . settings . get ( 'pan_reverse' , False ) direction = event . direction if rev : direction = math . fmod ( direction + 180.0 , 360.0 ) pan_accel = self . settings . get ( 'scroll_pan_acceleration' , 1.0 ) scr_pan_adj_factor = 1.4142135623730951 amount = ( event . amount * scr_pan_adj_factor * pan_accel ) / 360.0 self . pan_omni ( viewer , direction , amount ) return True | Interactively pan the image by scrolling motion . |
24,878 | def sc_dist ( self , viewer , event , msg = True ) : direction = self . get_direction ( event . direction ) self . _cycle_dist ( viewer , msg , direction = direction ) return True | Interactively change the color distribution algorithm by scrolling . |
24,879 | def sc_cmap ( self , viewer , event , msg = True ) : direction = self . get_direction ( event . direction ) self . _cycle_cmap ( viewer , msg , direction = direction ) return True | Interactively change the color map by scrolling . |
24,880 | def sc_imap ( self , viewer , event , msg = True ) : direction = self . get_direction ( event . direction ) self . _cycle_imap ( viewer , msg , direction = direction ) return True | Interactively change the intensity map by scrolling . |
24,881 | def pa_naxis ( self , viewer , event , msg = True ) : event = self . _pa_synth_scroll_event ( event ) if event . state != 'move' : return False axis = 2 direction = self . get_direction ( event . direction ) return self . _nav_naxis ( viewer , axis , direction , msg = msg ) | Interactively change the slice of the image in a data cube by pan gesture . |
24,882 | def mode_key_down ( self , viewer , keyname ) : if keyname not in self . mode_map : if ( keyname not in self . mode_tbl ) or ( self . _kbdmode != 'meta' ) : return False bnch = self . mode_tbl [ keyname ] else : bnch = self . mode_map [ keyname ] mode_name = bnch . name self . logger . debug ( "cur mode='%s' mode pressed='%s'" % ( self . _kbdmode , mode_name ) ) if mode_name == self . _kbdmode : self . reset_mode ( viewer ) return True if self . _delayed_reset : self . _delayed_reset = False return True if ( ( self . _kbdmode in ( None , 'meta' ) ) or ( self . _kbdmode_type != 'locked' ) or ( mode_name == 'meta' ) ) : if self . _kbdmode is not None : self . reset_mode ( viewer ) if self . _kbdmode in ( None , 'meta' ) : mode_type = bnch . type if mode_type is None : mode_type = self . _kbdmode_type_default self . set_mode ( mode_name , mode_type ) if bnch . msg is not None : viewer . onscreen_message ( bnch . msg ) return True return False | This method is called when a key is pressed and was not handled by some other handler with precedence such as a subcanvas . |
24,883 | def mode_key_up ( self , viewer , keyname ) : if keyname not in self . mode_map : return False bnch = self . mode_map [ keyname ] if self . _kbdmode == bnch . name : if bnch . type == 'held' : if self . _button == 0 : self . reset_mode ( viewer ) else : self . _delayed_reset = True return True return False | This method is called when a key is pressed in a mode and was not handled by some other handler with precedence such as a subcanvas . |
24,884 | def get_4pt_bezier ( steps , points ) : for i in range ( steps ) : t = i / float ( steps ) xloc = ( math . pow ( 1 - t , 3 ) * points [ 0 ] [ 0 ] + 3 * t * math . pow ( 1 - t , 2 ) * points [ 1 ] [ 0 ] + 3 * ( 1 - t ) * math . pow ( t , 2 ) * points [ 2 ] [ 0 ] + math . pow ( t , 3 ) * points [ 3 ] [ 0 ] ) yloc = ( math . pow ( 1 - t , 3 ) * points [ 0 ] [ 1 ] + 3 * t * math . pow ( 1 - t , 2 ) * points [ 1 ] [ 1 ] + 3 * ( 1 - t ) * math . pow ( t , 2 ) * points [ 2 ] [ 1 ] + math . pow ( t , 3 ) * points [ 3 ] [ 1 ] ) yield ( xloc , yloc ) | Gets a series of bezier curve points with 1 set of 4 control points . |
24,885 | def get_bezier ( steps , points ) : res = [ ] num_pts = len ( points ) for i in range ( 0 , num_pts + 1 , 3 ) : if i + 4 < num_pts + 1 : res . extend ( list ( get_4pt_bezier ( steps , points [ i : i + 4 ] ) ) ) return res | Gets a series of bezier curve points with any number of sets of 4 control points . |
24,886 | def get_bezier_ellipse ( x , y , xradius , yradius , kappa = 0.5522848 ) : xs , ys = x - xradius , y - yradius ox , oy = xradius * kappa , yradius * kappa xe , ye = x + xradius , y + yradius pts = [ ( xs , y ) , ( xs , y - oy ) , ( x - ox , ys ) , ( x , ys ) , ( x + ox , ys ) , ( xe , y - oy ) , ( xe , y ) , ( xe , y + oy ) , ( x + ox , ye ) , ( x , ye ) , ( x - ox , ye ) , ( xs , y + oy ) , ( xs , y ) ] return pts | Get a set of 12 bezier control points necessary to form an ellipse . |
24,887 | def set_cmap_cb ( self , w , index ) : name = cmap . get_names ( ) [ index ] self . t_ . set ( color_map = name ) | This callback is invoked when the user selects a new color map from the preferences pane . |
24,888 | def set_imap_cb ( self , w , index ) : name = imap . get_names ( ) [ index ] self . t_ . set ( intensity_map = name ) | This callback is invoked when the user selects a new intensity map from the preferences pane . |
24,889 | def set_calg_cb ( self , w , index ) : name = self . calg_names [ index ] self . t_ . set ( color_algorithm = name ) | This callback is invoked when the user selects a new color hashing algorithm from the preferences pane . |
24,890 | def autocut_params_changed_cb ( self , paramObj , ac_obj ) : args , kwdargs = paramObj . get_params ( ) params = list ( kwdargs . items ( ) ) self . t_ . set ( autocut_params = params ) | This callback is called when the user changes the attributes of an object via the paramSet . |
24,891 | def set_sort_cb ( self , w , index ) : name = self . sort_options [ index ] self . t_ . set ( sort_order = name ) | This callback is invoked when the user selects a new sort order from the preferences pane . |
24,892 | def set_scrollbars_cb ( self , w , tf ) : scrollbars = 'on' if tf else 'off' self . t_ . set ( scrollbars = scrollbars ) | This callback is invoked when the user checks the Use Scrollbars box in the preferences pane . |
24,893 | def zoomset_cb ( self , setting , value , channel ) : if not self . gui_up : return info = channel . extdata . _info_info if info is None : return scale_x , scale_y = value if scale_x == scale_y : text = self . fv . scale2text ( scale_x ) else : textx = self . fv . scale2text ( scale_x ) texty = self . fv . scale2text ( scale_y ) text = "X: %s Y: %s" % ( textx , texty ) info . winfo . zoom . set_text ( text ) | This callback is called when the main window is zoomed . |
24,894 | def redo ( self ) : image = self . channel . get_current_image ( ) if image is None : return True path = image . get ( 'path' , None ) if path is None : self . fv . show_error ( "Cannot open image: no value for metadata key 'path'" ) return if path . endswith ( 'asdf' ) : return True if path != self . img_path : self . img_path = path if self . file_obj is not None : try : self . file_obj . close ( ) except Exception : pass self . file_obj = io_fits . get_fitsloader ( logger = self . logger ) self . file_obj . open_file ( path ) upper = len ( self . file_obj ) - 1 self . prep_hdu_menu ( self . w . hdu , self . file_obj . hdu_info ) self . num_hdu = upper self . logger . debug ( "there are %d hdus" % ( upper + 1 ) ) self . w . numhdu . set_text ( "%d" % ( upper + 1 ) ) self . w . hdu . set_enabled ( len ( self . file_obj ) > 0 ) name = image . get ( 'name' , iohelper . name_image_from_path ( path ) ) idx = image . get ( 'idx' , None ) match = re . match ( r'^(.+)\[(.+)\]$' , name ) if match : name = match . group ( 1 ) self . name_pfx = name htype = None if idx is not None : info = self . file_obj . hdu_db . get ( idx , None ) if info is not None : htype = info . htype . lower ( ) toc_ent = self . _toc_fmt % info self . w . hdu . show_text ( toc_ent ) if self . img_name != name : self . img_name = name dims = [ 0 , 0 ] data = image . get_data ( ) if data is None : self . logger . warning ( "Empty data part in HDU %s" % ( str ( idx ) ) ) elif htype in ( 'bintablehdu' , 'tablehdu' , ) : pass elif htype not in ( 'imagehdu' , 'primaryhdu' , 'compimagehdu' ) : self . logger . warning ( "HDU %s is not an image (%s)" % ( str ( idx ) , htype ) ) else : mddata = image . get_mddata ( ) if mddata is not None : dims = list ( mddata . shape ) dims . reverse ( ) self . build_naxis ( dims , image ) | Called when an image is set in the channel . |
24,895 | def reorder_image ( dst_order , src_arr , src_order ) : depth = src_arr . shape [ 2 ] if depth != len ( src_order ) : raise ValueError ( "src_order (%s) does not match array depth (%d)" % ( src_order , depth ) ) bands = [ ] if dst_order == src_order : return np . ascontiguousarray ( src_arr ) elif 'A' not in dst_order or 'A' in src_order : idx = np . array ( [ src_order . index ( c ) for c in dst_order ] ) return np . ascontiguousarray ( src_arr [ ... , idx ] ) else : indexes = [ src_order . index ( c ) for c in dst_order . replace ( 'A' , '' ) ] bands = [ src_arr [ ... , idx , np . newaxis ] for idx in indexes ] ht , wd = src_arr . shape [ : 2 ] dst_type = src_arr . dtype dst_max_val = np . iinfo ( dst_type ) . max alpha = np . full ( ( ht , wd , 1 ) , dst_max_val , dtype = dst_type ) bands . insert ( dst_order . index ( 'A' ) , alpha ) return np . concatenate ( bands , axis = - 1 ) | Reorder src_arr with order of color planes in src_order as dst_order . |
24,896 | def strip_z ( pts ) : pts = np . asarray ( pts ) if pts . shape [ - 1 ] > 2 : pts = np . asarray ( ( pts . T [ 0 ] , pts . T [ 1 ] ) ) . T return pts | Strips a Z component from pts if it is present . |
24,897 | def get_bounds ( pts ) : pts_t = np . asarray ( pts ) . T return np . asarray ( ( [ np . min ( _pts ) for _pts in pts_t ] , [ np . max ( _pts ) for _pts in pts_t ] ) ) | Return the minimum point and maximum point bounding a set of points . |
24,898 | def trim_prefix ( text , nchr ) : res = [ ] for line in text . split ( '\n' ) : if line . startswith ( ' ' * nchr ) : line = line [ nchr : ] res . append ( line ) return '\n' . join ( res ) | Trim characters off of the beginnings of text lines . |
24,899 | def _get_color ( self , r , g , b ) : clr = ( r , g , b ) return clr | Convert red green and blue values specified in floats with range 0 - 1 to whatever the native widget color object is . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.