#!/usr/bin/env python # ------------------------------------------------------------------------ # # Program for reading UFO data... # ------------------------------------------------------------------------ # import ROOT # Lists to hold raw information from data file # Note: Some of these will be strings so after loading the data we need to parse it month = [] # Integer day = [] # Integer year = [] # Integer time = [] # Integer (24 hr clock on the form hhmm) city = [] # String state = [] # String shape = [] # String duration = [] # String (needs to be parsed later) description = [] # String # ############################################################## # LOAD DATA # ############################################################## print "Loading data..." # Open file to read index = 0 with open("data.txt", "r") as datafile: # Go through each line for line in datafile: # Line contains EOL information if line.strip(): # The information is separated by tabs splittedline = line.split("\t") # Append information to our lists # ... Time and date fulltime = splittedline[0] # Get the first part fulltimesplitted = fulltime.split(" ") # Split line between date and time finaltime = fulltimesplitted[1] # Get the time finaltime = finaltime.replace(":", "") # Remove the colon (:) from the time string if not finaltime: # No time information, field is blank finaltime = "-1" time.append(int(float(finaltime))) # Add time as an integer to our list fulldate = fulltimesplitted[0] # Get the date fulldatesplitted = fulldate.split("/") # Split the date into month, day and year if not fulldate: # No date information, field is blank month.append(int(-1)) # Add month as an integer to our list day.append(int(-1)) # Add day as an integer to our list year.append(int(-1)) # Add year as an integer to our list else: month.append(int(float(fulldatesplitted[0]))) # Add month as an integer to our list day.append(int(float(fulldatesplitted[1]))) # Add day as an integer to our list year.append(int(float(fulldatesplitted[2]))) # Add year as an integer to our list # ... City and state fulllocation = splittedline[1] # Get the second part fulllocationsplitted = fulllocation.split(",") # Split into city and state fullcity = fulllocationsplitted[0] # Get the city if not fullcity: # No city information, field is blank fullcity = "-1" city.append(fullcity) # Add city as a string to our list fullstate = fulllocationsplitted[1].replace(" ", "") # Get state and remove any spaces state.append(fullstate) # Add state as a string to our list # ... Shape fullshape = splittedline[2] # Get the shape if not fullshape: # No shape information, field is blank fullshape = "-1" shape.append(fullshape) # ... Duration fullduration = splittedline[3] # Get the duration if not fullduration: # No duration information, field is blank fullduration = "-1" duration.append(fullduration) # ... Description if (len(splittedline) < 5): # No description description.append("-1") else: fulldescription = splittedline[4] if not fulldescription: # No description infor, field is blank description.append("-1") else: description.append(fulldescription) index += 1 print "%d datapoints loaded!"%(index) # DEBUG Output of loaded data for i in range( 10 ): print "%d: Date %d/%d/%d, Time %d, City %s, State %s, Shape %s, Duration %s"%(i+1, day[i], month[i], year[i], time[i], city[i], state[i], shape[i], duration[i]) # ############################################################## # ANALYSE DATA # ############################################################## print "Analysing data..." # ... Do something with data (etc. parse and then plot) print "Done!"