Skip to content

Commit

Permalink
Cleaned up a little.
Browse files Browse the repository at this point in the history
  • Loading branch information
hover2pi committed Feb 23, 2016
1 parent 4cb2f55 commit 584c7ad
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions astrodbkit/astrodb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
# encoding: utf-8
# Author: Joe Filippazzo, jcfilippazzo@gmail.com

import io, os, sys, itertools, sqlite3, warnings
Expand Down Expand Up @@ -141,7 +142,7 @@ def add_data(self, ascii, table, delimiter='|', bands=''):

# Run table clean up
try: self.clean_up(table)
except IOError: print 'Could not run clean_up() method.'
except: print 'Could not run clean_up() method.'

else: print 'Please check the file path {}'.format(ascii)

Expand Down Expand Up @@ -323,7 +324,7 @@ def inventory(self, source_id, plot=False, fetch=False):

else: pass

except:
except IOError:
print 'Could not retrieve data from {} table.'.format(table.upper())

if fetch: return data_tables
Expand Down Expand Up @@ -457,8 +458,8 @@ def modify(self, SQL, params=''):
else:
self.list(SQL, params)
self.conn.commit()
# print 'Number of records modified: {}'.format(self.query("SELECT changes()", fetch='one')[0])
except IOError:
print 'Number of records modified: {}'.format(self.list("SELECT changes()").fetchone()[0] or '0')
except:
print "Could not execute: "+SQL

def output_spectrum(self, spectrum_id, filepath, original=False):
Expand Down Expand Up @@ -524,7 +525,7 @@ def plot_spectrum(self, spectrum_id, overplot=False, color='b'):
X, Y = plt.xlim(), plt.ylim()
try: ax.fill_between(spec.data[0], spec.data[1]-spec.data[2], spec.data[1]+spec.data[2], color=color, alpha=0.3), ax.set_xlim(X), ax.set_ylim(Y)
except: print 'No uncertainty array for spectrum {}'.format(spectrum_id)
except IOError: print "Could not plot spectrum {}".format(spectrum_id); plt.close()
except: print "Could not plot spectrum {}".format(spectrum_id); plt.close()
else: print "No spectrum {} in the SPECTRA table.".format(spectrum_id)

def query(self, SQL, params='', fmt='array', fetch='all', unpack=False, export='', verbose=False):
Expand Down Expand Up @@ -685,7 +686,7 @@ def table(self, table, columns, types, constraints='', new_table=False):
if 'UNIQUE' not in constraints[0].upper() and 'NOT NULL' not in constraints[0].upper():
print "'id' column constraints must be 'UNIQUE NOT NULL'"; goodtogo = False
else:
constraints = ['UNIQUE NOT NULL']+(['']*len(columns)-1)
constraints = ['UNIQUE NOT NULL']+(['']*(len(columns)-1))
if not len(columns)==len(types)==len(constraints):
print "Must provide equal length *columns ({}), *types ({}), and *constraints ({}) sequences."\
.format(len(columns),len(types),len(constraints)); goodtogo = False
Expand Down Expand Up @@ -1059,7 +1060,8 @@ def pprint(data, names='', title=''):
except: pass

# Shorten the column names for slimmer data
for old,new in zip(*[data.colnames,[i.replace('wavelength','wav').replace('publication','pub').replace('instrument','inst').replace('telescope','scope') for i in data.colnames]]): data.rename_column(old,new) if new!=old else None
for old,new in zip(*[data.colnames,[i.replace('wavelength','wav').replace('publication','pub').replace('instrument','inst').replace('telescope','scope') for i in data.colnames]]):
data.rename_column(old,new) if new!=old else None

# Print it!
if title: print '\n'+title
Expand Down

0 comments on commit 584c7ad

Please sign in to comment.