SSDataLab / tess-ephem

Where are Solar System objects located in TESS data?
MIT License
2 stars 2 forks source link

`interpolation_step="7D"` raises a ValueError #2

Closed barentsen closed 3 years ago

barentsen commented 3 years ago

@jessie-dotson pointed me to the following failure for "2004 QX2", which occurs when interpolation_step="7D" but not when interpolation_step="12H".

>>> from tess_ephem import ephem
>>> ephem("2004 QX2", interpolation_step="7D")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/gb/dev/tess-ephem/src/tess_ephem/ephem.py", line 180, in ephem
    return te.predict(time=time, verbose=verbose)
  File "/Users/gb/dev/tess-ephem/src/tess_ephem/ephem.py", line 100, in predict
    crd = SkyCoord(sky.ra, sky.dec, unit="deg")
  File "/Users/gb/Library/Caches/pypoetry/virtualenvs/tess-ephem-_eKBvW1X-py3.8/lib/python3.8/site-packages/astropy/coordinates/sky_coordinate.py", line 315, in __init__
    skycoord_kwargs, components, info = _parse_coordinate_data(
  File "/Users/gb/Library/Caches/pypoetry/virtualenvs/tess-ephem-_eKBvW1X-py3.8/lib/python3.8/site-packages/astropy/coordinates/sky_coordinate_parsers.py", line 301, in _parse_coordinate_data
    _components[frame_attr_name] = attr_class(arg, unit=unit)
  File "/Users/gb/Library/Caches/pypoetry/virtualenvs/tess-ephem-_eKBvW1X-py3.8/lib/python3.8/site-packages/astropy/coordinates/angles.py", line 536, in __new__
    self._validate_angles()
  File "/Users/gb/Library/Caches/pypoetry/virtualenvs/tess-ephem-_eKBvW1X-py3.8/lib/python3.8/site-packages/astropy/coordinates/angles.py", line 557, in _validate_angles
    raise ValueError('Latitude angle(s) must be within -90 deg <= angle <= 90 deg, '
ValueError: Latitude angle(s) must be within -90 deg <= angle <= 90 deg, got [ 2.57963712e+01  2.59729000e+01  2.61491591e+01  2.63251927e+01
  2.65010451e+01  2.66767606e+01  2.68523836e+01  2.70279586e+01
  2.72035300e+01  2.73791423e+01  2.75548400e+01  2.77306677e+01
  2.79066700e+01  2.80828914e+01  2.82593765e+01  2.84361700e+01
  2.86132785e+01  2.87905570e+01  2.89678223e+01  2.91448914e+01
  2.93215812e+01  2.94977084e+01  2.96730900e+01  2.98475820e+01
  3.00211970e+01  3.01939869e+01  3.03660034e+01  3.05372983e+01
  3.07079232e+01  3.08779300e+01  3.10473073e+01  3.12157924e+01
  3.13830595e+01  3.15487828e+01  3.17126363e+01  3.18742941e+01
  3.20334300e+01  3.21897549e+01  3.23431267e+01  3.24934402e+01
  3.26405899e+01  3.27844702e+01  3.29249755e+01  3.30620000e+01
  3.31953654e+01  3.33246046e+01  3.34491777e+01  3.35685449e+01
  3.36821661e+01  3.37895012e+01  3.38900100e+01  3.39831707e+01
  3.40685360e+01  3.41456770e+01  3.42141650e+01  3.42735709e+01
  3.43234656e+01  3.43634200e+01  3.43930064e+01  3.44118034e+01
  3.44193911e+01  3.44153495e+01  3.43992587e+01  3.43706988e+01
  3.43292500e+01  3.42744390e+01  3.42055787e+01  3.41219286e+01
  3.40227474e+01  3.39072937e+01  3.37748253e+01  3.36246000e+01
  3.34561130e+01  3.32698111e+01  3.30663784e+01  3.28464976e+01
  3.26108507e+01  3.23601183e+01  3.20949800e+01  3.18159189e+01
  3.15226360e+01  3.12146334e+01  3.08914093e+01  3.05524580e+01
  3.01972694e+01  2.98253300e+01  2.94365809e+01  2.90327955e+01
  2.86162057e+01  2.81890430e+01  2.77535372e+01  2.73119154e+01
  2.68664000e+01  2.64186883e+01  2.59683930e+01  2.55146027e+01
  2.50564029e+01  2.45928761e+01  2.41231024e+01  2.36461600e+01
  2.31617181e+01  2.26718160e+01  2.21790903e+01  2.16861816e+01
  2.11957325e+01  2.07103853e+01  2.02327800e+01  1.97648335e+01
  1.93055831e+01  1.88533460e+01  1.84064407e+01  1.79631871e+01
  1.75219081e+01  1.70809300e+01  1.66392032e+01  1.61981618e+01
  1.57598643e+01  1.53263723e+01  1.48997496e+01  1.44820608e+01
  1.40753700e+01  1.36810975e+01  1.32980924e+01  1.29245618e+01
  1.25587140e+01  1.21987598e+01  1.18429129e+01  1.14893900e+01
  1.11369023e+01  1.07861249e+01  1.04382247e+01  1.00943697e+01
  9.75572827e+00  9.42346897e+00  9.09876000e+00  8.78239871e+00
  8.47370106e+00  8.17161352e+00  7.87508371e+00  7.58306071e+00
  7.29449526e+00  7.00834000e+00  6.72366578e+00  6.44000899e+00
  6.15702125e+00  5.87435321e+00  5.59165455e+00  5.30857412e+00
  5.02476000e+00  4.73993661e+00  4.45413684e+00  4.16747252e+00
  3.88005758e+00  3.59200809e+00  3.30344217e+00  3.01448000e+00
  2.72468311e+00  2.43136831e+00  2.13128329e+00  1.82116671e+00
  1.49774828e+00  1.15774878e+00  7.97880000e-01  4.15744230e-01
  1.25420645e-02 -4.09607700e-01 -8.48562953e-01 -1.30215697e+00
 -1.76819804e+00 -2.24447000e+00 -2.73255296e+00 -3.24933644e+00
 -3.81565650e+00 -4.45250267e+00 -5.18104188e+00 -6.02263867e+00
 -6.99885000e+00 -8.12249230e+00 -9.37083894e+00 -1.07120811e+01
 -1.21142760e+01 -1.35455376e+01 -1.49742803e+01 -1.63694600e+01
 -1.77006228e+01 -1.89370767e+01 -2.00474889e+01 -2.10000491e+01
 -2.17625929e+01 -2.23026713e+01 -2.25875900e+01 -2.25984338e+01
 -2.23720888e+01 -2.19594349e+01 -2.14114120e+01 -2.07790241e+01
 -2.01132833e+01 -1.94651100e+01 -1.88750238e+01 -1.83425439e+01
 -1.78569910e+01 -1.74077295e+01 -1.69841675e+01 -1.65757544e+01
 -1.61719800e+01 -1.57644468e+01 -1.53530684e+01 -1.49398271e+01
 -1.45266971e+01 -1.41156434e+01 -1.37086202e+01 -1.33075700e+01
 -1.29140605e+01 -1.25282016e+01 -1.21497443e+01 -1.17784451e+01
 -1.14140658e+01 -1.10563734e+01 -1.07051400e+01 -1.03601016e+01
 -1.00208320e+01 -9.68686328e+00 -9.35772765e+00 -9.03295708e+00
 -8.71208371e+00 -8.39464000e+00 -8.08025583e+00 -7.76894965e+00
 -7.46083766e+00 -7.15603676e+00 -6.85466458e+00 -6.55683936e+00
 -6.26268000e+00 -5.97226702e+00 -5.68552567e+00 -5.40234278e+00
 -5.12260565e+00 -4.84620211e+00 -4.57302057e+00 -4.30295000e+00
 -4.03585708e+00 -3.77151739e+00 -3.50968371e+00 -3.25010895e+00
 -2.99254618e+00 -2.73674868e+00 -2.48247000e+00 -2.22954989e+00
 -1.97817208e+00 -1.72860660e+00 -1.48112384e+00 -1.23599448e+00
 -9.93489490e-01 -7.53880000e-01 -5.17324445e-01 -2.83529840e-01
 -5.20903371e-02  1.77399849e-01  4.05346370e-01  6.32154685e-01
  8.58230000e-01  1.08385062e+00  1.30878816e+00  1.53268739e+00
  1.75519285e+00  1.97594892e+00  2.19459989e+00  2.41079000e+00
  2.62428881e+00  2.83536725e+00  3.04442157e+00  3.25184800e+00
  3.45804261e+00  3.66340137e+00  3.86832000e+00  4.07307527e+00
  4.27746876e+00  4.48118316e+00  4.68390102e+00  4.88530483e+00
  5.08507701e+00  5.28290000e+00  5.47855711e+00  5.67223508e+00
  5.86422148e+00  6.05480382e+00  6.24426951e+00  6.43290586e+00
  6.62100000e+00  6.80875587e+00  6.99604517e+00  7.18265642e+00
  7.36837813e+00  7.55299870e+00  7.73630653e+00  7.91809000e+00
  8.09820228e+00  8.27675561e+00  8.45392697e+00  8.62989329e+00
  8.80483141e+00  8.97891810e+00  9.15233000e+00  9.32519660e+00
  9.49745907e+00  9.66901146e+00  9.83974778e+00  1.00095620e+01
  1.01783481e+01  1.03460000e+01  1.05124349e+01  1.06776630e+01
  1.08417178e+01  1.10046327e+01  1.11664408e+01  1.13271756e+01
  1.14868700e+01  1.16455549e+01  1.18032515e+01  1.19599787e+01
  1.21157553e+01  1.22706002e+01  1.24245322e+01  1.25775700e+01
  1.27297157e+01  1.28809051e+01  1.30310571e+01  1.31800907e+01
  1.33279248e+01  1.34744783e+01  1.36196700e+01  1.37634458e+01
  1.39058605e+01  1.40469958e+01  1.41869336e+01  1.43257558e+01
  1.44635440e+01  1.46003800e+01  1.47363075e+01  1.48712190e+01
  1.50049689e+01  1.51374116e+01  1.52684015e+01  1.53977929e+01
  1.55254400e+01  1.56512332e+01  1.57752068e+01  1.58974311e+01
  1.60179764e+01  1.61369129e+01  1.62543107e+01  1.63702400e+01
  1.64847336e+01  1.65976748e+01  1.67089100e+01  1.68182850e+01
  1.69256461e+01  1.70308391e+01  1.71337100e+01  1.72341319e+01
  1.73320865e+01  1.74275823e+01  1.75206280e+01  1.76112321e+01
  1.76994033e+01  1.77851500e+01  1.78684495e+01  1.79491541e+01
  1.80270848e+01  1.81020628e+01  1.81739090e+01  1.82424444e+01
  1.83074900e+01  1.83688886e+01  1.84265703e+01  1.84804874e+01
  1.85305919e+01  1.85768358e+01  1.86191711e+01  1.86575500e+01
  1.86918991e+01  1.87220442e+01  1.87477860e+01  1.87689249e+01
  1.87852615e+01  1.87965963e+01  1.88027300e+01  1.88034949e+01
  1.87988513e+01  1.87887913e+01  1.87733071e+01  1.87523907e+01
  1.87260343e+01  1.86942300e+01  1.86569305e+01  1.86139304e+01
  1.85649848e+01  1.85098490e+01  1.84482779e+01  1.83800266e+01
  1.83048500e+01  1.82225852e+01  1.81333974e+01  1.80375342e+01
  1.79352427e+01  1.78267702e+01  1.77123636e+01  1.75922700e+01
  1.74666670e+01  1.73354559e+01  1.71984683e+01  1.70555358e+01
  1.69064896e+01  1.67511608e+01  1.65893800e+01  1.64210933e+01
  1.62467084e+01  1.60667484e+01  1.58817361e+01  1.56921942e+01
  1.54986448e+01  1.53016100e+01  1.51015235e+01  1.48984681e+01
  1.46924387e+01  1.44834299e+01  1.42714361e+01  1.40564515e+01
  1.38384700e+01  1.36175656e+01  1.33941331e+01  1.31686479e+01
  1.29415850e+01  1.27134196e+01  1.24846264e+01  1.22556800e+01
  1.20270092e+01  1.17988606e+01  1.15714358e+01  1.13449364e+01
  1.11195643e+01  1.08955215e+01  1.06730100e+01  1.04522081e+01
  1.02331986e+01  1.00160401e+01  9.80079183e+00  9.58751284e+00
  9.37626243e+00  9.16710000e+00  8.96013126e+00  8.75564699e+00
  8.55398451e+00  8.35548150e+00  8.16047591e+00  7.96930594e+00
  7.78231000e+00  7.59972477e+00  7.42137950e+00  7.24700165e+00
  7.07631885e+00  6.90905892e+00  6.74494989e+00  6.58372000e+00
  6.42520813e+00  6.26969495e+00  6.11757173e+00  5.96922993e+00
  5.82506118e+00  5.68545725e+00  5.55081000e+00  5.42137490e+00
  5.29686146e+00  5.17684275e+00  5.06089192e+00  4.94858225e+00
  4.83948710e+00  4.73318000e+00  4.62936655e+00  4.52828023e+00
  4.43028654e+00  4.33575104e+00  4.24503935e+00  4.15851711e+00
  4.07655000e+00  3.99937920e+00  3.92674773e+00  3.85827413e+00
  3.79357695e+00  3.73227477e+00  3.67398623e+00  3.61833000e+00
  3.56502737e+00  3.51420999e+00  3.46611208e+00  3.42096788e+00
  3.37901163e+00  3.34047759e+00  3.30560000e+00  3.27453906e+00
  3.24715868e+00  3.22324870e+00  3.20259899e+00  3.18499939e+00
  3.17023977e+00  3.15811000e+00  3.14844220e+00  3.14123751e+00
  3.13653935e+00  3.13439111e+00  3.13483621e+00  3.13791803e+00
  3.14368000e+00  3.15215410e+00  3.16332668e+00  3.17717269e+00
  3.19366708e+00  3.21278480e+00  3.23450079e+00  3.25879000e+00
  3.28561983e+00  3.31492747e+00  3.34664255e+00  3.38069470e+00
  3.41701356e+00  3.45552877e+00  3.49617000e+00  3.53888124e+00
  3.58366389e+00  3.63053370e+00  3.67950644e+00  3.73059788e+00
  3.78382380e+00  3.83920000e+00  3.89673201e+00  3.95638434e+00
  4.01811123e+00  4.08186695e+00  4.14760578e+00  4.21528203e+00
  4.28485000e+00  4.35626846e+00  4.42951391e+00  4.50456730e+00
  4.58140961e+00  4.66002182e+00  4.74038494e+00  4.82248000e+00
  4.90629436e+00  4.99184071e+00  5.07913810e+00  5.16820561e+00
  5.25906233e+00  5.35172741e+00  5.44622000e+00  5.54254112e+00
  5.64061911e+00  5.74036418e+00  5.84168655e+00  5.94449646e+00
  6.04870417e+00  6.15422000e+00  6.26098345e+00  6.36905080e+00
  6.47850755e+00  6.58943924e+00  6.70193146e+00  6.81606983e+00
  6.93194000e+00  7.04959393e+00  7.16894880e+00  7.28988807e+00
  7.41229527e+00  7.53605393e+00  7.66104763e+00  7.78716000e+00
  7.91430987e+00  8.04255669e+00  8.17199513e+00  8.30271991e+00
  8.43482578e+00  8.56840753e+00  8.70356000e+00  8.84034664e+00
  8.97870535e+00  9.11854264e+00  9.25976511e+00  9.40227936e+00
  9.54599208e+00  9.69081000e+00  9.83666261e+00  9.98357019e+00
  1.01315758e+01  1.02807224e+01  1.04310532e+01  1.05826114e+01
  1.07354400e+01  1.08895745e+01  1.10450186e+01  1.12017686e+01
  1.13598205e+01  1.15191705e+01  1.16798149e+01  1.18417500e+01
  1.20049649e+01  1.21694189e+01  1.23350642e+01  1.25018528e+01
  1.26697368e+01  1.28386685e+01  1.30086000e+01  1.31795071e+01
  1.33514594e+01  1.35245499e+01  1.36988719e+01  1.38745186e+01
  1.40515835e+01  1.42301600e+01  1.44102996e+01  1.45918858e+01
  1.47747602e+01  1.49587642e+01  1.51437394e+01  1.53295274e+01
  1.55159700e+01  1.57029730e+01  1.58906994e+01  1.60793764e+01
  1.62692314e+01  1.64604919e+01  1.66533856e+01  1.68481400e+01
  1.70448962e+01  1.72434476e+01  1.74435011e+01  1.76447633e+01
  1.78469409e+01  1.80497409e+01  1.82528700e+01  1.84561426e+01
  1.86598019e+01  1.88641986e+01  1.90696837e+01  1.92766081e+01
  1.94853232e+01  1.96961800e+01  1.99093958e+01  2.01246512e+01
  2.03414929e+01  2.05594670e+01  2.07781203e+01  2.09969990e+01
  2.12156500e+01  2.14337748e+01  2.16516945e+01  2.18698849e+01
  2.20888223e+01  2.23089829e+01  2.25308434e+01  2.27548800e+01
  2.29813875e+01  2.32099338e+01  2.34399046e+01  2.36706858e+01
  2.39016632e+01  2.41322226e+01  2.43617500e+01  2.45897987e+01
  2.48165892e+01  2.50425094e+01  2.52679468e+01  2.54932892e+01
  2.57189244e+01  2.59452400e+01  2.61724254e+01  2.63998779e+01
  2.66267961e+01  2.68523783e+01  2.70758227e+01  2.72963272e+01
  2.75130900e+01  2.77254309e+01  2.79331569e+01  2.81361966e+01
  2.83344786e+01  2.85279311e+01  2.87164823e+01  2.89000600e+01
  2.90783484e+01  2.92500560e+01  2.94136464e+01  2.95675820e+01
  2.97103241e+01  2.98403334e+01  2.99560700e+01  3.00559884e+01
  3.01385220e+01  3.02021001e+01  3.02451526e+01  3.02661094e+01
  3.02633995e+01  3.02354500e+01  3.01800315e+01  3.00922955e+01
  2.99667398e+01  2.97978664e+01  2.95801879e+01  2.93082372e+01
  2.89765800e+01  2.85790547e+01  2.81063863e+01  2.75483930e+01
  2.68947005e+01  2.61346915e+01  2.52574644e+01  2.42518100e+01
  2.31171103e+01  2.18963991e+01  2.06442765e+01  1.94158857e+01
  1.82665423e+01  1.72513635e+01  1.64250400e+01  1.58266643e+01
  1.54345202e+01  1.52119865e+01  1.51226988e+01  1.51304297e+01
  1.51989760e+01  1.52920900e+01  1.53811544e+01  1.54682793e+01
  1.55632828e+01  1.56760095e+01  1.58163456e+01  1.59942528e+01
  1.62198200e+01  1.65005910e+01  1.68332254e+01  1.72113505e+01
  1.76281238e+01  1.80761313e+01  1.85473308e+01  1.90330500e+01
  1.95386033e+01  2.01275568e+01  2.08791845e+01  2.18754198e+01
  2.32037011e+01  2.49610172e+01  2.72586700e+01  3.02267270e+01
  3.40158149e+01  3.87912231e+01  4.47100920e+01  5.18693126e+01
  6.02196925e+01  6.94768300e+01  7.91100857e+01  8.84771241e+01
  9.70402895e+01  1.04505716e+02  1.10816309e+02  1.16063376e+02] deg
>>> ephem("2004 QX2", interpolation_step="12H")
Empty DataFrame
Columns: [sector, camera, ccd, column, row]
Index: []
barentsen commented 3 years ago

I determined the cause of this bug to be as follows:

  1. 2004 QX2 had a close approach with Earth/TESS. During this time, its declination changed very rapidly (>degrees/day).
  2. As a result, the object ephemeris which was obtained with resolution step="7D" was too coarse, which in turn caused the interpolation performed by TessEphem.predict_sky to be inaccurate.
  3. The inaccurate interpolation included illegal values for declination (>90 degrees), which caused SkyCoord to raise the ValueError seen in the exception message above.

Graphical illustration of the ephemeris of 2004 QX2, including its close encounter:

Screen Shot 2021-01-05 at 09 42 15
barentsen commented 3 years ago

I've addressed this in cb2af02873b8efda79dca83ca31fef16c5598ce9 by setting the default interpolation step to 12H.

This is an incomplete fix because there are likely extremely fast-moving objects for which this resolution is insufficient as well.

A better fix would be to properly detect and address periods affected by extreme motion. I opened issue #3 to address this.