#make_kbo_data_file.py # # by Joe Hahn, jhahn@spacescience.org, 21 January 2014. # # Read the input file kbos.txt which contains orbit elements for ~1600 known KBOs. # Those data come from the IAU Minor Planet Center, http://www.minorplanetcenter.net/ # The data that appears in the input file used here (kbos.txt) is cut and pasted from # http://www.minorplanetcenter.net/iau/lists/TNOs.html and # http://www.minorplanetcenter.net/iau/lists/Centaurs.html #to execute in ipython: > ipython --pylab In [1]: %run make_kbo_data_file.py #import modules used below import numpy as np import pandas as pd import matplotlib.pyplot as plt #read data file... file = open('kbos.txt','r') data = np.array(file.readlines()) file.close() Nlines = data.size #starting columns for each feature start_cols = [0, 37, 45, 54, 59, 70, 77, 84, 90, 97, 102, 110, 118, 130, 173] col_names = ['name', 'q', 'Q', 'H', 'Epoch', 'M', 'Peri', 'Node', 'Incl', 'e', 'a', 'Opps', 'Ref', 'NAME', 'Discovery'] Ncols = len(col_names) #store features in kb dataframe kb = pd.DataFrame(columns=col_names, index=range(Nlines), dtype=object) for i in range(Nlines): line = data[i] for j in range(Ncols): start = start_cols[j] stop = len(line) if (j < Ncols-1): stop = start_cols[j+1] val = line[start:stop].strip() col = col_names[j] kb[col][i] = val #change column types from string to float cols = ['q', 'Q', 'M', 'Peri', 'Node', 'Incl', 'e', 'a'] kb[cols] = kb[cols].astype(float) #save as csv file kb.to_csv('kbos.csv')