-
Notifications
You must be signed in to change notification settings - Fork 34
Unit expection error Ephem.from_horizons #414
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
Labels
potential bug
automated label to indicate issue reports
Comments
That astropy cannot parse the string 'hour' as a unit surprises me. I'm not able to reproduce this error, even after creating a clean environment with the same package versions:
Does the following code run for you?
Or, perhaps try running the tutorial with a clean, isolated virtual environment and sbpy installed via |
found the potential source of the curious error ... there was a cell in the
notebook:
*from astropy.units import cdscds.enable()*
if this cell is run then one gets the ValueError: hourangle is not a valid
unit.
…On Mon, Sep 16, 2024 at 3:02 PM Michael Kelley ***@***.***> wrote:
That astropy cannot parse the string 'hour' as a unit surprises me. I'm
not able to reproduce this error, even after creating a clean environment
with the same package versions:
astropy==5.3.4
astroquery==0.4.6
matplotlib==3.8.0
numpy==1.26.3
sbpy==0.5.0
scipy==1.11.4
specutils==1.11.0
Does the following code run for you?
import astropy.units as u
u.Unit('hour')
Or, perhaps try running the tutorial with a clean, isolated virtual
environment and sbpy installed via pip install sbpy[recommended]?
—
Reply to this email directly, view it on GitHub
<#414 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQ5PTL2UINOW3OB3BS7P5D3ZW42NRAVCNFSM6AAAAABOJR2JT6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJTHAYDKOJVGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Chick Woodward, Professor
Fellow American Astronomical Society
Fellow African Scientists Institute
Board Member - American Institute of Physics [AIP]
MN Institute for Astrophysics
116 Church Street, SE
University of Minnesota, Minneapolis, MN 55455
Ph: 612-624-0254 / Fax: 612-624-0254
The information transmitted in this e-mail is intended only for the person
or entity to which it is addressed and may contain confidential and/or
privileged material. If you are not the intended recipient, you are hereby
notified that any review, retransmission, dissemination, distribution, or
copying of this message is strictly prohibited. If you have received this
communication in error, please destroy and delete this message from any
computer and contact us immediately by return e-mail.
|
Ah, that makes sense! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
High-level problem description
Getting a value error thrown after jupyter notebook cell run:
ValueError: 'hour' did not parse as unit: At col 0, hour is not a valid unit. If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see https://docs.astropy.org/en/latest/units/combining_and_defining.html
What did you do?
from sbpy.data import Ephem
import astropy.units as u
from astropy.time import Time
targets = ['2100', '2018 RC1', 'Ganymed']
eph = Ephem.from_horizons(targets, location=568,
epochs={'start': Time('2018-01-01'),
'stop': Time('2018-02-01'),
'step':1*u.hour})
eph.table
What did you expect?
Should reproduce table as demonstrated in tutorial
https://github.com/NASA-Planetary-Science/sbpy-tutorial/blob/main/notebooks/data/Ephem.ipynb
What did really happen?
What is the actual result of the code snippet?
ValueError Traceback (most recent call last)
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/units/format/generic.py:587, in Generic._do_parse(cls, s, debug)
584 try:
585 # This is a short circuit for the case where the string
586 # is just a single unit name
--> 587 return cls._parse_unit(s, detailed_exception=False)
588 except ValueError as e:
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/units/format/generic.py:483, in Generic._parse_unit(cls, s, detailed_exception)
482 else:
--> 483 raise ValueError()
ValueError:
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/units/format/generic.py:453, in Generic._get_unit(cls, t)
452 try:
--> 453 return cls._parse_unit(t.value)
454 except ValueError as e:
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/units/format/generic.py:481, in Generic._parse_unit(cls, s, detailed_exception)
480 if detailed_exception:
--> 481 raise ValueError(f"{s} is not a valid unit. {did_you_mean(s, registry)}")
482 else:
ValueError: hour is not a valid unit.
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/units/core.py:2098, in _UnitMetaClass.call(self, s, represents, format, namespace, doc, parse_strict)
2097 try:
-> 2098 return f.parse(s)
2099 except NotImplementedError:
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/units/format/generic.py:571, in Generic.parse(cls, s, debug)
569 s = cls._regex_deg.sub(cls._convert_deg, s)
--> 571 result = cls._do_parse(s, debug=debug)
572 # Check for excess solidi, but exclude fractional exponents (accepted)
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/units/format/generic.py:590, in Generic._do_parse(cls, s, debug)
589 try:
--> 590 return cls._parser.parse(s, lexer=cls._lexer, debug=debug)
591 except ValueError as e:
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/utils/parsing.py:116, in ThreadSafeParser.parse(self, *args, **kwargs)
115 with self._lock:
--> 116 return self.parser.parse(*args, **kwargs)
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/extern/ply/yacc.py:333, in LRParser.parse(self, input, lexer, debug, tracking, tokenfunc)
332 else:
--> 333 return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/extern/ply/yacc.py:1063, in LRParser.parseopt_notrack(self, input, lexer, debug, tracking, tokenfunc)
1062 if not lookaheadstack:
-> 1063 lookahead = get_token() # Get the next token
1064 else:
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/extern/ply/lex.py:350, in Lexer.token(self)
348 self.lexpos = lexpos
--> 350 newtok = func(tok)
352 # Every function must return a token, if nothing, we just move to next token
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/units/format/generic.py:123, in Generic._make_lexer..t_UNIT(t)
122 "%|([YZEPTGMkhdcmu\N{MICRO SIGN}npfazy]?'((?!\d)\w)+')|((?!\d)\w)+"
--> 123 t.value = cls._get_unit(t)
124 return t
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/units/format/generic.py:459, in Generic._get_unit(cls, t)
457 return registry.aliases[t.value]
--> 459 raise ValueError(f"At col {t.lexpos}, {str(e)}")
ValueError: At col 0, hour is not a valid unit.
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
Cell In[19], line 6
3 from astropy.time import Time
5 targets = ['2100', '2018 RC1', 'Ganymed']
----> 6 eph = Ephem.from_horizons(targets, location=568,
7 epochs={'start': Time('2018-01-01'),
8 'stop': Time('2018-02-01'),
9 'step':1*u.hour})
11 eph.table
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/sbpy/utils/decorators.py:78, in requires..decorator..wrapper(*func_args, **func_kwargs)
75 except RequiredPackageUnavailable as exc:
76 # trim a couple levels of the traceback to clean up error messages
77 raise exc.with_traceback(exc.traceback.tb_next.tb_next)
---> 78 return wrapped_function(*func_args, **func_kwargs)
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/sbpy/bib/core.py:183, in cite..decorator..wrapper(*args, **kwargs)
180 @wraps(f)
181 def wrapper(*args, **kwargs):
182 # only cite after successful call
--> 183 result = f(*args, **kwargs)
184 register(f, citations)
185 return result
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/sbpy/data/ephem.py:239, in Ephem.from_horizons(cls, targetids, id_type, epochs, location, **kwargs)
236 all_eph['epoch'] = Time(all_eph['datetime_jd'], format='jd',
237 scale='utc')
238 if 'siderealtime' in all_eph.colnames:
--> 239 all_eph['siderealtime'].unit = u.Unit('hour')
241 all_eph.remove_column('datetime_jd')
242 all_eph.remove_column('datetime_str')
File ~/anaconda3/envs/sbpy/lib/python3.11/site-packages/astropy/units/core.py:2121, in _UnitMetaClass.call(self, s, represents, format, namespace, doc, parse_strict)
2111 msg = (
2112 f"'{s}' did not parse as {format_clause}unit: {str(e)} "
2113 "If this is meant to be a custom unit, "
(...)
2118 "https://docs.astropy.org/en/latest/units/combining_and_defining.html"
2119 )
2120 if parse_strict == "raise":
-> 2121 raise ValueError(msg)
2122 elif parse_strict == "warn":
2123 warnings.warn(msg, UnitsWarning)
ValueError: 'hour' did not parse as unit: At col 0, hour is not a valid unit. If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see https://docs.astropy.org/en/latest/units/combining_and_defining.html
Provide information on your environment:
print(mpl.version)
print(specutils.version)
print(scipy.version)
print(sbpy.version)
print(astropy.version)
print(np.version)
print(astroquery.version)
3.8.0
1.11.0
1.11.4
0.5.0
5.3.4
1.26.3
0.4.6
M3 MacOSX 14.2.1
The text was updated successfully, but these errors were encountered: