original_docstring: 
      Main wrapper to obtain and process a light curve
      
docstring: Main wrapper to obtain and process a light curve
docstring_tokens: Main wrapper to obtain and process a light curve
code: def RunLC(file='', objectid='', lctype='',
            display=False, readfile=False, debug=False, dofake=True,
            dbmode='fits', gapwindow=0.1, maxgap=0.125,
            fakefreq=.25, mode='davenport', iterations=10):
      '''
      Main wrapper to obtain and process a light curve
      '''
      # get the data
      if debug is True:
          print(str(datetime.datetime.now()) + ' GetLC started')
          print(file, objectid)
  
      if dbmode in ('txt','ktwo','everest','vdb','csv','kplr','k2sc','random','test'):
          outfile, objectid, lc = Get(dbmode,file=file, objectid=objectid)
      # UNUSED, UNTESTED, DELETE?
      # elif dbmode = 'mysql':
      #     outfile, objectid, lc  = GetLCdb(objectid, type='', readfile=False,
      #               savefile=False, exten = '.lc.gz',
      #               onecadence=False)
  
      #-----------------------------------------------
  
      if debug is True:
          print('outfile = ' + outfile)
  
      ### Basic flattening
      # flatten quarters with polymonial
      flux_qtr = detrend.QtrFlat(lc.time.values, lc.flux_raw.values, lc.qtr.iloc[0])
  
      # then flatten between gaps
      lc['flux'] = detrend.GapFlat(lc.time.values, flux_qtr, maxgap=maxgap)
  
      #find continuous observing periods
      _, dlr = detrend.FindGaps(lc.time.values, maxgap=maxgap)
      if debug is True:
          print("dl, dr: {}".format(dlr))
  
      # uQtr = np.unique(qtr)
      if debug is True:
          print(str(datetime.datetime.now()) + ' MultiFind started')
      istart, istop, lc['flux_model'] = MultiFind(lc,dlr,gapwindow=gapwindow,
                                                  debug=debug, mode=mode)
  
      df1 = pd.DataFrame({'istart':istart,
                          'istop':istop,
                          'ed68':np.full_like(istart,-99),
                          'ed90':np.full_like(istart,-99)})
      allfakes = pd.DataFrame()
      # run artificial flare test in this gap
  
  
      if dofake is True:
          dffake = pd.DataFrame()
          for k in range(iterations):
              fakeres = FakeFlares(df1, lc, dlr, mode, savefile=True,
                  gapwindow=gapwindow,
                  outfile='{}fake.json'.format(file),
                  display=display, fakefreq=fakefreq, debug=debug)
              dffake = dffake.append(fakeres, ignore_index=True)
  
          dffake.to_csv('{}_all_fakes.csv'.format(outfile))
  
          df1['ed68'], df1['ed90'] = FakeCompleteness(dffake,fakefreq,iterations,
                                                      display=display,
                                                      file=objectid)
  
  
  
      if display is True:
          print(str(len(istart))+' flare candidates found.')
  
          fig, ax = plt.subplots(figsize=(8,4))
  
          ax = help.Plot(lc, ax, istart=istart, istop=istop, onlybit=10.)
          plt.show()
          plt.savefig(file + '_lightcurve.png', dpi=300, bbox_inches='tight', pad_inches=0.5)
          plt.close()
      # '''
      # #-- IF YOU WANT TO PLAY WITH THE WAVELET STUFF MORE, WORK HERE
      # test_model = detrend.WaveletSmooth(time, flux)
      # test_cand = DetectCandidate(time, flux, error, test_model)
      #
      # print(len(cand))
      # print(len(test_cand))
      #
      # if display is True:
      #     plt.figure()
      #     plt.plot(time, flux, 'k')
      #     plt.plot(time, test_model, 'green')
      #
      #     plt.scatter(time[test_cand], flux[test_cand], color='orange', marker='p',s=60, alpha=0.8)
      #     plt.show()
      # '''
  
      # set this to silence bad fit warnings from polyfit
      warnings.simplefilter('ignore', np.RankWarning)
  
      metadata = {'ObjectID' : objectid,
                   'File' : file,
                   'Date-Run' : str(datetime.datetime.now()),
                   'Appaloosa-Version': __version__,
                   'N_epoch in LC' : str(len(lc.time)),
                   'Total exp time of LC' : str(np.sum(lc.exptime)),
                   }
  
      if debug is True:
          print(str(datetime.datetime.now()) + 'Getting output header')
  
      header = FlareStats(lc, ReturnHeader=True)
      header = header + ['ED68i','ED90i']
      dfout = pd.DataFrame()
  
      if debug is True:
          print(str(datetime.datetime.now()) + 'Getting FlareStats')
  
      # loop over EACH FLARE, compute stats
      df2 = pd.DataFrame({'istart':istart,'istop':istop})
      stats_i = []
  
      for i in range(0,len(istart)):
          stats_i = FlareStats(lc, istart=istart[i], istop=istop[i])
  
          stats_i = np.append(stats_i,[df1.ed68.iloc[i],df1.ed90.iloc[i]])
          stats_i = [[item] for item in stats_i]
          dfout = dfout.append(pd.DataFrame(dict(zip(header,stats_i))),
                               ignore_index=True)
      if not dfout.empty:
          dfout.to_csv(outfile + '_flare_stats.csv')
          with open(outfile + '_flare_stats_meta.json','w') as f:
              j = json.dumps(metadata)
              f.write(j)
  
      #Add the number of flares from this LC to the list
      flist = 'flarelist.csv'.format(outfile)
      header = ['Object ID',' Date of Run','Number of Flares','Filename',
                          'Total Exposure Time of LC in Days','BJD-2454833 days']
  
      if glob.glob(flist)==[]:
          dfout = pd.DataFrame()
      else:
          dfout = pd.read_csv(flist)
  
      line=[objectid, datetime.datetime.now(), len(istart),file,np.sum(lc.exptime),lc.time[0]]
      line = [[item] for item in line]
      dfout = dfout.append(pd.DataFrame(dict(zip(header,line))),
                               ignore_index=True)
      dfout.to_csv(flist)
      return
