import pandas as pd
import numpy as np
import operator
from sys import argv
import os 

def extract( file_name ):
        with open(file_name) as f:
                for i,line in enumerate(f,1):
                        if "SCN" in line:
                                return i

os.system('ltahdr -i'+ argv[1]+ '> lta_file.txt')
dictionary = {}
#lta_file = str(argv[1])
skipped_rows = extract('lta_file.txt')-1

header = pd.read_csv('lta_file.txt',skiprows=skipped_rows,delimiter=r"\s+")
flux = list(set(header["OBJECT"]))
print flux

header['Nrecs'] = header['Nrecs'].astype(float)

for i in flux :
        temp = header.loc[header.OBJECT==i,'Nrecs'].values
        temp = np.mean(temp)
        dictionary[i]=temp
print dictionary

source = max(dictionary.iteritems(),key=operator.itemgetter(1))[0]
print source



import pandas as pd
import numpy as np
import operator
from sys import argv
import os 

def extract( file_name ):
    with open(file_name) as f:
        for i,line in enumerate(f,1):
            if "SCN" in line:
                return i
def main(lta_name):
    os.system('ltahdr -i'+ lta_name + '> lta_file.txt')
    dictionary = {}
    #lta_file = str(argv[1])
    skipped_rows = extract('lta_file.txt')-1

    header = pd.read_csv('lta_file.txt',skiprows=skipped_rows,delimiter=r"\s+")
    flux = list(set(header["OBJECT"]))
    #print flux

    header['Nrecs'] = header['Nrecs'].astype(float)

    for i in flux :
        temp = header.loc[header.OBJECT==i,'Nrecs'].values
        temp = np.mean(temp)
        dictionary[i]=temp
    #print dictionary

    source = max(dictionary.iteritems(),key=operator.itemgetter(1))[0]
    return source

Insert main body of code into function
Insert main body of code into function

  import pandas as pd
  import numpy as np
  import operator
  from sys import argv
  import os 
  
  def extract( file_name ):
-         with open(file_name) as f:
+     with open(file_name) as f:
-                 for i,line in enumerate(f,1):
+         for i,line in enumerate(f,1):
-                         if "SCN" in line:
+             if "SCN" in line:
-                                 return i
+                 return i
+ def main(lta_name):
+     os.system('ltahdr -i'+ lta_name + '> lta_file.txt')
+     dictionary = {}
+     #lta_file = str(argv[1])
+     skipped_rows = extract('lta_file.txt')-1
  
+     header = pd.read_csv('lta_file.txt',skiprows=skipped_rows,delimiter=r"\s+")
+     flux = list(set(header["OBJECT"]))
+     #print flux
- os.system('ltahdr -i'+ argv[1]+ '> lta_file.txt')
- dictionary = {}
- #lta_file = str(argv[1])
- skipped_rows = extract('lta_file.txt')-1
  
+     header['Nrecs'] = header['Nrecs'].astype(float)
- header = pd.read_csv('lta_file.txt',skiprows=skipped_rows,delimiter=r"\s+")
- flux = list(set(header["OBJECT"]))
- print flux
  
- header['Nrecs'] = header['Nrecs'].astype(float)
- 
- for i in flux :
+     for i in flux :
          temp = header.loc[header.OBJECT==i,'Nrecs'].values
          temp = np.mean(temp)
          dictionary[i]=temp
- print dictionary
+     #print dictionary
  
- source = max(dictionary.iteritems(),key=operator.itemgetter(1))[0]
+     source = max(dictionary.iteritems(),key=operator.itemgetter(1))[0]
- print source
+     return source
  
- 
- 
Insert main body of code into function
## Code Before:
import pandas as pd
import numpy as np
import operator
from sys import argv
import os 

def extract( file_name ):
        with open(file_name) as f:
                for i,line in enumerate(f,1):
                        if "SCN" in line:
                                return i

os.system('ltahdr -i'+ argv[1]+ '> lta_file.txt')
dictionary = {}
#lta_file = str(argv[1])
skipped_rows = extract('lta_file.txt')-1

header = pd.read_csv('lta_file.txt',skiprows=skipped_rows,delimiter=r"\s+")
flux = list(set(header["OBJECT"]))
print flux

header['Nrecs'] = header['Nrecs'].astype(float)

for i in flux :
        temp = header.loc[header.OBJECT==i,'Nrecs'].values
        temp = np.mean(temp)
        dictionary[i]=temp
print dictionary

source = max(dictionary.iteritems(),key=operator.itemgetter(1))[0]
print source



## Instruction:
Insert main body of code into function
## Code After:
import pandas as pd
import numpy as np
import operator
from sys import argv
import os 

def extract( file_name ):
    with open(file_name) as f:
        for i,line in enumerate(f,1):
            if "SCN" in line:
                return i
def main(lta_name):
    os.system('ltahdr -i'+ lta_name + '> lta_file.txt')
    dictionary = {}
    #lta_file = str(argv[1])
    skipped_rows = extract('lta_file.txt')-1

    header = pd.read_csv('lta_file.txt',skiprows=skipped_rows,delimiter=r"\s+")
    flux = list(set(header["OBJECT"]))
    #print flux

    header['Nrecs'] = header['Nrecs'].astype(float)

    for i in flux :
        temp = header.loc[header.OBJECT==i,'Nrecs'].values
        temp = np.mean(temp)
        dictionary[i]=temp
    #print dictionary

    source = max(dictionary.iteritems(),key=operator.itemgetter(1))[0]
    return source
