[AstroPy] (Table) unit formatting

Thomas Robitaille thomas.robitaille at gmail.com
Wed Nov 1 11:15:15 EDT 2017


Hi Peter,

The issue is that the FITS standard includes a prescription about how units
should be formatted, and we follow the standard strictly when writing files
to make sure the files we produce are standard-compliant. I would therefore
advise against trying to modify TUNIT to make it more 'human-friendly'
since it will result in it being non-standard-compliant and could cause
issues when other people try and read it in. When the table is loaded into
a Table object in Python you can of course convert units to various string
representations including latex - but we should stick to the standard when
writing FITS files.

The fact that the format on Table columns is not propagated to TDISP sounds
like an oversight. Can you open an issue in the astropy repository?

https://github.com/astropy/astropy/issues/new

We indeed don't currently print descriptions when showing a Table object in
Python and also don't write them to FITS. Feel free to open feature
requests for these in the issue tracker above too. Keep that issue separate
from the TDISP issue which I think is an actual bug/oversight - whereas I
think there is no 'standard' way to write descriptions for columns to FITS
so this is more of a possible feature request.

I hope this helps!

Cheers,
Tom




On 25 October 2017 at 14:28, Peter Weilbacher <pweilbacher at aip.de> wrote:

> Dear all,
>
> I'm trying to add units to table columns with AstroPy (v2.0.1) and save
> the resulting table as FITS (for now). So I enter unit strings like this
>    table['colname'].unit = 'erg/s/cm**2'
> and write the table to disk. Unfortunately, I not only get the annoying
> units warning about the multiple slashes (any way to turn that off?) but
> also discover that the strong got converted to 'cm-2 erg s-1' which
> while correct is really ugly -- nobody would write it like that in a
> paper! And actually, when I use print to look at the table before
> saving, I see that units as 'erg / (cm2 s)' which is not nice, either,
> but that I can live with.
>
> Can I adjust this behavior of do I have to edit the TUNITn manually
> after saving the file?
>
> By the way, I was also looking for a way to influence the display of the
> columns, i.e. the TDISPn keywords. If I set a format using
>    t['colname'].format = '%4.2f'
> this is used when printing the table, but does not end up in the
> corresponding TDISPn after writing to FITS. Am I missing something?
>
> Finally, I'd like to give potential users of my file a longer
> description, and hoped there was a way to write something to the FITS
> comment part (after the slash of the TTYPEn keywords). Setting
>    t['colname'].description = 'a descriptive message'
> works, but influences neither printing of the table nor writing to FITS.
>
> Any hints?
>    Peter.
> --
> Dr. Peter M. Weilbacher             http://www.aip.de/People/PWeilbacher
> Phone +49 331 74 99-667                       encryption key ID 7D6B4AA0
> ------------------------------------------------------------------------
> Leibniz-Institut für Astrophysik Potsdam (AIP)
> An der Sternwarte 16, D-14482 Potsdam
>
> Vorstand: Prof. Dr. Matthias Steinmetz, Matthias Winker
> Stiftung bürgerlichen Rechts, Stiftungsverz. Brandenburg: 26 742-00/7026
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20171101/919e75ad/attachment-0001.html>


More information about the AstroPy mailing list