code_tokens: def RunLC ( file = '' , objectid = '' , lctype = '' , display = False , readfile = False , debug = False , dofake = True , dbmode = 'fits' , gapwindow = 0.1 , maxgap = 0.125 , fakefreq = .25 , mode = 'davenport' , iterations = 10 ) : if debug is True : print ( str ( datetime . datetime . now ( ) ) + ' GetLC started' ) print ( file , objectid ) if dbmode in ( 'txt' , 'ktwo' , 'everest' , 'vdb' , 'csv' , 'kplr' , 'k2sc' , 'random' , 'test' ) : outfile , objectid , lc = Get ( dbmode , file = file , objectid = objectid ) if debug is True : print ( 'outfile = ' + outfile ) flux_qtr = detrend . QtrFlat ( lc . time . values , lc . flux_raw . values , lc . qtr . iloc [ 0 ] ) lc [ 'flux' ] = detrend . GapFlat ( lc . time . values , flux_qtr , maxgap = maxgap ) _ , dlr = detrend . FindGaps ( lc . time . values , maxgap = maxgap ) if debug is True : print ( "dl, dr: {}" . format ( dlr ) ) if debug is True : print ( str ( datetime . datetime . now ( ) ) + ' MultiFind started' ) istart , istop , lc [ 'flux_model' ] = MultiFind ( lc , dlr , gapwindow = gapwindow , debug = debug , mode = mode ) df1 = pd . DataFrame ( { 'istart' : istart , 'istop' : istop , 'ed68' : np . full_like ( istart , - 99 ) , 'ed90' : np . full_like ( istart , - 99 ) } ) allfakes = pd . DataFrame ( ) if dofake is True : dffake = pd . DataFrame ( ) for k in range ( iterations ) : fakeres = FakeFlares ( df1 , lc , dlr , mode , savefile = True , gapwindow = gapwindow , outfile = '{}fake.json' . format ( file ) , display = display , fakefreq = fakefreq , debug = debug ) dffake = dffake . append ( fakeres , ignore_index = True ) dffake . to_csv ( '{}_all_fakes.csv' . format ( outfile ) ) df1 [ 'ed68' ] , df1 [ 'ed90' ] = FakeCompleteness ( dffake , fakefreq , iterations , display = display , file = objectid ) if display is True : print ( str ( len ( istart ) ) + ' flare candidates found.' ) fig , ax = plt . subplots ( figsize = ( 8 , 4 ) ) ax = help . Plot ( lc , ax , istart = istart , istop = istop , onlybit = 10. ) plt . show ( ) plt . savefig ( file + '_lightcurve.png' , dpi = 300 , bbox_inches = 'tight' , pad_inches = 0.5 ) plt . close ( ) warnings . simplefilter ( 'ignore' , np . RankWarning ) metadata = { 'ObjectID' : objectid , 'File' : file , 'Date-Run' : str ( datetime . datetime . now ( ) ) , 'Appaloosa-Version' : __version__ , 'N_epoch in LC' : str ( len ( lc . time ) ) , 'Total exp time of LC' : str ( np . sum ( lc . exptime ) ) , } if debug is True : print ( str ( datetime . datetime . now ( ) ) + 'Getting output header' ) header = FlareStats ( lc , ReturnHeader = True ) header = header + [ 'ED68i' , 'ED90i' ] dfout = pd . DataFrame ( ) if debug is True : print ( str ( datetime . datetime . now ( ) ) + 'Getting FlareStats' ) df2 = pd . DataFrame ( { 'istart' : istart , 'istop' : istop } ) stats_i = [ ] for i in range ( 0 , len ( istart ) ) : stats_i = FlareStats ( lc , istart = istart [ i ] , istop = istop [ i ] ) stats_i = np . append ( stats_i , [ df1 . ed68 . iloc [ i ] , df1 . ed90 . iloc [ i ] ] ) stats_i = [ [ item ] for item in stats_i ] dfout = dfout . append ( pd . DataFrame ( dict ( zip ( header , stats_i ) ) ) , ignore_index = True ) if not dfout . empty : dfout . to_csv ( outfile + '_flare_stats.csv' ) with open ( outfile + '_flare_stats_meta.json' , 'w' ) as f : j = json . dumps ( metadata ) f . write ( j ) flist = 'flarelist.csv' . format ( outfile ) header = [ 'Object ID' , ' Date of Run' , 'Number of Flares' , 'Filename' , 'Total Exposure Time of LC in Days' , 'BJD-2454833 days' ] if glob . glob ( flist ) == [ ] : dfout = pd . DataFrame ( ) else : dfout = pd . read_csv ( flist ) line = [ objectid , datetime . datetime . now ( ) , len ( istart ) , file , np . sum ( lc . exptime ) , lc . time [ 0 ] ] line = [ [ item ] for item in line ] dfout = dfout . append ( pd . DataFrame ( dict ( zip ( header , line ) ) ) , ignore_index = True ) dfout . to_csv ( flist ) return
short_docstring: Main wrapper to obtain and process a light curve
short_docstring_tokens: Main wrapper to obtain and process a light curve
comment: '''
      Main wrapper to obtain and process a light curve
      '''$SEP$# get the data
  $SEP$# UNUSED, UNTESTED, DELETE?
  $SEP$# elif dbmode = 'mysql':
  $SEP$#     outfile, objectid, lc  = GetLCdb(objectid, type='', readfile=False,
  $SEP$#               savefile=False, exten = '.lc.gz',
  $SEP$#               onecadence=False)
  $SEP$#-----------------------------------------------
  $SEP$### Basic flattening
  $SEP$# flatten quarters with polymonial
  $SEP$# then flatten between gaps
  $SEP$#find continuous observing periods
  $SEP$# uQtr = np.unique(qtr)
  $SEP$# run artificial flare test in this gap
  $SEP$# '''
  $SEP$# #-- IF YOU WANT TO PLAY WITH THE WAVELET STUFF MORE, WORK HERE
  $SEP$# test_model = detrend.WaveletSmooth(time, flux)
  $SEP$# test_cand = DetectCandidate(time, flux, error, test_model)
  $SEP$#
  $SEP$# print(len(cand))
  $SEP$# print(len(test_cand))
  $SEP$#
  $SEP$# if display is True:
  $SEP$#     plt.figure()
  $SEP$#     plt.plot(time, flux, 'k')
  $SEP$#     plt.plot(time, test_model, 'green')
  $SEP$#
  $SEP$#     plt.scatter(time[test_cand], flux[test_cand], color='orange', marker='p',s=60, alpha=0.8)
  $SEP$#     plt.show()
  $SEP$# '''
  $SEP$# set this to silence bad fit warnings from polyfit
  $SEP$# loop over EACH FLARE, compute stats
  $SEP$#Add the number of flares from this LC to the list
  