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

Problem with version 0.3.0, Python 3.10 and Ubuntu 22.04 #113

Closed
pgr123 opened this issue Jan 10, 2023 · 18 comments
Closed

Problem with version 0.3.0, Python 3.10 and Ubuntu 22.04 #113

pgr123 opened this issue Jan 10, 2023 · 18 comments

Comments

@pgr123
Copy link

pgr123 commented Jan 10, 2023

Good morning,
I tried my old program with the new version 0.3.0 under Python 3.10 and I cannot make it work
When I try
from utide import solve,reconstruct
I get the error `
Traceback (most recent call last):

File "/tmp/ipykernel_3117/1389739857.py", line 1, in
from utide import solve,reconstruct

File "/home/pascal/.local/lib/python3.10/site-packages/utide/init.py", line 3, in
from ._solve import solve

File "/home/pascal/.local/lib/python3.10/site-packages/utide/_solve.py", line 9, in
from .harmonics import ut_E

File "/home/pascal/.local/lib/python3.10/site-packages/utide/harmonics.py", line 11, in
from ._ut_constants import ut_constants

File "/home/pascal/.local/lib/python3.10/site-packages/utide/_ut_constants.py", line 13, in
ut_constants = loadbunch(_ut_constants_fname, masked=False)

File "/home/pascal/.local/lib/python3.10/site-packages/utide/utilities.py", line 288, in loadbunch
out[k] = _structured_to_bunch(xx[k], masked=masked)

File "/usr/lib/python3/dist-packages/numpy/lib/npyio.py", line 254, in getitem
return format.read_array(bytes,

File "/usr/lib/python3/dist-packages/numpy/lib/format.py", line 743, in read_array
raise ValueError("Object arrays cannot be loaded when "

ValueError: Object arrays cannot be loaded when allow_pickle=False

Do you know why and what can I do ?
Thank you.
Good year.

Pascal
@efiring
Copy link
Collaborator

efiring commented Jan 10, 2023

Pascal, what is the version of numpy you are using?
Using utide 0.3.0 from conda-forge in a Python 3.10 environment,
with numpy 1.23.5, I can't reproduce the problem.

@efiring
Copy link
Collaborator

efiring commented Jan 10, 2023

Also, I just now tried to reproduce this on ubuntu 22.04, with

pip3 install --user utide

It works, no problem. But this is with the Ubuntu 22.04
python, which is 3.8.
I'm guessing your problem is that you are pulling in numpy from
the system python 3.8, and utide from your local python 3.10.

@pgr123
Copy link
Author

pgr123 commented Jan 11, 2023

Thank you for your answers but I have Ubuntu 22.04.1 and the default version of Python is 3.10.6-1~22.04 and not 3.8.
I have updated numpy to version 1.24.1 and try all what you suggest but that does not work.
It seems that utide is not compatible with Python 3.10.
(It works well with Ubuntu 20.04.5 and Python 3.8.10)
What can I do, please. I love utide and I hope I can continue to use it.
Thank you.
Have a good day.

@efiring
Copy link
Collaborator

efiring commented Jan 11, 2023

You are at least partly correct: I was confused about the ubuntu version on the other machine I tried.
But the problem is not python 3.10 itself, because I have tried that, and Python 3.10 is part of the
test matrix for Utide on github. Under these circumstances, the natural presumption is that there
is something odd about your installation.

I think there are clues in your traceback, e.g.:

File "/home/pascal/.local/lib/python3.10/site-packages/utide/utilities.py", line 288, in loadbunch
out[k] = _structured_to_bunch(xx[k], masked=masked)

For Utide 0.3.0, this is line 298, not 288. So it seems that what you have installed somehow is
not what it is supposed to be. You can verify this: https://github.com/wesleybowman/UTide/blame/v0.3.0/utide/utilities.py.

In general I recommend the use of miniconda, with a minimal base environment, and one or more
named working environments. This makes it easy to keep things updated, and to try different
versions of packages fully isolated in their own environments, without disturbing a primary
working environment.

@pgr123
Copy link
Author

pgr123 commented Jan 11, 2023

Thank you, but I am sorry, I verified the code and the code I use (which is installed) is the same as utilities.py and the error 'structured_to_bunch' is well on line 298 but it seems to refer to line 288 :
out = Bunch()
So I think that the problem is well reported ! And not solved !
Thank you for your help.

@ocefpaf
Copy link
Collaborator

ocefpaf commented Jan 11, 2023

So I think that the problem is well reported ! And not solved !

Not really. Can you please provide:

  • how did you install your Python?
  • are you using any sort of environment isolation?
  • pip freeze from the environment you are calling utide?

I just tested on the same Ubuntu with the system Python, creating a python 3.10 environment with pyenv, and everything works.

@pgr123
Copy link
Author

pgr123 commented Jan 11, 2023

Thank you.
I don't install Python, it is installed by Ubuntu. I use Python 3.10.6 which is the default with Ubuntu 22.04.
I don't use any environment isolation.
I did not create special environment : I made as usual pip3 install utide and/or sudo pip3 install utide.

@pgr123
Copy link
Author

pgr123 commented Jan 11, 2023

And excuse my very bad english, please.

@pgr123
Copy link
Author

pgr123 commented Jan 11, 2023

Congratulations to efiring and ocefpaf for your responsiveness.

@ocefpaf
Copy link
Collaborator

ocefpaf commented Jan 11, 2023

I did not create special environment : I made as usual pip3 install utide and/or sudo pip3 install utide.

Not a problem. Don't worry about it.

I don't install Python, it is installed by Ubuntu. I use Python 3.10.6 which is the default with Ubuntu 22.04.

You are using system python.

I don't use any environment isolation.

You should consider using it. Otherwise many issues and incompatibilities will arise from mixing packages are Ubuntu and PyPI updates them.

I did not create special environment : I made as usual pip3 install utide and/or sudo pip3 install utide.

The former is OK if it is inside an environment. The latter, using sudo, is not recommended at all. You should consider stop using sudo to install packages with pip.

Here is my environment pretty close to yours:

❯ /usr/bin/lsb_release  --all 
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.1 LTS
Release:	22.04
Codename:	jammy
❯ python3 --version
Python 3.10.6

And this is how I tested it:

  1. install pyenv: https://brain2life.hashnode.dev/how-to-install-pyenv-python-version-manager-on-ubuntu-2004
  2. pyenv install 3.10.6
  3. pyenv virtualenv 3.10.6 UTIDE
  4. pyenv activate UTIDE # You may need to use https://stackoverflow.com/questions/45577194/failed-to-activate-virtualenv-with-pyenv
  5. python -m pip install utide
  6. python -c "from utide import solve, reconstruct"

However, I highly recommend you to start using miniconda/miniforge instead. See https://ioos.github.io/ioos_code_lab/content/ioos_installation_conda.html for some instructions on how to do that.

PS: I'm 90% sure that the problem you are seeing is a bad mix of apt installed packages and pip. Without the results of pip freeze I cannot tell for sure.

@pgr123
Copy link
Author

pgr123 commented Jan 12, 2023

Here is the result of pip freeze :
pip freeze.txt

Also, When I try the test_solve.py (in the directory tests of UTide-0.3.0), I get warnings :
/usr/local/lib/python3.10/dist-packages/utide/harmonics.py:16: RuntimeWarning: invalid value encountered in cast
nshallow = np.ma.masked_invalid(const.nshallow).astype(int)
/usr/local/lib/python3.10/dist-packages/utide/harmonics.py:17: RuntimeWarning: invalid value encountered in cast
ishallow = np.ma.masked_invalid(const.ishallow).astype(int) - 1

It seems that the tests in the directory 'tests' of UTide-0.3.0 works, so the problem is surely in my program but my program works fine in Ubuntu 20.04.5 with Python 3.8 so I don't understand where is the problem with Ubuntu 22.04.1 and Python 3.10. I try on 3 differents computers.
Thank you

@efiring
Copy link
Collaborator

efiring commented Jan 12, 2023

Those warnings indicate that you are not now encountering the original exception,
which was bringing everything to a halt at the initial import stage. They also show that
you are using a different installation of UTide: in the warning, UTide is installed in
/usr/local (presumably installed using sudo), while in the original it is in your ~/.local
tree. You shouldn't be getting those warnings, though, at least with numpy 1.23.4. I
would not be surprised if there is some earlier numpy version that would generate
them, but they would be harmless.

@pgr123
Copy link
Author

pgr123 commented Jan 12, 2023

Thank you.
I think I understand where is the problem : how can I access the name, A, g of the coefficients after a call to coef=solve(d,h,...
My program uses coef['A'][i] but that does not work with the new version and in Spyder if I see coef, there is A but nothing in.
I use

print( "Onde\tA\tA_ci\tg\tg_ci")
print( "Z0\t%g" %(coef['mean']))   #This seems to work
for i in range(len(coef['name'])):    #But not that
    print( "%s\t%g\t%g\t%g\t%g" %(coef['name'][i],coef['A'][i],coef['A_ci'][i],coef['g'][i],coef['g_ci'][i]))

but that does not work ! Why ?
So, where is the problem with that new version ?
Thank you very much for your help.
Pascal

@pgr123
Copy link
Author

pgr123 commented Jan 12, 2023

WHen I run my program, I get absurd results for A, g, ... and I have the warnings :

/usr/local/lib/python3.10/dist-packages/utide/periodogram.py:342: RuntimeWarning: divide by zero encountered in scalar divide
  fs = 1 / dt  # sampling frequency: cycles (samples) per hour
/usr/local/lib/python3.10/dist-packages/utide/periodogram.py:344: RuntimeWarning: divide by zero encountered in divide
  allfrq = np.arange(nt // 2 + 1) / (nt * dt)
/usr/local/lib/python3.10/dist-packages/utide/periodogram.py:344: RuntimeWarning: invalid value encountered in divide
  allfrq = np.arange(nt // 2 + 1) / (nt * dt)
/usr/local/lib/python3.10/dist-packages/utide/periodogram.py:77: RuntimeWarning: invalid value encountered in cast
  i_constit = np.round(np.interp(cfreq, freq, indices)).astype(int)

In my data, the interval of time is da[1]-da[0]=0.0069444444961845875 (that is ten minutes).

What is the problem in periodogram.py ?

@pgr123
Copy link
Author

pgr123 commented Jan 12, 2023

I think that I solve my problem. I have to add epoch='matlab' in the opts !
Thank you very much and excuse me.

@pgr123
Copy link
Author

pgr123 commented Jan 12, 2023

But is there a doc for the new version ?
Because I did not know the parameter epoch.
It seems that now we can have the dates as a datetime and we are not obligated to have the date in matlab datenum format.
Is this true ?

@efiring
Copy link
Collaborator

efiring commented Jan 12, 2023

Yes. See the docstring for solve. Here is the top part:

Signature: utide.solve(t, u, v=None, lat=None, **opts)
Docstring:
Calculate amplitude, phase, confidence intervals of tidal constituents.

Parameters
----------
t : array_like
    Time in days since `epoch`, or np.datetime64 array, or pandas datetime array.
u : array_like
    Sea-surface height, velocity component, etc.
v : {None, array_like}, optional
    If `u` is a velocity component, `v` is the orthogonal component.
lat : float, required
    Latitude in degrees.
epoch : {string, `datetime.date`, `datetime.datetime`}, if datenum is provided in t.
    Default `None` if `t` is `datetime`, `np.datetime64`, or `pd.datetime array.`
    Optional valid strings are
        - 'python' : if `t` is days since '0000-12-31'
        - 'matlab' : if `t` is days since '0000-00-00'
    Or, an arbitrary date in the form 'YYYY-MM-DD'.

@pgr123
Copy link
Author

pgr123 commented Jan 14, 2023

Solved !
Thank you for your help !
Good week-end.

@pgr123 pgr123 closed this as completed Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants