astropy: Problem with "decimalyear" applied to MaskedColumn type

Description

The “decimalyear” type produces odd errors when applied to the MaskedColumn type. The “jyear” type does not, and appears to behave properly.

Expected behavior

I would expect “decimalyear” and “jyear” to work similarly, although the difference between them is not clear from the documentation.

How to Reproduce

# Begin decimalyear_test.py
# A simple illustration of possible bug in "decimalyear"

import astropy
from astropy.coordinates import SkyCoord
from astropy.units import Quantity
from astroquery.gaia import Gaia
from astropy.time import Time

coord = SkyCoord(ra=0.0, dec=0.0, unit=astropy.units.deg)
width = Quantity(0.05, unit=astropy.units.deg)
height = Quantity(0.05, unit=astropy.units.deg)

Gaia.MAIN_GAIA_TABLE = "gaiadr3.gaia_source" 
searchout  = Gaia.query_object_async(coordinate=coord, width=width, height=height)	

epochs=searchout['ref_epoch']
print(epochs,"\n")

print("epochs is instance of MaskedColumn:", isinstance(epochs, astropy.table.column.MaskedColumn),"\n")

print("epochs in jyear: ",Time(epochs,format='jyear'),"\n")
print("epochs in decimalyear: ",Time(epochs,format='decimalyear'))

print("\n")
epoch2=Time(2016.0,format='jyear')
print("epoch2 in jyear=", epoch2)

epoch3=Time(2016.0,format='decimalyear')
print("epoch3 in decimalyear=", epoch3)

# End decimalyear_test.py

Versions

Linux-5.19.0-35-generic-x86_64-with-glibc2.35 Python 3.9.13 (main, Aug 25 2022, 23:26:10) [GCC 11.2.0] astropy 5.1

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

There is a bug, in that the units are used if a Quantity is passed into decimalyear – I think the solution is to explicitly forbid having units for this class, since the scale of the unit year is different than that assumed here (like for byear).

p.s. 365.2425 is what one would get if a Gregorian year were used! Caesar didn’t bother with the details for his Julian calendar too much…

It is still a problem in astropy5.3.dev756+gc0a24c1dc Here is the printout :

# print(epochs,"\n")
ref_epoch
yr
---------
   2016.0
   2016.0
   2016.0
   2016.0
   2016.0
   2016.0 

# print("epochs is instance of MaskedColumn:", isinstance(epochs, astropy.table.column.MaskedColumn),"\n")
epochs is instance of MaskedColumn: True 

# print("epochs in jyear: ",Time(epochs,format='jyear'),"\n")
epochs in jyear:  [2016. 2016. 2016. 2016. 2016. 2016.] 

# print("epochs in decimalyear: ",Time(epochs,format='decimalyear'))
erfa/core.py:154: ErfaWarning: ERFA function "dtf2d" yielded 6 of "dubious year (Note 6)"
  warnings.warn('ERFA function "{}" yielded {}'.format(func_name, wmsg),
erfa/core.py:154: ErfaWarning: ERFA function "utctai" yielded 6 of "dubious year (Note 3)"
  warnings.warn('ERFA function "{}" yielded {}'.format(func_name, wmsg),
erfa/core.py:154: ErfaWarning: ERFA function "taiutc" yielded 6 of "dubious year (Note 4)"
  warnings.warn('ERFA function "{}" yielded {}'.format(func_name, wmsg),
erfa/core.py:154: ErfaWarning: ERFA function "d2dtf" yielded 6 of "dubious year (Note 5)"
  warnings.warn('ERFA function "{}" yielded {}'.format(func_name, wmsg),
epochs in decimalyear:  [736344. 736344. 736344. 736344. 736344. 736344.]

# print("epoch2 in jyear=", epoch2)
epoch2 in jyear= 2016.0
# print("epoch3 in decimalyear=", epoch3)
epoch3 in decimalyear= 2016.0