idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
1,200
def _init_draw ( self ) : if self . original is not None : self . original . set_data ( np . random . random ( ( 10 , 10 , 3 ) ) ) self . processed . set_data ( np . random . random ( ( 10 , 10 , 3 ) ) )
Initializes the drawing of the frames by setting the images to random colors .
1,201
def read_frame ( self ) : ret , frame = self . capture . read ( ) if not ret : self . event_source . stop ( ) try : self . capture . release ( ) except AttributeError : pass return None if self . convert_color != - 1 and is_color_image ( frame ) : return cv2 . cvtColor ( frame , self . convert_color ) return frame
Reads a frame and converts the color if needed .
1,202
def annotate ( self , framedata ) : for artist in self . annotation_artists : artist . remove ( ) self . annotation_artists = [ ] for annotation in self . annotations : if annotation [ 2 ] > framedata : return if annotation [ 2 ] == framedata : pos = annotation [ 0 : 2 ] shape = self . annotations_default [ 'shape' ] c...
Annotates the processed axis with given annotations for the provided framedata .
1,203
def _draw_frame ( self , framedata ) : original = self . read_frame ( ) if original is None : self . update_info ( self . info_string ( message = 'Finished.' , frame = framedata ) ) return if self . original is not None : processed = self . process_frame ( original . copy ( ) ) if self . cmap_original is not None : ori...
Reads processes and draws the frames .
1,204
def update_info ( self , custom = None ) : self . figure . suptitle ( self . info_string ( ) if custom is None else custom )
Updates the figure s suptitle .
1,205
def info_string ( self , size = None , message = '' , frame = - 1 ) : info = [ ] if size is not None : info . append ( 'Size: {1}x{0}' . format ( * size ) ) elif self . size is not None : info . append ( 'Size: {1}x{0}' . format ( * self . size ) ) if frame >= 0 : info . append ( 'Frame: {}' . format ( frame ) ) if mes...
Returns information about the stream .
1,206
def _slice_required_len ( slice_obj ) : if slice_obj . step and slice_obj . step != 1 : return None if slice_obj . start is None and slice_obj . stop is None : return None if slice_obj . start and slice_obj . start < 0 : return None if slice_obj . stop and slice_obj . stop < 0 : return None if slice_obj . stop : if sli...
Calculate how many items must be in the collection to satisfy this slice
1,207
def stylize ( text , styles , reset = True ) : terminator = attr ( "reset" ) if reset else "" return "{}{}{}" . format ( "" . join ( styles ) , text , terminator )
conveniently styles your text as and resets ANSI codes at its end .
1,208
def attribute ( self ) : paint = { "bold" : self . ESC + "1" + self . END , 1 : self . ESC + "1" + self . END , "dim" : self . ESC + "2" + self . END , 2 : self . ESC + "2" + self . END , "underlined" : self . ESC + "4" + self . END , 4 : self . ESC + "4" + self . END , "blink" : self . ESC + "5" + self . END , 5 : sel...
Set or reset attributes
1,209
def foreground ( self ) : code = self . ESC + "38;5;" if str ( self . color ) . isdigit ( ) : self . reverse_dict ( ) color = self . reserve_paint [ str ( self . color ) ] return code + self . paint [ color ] + self . END elif self . color . startswith ( "#" ) : return code + str ( self . HEX ) + self . END else : retu...
Print 256 foreground colors
1,210
def reset ( self , required = False ) : reset = self . _ow . reset ( ) if required and reset : raise OneWireError ( "No presence pulse found. Check devices and wiring." ) return not reset
Perform a reset and check for presence pulse .
1,211
def scan ( self ) : devices = [ ] diff = 65 rom = False count = 0 for _ in range ( 0xff ) : rom , diff = self . _search_rom ( rom , diff ) if rom : count += 1 if count > self . maximum_devices : raise RuntimeError ( "Maximum device count of {} exceeded." . format ( self . maximum_devices ) ) devices . append ( OneWireA...
Scan for devices on the bus and return a list of addresses .
1,212
def crc8 ( data ) : crc = 0 for byte in data : crc ^= byte for _ in range ( 8 ) : if crc & 0x01 : crc = ( crc >> 1 ) ^ 0x8C else : crc >>= 1 crc &= 0xFF return crc
Perform the 1 - Wire CRC check on the provided data .
1,213
def preferences_class_prepared ( sender , * args , ** kwargs ) : cls = sender if issubclass ( cls , Preferences ) : cls . add_to_class ( 'singleton' , SingletonManager ( ) ) setattr ( preferences . Preferences , cls . _meta . object_name , property ( lambda x : cls . singleton . get ( ) ) )
Adds various preferences members to preferences . preferences thus enabling easy access from code .
1,214
def site_cleanup ( sender , action , instance , ** kwargs ) : if action == 'post_add' : if isinstance ( instance , Preferences ) and hasattr ( instance . __class__ , 'objects' ) : site_conflicts = instance . __class__ . objects . filter ( sites__in = instance . sites . all ( ) ) . only ( 'id' ) . distinct ( ) for confl...
Make sure there is only a single preferences object per site . So remove sites from pre - existing preferences objects .
1,215
def get_queryset ( self ) : queryset = super ( SingletonManager , self ) . get_queryset ( ) current_site = None if getattr ( settings , 'SITE_ID' , None ) is not None : current_site = Site . objects . get_current ( ) if current_site is not None : queryset = queryset . filter ( sites = settings . SITE_ID ) if not querys...
Return the first preferences object for the current site . If preferences do not exist create it .
1,216
def load_iterable ( self , iterable , session = None ) : data = [ ] load = self . loads for v in iterable : data . append ( load ( v ) ) return data
Load an iterable .
1,217
def _search ( self , words , include = None , exclude = None , lookup = None ) : lookup = lookup or 'contains' query = self . router . worditem . query ( ) if include : query = query . filter ( model_type__in = include ) if exclude : query = query . exclude ( model_type__in = include ) if not words : return [ query ] q...
Full text search . Return a list of queries to intersect .
1,218
def redis_client ( address = None , connection_pool = None , timeout = None , parser = None , ** kwargs ) : if not connection_pool : if timeout == 0 : if not async : raise ImportError ( 'Asynchronous connection requires async ' 'bindings installed.' ) return async . pool . redis ( address , ** kwargs ) else : kwargs [ ...
Get a new redis client .
1,219
def dict_flat_generator ( value , attname = None , splitter = JSPLITTER , dumps = None , prefix = None , error = ValueError , recursive = True ) : if not isinstance ( value , dict ) or not recursive : if not prefix : raise error ( 'Cannot assign a non dictionary to a JSON field' ) else : name = '%s%s%s' % ( attname , s...
Convert a nested dictionary into a flat dictionary representation
1,220
def addmul_number_dicts ( series ) : if not series : return vtype = value_type ( ( s [ 1 ] for s in series ) ) if vtype == 1 : return sum ( ( weight * float ( d ) for weight , d in series ) ) elif vtype == 3 : keys = set ( series [ 0 ] [ 1 ] ) for serie in series [ 1 : ] : keys . intersection_update ( serie [ 1 ] ) res...
Multiply dictionaries by a numeric values and add them together .
1,221
def Download ( campaign = 0 , queue = 'build' , email = None , walltime = 8 , ** kwargs ) : if type ( campaign ) is int : subcampaign = - 1 elif type ( campaign ) is float : x , y = divmod ( campaign , 1 ) campaign = int ( x ) subcampaign = round ( y * 10 ) pbsfile = os . path . join ( EVEREST_SRC , 'missions' , 'k2' ,...
Submits a cluster job to the build queue to download all TPFs for a given campaign .
1,222
def Run ( campaign = 0 , EPIC = None , nodes = 5 , ppn = 12 , walltime = 100 , mpn = None , email = None , queue = None , ** kwargs ) : if type ( campaign ) is int : subcampaign = - 1 elif type ( campaign ) is float : x , y = divmod ( campaign , 1 ) campaign = int ( x ) subcampaign = round ( y * 10 ) if EVEREST_DEV and...
Submits a cluster job to compute and plot data for all targets in a given campaign .
1,223
def PrimaryHDU ( model ) : cards = model . _mission . HDUCards ( model . meta , hdu = 0 ) if 'KEPMAG' not in [ c [ 0 ] for c in cards ] : cards . append ( ( 'KEPMAG' , model . mag , 'Kepler magnitude' ) ) cards . append ( ( 'COMMENT' , '************************' ) ) cards . append ( ( 'COMMENT' , '* EVEREST INFO ...
Construct the primary HDU file containing basic header info .
1,224
def PixelsHDU ( model ) : cards = model . _mission . HDUCards ( model . meta , hdu = 2 ) cards = [ ] cards . append ( ( 'COMMENT' , '************************' ) ) cards . append ( ( 'COMMENT' , '* EVEREST INFO *' ) ) cards . append ( ( 'COMMENT' , '************************' ) ) cards . append ( ( 'MISSION' , mo...
Construct the HDU containing the pixel - level light curve .
1,225
def ApertureHDU ( model ) : cards = model . _mission . HDUCards ( model . meta , hdu = 3 ) cards . append ( ( 'COMMENT' , '************************' ) ) cards . append ( ( 'COMMENT' , '* EVEREST INFO *' ) ) cards . append ( ( 'COMMENT' , '************************' ) ) cards . append ( ( 'MISSION' , model . miss...
Construct the HDU containing the aperture used to de - trend .
1,226
def ImagesHDU ( model ) : cards = model . _mission . HDUCards ( model . meta , hdu = 4 ) cards . append ( ( 'COMMENT' , '************************' ) ) cards . append ( ( 'COMMENT' , '* EVEREST INFO *' ) ) cards . append ( ( 'COMMENT' , '************************' ) ) cards . append ( ( 'MISSION' , model . missio...
Construct the HDU containing sample postage stamp images of the target .
1,227
def HiResHDU ( model ) : cards = model . _mission . HDUCards ( model . meta , hdu = 5 ) cards . append ( ( 'COMMENT' , '************************' ) ) cards . append ( ( 'COMMENT' , '* EVEREST INFO *' ) ) cards . append ( ( 'COMMENT' , '************************' ) ) cards . append ( ( 'MISSION' , model . mission...
Construct the HDU containing the hi res image of the target .
1,228
def MaskSolveSlow ( A , b , w = 5 , progress = True , niter = None ) : N = b . shape [ 0 ] if niter is None : niter = N - w + 1 X = np . empty ( ( niter , N - w ) ) for n in prange ( niter ) : mask = np . arange ( n , n + w ) An = np . delete ( np . delete ( A , mask , axis = 0 ) , mask , axis = 1 ) Un = cholesky ( An ...
Identical to MaskSolve but computes the solution the brute - force way .
1,229
def unmasked ( self , depth = 0.01 ) : return 1 - ( np . hstack ( self . _O2 ) + np . hstack ( self . _O3 ) / depth ) / np . hstack ( self . _O1 )
Return the unmasked overfitting metric for a given transit depth .
1,230
def show ( self ) : try : if platform . system ( ) . lower ( ) . startswith ( 'darwin' ) : subprocess . call ( [ 'open' , self . pdf ] ) elif os . name == 'nt' : os . startfile ( self . pdf ) elif os . name == 'posix' : subprocess . call ( [ 'xdg-open' , self . pdf ] ) else : raise IOError ( "" ) except IOError : log ....
Show the overfitting PDF summary .
1,231
def season ( self ) : try : self . _season except AttributeError : self . _season = self . _mission . Season ( self . ID ) if hasattr ( self . _season , '__len__' ) : raise AttributeError ( "Please choose a campaign/season for this target: %s." % self . _season ) return self . _season
Return the current observing season .
1,232
def fcor ( self ) : if self . XCBV is None : return None else : return self . flux - self . _mission . FitCBVs ( self )
The CBV - corrected de - trended flux .
1,233
def plot_info ( self , dvs ) : axl , axc , axr = dvs . title ( ) axc . annotate ( "%s %d" % ( self . _mission . IDSTRING , self . ID ) , xy = ( 0.5 , 0.5 ) , xycoords = 'axes fraction' , ha = 'center' , va = 'center' , fontsize = 18 ) axc . annotate ( r"%.2f ppm $\rightarrow$ %.2f ppm" % ( self . cdppr , self . cdpp ) ...
Plots miscellaneous de - trending information on the data validation summary figure .
1,234
def compute ( self ) : if self . transit_model is not None : return self . compute_joint ( ) log . info ( 'Computing the model...' ) model = [ None for b in self . breakpoints ] for b , brkpt in enumerate ( self . breakpoints ) : m = self . get_masked_chunk ( b ) c = self . get_chunk ( b ) mK = GetCovariance ( self . k...
Compute the model for the current value of lambda .
1,235
def apply_mask ( self , x = None ) : if x is None : return np . delete ( np . arange ( len ( self . time ) ) , self . mask ) else : return np . delete ( x , self . mask , axis = 0 )
Returns the outlier mask an array of indices corresponding to the non - outliers .
1,236
def get_cdpp ( self , flux = None ) : if flux is None : flux = self . flux return self . _mission . CDPP ( self . apply_mask ( flux ) , cadence = self . cadence )
Returns the scalar CDPP for the light curve .
1,237
def get ( ID , pipeline = 'everest2' , campaign = None ) : log . info ( 'Downloading %s light curve for %d...' % ( pipeline , ID ) ) if EVEREST_DEV : if pipeline . lower ( ) == 'everest2' or pipeline . lower ( ) == 'k2sff' : from . import Season , TargetDirectory , FITSFile if campaign is None : campaign = Season ( ID ...
Returns the time and flux for a given EPIC ID and a given pipeline name .
1,238
def plot ( ID , pipeline = 'everest2' , show = True , campaign = None ) : time , flux = get ( ID , pipeline = pipeline , campaign = campaign ) mask = np . where ( np . isnan ( flux ) ) [ 0 ] time = np . delete ( time , mask ) flux = np . delete ( flux , mask ) fig , ax = pl . subplots ( 1 , figsize = ( 10 , 4 ) ) fig ....
Plots the de - trended flux for the given EPIC ID and for the specified pipeline .
1,239
def get_outliers ( self ) : log . info ( "Clipping outliers..." ) log . info ( 'Iter %d/%d: %d outliers' % ( 0 , self . oiter , len ( self . outmask ) ) ) def M ( x ) : return np . delete ( x , np . concatenate ( [ self . nanmask , self . badmask , self . transitmask ] ) , axis = 0 ) t = M ( self . time ) outmask = [ n...
Performs iterative sigma clipping to get outliers .
1,240
def get_ylim ( self ) : bn = np . array ( list ( set ( np . concatenate ( [ self . badmask , self . nanmask ] ) ) ) , dtype = int ) fraw = np . delete ( self . fraw , bn ) lo , hi = fraw [ np . argsort ( fraw ) ] [ [ 3 , - 3 ] ] flux = np . delete ( self . flux , bn ) fsort = flux [ np . argsort ( flux ) ] if fsort [ i...
Computes the ideal y - axis limits for the light curve plot . Attempts to set the limits equal to those of the raw light curve but if more than 1% of the flux lies either above or below these limits auto - expands to include those points . At the end adds 5% padding to both the top and the bottom .
1,241
def plot_cbv ( self , ax , flux , info , show_cbv = False ) : bnmask = np . array ( list ( set ( np . concatenate ( [ self . badmask , self . nanmask ] ) ) ) , dtype = int ) def M ( x ) : return np . delete ( x , bnmask ) if self . cadence == 'lc' : ax . plot ( M ( self . time ) , M ( flux ) , ls = 'none' , marker = '....
Plots the final CBV - corrected light curve .
1,242
def load_tpf ( self ) : if not self . loaded : if self . _data is not None : data = self . _data else : data = self . _mission . GetData ( self . ID , season = self . season , cadence = self . cadence , clobber = self . clobber_tpf , aperture_name = self . aperture_name , saturated_aperture_name = self . saturated_aper...
Loads the target pixel file .
1,243
def load_model ( self , name = None ) : if self . clobber : return False if name is None : name = self . name file = os . path . join ( self . dir , '%s.npz' % name ) if os . path . exists ( file ) : if not self . is_parent : log . info ( "Loading '%s.npz'..." % name ) try : data = np . load ( file ) for key in data . ...
Loads a saved version of the model .
1,244
def save_model ( self ) : log . info ( "Saving data to '%s.npz'..." % self . name ) d = dict ( self . __dict__ ) d . pop ( '_weights' , None ) d . pop ( '_A' , None ) d . pop ( '_B' , None ) d . pop ( '_f' , None ) d . pop ( '_mK' , None ) d . pop ( 'K' , None ) d . pop ( 'dvs' , None ) d . pop ( 'clobber' , None ) d ....
Saves all of the de - trending information to disk in an npz file and saves the DVS as a pdf .
1,245
def exception_handler ( self , pdb ) : exctype , value , tb = sys . exc_info ( ) errfile = os . path . join ( self . dir , self . name + '.err' ) with open ( errfile , 'w' ) as f : for line in traceback . format_exception_only ( exctype , value ) : ln = line . replace ( '\n' , '' ) log . error ( ln ) print ( ln , file ...
A custom exception handler .
1,246
def init_kernel ( self ) : if self . kernel_params is None : X = self . apply_mask ( self . fpix / self . flux . reshape ( - 1 , 1 ) ) y = self . apply_mask ( self . flux ) - np . dot ( X , np . linalg . solve ( np . dot ( X . T , X ) , np . dot ( X . T , self . apply_mask ( self . flux ) ) ) ) white = np . nanmedian (...
Initializes the covariance matrix with a guess at the GP kernel parameters .
1,247
def run ( self ) : try : log . info ( "Loading target data..." ) self . load_tpf ( ) self . mask_planets ( ) self . plot_aperture ( [ self . dvs . top_right ( ) for i in range ( 4 ) ] ) self . init_kernel ( ) M = self . apply_mask ( np . arange ( len ( self . time ) ) ) self . cdppr_arr = self . get_cdpp_arr ( ) self ....
Runs the de - trending step .
1,248
def publish ( self , ** kwargs ) : try : self . cbv_win = 999 self . cbv_order = 3 self . cbv_num = 1 self . _mission . GetTargetCBVs ( self ) cbv = CBV ( ) self . plot_info ( cbv ) self . plot_cbv ( cbv . body ( ) , self . fcor , 'Corrected' ) self . plot_cbv ( cbv . body ( ) , self . flux , 'De-trended' , show_cbv = ...
Correct the light curve with the CBVs generate a cover page for the DVS figure and produce a FITS file for publication .
1,249
def run ( self ) : try : self . plot_aperture ( [ self . dvs . top_right ( ) for i in range ( 4 ) ] ) self . plot_lc ( self . dvs . left ( ) , info_right = 'nPLD' , color = 'k' ) self . cross_validate ( self . dvs . right ( ) ) self . compute ( ) self . cdpp_arr = self . get_cdpp_arr ( ) self . cdpp = self . get_cdpp (...
Runs the de - trending .
1,250
def validation_scatter ( self , log_lam , b , masks , pre_v , gp , flux , time , med ) : self . lam [ b ] = 10 ** log_lam scatter = [ None for i in range ( len ( masks ) ) ] for i in range ( len ( masks ) ) : model = self . cv_compute ( b , * pre_v [ i ] ) try : gpm , _ = gp . predict ( flux - model - med , time [ mask...
Computes the scatter in the validation set .
1,251
def iterdirty ( self ) : return iter ( chain ( itervalues ( self . _new ) , itervalues ( self . _modified ) ) )
Ordered iterator over dirty elements .
1,252
def commit ( self , callback = None ) : if self . executed : raise InvalidTransaction ( 'Invalid operation. ' 'Transaction already executed.' ) session = self . session self . session = None self . on_result = self . _commit ( session , callback ) return self . on_result
Close the transaction and commit session to the backend .
1,253
def load_related ( self , meta , fname , data , fields , encoding ) : field = meta . dfields [ fname ] if field in meta . multifields : fmeta = field . structure_class ( ) . _meta if fmeta . name in ( 'hashtable' , 'zset' ) : return ( ( native_str ( id , encoding ) , pairs_to_dict ( fdata , encoding ) ) for id , fdata ...
Parse data for related objects .
1,254
def _execute_query ( self ) : pipe = self . pipe if not self . card : if self . meta . ordering : self . ismember = getattr ( self . backend . client , 'zrank' ) self . card = getattr ( pipe , 'zcard' ) self . _check_member = self . zism else : self . ismember = getattr ( self . backend . client , 'sismember' ) self . ...
Execute the query without fetching data . Returns the number of elements in the query .
1,255
def order ( self , last ) : desc = last . desc field = last . name nested = last . nested nested_args = [ ] while nested : meta = nested . model . _meta nested_args . extend ( ( self . backend . basekey ( meta ) , nested . name ) ) last = nested nested = nested . nested method = 'ALPHA' if last . field . internal_type ...
Perform ordering with respect model fields .
1,256
def related_lua_args ( self ) : related = self . queryelem . select_related if related : meta = self . meta for rel in related : field = meta . dfields [ rel ] relmodel = field . relmodel bk = self . backend . basekey ( relmodel . _meta ) if relmodel else '' fields = list ( related [ rel ] ) if meta . pkname ( ) in fie...
Generator of load_related arguments
1,257
def pop_range ( self , start , stop = None , withscores = True , ** options ) : return self . backend . execute ( self . client . zpopbyscore ( self . id , start , stop , withscores = withscores , ** options ) , partial ( self . _range , withscores ) )
Remove and return a range from the ordered set by score .
1,258
def execute_session ( self , session_data ) : pipe = self . client . pipeline ( ) for sm in session_data : meta = sm . meta if sm . structures : self . flush_structure ( sm , pipe ) delquery = None if sm . deletes is not None : delquery = sm . deletes . backend_query ( pipe = pipe ) self . accumulate_delete ( pipe , de...
Execute a session in redis .
1,259
def flush ( self , meta = None ) : pattern = self . basekey ( meta ) if meta else self . namespace return self . client . delpattern ( '%s*' % pattern )
Flush all model keys from the database
1,260
def GetCovariance ( kernel , kernel_params , time , errors ) : K = np . diag ( errors ** 2 ) K += GP ( kernel , kernel_params , white = False ) . get_matrix ( time ) return K
Returns the covariance matrix for a given light curve segment .
1,261
def NegLnLike ( x , time , flux , errors , kernel ) : gp = GP ( kernel , x , white = True ) gp . compute ( time , errors ) if OLDGEORGE : nll = - gp . lnlikelihood ( flux ) ngr = - 2 * gp . grad_lnlikelihood ( flux ) / np . sqrt ( gp . kernel . pars ) else : nll = - gp . log_likelihood ( flux ) ngr = - 2 * gp . grad_lo...
Returns the negative log - likelihood function and its gradient .
1,262
def missing_intervals ( startdate , enddate , start , end , dateconverter = None , parseinterval = None , intervals = None ) : parseinterval = parseinterval or default_parse_interval dateconverter = dateconverter or todate startdate = dateconverter ( parseinterval ( startdate , 0 ) ) enddate = max ( startdate , datecon...
Given a startdate and an enddate dates evaluate the date intervals from which data is not available . It return a list of two - dimensional tuples containing start and end date for the interval . The list could countain 0 1 or 2 tuples .
1,263
def InitLog ( file_name = None , log_level = logging . DEBUG , screen_level = logging . CRITICAL , pdb = False ) : root = logging . getLogger ( ) root . handlers = [ ] root . setLevel ( logging . DEBUG ) if file_name is not None : if not os . path . exists ( os . path . dirname ( file_name ) ) : os . makedirs ( os . pa...
A little routine to initialize the logging functionality .
1,264
def ExceptionHook ( exctype , value , tb ) : for line in traceback . format_exception_only ( exctype , value ) : log . error ( line . replace ( '\n' , '' ) ) for line in traceback . format_tb ( tb ) : log . error ( line . replace ( '\n' , '' ) ) sys . __excepthook__ ( exctype , value , tb )
A custom exception handler that logs errors to file .
1,265
def prange ( * x ) : try : root = logging . getLogger ( ) if len ( root . handlers ) : for h in root . handlers : if ( type ( h ) is logging . StreamHandler ) and ( h . level != logging . CRITICAL ) : from tqdm import tqdm return tqdm ( range ( * x ) ) return range ( * x ) else : from tqdm import tqdm return tqdm ( ran...
Progress bar range with tqdm
1,266
def back ( self , * fields ) : ts = self . irange ( - 1 , - 1 , fields = fields ) if ts : return ts . end ( ) , ts [ 0 ]
Return the back pair of the structure
1,267
def Search ( ID , mission = 'k2' ) : assert mission == 'k2' , "Only the K2 mission is supported for now." print ( "Searching for target %d..." % ID ) season = missions . k2 . Season ( ID ) if season in [ 91 , 92 , [ 91 , 92 ] ] : print ( "Campaign 9 is currently not part of the EVEREST catalog." ) return elif season ==...
Why is my target not in the EVEREST database?
1,268
def _get_norm ( self ) : log . info ( 'Computing the PLD normalization...' ) mod = [ None for b in self . breakpoints ] for b , brkpt in enumerate ( self . breakpoints ) : c = self . get_chunk ( b ) inds = np . array ( list ( set ( np . concatenate ( [ self . transitmask , self . recmask ] ) ) ) , dtype = int ) M = np ...
Computes the PLD flux normalization array .
1,269
def plot_pipeline ( self , pipeline , * args , ** kwargs ) : if pipeline != 'everest2' : return getattr ( missions , self . mission ) . pipelines . plot ( self . ID , pipeline , * args , ** kwargs ) else : plot_raw = kwargs . get ( 'plot_raw' , False ) plot_cbv = kwargs . get ( 'plot_cbv' , True ) show = kwargs . get (...
Plots the light curve for the target de - trended with a given pipeline .
1,270
def get_pipeline ( self , * args , ** kwargs ) : return getattr ( missions , self . mission ) . pipelines . get ( self . ID , * args , ** kwargs )
Returns the time and flux arrays for the target obtained by a given pipeline .
1,271
def _save_npz ( self ) : d = dict ( self . __dict__ ) d . pop ( '_weights' , None ) d . pop ( '_A' , None ) d . pop ( '_B' , None ) d . pop ( '_f' , None ) d . pop ( '_mK' , None ) d . pop ( 'K' , None ) d . pop ( 'dvs' , None ) d . pop ( 'clobber' , None ) d . pop ( 'clobber_tpf' , None ) d . pop ( '_mission' , None )...
Saves all of the de - trending information to disk in an npz file
1,272
def Interpolate ( time , mask , y ) : yy = np . array ( y ) t_ = np . delete ( time , mask ) y_ = np . delete ( y , mask , axis = 0 ) if len ( yy . shape ) == 1 : yy [ mask ] = np . interp ( time [ mask ] , t_ , y_ ) elif len ( yy . shape ) == 2 : for n in range ( yy . shape [ 1 ] ) : yy [ mask , n ] = np . interp ( ti...
Masks certain elements in the array y and linearly interpolates over them returning an array y of the same length .
1,273
def Smooth ( x , window_len = 100 , window = 'hanning' ) : if window_len == 0 : return np . zeros_like ( x ) s = np . r_ [ 2 * x [ 0 ] - x [ window_len - 1 : : - 1 ] , x , 2 * x [ - 1 ] - x [ - 1 : - window_len : - 1 ] ] if window == 'flat' : w = np . ones ( window_len , 'd' ) else : w = eval ( 'np.' + window + '(windo...
Smooth data by convolving on a given timescale .
1,274
def SavGol ( y , win = 49 ) : if len ( y ) >= win : return y - savgol_filter ( y , win , 2 ) + np . nanmedian ( y ) else : return y
Subtracts a second order Savitsky - Golay filter with window size win and returns the result . This acts as a high pass filter .
1,275
def NumRegressors ( npix , pld_order , cross_terms = True ) : res = 0 for k in range ( 1 , pld_order + 1 ) : if cross_terms : res += comb ( npix + k - 1 , k ) else : res += npix return int ( res )
Return the number of regressors for npix pixels and PLD order pld_order .
1,276
def Downbin ( x , newsize , axis = 0 , operation = 'mean' ) : assert newsize < x . shape [ axis ] , "The new size of the array must be smaller than the current size." oldsize = x . shape [ axis ] newshape = list ( x . shape ) newshape [ axis ] = newsize newshape . insert ( axis + 1 , oldsize // newsize ) trim = oldsize...
Downbins an array to a smaller size .
1,277
def lookup ( var_name , contexts = ( ) , start = 0 ) : start = len ( contexts ) if start >= 0 else start for context in reversed ( contexts [ : start ] ) : try : if var_name in context : return context [ var_name ] except TypeError as te : continue return None
lookup the value of the var_name on the stack of contexts
1,278
def delimiters_to_re ( delimiters ) : delimiters = tuple ( delimiters ) if delimiters in re_delimiters : re_tag = re_delimiters [ delimiters ] else : open_tag , close_tag = delimiters open_tag = '' . join ( [ c if c . isalnum ( ) else '\\' + c for c in open_tag ] ) close_tag = '' . join ( [ c if c . isalnum ( ) else '\...
convert delimiters to corresponding regular expressions
1,279
def _escape ( self , text ) : ret = EMPTYSTRING if text is None else str ( text ) if self . escape : return html_escape ( ret ) else : return ret
Escape text according to self . escape
1,280
def _lookup ( self , dot_name , contexts ) : filters = [ x for x in map ( lambda x : x . strip ( ) , dot_name . split ( '|' ) ) ] dot_name = filters [ 0 ] filters = filters [ 1 : ] if not dot_name . startswith ( '.' ) : dot_name = './' + dot_name paths = dot_name . split ( '/' ) last_path = paths [ - 1 ] refer_context ...
lookup value for names like a . b . c and handle filters as well
1,281
def _render_children ( self , contexts , partials ) : ret = [ ] for child in self . children : ret . append ( child . _render ( contexts , partials ) ) return EMPTYSTRING . join ( ret )
Render the children tokens
1,282
def _render ( self , contexts , partials ) : val = self . _lookup ( self . value , contexts ) if val : return EMPTYSTRING return self . _render_children ( contexts , partials )
render inverted section
1,283
def Setup ( ) : if not os . path . exists ( os . path . join ( EVEREST_DAT , 'k2' , 'cbv' ) ) : os . makedirs ( os . path . join ( EVEREST_DAT , 'k2' , 'cbv' ) ) GetK2Stars ( clobber = False )
Called when the code is installed . Sets up directories and downloads the K2 catalog .
1,284
def CDPP ( flux , mask = [ ] , cadence = 'lc' ) : rmswin = 13 svgwin = 49 if cadence == 'sc' : newsize = len ( flux ) // 30 flux = Downbin ( flux , newsize , operation = 'mean' ) flux_savgol = SavGol ( np . delete ( flux , mask ) , win = svgwin ) if len ( flux_savgol ) : return Scatter ( flux_savgol / np . nanmedian ( ...
Compute the proxy 6 - hr CDPP metric .
1,285
def HasShortCadence ( EPIC , season = None ) : if season is None : season = Campaign ( EPIC ) if season is None : return None stars = GetK2Campaign ( season ) i = np . where ( [ s [ 0 ] == EPIC for s in stars ] ) [ 0 ] if len ( i ) : return stars [ i [ 0 ] ] [ 3 ] else : return None
Returns True if short cadence data is available for this target .
1,286
def DVSFile ( ID , season , cadence = 'lc' ) : if cadence == 'sc' : strcadence = '_sc' else : strcadence = '' return 'hlsp_everest_k2_llc_%d-c%02d_kepler_v%s_dvs%s.pdf' % ( ID , season , EVEREST_MAJOR_MINOR , strcadence )
Returns the name of the DVS PDF for a given target .
1,287
def GetTargetCBVs ( model ) : season = model . season name = model . name if name . endswith ( '.sc' ) : name = name [ : - 3 ] model . XCBV = sysrem . GetCBVs ( season , model = name , niter = model . cbv_niter , sv_win = model . cbv_win , sv_order = model . cbv_order )
Returns the design matrix of CBVs for the given target .
1,288
def StatsToCSV ( campaign , model = 'nPLD' ) : statsfile = os . path . join ( EVEREST_SRC , 'missions' , 'k2' , 'tables' , 'c%02d_%s.cdpp' % ( campaign , model ) ) csvfile = os . path . join ( os . path . dirname ( EVEREST_SRC ) , 'docs' , 'c%02d.csv' % campaign ) epic , kp , cdpp6r , cdpp6 , _ , _ , _ , _ , saturated ...
Generate the CSV file used in the search database for the documentation .
1,289
def do_pending_lookups ( event , sender , ** kwargs ) : key = ( sender . _meta . app_label , sender . _meta . name ) for callback in pending_lookups . pop ( key , [ ] ) : callback ( sender )
Handle any pending relations to the sending model . Sent from class_prepared .
1,290
def Many2ManyThroughModel ( field ) : from stdnet . odm import ModelType , StdModel , ForeignKey , CompositeIdField name_model = field . model . _meta . name name_relmodel = field . relmodel . _meta . name if name_model == name_relmodel : name_relmodel += '2' through = field . through if through is None : name = '{0}_{...
Create a Many2Many through model with two foreign key fields and a CompositeFieldId depending on the two foreign keys .
1,291
def makeMany2ManyRelatedManager ( formodel , name_relmodel , name_formodel ) : class _Many2ManyRelatedManager ( Many2ManyRelatedManager ) : pass _Many2ManyRelatedManager . formodel = formodel _Many2ManyRelatedManager . name_relmodel = name_relmodel _Many2ManyRelatedManager . name_formodel = name_formodel return _Many2M...
formodel is the model which the manager .
1,292
def metaphone_processor ( words ) : for word in words : for w in double_metaphone ( word ) : if w : w = w . strip ( ) if w : yield w
Double metaphone word processor .
1,293
def tolerant_metaphone_processor ( words ) : for word in words : r = 0 for w in double_metaphone ( word ) : if w : w = w . strip ( ) if w : r += 1 yield w if not r : yield word
Double metaphone word processor slightly modified so that when no words are returned by the algorithm the original word is returned .
1,294
def stemming_processor ( words ) : stem = PorterStemmer ( ) . stem for word in words : word = stem ( word , 0 , len ( word ) - 1 ) yield word
Porter Stemmer word processor
1,295
def Pool ( pool = 'AnyPool' , ** kwargs ) : if pool == 'MPIPool' : return MPIPool ( ** kwargs ) elif pool == 'MultiPool' : return MultiPool ( ** kwargs ) elif pool == 'SerialPool' : return SerialPool ( ** kwargs ) elif pool == 'AnyPool' : if MPIPool . enabled ( ) : return MPIPool ( ** kwargs ) elif MultiPool . enabled ...
Chooses between the different pools . If pool == AnyPool chooses based on availability .
1,296
def wait ( self ) : if self . is_master ( ) : raise RuntimeError ( "Master node told to await jobs." ) status = MPI . Status ( ) while True : if self . debug : print ( "Worker {0} waiting for task." . format ( self . rank ) ) task = self . comm . recv ( source = 0 , tag = MPI . ANY_TAG , status = status ) if self . deb...
If this isn t the master process wait for instructions .
1,297
def commit_when_no_transaction ( f ) : def _ ( self , * args , ** kwargs ) : r = f ( self , * args , ** kwargs ) return self . session . add ( self ) if self . session is not None else r _ . __name__ = f . __name__ _ . __doc__ = f . __doc__ return _
Decorator for committing changes when the instance session is not in a transaction .
1,298
def irange ( self , start = 0 , end = - 1 , callback = None , withscores = True , ** options ) : backend = self . read_backend res = backend . structure ( self ) . irange ( start , end , withscores = withscores , ** options ) if not callback : callback = self . load_data if withscores else self . load_values return bac...
Return the range by rank between start and end .
1,299
def pop_front ( self ) : backend = self . backend return backend . execute ( backend . structure ( self ) . pop_front ( ) , self . value_pickler . loads )
Remove the first element from of the list .