idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
22,300 | def derive_signature ( key , qs ) : key , qs = ( key or "" , qs or "" ) return hmac . new ( key . encode ( ) , qs . encode ( ) , hashlib . sha1 ) . hexdigest ( ) | Derives the signature from the supplied query string using the key . |
22,301 | def sign ( key , qs ) : sig = derive_signature ( key , qs ) return "%s&%s" % ( qs , urlencode ( [ ( "sig" , sig ) ] ) ) | Signs the query string using the key . |
22,302 | def verify_signature ( key , qs ) : unsigned_qs = re . sub ( r'&?sig=[^&]*' , '' , qs ) sig = derive_signature ( key , unsigned_qs ) return urlparse . parse_qs ( qs ) . get ( "sig" , [ None ] ) [ 0 ] == sig | Verifies that the signature in the query string is correct . |
22,303 | def canonical_name ( name ) : if name . lower ( ) == 'planck' : return 'planck' try : return scipy_windows . _win_equiv [ name . lower ( ) ] . __name__ except AttributeError : try : return getattr ( scipy_windows , name . lower ( ) ) . __name__ except AttributeError : pass except KeyError : pass raise ValueError ( 'no ... | Find the canonical name for the given window in scipy . signal |
22,304 | def recommended_overlap ( name , nfft = None ) : try : name = canonical_name ( name ) except KeyError as exc : raise ValueError ( str ( exc ) ) try : rov = ROV [ name ] except KeyError : raise ValueError ( "no recommended overlap for %r window" % name ) if nfft : return int ( ceil ( nfft * rov ) ) return rov | Returns the recommended fractional overlap for the given window |
22,305 | def planck ( N , nleft = 0 , nright = 0 ) : w = numpy . ones ( N ) if nleft : w [ 0 ] *= 0 zleft = numpy . array ( [ nleft * ( 1. / k + 1. / ( k - nleft ) ) for k in range ( 1 , nleft ) ] ) w [ 1 : nleft ] *= expit ( - zleft ) if nright : w [ N - 1 ] *= 0 zright = numpy . array ( [ - nright * ( 1. / ( k - nright ) + 1.... | Return a Planck taper window . |
22,306 | def bool_env ( key , default = False ) : try : return os . environ [ key ] . lower ( ) in TRUE except KeyError : return default | Parse an environment variable as a boolean switch |
22,307 | def call ( cmd , stdout = PIPE , stderr = PIPE , on_error = 'raise' , ** kwargs ) : if isinstance ( cmd , ( list , tuple ) ) : cmdstr = ' ' . join ( cmd ) kwargs . setdefault ( 'shell' , False ) else : cmdstr = str ( cmd ) kwargs . setdefault ( 'shell' , True ) proc = Popen ( cmd , stdout = stdout , stderr = stderr , *... | Call out to the shell using subprocess . Popen |
22,308 | def read_with_columns ( func ) : def wrapper ( * args , ** kwargs ) : columns = kwargs . pop ( "columns" , None ) tab = func ( * args , ** kwargs ) if columns is None : return tab return tab [ columns ] return _safe_wraps ( wrapper , func ) | Decorate a Table read method to use the columns keyword |
22,309 | def read_with_selection ( func ) : def wrapper ( * args , ** kwargs ) : selection = kwargs . pop ( 'selection' , None ) or [ ] tab = func ( * args , ** kwargs ) if selection : return filter_table ( tab , selection ) return tab return _safe_wraps ( wrapper , func ) | Decorate a Table read method to apply selection keyword |
22,310 | def decorate_registered_reader ( name , data_class = EventTable , columns = True , selection = True , ) : reader = registry . get_reader ( name , data_class ) wrapped = ( read_with_columns ( read_with_selection ( reader ) ) ) return registry . register_reader ( name , data_class , wrapped , force = True ) | Wrap an existing registered reader to use GWpy s input decorators |
22,311 | def table_from_root ( source , treename = None , columns = None , ** kwargs ) : import root_numpy try : selection = kwargs . pop ( 'selection' ) except KeyError : filters = None else : rootfilters = [ ] filters = [ ] for col , op_ , value in parse_column_filters ( selection ) : try : opstr = [ key for key in OPERATORS ... | Read a Table from a ROOT tree |
22,312 | def table_to_root ( table , filename , ** kwargs ) : import root_numpy root_numpy . array2root ( table . as_array ( ) , filename , ** kwargs ) | Write a Table to a ROOT file |
22,313 | def _gps_scale_factory ( unit ) : class FixedGPSScale ( GPSScale ) : name = str ( '{0}s' . format ( unit . long_names [ 0 ] if unit . long_names else unit . names [ 0 ] ) ) def __init__ ( self , axis , epoch = None ) : super ( FixedGPSScale , self ) . __init__ ( axis , epoch = epoch , unit = unit ) return FixedGPSScale | Construct a GPSScale for this unit |
22,314 | def set_epoch ( self , epoch ) : if epoch is None : self . _epoch = None return if isinstance ( epoch , ( Number , Decimal ) ) : self . _epoch = float ( epoch ) else : self . _epoch = float ( to_gps ( epoch ) ) | Set the GPS epoch |
22,315 | def set_unit ( self , unit ) : if unit is None or ( isinstance ( unit , units . NamedUnit ) and unit . physical_type == 'time' ) : self . _unit = unit return if isinstance ( unit , Number ) : unit = units . Unit ( unit * units . second ) try : unit = units . Unit ( unit ) except ValueError as exc : try : unit = units .... | Set the GPS step scale |
22,316 | def get_unit_name ( self ) : if not self . unit : return None name = sorted ( self . unit . names , key = len ) [ - 1 ] return '%ss' % name | Returns the name of the unit for this GPS scale |
22,317 | def transform_non_affine ( self , values ) : scale = self . scale or 1 epoch = self . epoch or 0 values = numpy . asarray ( values ) if self . _parents or ( epoch == 0 and scale == 1 ) : return self . _transform ( values , float ( epoch ) , float ( scale ) ) flat = values . flatten ( ) def _trans ( x ) : return self . ... | Transform an array of GPS times . |
22,318 | def deprecated_function ( func , warning = DEPRECATED_FUNCTION_WARNING ) : @ wraps ( func ) def wrapped_func ( * args , ** kwargs ) : warnings . warn ( DEPRECATED_FUNCTION_WARNING . format ( func ) , category = DeprecationWarning , stacklevel = 2 , ) return func ( * args , ** kwargs ) return wrapped_func | Adds a DeprecationWarning to a function |
22,319 | def return_as ( returntype ) : def decorator ( func ) : def wrapped ( * args , ** kwargs ) : result = func ( * args , ** kwargs ) try : return returntype ( result ) except ( TypeError , ValueError ) as exc : exc . args = ( 'failed to cast return from {0} as {1}: {2}' . format ( func . __name__ , returntype . __name__ ,... | Decorator to cast return of function as the given type |
22,320 | def format_citations ( zid , url = 'https://zenodo.org/' , hits = 10 , tag_prefix = 'v' ) : url = ( '{url}/api/records/?' 'page=1&' 'size={hits}&' 'q=conceptrecid:"{id}"&' 'sort=-version&' 'all_versions=True' . format ( id = zid , url = url , hits = hits ) ) metadata = requests . get ( url ) . json ( ) lines = [ ] for ... | Query and format a citations page from Zenodo entries |
22,321 | def read ( source , channels , start = None , end = None , scaled = None , type = None , series_class = TimeSeries ) : source = file_list ( source ) ctype = channel_dict_kwarg ( type , channels , ( str , ) ) out = series_class . DictClass ( ) for i , file_ in enumerate ( source ) : if i == 1 : for name in out : out [ n... | Read a dict of series from one or more GWF files |
22,322 | def read_gwf ( filename , channels , start = None , end = None , scaled = None , ctype = None , series_class = TimeSeries ) : if not start : start = 0 if not end : end = 0 span = Segment ( start , end ) stream = io_gwf . open_gwf ( filename , 'r' ) nframes = stream . GetNumberOfFrames ( ) out = series_class . DictClass... | Read a dict of series data from a single GWF file |
22,323 | def _read_channel ( stream , num , name , ctype , epoch , start , end , scaled = True , series_class = TimeSeries ) : data = _get_frdata ( stream , num , name , ctype = ctype ) return read_frdata ( data , epoch , start , end , scaled = scaled , series_class = series_class ) | Read a channel from a specific frame in a stream |
22,324 | def _get_frdata ( stream , num , name , ctype = None ) : ctypes = ( ctype , ) if ctype else ( 'adc' , 'proc' , 'sim' ) for ctype in ctypes : _reader = getattr ( stream , 'ReadFr{0}Data' . format ( ctype . title ( ) ) ) try : return _reader ( num , name ) except IndexError as exc : if FRERR_NO_CHANNEL_OF_TYPE . match ( ... | Brute force - ish method to return the FrData structure for a channel |
22,325 | def read_frdata ( frdata , epoch , start , end , scaled = True , series_class = TimeSeries ) : datastart = epoch + frdata . GetTimeOffset ( ) try : trange = frdata . GetTRange ( ) except AttributeError : trange = 0. if ( end and datastart >= end ) or ( trange and datastart + trange < start ) : raise _Skip ( ) try : slo... | Read a series from an FrData structure |
22,326 | def read_frvect ( vect , epoch , start , end , name = None , series_class = TimeSeries ) : if vect . GetName ( ) and name and vect . GetName ( ) != name : raise _Skip ( ) arr = vect . GetDataArray ( ) nsamp = arr . size dim = vect . GetDim ( 0 ) dx = dim . dx x0 = dim . startX dimstart = epoch + x0 dimend = dimstart + ... | Read an array from an FrVect structure |
22,327 | def write ( tsdict , outfile , start = None , end = None , name = 'gwpy' , run = 0 , compression = 257 , compression_level = 6 ) : if not start : starts = { LIGOTimeGPS ( tsdict [ key ] . x0 . value ) for key in tsdict } if len ( starts ) != 1 : raise RuntimeError ( "Cannot write multiple TimeSeries to a single " "fram... | Write data to a GWF file using the frameCPP API |
22,328 | def append_to_frame ( frame , timeseries , type = 'proc' , channelid = 0 ) : if timeseries . channel : channel = str ( timeseries . channel ) else : channel = str ( timeseries . name ) offset = float ( LIGOTimeGPS ( timeseries . t0 . value ) - LIGOTimeGPS ( * frame . GetGTime ( ) ) ) if type . lower ( ) == 'adc' : frda... | Append data from a TimeSeries to a ~frameCPP . FrameH |
22,329 | def create_frvect ( timeseries ) : dims = frameCPP . Dimension ( timeseries . size , timeseries . dx . value , str ( timeseries . dx . unit ) , 0 ) vect = frameCPP . FrVect ( timeseries . name or '' , FRVECT_TYPE_FROM_NUMPY [ timeseries . dtype . type ] , 1 , dims , str ( timeseries . unit ) ) vect . GetDataArray ( ) [... | Create a ~frameCPP . FrVect from a TimeSeries |
22,330 | def _bool_segments ( array , start = 0 , delta = 1 , minlen = 1 ) : array = iter ( array ) i = 0 while True : try : val = next ( array ) except StopIteration : return if val : n = 1 try : while next ( array ) : n += 1 except StopIteration : return finally : if n >= minlen : yield ( start + i * delta , start + ( i + n )... | Yield segments of consecutive True values in a boolean array |
22,331 | def to_dqflag ( self , name = None , minlen = 1 , dtype = None , round = False , label = None , description = None ) : from . . segments import DataQualityFlag if dtype is None : dtype = self . t0 . dtype if isinstance ( dtype , numpy . dtype ) : dtype = dtype . type start = dtype ( self . t0 . value ) dt = dtype ( sel... | Convert this series into a ~gwpy . segments . DataQualityFlag . |
22,332 | def bits ( self ) : try : return self . _bits except AttributeError : if self . dtype . name . startswith ( ( 'uint' , 'int' ) ) : nbits = self . itemsize * 8 self . bits = Bits ( [ 'Bit %d' % b for b in range ( nbits ) ] , channel = self . channel , epoch = self . epoch ) return self . bits elif hasattr ( self . chann... | list of Bits for this StateVector |
22,333 | def boolean ( self ) : try : return self . _boolean except AttributeError : nbits = len ( self . bits ) boolean = numpy . zeros ( ( self . size , nbits ) , dtype = bool ) for i , sample in enumerate ( self . value ) : boolean [ i , : ] = [ int ( sample ) >> j & 1 for j in range ( nbits ) ] self . _boolean = Array2D ( b... | A mapping of this StateVector to a 2 - D array containing all binary bits as booleans for each time point . |
22,334 | def get_bit_series ( self , bits = None ) : if bits is None : bits = [ b for b in self . bits if b not in { None , '' } ] bindex = [ ] for bit in bits : try : bindex . append ( ( self . bits . index ( bit ) , bit ) ) except ( IndexError , ValueError ) as exc : exc . args = ( 'Bit %r not found in StateVector' % bit , ) ... | Get the StateTimeSeries for each bit of this StateVector . |
22,335 | def read ( cls , source , * args , ** kwargs ) : return super ( StateVector , cls ) . read ( source , * args , ** kwargs ) | Read data into a StateVector |
22,336 | def to_dqflags ( self , bits = None , minlen = 1 , dtype = float , round = False ) : from . . segments import DataQualityDict out = DataQualityDict ( ) bitseries = self . get_bit_series ( bits = bits ) for bit , sts in bitseries . items ( ) : out [ bit ] = sts . to_dqflag ( name = bit , minlen = minlen , round = round ... | Convert this StateVector into a ~gwpy . segments . DataQualityDict |
22,337 | def fetch ( cls , channel , start , end , bits = None , host = None , port = None , verbose = False , connection = None , type = Nds2ChannelType . any ( ) ) : new = cls . DictClass . fetch ( [ channel ] , start , end , host = host , port = port , verbose = verbose , connection = connection ) [ channel ] if bits : new .... | Fetch data from NDS into a StateVector . |
22,338 | def plot ( self , format = 'segments' , bits = None , ** kwargs ) : if format == 'timeseries' : return super ( StateVector , self ) . plot ( ** kwargs ) if format == 'segments' : from . . plot import Plot kwargs . setdefault ( 'xscale' , 'auto-gps' ) return Plot ( * self . to_dqflags ( bits = bits ) . values ( ) , proj... | Plot the data for this StateVector |
22,339 | def resample ( self , rate ) : rate1 = self . sample_rate . value if isinstance ( rate , units . Quantity ) : rate2 = rate . value else : rate2 = float ( rate ) if ( rate2 / rate1 ) . is_integer ( ) : raise NotImplementedError ( "StateVector upsampling has not " "been implemented yet, sorry." ) elif ( rate1 / rate2 ) .... | Resample this StateVector to a new rate |
22,340 | def read ( cls , source , format = None , coalesce = False , ** kwargs ) : def combiner ( listofseglists ) : out = cls ( seg for seglist in listofseglists for seg in seglist ) if coalesce : return out . coalesce ( ) return out return io_read_multi ( combiner , cls , source , format = format , ** kwargs ) | Read segments from file into a SegmentList |
22,341 | def write ( self , target , * args , ** kwargs ) : return io_registry . write ( self , target , * args , ** kwargs ) | Write this SegmentList to a file |
22,342 | def table_from_cwb ( source , * args , ** kwargs ) : return EventTable . read ( source , 'waveburst' , * args , format = 'root' , ** kwargs ) | Read an EventTable from a Coherent WaveBurst ROOT file |
22,343 | def get_backend_mod ( name = None ) : if name is None : name = get_backend ( ) backend_name = ( name [ 9 : ] if name . startswith ( "module://" ) else "matplotlib.backends.backend_{}" . format ( name . lower ( ) ) ) return importlib . import_module ( backend_name ) | Returns the imported module for the given backend name |
22,344 | def _group_axes_data ( inputs , separate = None , flat = False ) : if separate is None and inputs : if any ( isinstance ( x , iterable_types + ( dict , ) ) for x in inputs ) : separate = True elif not all ( type ( x ) is type ( inputs [ 0 ] ) for x in inputs ) : separate = True out = [ ] for x in inputs : if isinstance... | Determine the number of axes from the input args to this Plot |
22,345 | def _init_axes ( self , data , method = 'plot' , xscale = None , sharex = False , sharey = False , geometry = None , separate = None , ** kwargs ) : if isinstance ( sharex , bool ) : sharex = "all" if sharex else "none" if isinstance ( sharey , bool ) : sharey = "all" if sharey else "none" axes_kw = { key : kwargs . po... | Populate this figure with data creating Axes as necessary |
22,346 | def refresh ( self ) : for cbar in self . colorbars : cbar . draw_all ( ) self . canvas . draw ( ) | Refresh the current figure |
22,347 | def close ( self ) : from matplotlib . pyplot import close for ax in self . axes [ : : - 1 ] : ax . set_xscale ( 'linear' ) ax . set_yscale ( 'linear' ) ax . cla ( ) close ( self ) | Close the plot and release its memory . |
22,348 | def get_axes ( self , projection = None ) : if projection is None : return self . axes return [ ax for ax in self . axes if ax . name == projection . lower ( ) ] | Find all Axes optionally matching the given projection |
22,349 | def colorbar ( self , mappable = None , cax = None , ax = None , fraction = 0. , label = None , emit = True , ** kwargs ) : mappable , kwargs = gcbar . process_colorbar_kwargs ( self , mappable , ax , cax = cax , fraction = fraction , ** kwargs ) cbar = super ( Plot , self ) . colorbar ( mappable , ** kwargs ) self . c... | Add a colorbar to the current Plot |
22,350 | def add_colorbar ( self , * args , ** kwargs ) : warnings . warn ( "{0}.add_colorbar was renamed {0}.colorbar, this warnings will " "result in an error in the future" . format ( type ( self ) . __name__ ) , DeprecationWarning ) return self . colorbar ( * args , ** kwargs ) | DEPRECATED use Plot . colorbar instead |
22,351 | def add_segments_bar ( self , segments , ax = None , height = 0.14 , pad = 0.1 , sharex = True , location = 'bottom' , ** plotargs ) : if not ax : ax = self . gca ( ) axes_kw = { 'pad' : pad , 'add_to_figure' : True , 'sharex' : ax if sharex is True else sharex or None , 'axes_class' : get_projection_class ( 'segments'... | Add a segment bar Plot indicating state information . |
22,352 | def get_hacr_channels ( db = None , gps = None , connection = None , ** conectkwargs ) : if connection is None : if gps is None : gps = from_gps ( 'now' ) if db is None : db = get_database_names ( gps , gps ) [ 0 ] connection = connect ( db = db , ** conectkwargs ) out = query ( "select channel from job where monitorNa... | Return the names of all channels present in the given HACR database |
22,353 | def get_hacr_triggers ( channel , start , end , columns = HACR_COLUMNS , pid = None , monitor = 'chacr' , selection = None , ** connectkwargs ) : if columns is None : columns = HACR_COLUMNS columns = list ( columns ) span = Segment ( * map ( to_gps , ( start , end ) ) ) selectionstr = 'and %s' % format_db_selection ( s... | Fetch a table of HACR triggers in the given interval |
22,354 | def connect ( db , host = HACR_DATABASE_SERVER , user = HACR_DATABASE_USER , passwd = HACR_DATABASE_PASSWD ) : try : import pymysql except ImportError as e : e . args = ( 'pymysql is required to fetch HACR triggers' , ) raise return pymysql . connect ( host = host , user = user , passwd = passwd , db = db ) | Connect to the given SQL database |
22,355 | def query ( querystr , connection = None , ** connectkwargs ) : if connection is None : connection = connect ( ** connectkwargs ) cursor = connection . cursor ( ) cursor . execute ( querystr ) return cursor . fetchall ( ) | Execute a query of the given SQL database |
22,356 | def add_filter ( self , filter_ , frequencies = None , dB = True , analog = False , sample_rate = None , ** kwargs ) : if not analog : if not sample_rate : raise ValueError ( "Must give sample_rate frequency to display " "digital (analog=False) filter" ) sample_rate = Quantity ( sample_rate , 'Hz' ) . value dt = 2 * pi... | Add a linear time - invariant filter to this BodePlot |
22,357 | def add_frequencyseries ( self , spectrum , dB = True , power = False , ** kwargs ) : kwargs . setdefault ( 'label' , spectrum . name ) mag = numpy . absolute ( spectrum . value ) if dB : mag = to_db ( mag ) if not power : mag *= 2. phase = numpy . angle ( spectrum . value , deg = True ) w = spectrum . frequencies . va... | Plot the magnitude and phase of a complex - valued FrequencySeries |
22,358 | def read_omega_scan_config ( source ) : out = ChannelList ( ) append = out . append if isinstance ( source , FILE_LIKE ) : close = False else : source = open ( source , 'r' ) close = True try : section = None while True : try : line = next ( source ) except StopIteration : break if line == '' or line == '\n' or line . ... | Parse an Omega - scan configuration file into a ChannelList |
22,359 | def parse_omega_channel ( fobj , section = None ) : params = OrderedDict ( ) while True : line = next ( fobj ) if line == '}\n' : break key , value = line . split ( ':' , 1 ) params [ key . strip ( ) . rstrip ( ) ] = omega_param ( value ) out = Channel ( params . get ( 'channelName' ) , sample_rate = params . get ( 'sa... | Parse a Channel from an Omega - scan configuration file |
22,360 | def omega_param ( val ) : val = val . strip ( ) . rstrip ( ) if val . startswith ( ( '"' , "'" ) ) : return str ( val [ 1 : - 1 ] ) if val . startswith ( '[' ) : return tuple ( map ( float , val [ 1 : - 1 ] . split ( ) ) ) return float ( val ) | Parse a value from an Omega - scan configuration file |
22,361 | def write_omega_scan_config ( channellist , fobj , header = True ) : if isinstance ( fobj , FILE_LIKE ) : close = False else : fobj = open ( fobj , 'w' ) close = True try : if header : print ( '# Q Scan configuration file' , file = fobj ) print ( '# Generated with GWpy from a ChannelList' , file = fobj ) group = None f... | Write a ChannelList to an Omega - pipeline scan configuration file |
22,362 | def print_omega_channel ( channel , file = sys . stdout ) : print ( '{' , file = file ) try : params = channel . params . copy ( ) except AttributeError : params = OrderedDict ( ) params . setdefault ( 'channelName' , str ( channel ) ) params . setdefault ( 'alwaysPlotFlag' , int ( params . pop ( 'important' , False ) ... | Print a Channel in Omega - pipeline scan format |
22,363 | def _get_nds2_name ( channel ) : if hasattr ( channel , 'ndsname' ) : return channel . ndsname if hasattr ( channel , 'channel_type' ) : return '%s,%s' % ( channel . name , channel . channel_type_to_string ( channel . channel_type ) ) return str ( channel ) | Returns the NDS2 - formatted name for a channel |
22,364 | def parse_nds_env ( env = 'NDSSERVER' ) : hosts = [ ] for host in os . getenv ( env ) . split ( ',' ) : try : host , port = host . rsplit ( ':' , 1 ) except ValueError : port = None else : port = int ( port ) if ( host , port ) not in hosts : hosts . append ( ( host , port ) ) return hosts | Parse the NDSSERVER environment variable into a list of hosts |
22,365 | def connect ( host , port = None ) : import nds2 if port is None and NDS1_HOSTNAME . match ( host ) : port = 8088 if port is None : return nds2 . connection ( host ) return nds2 . connection ( host , port ) | Open an nds2 . connection to a given host and port |
22,366 | def auth_connect ( host , port = None ) : try : return connect ( host , port ) except RuntimeError as exc : if 'Request SASL authentication' not in str ( exc ) : raise warnings . warn ( 'Error authenticating against {0}:{1}' . format ( host , port ) , NDSWarning ) kinit ( ) return connect ( host , port ) | Open an nds2 . connection handling simple authentication errors |
22,367 | def open_connection ( func ) : @ wraps ( func ) def wrapped_func ( * args , ** kwargs ) : if kwargs . get ( 'connection' , None ) is None : try : host = kwargs . pop ( 'host' ) except KeyError : raise TypeError ( "one of `connection` or `host` is required " "to query NDS2 server" ) kwargs [ 'connection' ] = auth_connec... | Decorate a function to create a nds2 . connection if required |
22,368 | def parse_nds2_enums ( func ) : @ wraps ( func ) def wrapped_func ( * args , ** kwargs ) : for kwd , enum_ in ( ( 'type' , Nds2ChannelType ) , ( 'dtype' , Nds2DataType ) ) : if kwargs . get ( kwd , None ) is None : kwargs [ kwd ] = enum_ . any ( ) elif not isinstance ( kwargs [ kwd ] , int ) : kwargs [ kwd ] = enum_ . ... | Decorate a function to translate a type string into an integer |
22,369 | def reset_epoch ( func ) : @ wraps ( func ) def wrapped_func ( * args , ** kwargs ) : connection = kwargs . get ( 'connection' , None ) epoch = connection . current_epoch ( ) if connection else None try : return func ( * args , ** kwargs ) finally : if epoch is not None : connection . set_epoch ( epoch . gps_start , ep... | Wrap a function to reset the epoch when finished |
22,370 | def find_channels ( channels , connection = None , host = None , port = None , sample_rate = None , type = Nds2ChannelType . any ( ) , dtype = Nds2DataType . any ( ) , unique = False , epoch = 'ALL' ) : if not isinstance ( epoch , tuple ) : epoch = ( epoch or 'All' , ) connection . set_epoch ( * epoch ) if isinstance (... | Query an NDS2 server for channel information |
22,371 | def _find_channel ( connection , name , ctype , dtype , sample_rate , unique = False ) : name , ctype = _strip_ctype ( name , ctype , connection . get_protocol ( ) ) found = connection . find_channels ( name , ctype , dtype , * sample_rate ) if not unique : return found if len ( found ) == 2 : found = [ c for c in foun... | Internal method to find a single channel |
22,372 | def _strip_ctype ( name , ctype , protocol = 2 ) : try : name , ctypestr = name . rsplit ( ',' , 1 ) except ValueError : pass else : ctype = Nds2ChannelType . find ( ctypestr ) . value if protocol == 1 and ctype in ( Nds2ChannelType . STREND . value , Nds2ChannelType . MTREND . value ) : name += ',{0}' . format ( ctype... | Strip the ctype from a channel name for the given nds server version |
22,373 | def get_availability ( channels , start , end , connection = None , host = None , port = None ) : from . . segments import ( Segment , SegmentList , SegmentListDict ) connection . set_epoch ( start , end ) names = list ( map ( _get_nds2_name , find_channels ( channels , epoch = ( start , end ) , connection = connection... | Query an NDS2 server for data availability |
22,374 | def minute_trend_times ( start , end ) : if start % 60 : start = int ( start ) // 60 * 60 if end % 60 : end = int ( end ) // 60 * 60 + 60 return int ( start ) , int ( end ) | Expand a [ start end ) interval for use in querying for minute trends |
22,375 | def find ( cls , name ) : try : return cls . _member_map_ [ name ] except KeyError : for ctype in cls . _member_map_ . values ( ) : if ctype . name == name : return ctype raise ValueError ( '%s is not a valid %s' % ( name , cls . __name__ ) ) | Returns the NDS2 channel type corresponding to the given name |
22,376 | def find ( cls , dtype ) : try : return cls . _member_map_ [ dtype ] except KeyError : try : dtype = numpy . dtype ( dtype ) . type except TypeError : for ndstype in cls . _member_map_ . values ( ) : if ndstype . value is dtype : return ndstype else : for ndstype in cls . _member_map_ . values ( ) : if ndstype . value ... | Returns the NDS2 type corresponding to the given python type |
22,377 | def reconnect ( connection ) : if isinstance ( connection , FflConnection ) : return type ( connection ) ( connection . ffldir ) kw = { 'context' : connection . _context } if connection . port != 80 else { } return connection . __class__ ( connection . host , port = connection . port , ** kw ) | Open a new datafind connection based on an existing connection |
22,378 | def _type_priority ( ifo , ftype , trend = None ) : for trendname , trend_regex in [ ( 'm-trend' , MINUTE_TREND_TYPE ) , ( 's-trend' , SECOND_TREND_TYPE ) , ] : if trend == trendname and trend_regex . match ( ftype ) : return 0 , len ( ftype ) for reg , prio in { HIGH_PRIORITY_TYPE : 1 , re . compile ( r'[A-Z]\d_C' ) :... | Prioritise the given GWF type based on its name or trend status . |
22,379 | def on_tape ( * files ) : for path in files : try : if os . stat ( path ) . st_blocks == 0 : return True except AttributeError : return False return False | Determine whether any of the given files are on tape |
22,380 | def with_connection ( func ) : @ wraps ( func ) def wrapped ( * args , ** kwargs ) : if kwargs . get ( 'connection' ) is None : kwargs [ 'connection' ] = _choose_connection ( host = kwargs . get ( 'host' ) , port = kwargs . get ( 'port' ) ) try : return func ( * args , ** kwargs ) except HTTPException : kwargs [ 'conne... | Decorate a function to open a new datafind connection if required |
22,381 | def find_best_frametype ( channel , start , end , frametype_match = None , allow_tape = True , connection = None , host = None , port = None ) : try : return find_frametype ( channel , gpstime = ( start , end ) , frametype_match = frametype_match , allow_tape = allow_tape , on_gaps = 'error' , connection = connection ,... | Intelligently select the best frametype from which to read this channel |
22,382 | def find_types ( observatory , match = None , trend = None , connection = None , ** connection_kw ) : return sorted ( connection . find_types ( observatory , match = match ) , key = lambda x : _type_priority ( observatory , x , trend = trend ) ) | Find the available data types for a given observatory . |
22,383 | def find_urls ( observatory , frametype , start , end , on_gaps = 'error' , connection = None , ** connection_kw ) : return connection . find_urls ( observatory , frametype , start , end , on_gaps = on_gaps ) | Find the URLs of files of a given data type in a GPS interval . |
22,384 | def ffl_path ( self , site , frametype ) : try : return self . paths [ ( site , frametype ) ] except KeyError : self . _find_paths ( ) return self . paths [ ( site , frametype ) ] | Returns the path of the FFL file for the given site and frametype |
22,385 | def find_types ( self , site = None , match = r'^(?!lastfile|spectro|\.).*' ) : self . _find_paths ( ) types = [ tag for ( site_ , tag ) in self . paths if site in ( None , site_ ) ] if match is not None : match = re . compile ( match ) return list ( filter ( match . search , types ) ) return types | Return the list of known data types . |
22,386 | def find_urls ( self , site , frametype , gpsstart , gpsend , match = None , on_gaps = 'warn' ) : span = Segment ( gpsstart , gpsend ) cache = [ e for e in self . _read_ffl_cache ( site , frametype ) if e . observatory == site and e . description == frametype and e . segment . intersects ( span ) ] urls = [ e . path fo... | Find all files of the given type in the [ start end ) GPS interval . |
22,387 | def read_series ( source , name , match = None ) : from ligo . lw . ligolw import ( LIGO_LW , Time , Array , Dim ) from ligo . lw . param import get_param xmldoc = read_ligolw ( source , contenthandler = series_contenthandler ( ) ) if match is None : match = dict ( ) def _is_match ( elem ) : try : if elem . Name != nam... | Read a Series from LIGO_LW - XML |
22,388 | def make_plot ( self ) : args = self . args fftlength = float ( args . secpfft ) overlap = args . overlap self . log ( 2 , "Calculating spectrum secpfft: %s, overlap: %s" % ( fftlength , overlap ) ) if overlap is not None : overlap *= fftlength self . log ( 3 , 'Reference channel: ' + self . ref_chan ) groups = Ordered... | Generate the coherence plot from all time series |
22,389 | def set_legend ( self ) : leg = super ( Coherence , self ) . set_legend ( ) if leg is not None : leg . set_title ( 'Coherence with:' ) return leg | Create a legend for this product |
22,390 | def parse_unit ( name , parse_strict = 'warn' , format = 'gwpy' ) : if name is None or isinstance ( name , units . UnitBase ) : return name try : return UNRECOGNIZED_UNITS [ name ] except KeyError : try : return units . Unit ( name , parse_strict = 'raise' ) except ValueError as exc : if ( parse_strict == 'raise' or 'd... | Attempt to intelligently parse a str as a ~astropy . units . Unit |
22,391 | def _row_from_frevent ( frevent , columns , selection ) : params = dict ( frevent . GetParam ( ) ) params [ 'time' ] = float ( LIGOTimeGPS ( * frevent . GetGTime ( ) ) ) params [ 'amplitude' ] = frevent . GetAmplitude ( ) params [ 'probability' ] = frevent . GetProbability ( ) params [ 'timeBefore' ] = frevent . GetTim... | Generate a table row from an FrEvent |
22,392 | def table_to_gwf ( table , filename , name , ** kwargs ) : from LDAStools . frameCPP import ( FrEvent , GPSTime ) write_kw = { key : kwargs . pop ( key ) for key in ( 'compression' , 'compression_level' ) if key in kwargs } frame = io_gwf . create_frame ( name = name , ** kwargs ) names = table . dtype . names for row ... | Create a new ~frameCPP . FrameH and fill it with data |
22,393 | def read ( cls , source , * args , ** kwargs ) : return io_registry . read ( cls , source , * args , ** kwargs ) | Read data into a FrequencySeries |
22,394 | def ifft ( self ) : from . . timeseries import TimeSeries nout = ( self . size - 1 ) * 2 dift = npfft . irfft ( self . value * nout ) / 2 new = TimeSeries ( dift , epoch = self . epoch , channel = self . channel , unit = self . unit , dx = 1 / self . dx / nout ) return new | Compute the one - dimensional discrete inverse Fourier transform of this FrequencySeries . |
22,395 | def interpolate ( self , df ) : f0 = self . f0 . decompose ( ) . value N = ( self . size - 1 ) * ( self . df . decompose ( ) . value / df ) + 1 fsamples = numpy . arange ( 0 , numpy . rint ( N ) , dtype = self . dtype ) * df + f0 out = type ( self ) ( numpy . interp ( fsamples , self . frequencies . value , self . valu... | Interpolate this FrequencySeries to a new resolution . |
22,396 | def from_lal ( cls , lalfs , copy = True ) : from . . utils . lal import from_lal_unit try : unit = from_lal_unit ( lalfs . sampleUnits ) except TypeError : unit = None channel = Channel ( lalfs . name , unit = unit , dtype = lalfs . data . data . dtype ) return cls ( lalfs . data . data , channel = channel , f0 = lalf... | Generate a new FrequencySeries from a LAL FrequencySeries of any type |
22,397 | def from_pycbc ( cls , fs , copy = True ) : return cls ( fs . data , f0 = 0 , df = fs . delta_f , epoch = fs . epoch , copy = copy ) | Convert a pycbc . types . frequencyseries . FrequencySeries into a FrequencySeries |
22,398 | def to_pycbc ( self , copy = True ) : from pycbc import types if self . epoch is None : epoch = None else : epoch = self . epoch . gps return types . FrequencySeries ( self . value , delta_f = self . df . to ( 'Hz' ) . value , epoch = epoch , copy = copy ) | Convert this FrequencySeries into a ~pycbc . types . frequencyseries . FrequencySeries |
22,399 | def _fetch_losc_data_file ( url , * args , ** kwargs ) : cls = kwargs . pop ( 'cls' , TimeSeries ) cache = kwargs . pop ( 'cache' , None ) verbose = kwargs . pop ( 'verbose' , False ) if url . endswith ( '.gz' ) : ext = os . path . splitext ( url [ : - 3 ] ) [ - 1 ] else : ext = os . path . splitext ( url ) [ - 1 ] if ... | Internal function for fetching a single LOSC file and returning a Series |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.