idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
22,400
def _overlapping ( files ) : segments = set ( ) for path in files : seg = file_segment ( path ) for s in segments : if seg . intersects ( s ) : return True segments . add ( seg ) return False
Quick method to see if a file list contains overlapping files
22,401
def fetch_losc_data ( detector , start , end , cls = TimeSeries , ** kwargs ) : start = to_gps ( start ) end = to_gps ( end ) span = Segment ( start , end ) kwargs . update ( { 'start' : start , 'end' : end , } ) url_kw = { key : kwargs . pop ( key ) for key in GWOSC_LOCATE_KWARGS if key in kwargs } if 'sample_rate' in...
Fetch LOSC data for a given detector
22,402
def read_losc_hdf5 ( h5f , path = 'strain/Strain' , start = None , end = None , copy = False ) : dataset = io_hdf5 . find_dataset ( h5f , path ) nddata = dataset [ ( ) ] xunit = parse_unit ( dataset . attrs [ 'Xunits' ] ) epoch = dataset . attrs [ 'Xstart' ] dt = Quantity ( dataset . attrs [ 'Xspacing' ] , xunit ) unit...
Read a TimeSeries from a LOSC - format HDF file .
22,403
def read_losc_hdf5_state ( f , path = 'quality/simple' , start = None , end = None , copy = False ) : dataset = io_hdf5 . find_dataset ( f , '%s/DQmask' % path ) maskset = io_hdf5 . find_dataset ( f , '%s/DQDescriptions' % path ) nddata = dataset [ ( ) ] bits = [ bytes . decode ( bytes ( b ) , 'utf-8' ) for b in maskse...
Read a StateVector from a LOSC - format HDF file .
22,404
def _gwf_channel ( path , series_class = TimeSeries , verbose = False ) : channels = list ( io_gwf . iter_channel_names ( file_path ( path ) ) ) if issubclass ( series_class , StateVector ) : regex = DQMASK_CHANNEL_REGEX else : regex = STRAIN_CHANNEL_REGEX found , = list ( filter ( regex . match , channels ) ) if verbo...
Find the right channel name for a LOSC GWF file
22,405
def from_segwizard ( source , gpstype = LIGOTimeGPS , strict = True ) : if isinstance ( source , string_types ) : with open ( source , 'r' ) as fobj : return from_segwizard ( fobj , gpstype = gpstype , strict = strict ) out = SegmentList ( ) fmt_pat = None for line in source : if line . startswith ( ( '#' , ';' ) ) : c...
Read segments from a segwizard format file into a SegmentList
22,406
def _line_format ( line ) : for pat in ( FOUR_COL_REGEX , THREE_COL_REGEX , TWO_COL_REGEX ) : if pat . match ( line ) : return pat raise ValueError ( "unable to parse segment from line {!r}" . format ( line ) )
Determine the column format pattern for a line in an ASCII segment file .
22,407
def _format_segment ( tokens , strict = True , gpstype = LIGOTimeGPS ) : try : start , end , dur = tokens except ValueError : return Segment ( * map ( gpstype , tokens ) ) seg = Segment ( gpstype ( start ) , gpstype ( end ) ) if strict and not float ( abs ( seg ) ) == float ( dur ) : raise ValueError ( "segment {0!r} h...
Format a list of tokens parsed from an ASCII file into a segment .
22,408
def to_segwizard ( segs , target , header = True , coltype = LIGOTimeGPS ) : if isinstance ( target , string_types ) : with open ( target , 'w' ) as fobj : return to_segwizard ( segs , fobj , header = header , coltype = coltype ) if header : print ( '# seg\tstart\tstop\tduration' , file = target ) for i , seg in enumer...
Write the given SegmentList to a file in SegWizard format .
22,409
def gopen ( name , * args , ** kwargs ) : if name . endswith ( '.gz' ) : return gzip . open ( name , * args , ** kwargs ) fobj = open ( name , * args , ** kwargs ) sig = fobj . read ( 3 ) fobj . seek ( 0 ) if sig == GZIP_SIGNATURE : fobj . close ( ) return gzip . open ( name , * args , ** kwargs ) return fobj
Open a file handling optional gzipping
22,410
def file_list ( flist ) : if ( isinstance ( flist , string_types ) and flist . endswith ( ( '.cache' , '.lcf' , '.ffl' ) ) ) : from . cache import read_cache return read_cache ( flist ) if isinstance ( flist , string_types ) : return flist . split ( ',' ) if isinstance ( flist , ( list , tuple ) ) : return list ( map (...
Parse a number of possible input types into a list of filepaths .
22,411
def file_path ( fobj ) : if isinstance ( fobj , string_types ) and fobj . startswith ( "file:" ) : return urlparse ( fobj ) . path if isinstance ( fobj , string_types ) : return fobj if ( isinstance ( fobj , FILE_LIKE ) and hasattr ( fobj , "name" ) ) : return fobj . name try : return fobj . path except AttributeError ...
Determine the path of a file .
22,412
def process_in_out_queues ( func , q_in , q_out ) : while True : idx , arg = q_in . get ( ) if idx is None : break q_out . put ( ( idx , func ( arg ) ) )
Iterate through a Queue call func and Queue the result
22,413
def multiprocess_with_queues ( nproc , func , inputs , verbose = False , ** progress_kw ) : if nproc != 1 and os . name == 'nt' : warnings . warn ( "multiprocessing is currently not supported on Windows, see " "https://github.com/gwpy/gwpy/issues/880, will continue with " "serial procesing (nproc=1)" ) nproc = 1 if pro...
Map a function over a list of inputs using multiprocess
22,414
def epoch ( self ) : try : if self . _epoch is None : return None return Time ( * modf ( self . _epoch ) [ : : - 1 ] , format = 'gps' , scale = 'utc' ) except AttributeError : self . _epoch = None return self . _epoch
GPS epoch associated with these data
22,415
def override_unit ( self , unit , parse_strict = 'raise' ) : self . _unit = parse_unit ( unit , parse_strict = parse_strict )
Forcefully reset the unit of these data
22,416
def flatten ( self , order = 'C' ) : return super ( Array , self ) . flatten ( order = order ) . view ( Quantity )
Return a copy of the array collapsed into one dimension .
22,417
def from_timeseries ( ts1 , ts2 , stride , fftlength = None , overlap = None , window = None , nproc = 1 , ** kwargs ) : if fftlength is None : fftlength = stride / 2. nsteps = int ( ts1 . size // ( stride * ts1 . sample_rate . value ) ) nproc = min ( nsteps , nproc ) if nsteps == 0 or nproc == 1 : return _from_timeser...
Calculate the coherence Spectrogram between two TimeSeries .
22,418
def read_channel_list_file ( * source ) : config = configparser . ConfigParser ( dict_type = OrderedDict ) source = file_list ( source ) success_ = config . read ( * source ) if len ( success_ ) != len ( source ) : raise IOError ( "Failed to read one or more CLF files" ) out = ChannelList ( ) out . source = source appe...
Read a ~gwpy . detector . ChannelList from a Channel List File
22,419
def write_channel_list_file ( channels , fobj ) : if not isinstance ( fobj , FILE_LIKE ) : with open ( fobj , "w" ) as fobj : return write_channel_list_file ( channels , fobj ) out = configparser . ConfigParser ( dict_type = OrderedDict ) for channel in channels : group = channel . group if not out . has_section ( grou...
Write a ~gwpy . detector . ChannelList to a INI - format channel list file
22,420
def register_method ( func , name = None , deprecated = False ) : if deprecated : func = deprecated_function ( func , "the {0!r} PSD methods is deprecated, and will be removed " "in a future release, please consider using {1!r} instead" . format ( name , name . split ( '-' , 1 ) [ 1 ] , ) , ) if name is None : name = f...
Register a method of calculating an average spectrogram .
22,421
def get_method ( name ) : name = _format_name ( name ) try : return METHODS [ name ] except KeyError as exc : exc . args = ( "no PSD method registered with name {0!r}" . format ( name ) , ) raise
Return the PSD method registered with the given name .
22,422
def inspiral_range_psd ( psd , snr = 8 , mass1 = 1.4 , mass2 = 1.4 , horizon = False ) : mass1 = units . Quantity ( mass1 , 'solMass' ) . to ( 'kg' ) mass2 = units . Quantity ( mass2 , 'solMass' ) . to ( 'kg' ) mtotal = mass1 + mass2 mchirp = ( mass1 * mass2 ) ** ( 3 / 5. ) / mtotal ** ( 1 / 5. ) fisco = ( constants . ...
Compute the inspiral sensitive distance PSD from a GW strain PSD
22,423
def inspiral_range ( psd , snr = 8 , mass1 = 1.4 , mass2 = 1.4 , fmin = None , fmax = None , horizon = False ) : mass1 = units . Quantity ( mass1 , 'solMass' ) . to ( 'kg' ) mass2 = units . Quantity ( mass2 , 'solMass' ) . to ( 'kg' ) mtotal = mass1 + mass2 fisco = ( constants . c ** 3 / ( constants . G * 6 ** 1.5 * pi...
Calculate the inspiral sensitive distance from a GW strain PSD
22,424
def burst_range_spectrum ( psd , snr = 8 , energy = 1e-2 ) : a = ( constants . G * energy * constants . M_sun * 0.4 / ( pi ** 2 * constants . c ) ) ** ( 1 / 2. ) dspec = psd ** ( - 1 / 2. ) * a / ( snr * psd . frequencies ) rspec = dspec . to ( 'Mpc' ) if rspec . f0 . value == 0.0 : rspec [ 0 ] = 0.0 return rspec
Calculate the frequency - dependent GW burst range from a strain PSD
22,425
def burst_range ( psd , snr = 8 , energy = 1e-2 , fmin = 100 , fmax = 500 ) : freqs = psd . frequencies . value if not fmin : fmin = psd . f0 if not fmax : fmax = psd . span [ 1 ] condition = ( freqs >= fmin ) & ( freqs < fmax ) integrand = burst_range_spectrum ( psd [ condition ] , snr = snr , energy = energy ) ** 3 r...
Calculate the integrated GRB - like GW burst range from a strain PSD
22,426
def format_norm ( kwargs , current = None ) : norm = kwargs . pop ( 'norm' , current ) or 'linear' vmin = kwargs . pop ( 'vmin' , None ) vmax = kwargs . pop ( 'vmax' , None ) clim = kwargs . pop ( 'clim' , ( vmin , vmax ) ) or ( None , None ) clip = kwargs . pop ( 'clip' , None ) if norm == 'linear' : norm = colors . N...
Format a ~matplotlib . colors . Normalize from a set of kwargs
22,427
def identify_gwf ( origin , filepath , fileobj , * args , ** kwargs ) : if fileobj is not None : loc = fileobj . tell ( ) fileobj . seek ( 0 ) try : if fileobj . read ( 4 ) == GWF_SIGNATURE : return True finally : fileobj . seek ( loc ) if filepath is not None : if filepath . endswith ( '.gwf' ) : return True if filepa...
Identify a filename or file object as GWF
22,428
def open_gwf ( filename , mode = 'r' ) : if mode not in ( 'r' , 'w' ) : raise ValueError ( "mode must be either 'r' or 'w'" ) from LDAStools import frameCPP filename = urlparse ( filename ) . path if mode == 'r' : return frameCPP . IFrameFStream ( str ( filename ) ) return frameCPP . OFrameFStream ( str ( filename ) )
Open a filename for reading or writing GWF format data
22,429
def write_frames ( filename , frames , compression = 257 , compression_level = 6 ) : from LDAStools import frameCPP stream = open_gwf ( filename , 'w' ) if isinstance ( frames , frameCPP . FrameH ) : frames = [ frames ] for frame in frames : stream . WriteFrame ( frame , compression , compression_level )
Write a list of frame objects to a file
22,430
def get_channel_type ( channel , framefile ) : channel = str ( channel ) for name , type_ in _iter_channels ( framefile ) : if channel == name : return type_ raise ValueError ( "%s not found in table-of-contents for %s" % ( channel , framefile ) )
Find the channel type in a given GWF file
22,431
def channel_in_frame ( channel , framefile ) : channel = str ( channel ) for name in iter_channel_names ( framefile ) : if channel == name : return True return False
Determine whether a channel is stored in this framefile
22,432
def _iter_channels ( framefile ) : from LDAStools import frameCPP if not isinstance ( framefile , frameCPP . IFrameFStream ) : framefile = open_gwf ( framefile , 'r' ) toc = framefile . GetTOC ( ) for typename in ( 'Sim' , 'Proc' , 'ADC' ) : typen = typename . lower ( ) for name in getattr ( toc , 'Get{0}' . format ( t...
Yields the name and type of each channel in a GWF file TOC
22,433
def data_segments ( paths , channel , warn = True ) : segments = SegmentList ( ) for path in paths : segments . extend ( _gwf_channel_segments ( path , channel , warn = warn ) ) return segments . coalesce ( )
Returns the segments containing data for a channel
22,434
def _gwf_channel_segments ( path , channel , warn = True ) : stream = open_gwf ( path ) toc = stream . GetTOC ( ) secs = toc . GetGTimeS ( ) nano = toc . GetGTimeN ( ) dur = toc . GetDt ( ) readers = [ getattr ( stream , 'ReadFr{0}Data' . format ( type_ . title ( ) ) ) for type_ in ( "proc" , "sim" , "adc" ) ] for i , ...
Yields the segments containing data for channel in this GWF path
22,435
def fdfilter ( data , * filt , ** kwargs ) : inplace = kwargs . pop ( 'inplace' , False ) analog = kwargs . pop ( 'analog' , False ) fs = kwargs . pop ( 'sample_rate' , None ) if kwargs : raise TypeError ( "filter() got an unexpected keyword argument '%s'" % list ( kwargs . keys ( ) ) [ 0 ] ) if fs is None : fs = 2 * (...
Filter a frequency - domain data object
22,436
def main ( args = None ) : parser = argparse . ArgumentParser ( description = __doc__ ) parser . add_argument ( "-V" , "--version" , action = "version" , version = __version__ , help = "show version number and exit" ) parser . add_argument ( "-l" , "--local" , action = "store_true" , default = False , help = "print dat...
Parse command - line arguments tconvert inputs and print
22,437
def timer ( func ) : name = func . __name__ @ wraps ( func ) def timed_func ( self , * args , ** kwargs ) : _start = time . time ( ) out = func ( self , * args , ** kwargs ) self . log ( 2 , '{0} took {1:.1f} sec' . format ( name , time . time ( ) - _start ) ) return out return timed_func
Time a method and print its duration after return
22,438
def to_float ( unit ) : def converter ( x ) : return Quantity ( x , unit ) . value converter . __doc__ %= str ( unit ) return converter
Factory to build a converter from quantity string to float
22,439
def log_norm ( func ) : @ wraps ( func ) def decorated_func ( * args , ** kwargs ) : norm , kwargs = format_norm ( kwargs ) kwargs [ 'norm' ] = norm return func ( * args , ** kwargs ) return decorated_func
Wrap func to handle custom gwpy keywords for a LogNorm colouring
22,440
def xlim_as_gps ( func ) : @ wraps ( func ) def wrapped_func ( self , left = None , right = None , ** kw ) : if right is None and numpy . iterable ( left ) : left , right = left kw [ 'left' ] = left kw [ 'right' ] = right gpsscale = self . get_xscale ( ) in GPS_SCALES for key in ( 'left' , 'right' ) : if gpsscale : try...
Wrap func to handle pass limit inputs through gwpy . time . to_gps
22,441
def restore_grid ( func ) : @ wraps ( func ) def wrapped_func ( self , * args , ** kwargs ) : grid = ( self . xaxis . _gridOnMinor , self . xaxis . _gridOnMajor , self . yaxis . _gridOnMinor , self . yaxis . _gridOnMajor ) try : return func ( self , * args , ** kwargs ) finally : self . xaxis . grid ( grid [ 0 ] , whic...
Wrap func to preserve the Axes current grid settings .
22,442
def set_epoch ( self , epoch ) : scale = self . get_xscale ( ) return self . set_xscale ( scale , epoch = epoch )
Set the epoch for the current GPS scale .
22,443
def imshow ( self , array , * args , ** kwargs ) : if isinstance ( array , Array2D ) : return self . _imshow_array2d ( array , * args , ** kwargs ) image = super ( Axes , self ) . imshow ( array , * args , ** kwargs ) self . autoscale ( enable = None , axis = 'both' , tight = None ) return image
Display an image i . e . data on a 2D regular raster .
22,444
def _imshow_array2d ( self , array , origin = 'lower' , interpolation = 'none' , aspect = 'auto' , ** kwargs ) : extent = tuple ( array . xspan ) + tuple ( array . yspan ) if self . get_xscale ( ) == 'log' and extent [ 0 ] == 0. : extent = ( 1e-300 , ) + extent [ 1 : ] if self . get_yscale ( ) == 'log' and extent [ 2 ]...
Render an ~gwpy . types . Array2D using Axes . imshow
22,445
def pcolormesh ( self , * args , ** kwargs ) : if len ( args ) == 1 and isinstance ( args [ 0 ] , Array2D ) : return self . _pcolormesh_array2d ( * args , ** kwargs ) return super ( Axes , self ) . pcolormesh ( * args , ** kwargs )
Create a pseudocolor plot with a non - regular rectangular grid .
22,446
def _pcolormesh_array2d ( self , array , * args , ** kwargs ) : x = numpy . concatenate ( ( array . xindex . value , array . xspan [ - 1 : ] ) ) y = numpy . concatenate ( ( array . yindex . value , array . yspan [ - 1 : ] ) ) xcoord , ycoord = numpy . meshgrid ( x , y , copy = False , sparse = True ) return self . pcol...
Render an ~gwpy . types . Array2D using Axes . pcolormesh
22,447
def plot_mmm ( self , data , lower = None , upper = None , ** kwargs ) : alpha = kwargs . pop ( 'alpha' , .1 ) line , = self . plot ( data , ** kwargs ) out = [ line ] kwargs . update ( { 'label' : '' , 'linewidth' : line . get_linewidth ( ) / 2 , 'color' : line . get_color ( ) , 'alpha' : alpha * 2 , } ) fill = [ data...
Plot a Series as a line with a shaded region around it .
22,448
def tile ( self , x , y , w , h , color = None , anchor = 'center' , edgecolors = 'face' , linewidth = 0.8 , ** kwargs ) : if color is not None and kwargs . get ( 'c_sort' , True ) : sortidx = color . argsort ( ) x = x [ sortidx ] y = y [ sortidx ] w = w [ sortidx ] h = h [ sortidx ] color = color [ sortidx ] if anchor...
Plot rectanguler tiles based onto these Axes .
22,449
def colorbar ( self , mappable = None , ** kwargs ) : fig = self . get_figure ( ) if kwargs . get ( 'use_axesgrid' , True ) : kwargs . setdefault ( 'fraction' , 0. ) if kwargs . get ( 'fraction' , 0. ) == 0. : kwargs . setdefault ( 'use_axesgrid' , True ) mappable , kwargs = gcbar . process_colorbar_kwargs ( fig , mapp...
Add a ~matplotlib . colorbar . Colorbar to these Axes
22,450
def tconvert ( gpsordate = 'now' ) : try : float ( gpsordate ) except ( TypeError , ValueError ) : return to_gps ( gpsordate ) return from_gps ( gpsordate )
Convert GPS times to ISO - format date - times and vice - versa .
22,451
def from_gps ( gps ) : try : gps = LIGOTimeGPS ( gps ) except ( ValueError , TypeError , RuntimeError ) : gps = LIGOTimeGPS ( float ( gps ) ) sec , nano = gps . gpsSeconds , gps . gpsNanoSeconds date = Time ( sec , format = 'gps' , scale = 'utc' ) . datetime return date + datetime . timedelta ( microseconds = nano * 1e...
Convert a GPS time into a datetime . datetime .
22,452
def _str_to_datetime ( datestr ) : try : return DATE_STRINGS [ str ( datestr ) . lower ( ) ] ( ) except KeyError : pass try : import maya return maya . when ( datestr ) . datetime ( ) except ImportError : pass with warnings . catch_warnings ( ) : warnings . simplefilter ( "error" , RuntimeWarning ) try : return datepar...
Convert str to datetime . datetime .
22,453
def _time_to_gps ( time ) : time = time . utc date = time . datetime micro = date . microsecond if isinstance ( date , datetime . datetime ) else 0 return LIGOTimeGPS ( int ( time . gps ) , int ( micro * 1e3 ) )
Convert a Time into LIGOTimeGPS .
22,454
def with_read_hdf5 ( func ) : @ wraps ( func ) def decorated_func ( fobj , * args , ** kwargs ) : if not isinstance ( fobj , h5py . HLObject ) : if isinstance ( fobj , FILE_LIKE ) : fobj = fobj . name with h5py . File ( fobj , 'r' ) as h5f : return func ( h5f , * args , ** kwargs ) return func ( fobj , * args , ** kwar...
Decorate an HDF5 - reading function to open a filepath if needed
22,455
def find_dataset ( h5o , path = None ) : if isinstance ( h5o , h5py . Dataset ) : return h5o elif path is None and len ( h5o ) == 1 : path = list ( h5o . keys ( ) ) [ 0 ] elif path is None : raise ValueError ( "Please specify the HDF5 path via the " "``path=`` keyword argument" ) return h5o [ path ]
Find and return the relevant dataset inside the given H5 object
22,456
def with_write_hdf5 ( func ) : @ wraps ( func ) def decorated_func ( obj , fobj , * args , ** kwargs ) : if not isinstance ( fobj , h5py . HLObject ) : append = kwargs . get ( 'append' , False ) overwrite = kwargs . get ( 'overwrite' , False ) if os . path . exists ( fobj ) and not ( overwrite or append ) : raise IOErr...
Decorate an HDF5 - writing function to open a filepath if needed
22,457
def create_dataset ( parent , path , overwrite = False , ** kwargs ) : if path in parent and overwrite : del parent [ path ] try : return parent . create_dataset ( path , ** kwargs ) except RuntimeError as exc : if str ( exc ) == 'Unable to create link (Name already exists)' : exc . args = ( '{0}: {1!r}, pass overwrite...
Create a new dataset inside the parent HDF5 object
22,458
def format_db_selection ( selection , engine = None ) : if selection is None : return '' selections = [ ] for col , op_ , value in parse_column_filters ( selection ) : if engine and engine . name == 'postgresql' : col = '"%s"' % col try : opstr = [ key for key in OPERATORS if OPERATORS [ key ] is op_ ] [ 0 ] except Key...
Format a column filter selection as a SQL database WHERE string
22,459
def fetch ( engine , tablename , columns = None , selection = None , ** kwargs ) : import pandas as pd if columns is None : columnstr = '*' else : columnstr = ', ' . join ( '"%s"' % c for c in columns ) selectionstr = format_db_selection ( selection , engine = engine ) qstr = 'SELECT %s FROM %s %s' % ( columnstr , tabl...
Fetch data from an SQL table into an EventTable
22,460
def q_scan ( data , mismatch = DEFAULT_MISMATCH , qrange = DEFAULT_QRANGE , frange = DEFAULT_FRANGE , duration = None , sampling = None , ** kwargs ) : from gwpy . timeseries import TimeSeries if isinstance ( data , TimeSeries ) : duration = abs ( data . span ) sampling = data . sample_rate . to ( 'Hz' ) . value kwargs...
Transform data by scanning over a QTiling
22,461
def _iter_qs ( self ) : cumum = log ( self . qrange [ 1 ] / self . qrange [ 0 ] ) / 2 ** ( 1 / 2. ) nplanes = int ( max ( ceil ( cumum / self . deltam ) , 1 ) ) dq = cumum / nplanes for i in xrange ( nplanes ) : yield self . qrange [ 0 ] * exp ( 2 ** ( 1 / 2. ) * dq * ( i + .5 ) )
Iterate over the Q values
22,462
def transform ( self , fseries , ** kwargs ) : weight = 1 + numpy . log10 ( self . qrange [ 1 ] / self . qrange [ 0 ] ) / numpy . sqrt ( 2 ) nind , nplanes , peak , result = ( 0 , 0 , 0 , None ) for plane in self : nplanes += 1 nind += sum ( [ 1 + row . ntiles * row . deltam for row in plane ] ) result = plane . transf...
Compute the time - frequency plane at fixed Q with the most significant tile
22,463
def farray ( self ) : bandwidths = 2 * pi ** ( 1 / 2. ) * self . frequencies / self . q return self . frequencies - bandwidths / 2.
Array of frequencies for the lower - edge of each frequency bin
22,464
def ntiles ( self ) : tcum_mismatch = self . duration * 2 * pi * self . frequency / self . q return next_power_of_two ( tcum_mismatch / self . deltam )
The number of tiles in this row
22,465
def get_window ( self ) : wfrequencies = self . _get_indices ( ) / self . duration xfrequencies = wfrequencies * self . qprime / self . frequency norm = self . ntiles / ( self . duration * self . sampling ) * ( 315 * self . qprime / ( 128 * self . frequency ) ) ** ( 1 / 2. ) return ( 1 - xfrequencies ** 2 ) ** 2 * norm
Generate the bi - square window for this row
22,466
def get_data_indices ( self ) : return numpy . round ( self . _get_indices ( ) + 1 + self . frequency * self . duration ) . astype ( int )
Returns the index array of interesting frequencies for this row
22,467
def interpolate ( self , tres = "<default>" , fres = "<default>" , logf = False , outseg = None ) : from scipy . interpolate import ( interp2d , InterpolatedUnivariateSpline ) from . . spectrogram import Spectrogram if outseg is None : outseg = self . energies [ 0 ] . span frequencies = self . plane . frequencies dtype...
Interpolate this QGram over a regularly - gridded spectrogram
22,468
def table ( self , snrthresh = 5.5 ) : from . . table import EventTable freqs = self . plane . frequencies bws = 2 * ( freqs - self . plane . farray ) names = ( 'time' , 'frequency' , 'duration' , 'bandwidth' , 'energy' ) rec = numpy . recarray ( ( 0 , ) , names = names , formats = [ 'f8' ] * len ( names ) ) for f , bw...
Represent this QPlane as an EventTable
22,469
def define ( cls , start , step , num , dtype = None ) : if dtype is None : dtype = max ( numpy . array ( start , subok = True , copy = False ) . dtype , numpy . array ( step , subok = True , copy = False ) . dtype , ) start = start . astype ( dtype , copy = False ) step = step . astype ( dtype , copy = False ) return ...
Define a new Index .
22,470
def regular ( self ) : try : return self . info . meta [ 'regular' ] except ( TypeError , KeyError ) : if self . info . meta is None : self . info . meta = { } self . info . meta [ 'regular' ] = self . is_regular ( ) return self . info . meta [ 'regular' ]
True if this index is linearly increasing
22,471
def is_regular ( self ) : if self . size <= 1 : return False return numpy . isclose ( numpy . diff ( self . value , n = 2 ) , 0 ) . all ( )
Determine whether this Index contains linearly increasing samples
22,472
def table_from_omicron ( source , * args , ** kwargs ) : if not args : kwargs . setdefault ( 'treename' , 'triggers' ) return EventTable . read ( source , * args , format = 'root' , ** kwargs )
Read an EventTable from an Omicron ROOT file
22,473
def plot ( self , * args , ** kwargs ) : out = [ ] args = list ( args ) while args : try : plotter = self . _plot_method ( args [ 0 ] ) except TypeError : break out . append ( plotter ( args [ 0 ] , ** kwargs ) ) args . pop ( 0 ) if args : out . extend ( super ( SegmentAxes , self ) . plot ( * args , ** kwargs ) ) self...
Plot data onto these axes
22,474
def plot_dict ( self , flags , label = 'key' , known = 'x' , ** kwargs ) : out = [ ] for lab , flag in flags . items ( ) : if label . lower ( ) == 'name' : lab = flag . name elif label . lower ( ) != 'key' : lab = label out . append ( self . plot_flag ( flag , label = to_string ( lab ) , known = known , ** kwargs ) ) r...
Plot a ~gwpy . segments . DataQualityDict onto these axes
22,475
def plot_flag ( self , flag , y = None , ** kwargs ) : if y is None : y = self . get_next_y ( ) if flag . isgood : kwargs . setdefault ( 'facecolor' , '#33cc33' ) kwargs . setdefault ( 'known' , '#ff0000' ) else : kwargs . setdefault ( 'facecolor' , '#ff0000' ) kwargs . setdefault ( 'known' , '#33cc33' ) known = kwargs...
Plot a ~gwpy . segments . DataQualityFlag onto these axes .
22,476
def plot_segmentlist ( self , segmentlist , y = None , height = .8 , label = None , collection = True , rasterized = None , ** kwargs ) : facecolor = kwargs . pop ( 'facecolor' , kwargs . pop ( 'color' , '#629fca' ) ) if is_color_like ( facecolor ) : kwargs . setdefault ( 'edgecolor' , tint ( facecolor , factor = .5 ) ...
Plot a ~gwpy . segments . SegmentList onto these axes
22,477
def plot_segmentlistdict ( self , segmentlistdict , y = None , dy = 1 , ** kwargs ) : if y is None : y = self . get_next_y ( ) collections = [ ] for name , segmentlist in segmentlistdict . items ( ) : collections . append ( self . plot_segmentlist ( segmentlist , y = y , label = name , ** kwargs ) ) y += dy return coll...
Plot a ~gwpy . segments . SegmentListDict onto these axes
22,478
def get_collections ( self , ignore = None ) : if ignore is None : return self . collections return [ c for c in self . collections if getattr ( c , '_ignore' , None ) == ignore ]
Return the collections matching the given _ignore value
22,479
def parse_keytab ( keytab ) : try : out = subprocess . check_output ( [ 'klist' , '-k' , keytab ] , stderr = subprocess . PIPE ) except OSError : raise KerberosError ( "Failed to locate klist, cannot read keytab" ) except subprocess . CalledProcessError : raise KerberosError ( "Cannot read keytab {!r}" . format ( keyta...
Read the contents of a KRB5 keytab file returning a list of credentials listed within
22,480
def y0 ( self ) : try : return self . _y0 except AttributeError : self . _y0 = Quantity ( 0 , self . yunit ) return self . _y0
Y - axis coordinate of the first data point
22,481
def dy ( self ) : try : return self . _dy except AttributeError : try : self . _yindex except AttributeError : self . _dy = Quantity ( 1 , self . yunit ) else : if not self . yindex . regular : raise AttributeError ( "This series has an irregular y-axis " "index, so 'dy' is not well defined" ) self . _dy = self . yinde...
Y - axis sample separation
22,482
def yunit ( self ) : try : return self . _dy . unit except AttributeError : try : return self . _y0 . unit except AttributeError : return self . _default_yunit
Unit of Y - axis index
22,483
def yindex ( self ) : try : return self . _yindex except AttributeError : self . _yindex = Index . define ( self . y0 , self . dy , self . shape [ 1 ] ) return self . _yindex
Positions of the data on the y - axis
22,484
def is_compatible ( self , other ) : super ( Array2D , self ) . is_compatible ( other ) if isinstance ( other , type ( self ) ) : try : if not self . dy == other . dy : raise ValueError ( "%s sample sizes do not match: " "%s vs %s." % ( type ( self ) . __name__ , self . dy , other . dy ) ) except AttributeError : raise...
Check whether this array and other have compatible metadata
22,485
def find_flag_groups ( h5group , strict = True ) : names = [ ] for group in h5group : try : names . append ( h5group [ group ] . attrs [ 'name' ] ) except KeyError : if strict : raise continue return names
Returns all HDF5 Groups under the given group that contain a flag
22,486
def _is_flag_group ( obj ) : return ( isinstance ( obj , h5py . Group ) and isinstance ( obj . get ( "active" ) , h5py . Dataset ) and isinstance ( obj . get ( "known" ) , h5py . Dataset ) )
Returns True if obj is an h5py . Group that looks like if contains a flag
22,487
def _find_flag_groups ( h5f ) : flag_groups = [ ] def _find ( name , obj ) : if _is_flag_group ( obj ) : flag_groups . append ( name ) h5f . visititems ( _find ) return flag_groups
Return all groups in h5f that look like flags
22,488
def _get_flag_group ( h5f , path ) : if path : return h5f [ path ] if _is_flag_group ( h5f ) : return h5f try : path , = _find_flag_groups ( h5f ) except ValueError : pass else : return h5f [ path ] raise ValueError ( "please pass a valid HDF5 Group, or specify the HDF5 Group " "path via the ``path=`` keyword argument"...
Determine the group to use in order to read a flag
22,489
def read_hdf5_flag ( h5f , path = None , gpstype = LIGOTimeGPS ) : dataset = _get_flag_group ( h5f , path ) active = SegmentList . read ( dataset [ 'active' ] , format = 'hdf5' , gpstype = gpstype ) try : known = SegmentList . read ( dataset [ 'known' ] , format = 'hdf5' , gpstype = gpstype ) except KeyError as first_k...
Read a DataQualityFlag object from an HDF5 file or group .
22,490
def read_hdf5_segmentlist ( h5f , path = None , gpstype = LIGOTimeGPS , ** kwargs ) : dataset = io_hdf5 . find_dataset ( h5f , path = path ) segtable = Table . read ( dataset , format = 'hdf5' , ** kwargs ) out = SegmentList ( ) for row in segtable : start = LIGOTimeGPS ( int ( row [ 'start_time' ] ) , int ( row [ 'sta...
Read a SegmentList object from an HDF5 file or group .
22,491
def read_hdf5_dict ( h5f , names = None , path = None , on_missing = 'error' , ** kwargs ) : if path : h5f = h5f [ path ] if names is None : names = kwargs . pop ( 'flags' , None ) if names is None : try : names = find_flag_groups ( h5f , strict = True ) except KeyError : names = None if not names : raise ValueError ( ...
Read a DataQualityDict from an HDF5 file
22,492
def write_hdf5_flag_group ( flag , h5group , ** kwargs ) : flag . active . write ( h5group , 'active' , ** kwargs ) kwargs [ 'append' ] = True flag . known . write ( h5group , 'known' , ** kwargs ) for attr in [ 'name' , 'label' , 'category' , 'description' , 'isgood' , 'padding' ] : value = getattr ( flag , attr ) if ...
Write a DataQualityFlag into the given HDF5 group
22,493
def write_hdf5_dict ( flags , output , path = None , append = False , overwrite = False , ** kwargs ) : if path : try : parent = output [ path ] except KeyError : parent = output . create_group ( path ) else : parent = output for name in flags : if name in parent : if not ( overwrite and append ) : raise IOError ( "Gro...
Write this DataQualityFlag to a h5py . Group .
22,494
def float_to_latex ( x , format = "%.2g" ) : r if x == 0. : return '0' base_str = format % x if "e" not in base_str : return base_str mantissa , exponent = base_str . split ( "e" ) if float ( mantissa ) . is_integer ( ) : mantissa = int ( float ( mantissa ) ) exponent = exponent . lstrip ( "0+" ) if exponent . startswi...
r Convert a floating point number to a latex representation .
22,495
def label_to_latex ( text ) : r if text is None : return '' out = [ ] x = None for m in re_latex_control . finditer ( text ) : a , b = m . span ( ) char = m . group ( ) [ 0 ] out . append ( text [ x : a ] ) out . append ( r'\%s' % char ) x = b if not x : return text out . append ( text [ b : ] ) return '' . join ( out ...
r Convert text into a latex - passable representation .
22,496
def preformat_cache ( cache , start = None , end = None ) : if isinstance ( cache , FILE_LIKE + string_types ) : return read_cache ( cache , sort = file_segment , segment = Segment ( start , end ) ) cache = type ( cache ) ( cache ) try : cache . sort ( key = file_segment ) except ValueError : return cache if start is N...
Preprocess a list of file paths for reading .
22,497
def progress_bar ( ** kwargs ) : tqdm_kw = { 'desc' : 'Processing' , 'file' : sys . stdout , 'bar_format' : TQDM_BAR_FORMAT , } tqdm_kw . update ( kwargs ) pbar = tqdm ( ** tqdm_kw ) if not pbar . disable : pbar . desc = pbar . desc . rstrip ( ': ' ) pbar . refresh ( ) return pbar
Create a tqdm . tqdm progress bar
22,498
def num_taps ( sample_rate , transitionwidth , gpass , gstop ) : gpass = 10 ** ( - gpass / 10. ) gstop = 10 ** ( - gstop / 10. ) return int ( 2 / 3. * log10 ( 1 / ( 10 * gpass * gstop ) ) * sample_rate / transitionwidth )
Returns the number of taps for an FIR filter with the given shape
22,499
def is_zpk ( zpktup ) : return ( isinstance ( zpktup , ( tuple , list ) ) and len ( zpktup ) == 3 and isinstance ( zpktup [ 0 ] , ( list , tuple , numpy . ndarray ) ) and isinstance ( zpktup [ 1 ] , ( list , tuple , numpy . ndarray ) ) and isinstance ( zpktup [ 2 ] , float ) )
Determin whether the given tuple is a ZPK - format filter definition