[AstroPy] ascii read question

Derek Homeier derek at astro.physik.uni-goettingen.de
Tue Jan 31 11:51:23 EST 2017


Hi Qinpeng,
> 
> I'm new to the AstroPy community, but I find the ascii read function very useful for ascii data import. However, I run into errors reading my table, probably due to the fact that I'm not quite familiar with all supported formats. 
> 
> I attach my table below, can somebody give me a hint how to read in all column names correctly? 
> 
> I have tried this when guessing failed: 
> a = ascii.read("199808041.AHA", format = "basic", delimiter = " ", guess = False), but I don't know what to do with the "[ " in the header. 
> 
the separate ‘[ ‘ instances cause a mismatch between the header and data column numbers, so you’d need
to get rid of either the blanks separating them from the actual names, or of the brackets altogether.
The read() function does provide a ‘header_Splitter’ keyword for some custom pre- and postprocessing of
the header lines - see http://docs.astropy.org/en/stable/api/astropy.io.ascii.BaseSplitter.html
but it seems to use it you need to do a little Class exercise:

class mysplitter(astropy.io.ascii.BaseSplitter):
     def __init__(self):
         self.process_line = lambda x: x.translate({ord('['):'', ord(']'):“})

Note that you have to remove the brackets from the header line before it is split by the whitespace. Then

a = ascii.read("199808041.AHA", format = "basic", delimiter = " ", guess = False, header_Splitter = mysplitter)

should work, but create column names entirely without the brackets.
Don’t know if anyone has an idea how to do this in a more straightforward manner...

HTH,
					Derek




More information about the AstroPy mailing list