Pycharm is not finding the functions in well known and working packages

59 Views Asked by At

I am using Pycharm to develop a script, and I would like to compute the beta angle for a specific satellite, i.e the angle between a satellite's orbital plane around Earth and the geocentric position of the sun.

To achieve this, I need to obtain the Sun's RA and DEC, and I explored the packages pyephem and PyAstronomy, with their methods ephem.SUN() and pyals.sunpos() respectively.

The problem is that it seems like these method are not defined, and pycharm raises the error Cannot find reference 'sunpos' in '__init__.py'.

I tried to explore the libraries content, and indeed it seems like those functions are not defined, but there must be a problem, since it is possible to find multiple tutorials online that use those functions.

1

There are 1 best solutions below

5
Brandon Rhodes On

The Sun class (note that only the first letter is capitalized, not all three) is loaded dynamically in PyEphem from the C-language module it compiles behind the scenes. This loop creates Sun plus an object for each planet:

https://github.com/brandon-rhodes/pyephem/blob/664f9e74cc7a39e839736e373b88b161a6877959/ephem/__init__.py#L92

# We also create a Python class ("Mercury", "Venus", etcetera) for
# each planet and moon for which _libastro offers specific algorithms.

for index, classname, name in _libastro.builtin_planets():
    exec('''
class %(name)s(_libastro.%(classname)s):
    "Create a Body instance representing %(name)s"
    __planet__ = %(index)r
''' % dict(name=name, classname=classname, index=index))

Maybe in some future version I should abandon the loop and just have a stack of nine definitions that create the objects directly. It would duplicate the list of planets between both the C and Python code, which is what I was probably trying to avoid; but how often does that list change, anyway? And it would be more explicit, which is considered an advantage in Python code; and, IDEs would understand what is going on.