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

Astroquery.mpc proper_motion issues numpy.core._exceptions._UFuncNoLoopError: ufunc 'multiply' #3019

Closed
jurezakrajsek opened this issue Jun 4, 2024 · 2 comments · Fixed by #3026

Comments

@jurezakrajsek
Copy link
Contributor

Im trying to generate ephemerides with MPC.get_ephemeris()
The procedure seems to fail for some comets

  File "E:\Jure\django-apps\cobs_dev\efemeride_new.py", line 90, in main
    eph = MPC.get_ephemeris('0120P',
  File "E:\Jure\django-apps\cobs_env\lib\site-packages\astroquery\utils\class_or_instance.py", line 25, in f
    return self.fn(obj, *args, **kwds)
  File "E:\Jure\django-apps\cobs_env\lib\site-packages\astroquery\utils\process_asyncs.py", line 29, in newmethod
    result = self._parse_result(response, verbose=verbose)
  File "E:\Jure\django-apps\cobs_env\lib\site-packages\astroquery\mpc\core.py", line 1167, in _parse_result
    tab[col].convert_unit_to(self._proper_motion_unit)
  File "E:\Jure\django-apps\cobs_env\lib\site-packages\astropy\table\column.py", line 1028, in convert_unit_to
    self.data[:] = self.unit.to(new_unit, self.data, equivalencies=equivalencies)
  File "E:\Jure\django-apps\cobs_env\lib\site-packages\astropy\units\core.py", line 1195, in to
    return self._get_converter(Unit(other), equivalencies)(value)
  File "E:\Jure\django-apps\cobs_env\lib\site-packages\astropy\units\core.py", line 1103, in <lambda>
    return lambda val: scale * _condition_arg(val)
numpy.core._exceptions._UFuncNoLoopError: ufunc 'multiply' did not contain a loop with signature matching types (dtype('float64'), dtype('<U9')) -> None

Here is my script:

from astroquery.mpc import MPC

eph = MPC.get_ephemeris('0120P',
                        location='106',
                        start='2024-06-04 20:00:00',
                        number=20,
                        step='30min',
                        ra_format={'sep': ':', 'unit': 'hourangle', 'precision': 1, 'pad': True},
                        dec_format={'sep': ':', 'precision': 0, 'alwayssign': True, 'pad': True},
                        proper_motion='sky',
                        proper_motion_unit='arcsec/min'
                        )

The issue seems to get from the arguments

 proper_motion='sky',
 proper_motion_unit='arcsec/min' 

If I remove this from the query I get the results returned.

If I try to generate the ephemeris from the website I get the result for comet 120P.

0120P
Date       UT      R.A. (J2000) Decl.    Delta     r     El.    Ph.   m1     Sky Motion        Object    Sun   Moon
            h m s                                                            "/min    "/min   Azi. Alt.  Alt.  Phase Dist. Alt.
2024 06 03 210000 12 13 32.8 -04 21 25   4.808   5.263  111.4  10.3  22.6   -0.013   -0.002   225  +29   -17   0.09   146  -27
2024 06 03 213000 12 13 32.8 -04 21 25   4.808   5.263  111.4  10.3  22.6   -0.012   -0.002   233  +25   -19   0.09   146  -26
2024 06 03 220000 12 13 32.8 -04 21 25   4.808   5.263  111.4  10.3  22.6   -0.012   -0.002   239  +21   -20   0.09   146  -25

How could I resolve this issue?

@jurezakrajsek
Copy link
Contributor Author

jurezakrajsek commented Jun 6, 2024

I think I found an issue with the parsing of the MPC ephemeris results.
The

This is the result for comet 113P produced today and where my error happens today.

Date       UT      R.A. (J2000) Decl.    Delta     r     El.    Ph.   m1     Sky Motion        Object    Sun   Moon
            h m s                                                            "/hr     "/hr    Azi. Alt.  Alt.  Phase Dist. Alt.
2024 06 06 195900 12 34 22.7 -10 03 31   3.997   4.527  115.5  11.7  23.1   -0.13    +2.96    204  +31   -10   0.00   112  -04
2024 06 06 202900 12 34 22.7 -10 03 29   3.998   4.527  115.4  11.7  23.1   -0.099   +2.97    212  +29   -13   0.00   112  -07
2024 06 06 205900 12 34 22.7 -10 03 28   3.998   4.527  115.4  11.7  23.1   -0.060   +2.97    220  +26   -16   0.00   111  -10
2024 06 06 212900 12 34 22.7 -10 03 26   3.998   4.527  115.4  11.7  23.1   -0.016   +2.97    227  +22   -18   0.00   111  -12
2024 06 06 215900 12 34 22.7 -10 03 25   3.999   4.527  115.4  11.7  23.1   +0.033   +2.98    234  +18   -20   0.00   111  -14
2024 06 06 222900 12 34 22.7 -10 03 23   3.999   4.528  115.4  11.7  23.1   +0.087   +2.98    240  +13   -21   0.00   111  -15
2024 06 06 225900 12 34 22.7 -10 03 22   3.999   4.528  115.3  11.7  23.1   +0.14    +2.98    246  +09   -22   0.00   110  -16

As can be seen the SkyMotion columns sometimes have the precision of 3 decimals arcsec/h.
So I looked at the _parse_result(self, result, **kwargs) function in the MPCClass and tried to print out the table of parsed results just after

tab = ascii.read(text_table, format='fixed_width_no_header',
                 names=names, col_starts=col_starts,
                 col_ends=col_ends, data_start=data_start,
                 fill_values=(('N/A', np.nan),), fast_reader=False)
for col, unit in zip(names, units):
    tab[col].unit = unit
print(tab)                             

And here is what I get:

113P/Spitaler
       Date           RA        Dec    Delta   r   Elongation Phase  V   dRA cos(Dec)    dDec    Azimuth Altitude Sun altitude Moon phase Moon distance Moon altitude
                                         AU    AU     deg      deg  mag   arcsec / h  arcsec / h   deg     deg        deg                      deg           deg
----------------- ---------- --------- ----- ----- ---------- ----- ---- ------------ ---------- ------- -------- ------------ ---------- ------------- -------------
2024 06 06 200000 12 34 22.7 -10 03 31 3.997 4.527      115.5  11.7 23.1        -0.13      +2.96     205       31          -10        0.0           112            -4
2024 06 06 203000 12 34 22.7 -10 03 29 3.998 4.527      115.4  11.7 23.1        -0.09  8   +2.97     213       29          -13        0.0           112            -7
2024 06 06 210000 12 34 22.7 -10 03 28 3.998 4.527      115.4  11.7 23.1        -0.05  9   +2.97     220       25          -16        0.0           111           -10
2024 06 06 213000 12 34 22.7 -10 03 26 3.998 4.527      115.4  11.7 23.1        -0.01  4   +2.97     227       22          -18        0.0           111           -12
2024 06 06 220000 12 34 22.7 -10 03 25 3.999 4.527      115.4  11.7 23.1         0.03  5   +2.98     234       18          -20        0.0           111           -14
2024 06 06 223000 12 34 22.7 -10 03 23 3.999 4.528      115.4  11.7 23.1         0.08  9   +2.98     240       13          -21        0.0           111           -15

As can be seen the dRA cos(Dec) and dDec are parsed inccorectlly where the precision fo dRA cos(Dec) is 3 decimals. The last digit is already parsed to the dDec column making it a string instead of a float column and the conversion to arcsec/min later fails.

The issue comes from setting the col_start and col_ends for Sky Motion in the _parse_result()
Current code:

elif 's=s' in result.request.body:  # sky Motion
    names += ('dRA cos(Dec)', 'dDec')
    units += ('arcsec/h', 'arcsec/h')
col_starts += (73, 81)
col_ends += (80, 89)

if 'Moon' in columns:
    # table includes Alt, Az, Sun and Moon geometry
    names += ('Azimuth', 'Altitude', 'Sun altitude', 'Moon phase',
              'Moon distance', 'Moon altitude')
    col_starts += tuple((col_ends[-1] + offset for offset in
                         (2, 9, 14, 20, 27, 33)))
    col_ends += tuple((col_ends[-1] + offset for offset in
                       (8, 13, 19, 26, 32, 37)))
    units += ('deg', 'deg', 'deg', None, 'deg', 'deg')

To fix this we need to parse one character more so the end of dRA cos(Dec) column is shifted one character to the right. But also the dDec column can have 3 decimals precision so the end of the column must also be shifted to the right now for 2 characters to column 91.

But changing the col_ends has the effect on all remaining columns, so we need to adjust the next part and all the starts and ands must be moved now one character to the left.

Corrected code

elif 's=s' in result.request.body:  # sky Motion
    names += ('dRA cos(Dec)', 'dDec')
    units += ('arcsec/h', 'arcsec/h')
col_starts += (73, 82)
col_ends += (81, 91)

if 'Moon' in columns:
    # table includes Alt, Az, Sun and Moon geometry
    names += ('Azimuth', 'Altitude', 'Sun altitude', 'Moon phase',
              'Moon distance', 'Moon altitude')
    col_starts += tuple((col_ends[-1] + offset for offset in
                         (1, 8, 13, 19, 26, 32)))
    col_ends += tuple((col_ends[-1] + offset for offset in
                       (7, 12, 18, 25, 31, 36)))
    units += ('deg', 'deg', 'deg', None, 'deg', 'deg')

This way I get the results parsed as expected and conversion to arcsec/min works:

113P/Spitaler
       Date           RA        Dec    Delta   r   Elongation Phase  V   dRA cos(Dec)    dDec    Azimuth Altitude Sun altitude Moon phase Moon distance Moon altitude
                                         AU    AU     deg      deg  mag   arcsec / h  arcsec / h   deg     deg        deg                      deg           deg
----------------- ---------- --------- ----- ----- ---------- ----- ---- ------------ ---------- ------- -------- ------------ ---------- ------------- -------------
2024 06 06 200000 12 34 22.7 -10 03 31 3.997 4.527      115.5  11.7 23.1        -0.13       2.96     205       31          -10        0.0           112            -4
2024 06 06 203000 12 34 22.7 -10 03 29 3.998 4.527      115.4  11.7 23.1       -0.098       2.97     213       29          -13        0.0           112            -7
2024 06 06 210000 12 34 22.7 -10 03 28 3.998 4.527      115.4  11.7 23.1       -0.059       2.97     220       25          -16        0.0           111           -10
2024 06 06 213000 12 34 22.7 -10 03 26 3.998 4.527      115.4  11.7 23.1       -0.014       2.97     227       22          -18        0.0           111           -12
2024 06 06 220000 12 34 22.7 -10 03 25 3.999 4.527      115.4  11.7 23.1        0.035       2.98     234       18          -20        0.0           111           -14
2024 06 06 223000 12 34 22.7 -10 03 23 3.999 4.528      115.4  11.7 23.1        0.089       2.98     240       13          -21        0.0           111           -15

@bsipocz
Copy link
Member

bsipocz commented Jun 11, 2024

cc @mkelley

jurezakrajsek added a commit to jurezakrajsek/astroquery that referenced this issue Jun 15, 2024
…recision

Modified test and data set for 3 digit sky motion precision
@bsipocz bsipocz linked a pull request Jun 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants