SciQLop / speasy

Space Physics made EASY! A simple Python package to deal with main Space Physics WebServices (CDA,SSC,AMDA,..)
Other
24 stars 7 forks source link

AttributeError: module 'speasy' has no attribute 'inventory' #27

Closed jgieseler closed 2 years ago

jgieseler commented 2 years ago

Description

The example using the dynamic inventory does not work because module 'speasy' has no attribute 'inventory'.

What I Did

First create a clean Python 3.9 environment with conda, install speasy via pip, and start python:

$ conda create --name speasy_test python=3.9
$ conda activate speasy_test
$ pip install --no-cache-dir speasy
Collecting speasy
  Downloading speasy-0.9.1-py2.py3-none-any.whl (21 kB)
[..]
Successfully installed Click-8.0.3 PyYAML-6.0 appdirs-1.4.4 astropy-5.0 attrs-21.4.0 cached-property-1.5.2 charset-normalizer-2.0.10 diskcache-5.4.0 idna-3.3 isodate-0.6.1 lxml-4.7.1 numpy-1.22.1 packaging-21.3 pandas-1.4.0 platformdirs-2.4.1 pyerfa-2.0.0.1 pyparsing-3.0.7 python-dateutil-2.8.2 pytz-2021.3 requests-2.27.1 requests-file-1.5.1 requests-toolbelt-0.9.1 six-1.16.0 speasy-0.9.1 spwc-0.9.0 urllib3-1.26.8 xmltodict-0.12.0 zeep-4.1.0
$ python

Then in python:

Python 3.9.7 (default, Sep 16 2021, 13:09:58) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import speasy
>>> speasy.__version__
'0.9.1'
>>> import speasy as spz
>>> ace_mag = spz.get_data('amda/imf', "2016-6-2", "2016-6-5")
>>> ace_mag
<speasy.common.variable.SpeasyVariable object at 0x7fb0de43e310>
>>> amda_tree = spz.inventory.data_tree.amda
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'speasy' has no attribute 'inventory'

I get the same result when using Python 3.8.12 (starting with conda create --name speasy_test python=3.8).

Using Python 3.6 or 3.7 completely fails to import speasy at all (ValueError: unsupported pickle protocol: 5), while importing with Python 3.5 causes an SyntaxError: invalid syntax. So the Python requirements according on pypi might need an update, too.

jeandet commented 2 years ago

Hello @jgieseler, you are facing two issues here.

  1. First we are quite late on schedule and dynamic inventory feature is in main branch but not released yet (it will be in 0.10.0), you can install it with pip install git+https://github.com/SciQLop/speasy
  2. You can't use speasy with python 3.6 and 3.9 at the same time, this could/should be improved in the future. The reason is that our cache is using diskcahe which uses the maximum available pickle protocol, so when you import speasy with python 3.9 you populate cache with pickled objects using protocol 5 and python 3.6 or 7 are limited to protocol 4. For now the only solution to fix this is to delete cache folder manually (you can get the path with spz.config.cache_path.get() ).

I hope this helps, Alexis.

jgieseler commented 2 years ago

Hi @jeandet, thanks for the quick reply!

  1. I see! I think it's a bit risky to update the docs to a newer version months before you introduce the changes to the actual released version. Why not do that in a different branch (like pre-release), and keep the main one untouched?
  2. Okay, thanks for the info! I assumed using different environments should take care of something like that, but you're right, the used cache folder is directly in my user home directory. Anyway, this shouldn't be a problem in general because I guess people don't usually switch that much between versions (I was just trying if this caused the initial problem).

So, I guess this issue #27 will vanish when you release version 0.10.0.

jeandet commented 2 years ago

@jgieseler,

I agree our Documentation is not great. We should be more clear about what is in main and what is released. The more we progress, the less we should change the code, the better our documentation will be ;).

Then hopefully next release will officially introduce dynamic inventories.

jgieseler commented 2 years ago

The more we progress, the less we should change the code, the better our documentation will be ;).

I'll keep fingers crossed, but this is an optimistic approach. Work is never over! 😅

jeandet commented 2 years ago

0.10.0 is out :)