Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a convenient way to get comment lines from an ASCII table #3136

Closed
taldcroft opened this issue Nov 24, 2014 · 10 comments
Closed

Provide a convenient way to get comment lines from an ASCII table #3136

taldcroft opened this issue Nov 24, 2014 · 10 comments

Comments

@taldcroft
Copy link
Member

Currently to get the comment lines from an ASCII data file you need to use get_reader:

>>> from astropy.io import ascii
>>> reader = ascii.get_reader(Reader=ascii.Basic)  # or whatever
>>> dat = reader.read(filename)
>>> comments = reader.comment_lines

There should be a better way.

@embray
Copy link
Member

embray commented Nov 24, 2014

When it comes to returning a Table, couldn't this go into the table's .meta?

@bsipocz
Copy link
Member

bsipocz commented Nov 24, 2014

+1 to have an option of putting the comments to .meta. However it may be very messy if in-line comments from the data part also end up in there.

@taldcroft
Copy link
Member Author

Yes, putting this in .meta is what I had envisioned.

@kslong
Copy link

kslong commented Nov 25, 2014

Since a message, I wrote to astropy@scipy.org may have stimulated this, I thought I would comment on this question. My minimum need is just to get hold of the comments, since if I have them I can parse them however I choose.

But what I would really prefer is something that was a keyword like approach, so that a comment line like

# Coord_Sys CYLIND

was interpreted so that Coord_Sys was the keyword and CYLIND was the value, analogous to the keyword system used for fits files.

If this were the case, one could easily translate between FITS tables and ascii files.

Just my two-cents. As I mentioned, just being able to get at the comments (without having to read the file multiple times) would be a help.

@embray
Copy link
Member

embray commented Nov 26, 2014

@kslong See astropy/astropy-APEs#7

Unfortunately there is no standard format by which such a construction could simply be guessed, though the above is a proposal for such a format.

@mdmueller
Copy link
Contributor

It looks like Ipac already does this, i.e. comment lines go into dat.meta['comments']. Do we want to include this behavior in BaseHeader.update_meta, or should it be specified by an optional keyword?

@taldcroft
Copy link
Member Author

I would say that dat.meta['comments'] is a good place by default and that it should be done in update_meta. I guess the header and data process_lines could be modified to capture comment lines instead of just dropping them. This will probably be a slight performance regression but maybe not too bad.

I think we want to have any line in the file that is a comment whether or not it occurs in the data section. In particular a case like below would lose all comments because the header is just the first line:

a  b c
# some comment
# another
1 2 3
4 5 6

@taldcroft
Copy link
Member Author

I was going to say two more things:

  • I haven't checked to see how many built-in readers override the base process_lines method.
  • Of course the fast readers are going to be different as well.

@hamogu
Copy link
Member

hamogu commented Dec 23, 2014

Should this be closed now that #3222 is merged?

@taldcroft
Copy link
Member Author

Closed by #3222.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants