Skip to content

VOTable unit format#11032

Merged
tomdonaldson merged 7 commits into
astropy:masterfrom
eerovaher:votable-units
Nov 16, 2020
Merged

VOTable unit format#11032
tomdonaldson merged 7 commits into
astropy:masterfrom
eerovaher:votable-units

Conversation

@eerovaher

Copy link
Copy Markdown
Member

The unit format of a VOTable is version dependent. Astropy has the capability of parsing the new unit format, but nonetheless assumes all VOTables are using the old unit specification.

This pull request would make Astropy use the old 'cds' unit format up until VOTable version 1.3 and the new 'vounit' unit format starting from VOTable version 1.4.

Addresses #10791

The VOTable unit format should depend on its version (see issue astropy#10791).
This commit adds a test that checks if the different VOTable versions
have the correct unit format associated with them.
Because the unit format of a VOTable depends on its version the Field
class must have access to this information, including in the test
functions. This commit adds a function to VOTableFile that creates the
appropriate Boolean flags. The same function can also be used in the
VOTableFile parse() and to_xml() methods.
Using angstroms with the 'vounit' format raises a UnitsWarning that
suggests angstroms should not be used. This warning causes
test_votable_quantity_write() to fail even though the functionality of
the underlying code is not compromised. Replacing angstroms with
something else allows the test to pass.
@eerovaher eerovaher mentioned this pull request Nov 12, 2020
@pllim pllim requested review from mhvk and tomdonaldson November 12, 2020 16:06
@pllim pllim added this to the v4.3 milestone Nov 12, 2020

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks all good to me - some nitpickly comments only. That said, as I'm really not familiar with vounit, I'd prefer to have @tomdonaldson sign off (in particular on choice of name/location of test/etc.

Also, for sure this needs an entry in CHANGES.rst! I guess one question is whether this is a bug fix and thus should be backported.

Comment thread astropy/io/votable/tree.py Outdated
config=None, pos=None, **extra):
if config is None:
config = {}
if hasattr(votable, '_get_version_flags'):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to pass in an old table?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know if it is possible to pass in an old table, but without this change two tests fail because the correct unit format could not be determined.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sounds like it is necessary, then, though I'll leave this to @tomdonaldson just to be sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about this check as well. I think it is OK since It seems necessary to protect the unit tests which are exercising Field without a containing votable. Testing Field that way (or designing Field that way) may be questionable, but addressing those questions would be outside the scope of this PR.

Comment thread astropy/io/votable/tests/tree_test.py Outdated


def test_unit_format():
from astropy.io.votable.table import parse

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just put imports on top.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread astropy/io/votable/tree.py Outdated
self.groups.append(group)
group.parse(iterator, config)

def _get_version_flags(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd maybe call this _get_version_checks or _get_version_info

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread astropy/table/tests/test_mixin.py Outdated
"""
t = QTable()
t['a'] = u.Quantity([1, 2, 4], unit='Angstrom')
t['a'] = u.Quantity([1, 2, 4], unit='m')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the new format not support Angstrom? My tendency would then be to use 'nm' to at least keep it a prefixed unit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Angstroms are supported but discouraged, so using them raises a UnitsWarning which seems to cause this test to fail. Running pytest -P table -p no:warnings does succeed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let's use 'nm' instead, then.

@eerovaher

Copy link
Copy Markdown
Member Author

This is the current warning about an invalid unit string in a VOTable:

class W50(VOTableSpecWarning):

It is correct for the older VOTable versions, but for newer ones the warning should refer to the VOUnit specification instead. Should I add W56 with the appropriate reference for use with the newer VOTables?

@mhvk

mhvk commented Nov 15, 2020

Copy link
Copy Markdown
Contributor

@eerovaher - yes, seems good to update the warning too! (though again, I know very little about VOTable - I was asked because of units!)

@tomdonaldson

Copy link
Copy Markdown
Contributor

This is the current warning about an invalid unit string in a VOTable:

class W50(VOTableSpecWarning):

It is correct for the older VOTable versions, but for newer ones the warning should refer to the VOUnit specification instead. Should I add W56 with the appropriate reference for use with the newer VOTables?

Yes, I think it would be great to add that new unit information to the warning(s). Would it be easier to add the info to the existing warning so that the one warning covers both cases? I don't have a strong opinion one way or the other.

I did notice some confusion in the related issue #10791 regarding the most up-to-date VOUnits specification. (It looks like there is a mixup in some IVOA document URL redirects.) The best URL for the latest VOUnits specification is: https://www.ivoa.net/documents/VOUnits

@tomdonaldson tomdonaldson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much @eerovaher for this PR, and @mhvk for the review.

I agree with the analysis regarding the versioning of units with respect to VOTable version, i.e. that the change in official VOTable unit syntax from cds to vounit occurs with VOTable 1.4.

I also agree that these changes fix the behavior correctly, so I will approve this with an update to the warning(s) as discussed.

Since this behavior should have been included with the initial support for VOTable 1.4, this should probably be treated as a bug fix and backported.

The unit format of a VOTable is version-dependent. The docstring of the
VOTable invalid unit string warning (W50) should therefore contain
references to both the old and the new unit format specification.
@eerovaher

Copy link
Copy Markdown
Member Author

I have updated W50 and I can update CHANGES.rst when the milestone for this pull request is reassigned.

@tomdonaldson

Copy link
Copy Markdown
Contributor

@eerovaher thanks, this looks great. Although this is fixing a bug from 4.0, I'm second guessing whether or not it warrants a backport. Would a 4.3 release meet your needs?

@eerovaher

Copy link
Copy Markdown
Member Author

I don't have a preference for which release this should be included in.

@tomdonaldson

Copy link
Copy Markdown
Contributor

I don't have a preference for which release this should be included in.

OK, sounds good. I'll leave the milestone at 4.3 then.

@tomdonaldson tomdonaldson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good. Thanks again for these changes!

@bsipocz

bsipocz commented Jan 27, 2021

Copy link
Copy Markdown
Member

Hmm, my bad, my issue is not with this PR, but with another one. I'm sorry about the noise.

namurphy pushed a commit to namurphy/astropy that referenced this pull request Feb 21, 2021
namurphy pushed a commit to namurphy/astropy that referenced this pull request Feb 21, 2021
namurphy pushed a commit to namurphy/astropy that referenced this pull request Feb 21, 2021
namurphy pushed a commit to namurphy/astropy that referenced this pull request Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants