Home » News & Blogs » Skipping inconsistent rows in asciitable
Bookmark and Share
Astropython

Skipping inconsistent rows in asciitable

29 Nov 2011, 22:11 UTC
Skipping inconsistent rows in asciitable
(200 words excerpt, click title or image to see full post)

The asciitable module provides a way to deal with tables that have one or more lines which don't match the format of the rest of the file.  This is done by overriding the asciitable.BaseReader.inconsistent_handler function with your own custom function.  The very simplest action is to just ignore the line entirely by returning None.  This mimics the behavior of the IDL readcol routine.  Another possibility is to fix the line values to ensure consistency with the rest, for instance by padding out to the right number of columns.The code below (or at https://gist.github.com/1406733) demonstrates the basic method for overriding the BaseReader.inconsistent_handler class method.  Note that this affects all reader classes.  The same could be done to a more specific Reader class as needed."""Provide examples of defining asciitable inconsistent_handler routines to
deal with tables that have rows that are inconsistent with the header
definition.
"""
import asciitable

DEBUG = True

def skip_bad_lines(self, str_vals, ncols):
"""Simply ignore every line with the wrong number of columns."""
if DEBUG:
print 'Skipping line:', ' '.join(str_vals)
return None

def fix_bad_lines(self, str_vals, ncols):
"""Pad with zeros at the end (not enough columns) or truncate
(too many columns)"""
if DEBUG:
...

Note: All formatting and links have been removed - click title or image to see full article.

Comment on this Post

* :
* :
:
* :
:
* required
 

Most Popular

 

Last Hour


Last day


Last week

Latest Vodcast

Latest Podcast

Most Popular Video

Advertise PTTU

Extrasolar Planets

  • Planetary Systems: 1163
  • Multiple Planet Systems: 473
  • Planets: 1854
more

NASA Picture of the Day

Astronomy Picture of the Day

astronomy_pod