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

Issues importing Pytides #28

Open
deborarodriguesp opened this issue Mar 6, 2024 · 3 comments
Open

Issues importing Pytides #28

deborarodriguesp opened this issue Mar 6, 2024 · 3 comments

Comments

@deborarodriguesp
Copy link

Hello!

So I was able to install pytides, and my code starts as:

from datetime import datetime
from pytides.tide import Tide

but I am having an error:

Traceback (most recent call last):
  File "D:\DOUTORAMENTO\Tide\Tide_Extractor\predict_tidal_signal.py", line 2, in <module>
    from pytides.tide import Tide
  File "C:\Users\Debora\anaconda3\envs\tide\Lib\site-packages\pytides\__init__.py", line 3, in <module>
    import tide
ModuleNotFoundError: No module named 'tide'

I don't know why, I opened the init file, and it seems fine. I also have tide.py in my folder, so I don't understand the issue...

Can somebody help me?

The init file from pytides is:

 # -*- coding: utf-8 -*-

import tide
import astro
import constituent
import nodal_corrections
@deborarodriguesp
Copy link
Author

Okay, so I found the alterations made by others in the init file, such as:

from . import tide
from . import astro
from . import constituent
from . import nodal_corrections

or

__all__ = ['tide', 'astro', 'constituent', 'nodal_corrections']

but I still have issues:

Traceback (most recent call last):
  File "D:\DOUTORAMENTO\Tide\Tide_Extractor\predict_tidal_signal.py", line 2, in <module>
    import pytides
  File "C:\Users\Debora\anaconda3\envs\tide\Lib\site-packages\pytides\__init__.py", line 3, in <module>
    from . import tide
  File "C:\Users\Debora\anaconda3\envs\tide\Lib\site-packages\pytides\tide.py", line 2, in <module>
    from collections import OrderedDict, Iterable
ImportError: cannot import name 'Iterable' from 'collections' (C:\Users\Debora\anaconda3\envs\tide\Lib\collections\__init__.py)

@jpatiani
Copy link

jpatiani commented Mar 7, 2024

Hello,

What python version do you use?
if you use python >3.10, you can try to modify the "tide.py" file.
change:
from collections import OrderedDict, Iterable
to:
from collections import OrderedDict
from collections.abc import Iterable

Or downgrade the python to 3.9.

Best wishes.

Okay, so I found the alterations made by others in the init file, such as:

from . import tide
from . import astro
from . import constituent
from . import nodal_corrections

or

__all__ = ['tide', 'astro', 'constituent', 'nodal_corrections']

but I still have issues:

Traceback (most recent call last):
  File "D:\DOUTORAMENTO\Tide\Tide_Extractor\predict_tidal_signal.py", line 2, in <module>
    import pytides
  File "C:\Users\Debora\anaconda3\envs\tide\Lib\site-packages\pytides\__init__.py", line 3, in <module>
    from . import tide
  File "C:\Users\Debora\anaconda3\envs\tide\Lib\site-packages\pytides\tide.py", line 2, in <module>
    from collections import OrderedDict, Iterable
ImportError: cannot import name 'Iterable' from 'collections' (C:\Users\Debora\anaconda3\envs\tide\Lib\collections\__init__.py)

@deborarodriguesp
Copy link
Author

Hello!

Thanks for the help, it did work!
But I still have other issues...

So, I have harmonic components information from FES2014, and I want to use it as input for my model, but said model only allows water level, thus I need to predict the water level. I am following this guide:

For now, this is my code:

# Specify the folder where your files are located
folder = 'D:/DOUTORAMENTO/Tide/Tide_Extractor/output/'

# Get a list of all files in the folder
fileList = [f for f in os.listdir(folder) if f.startswith('tidal_data_point_') and f.endswith('.txt')]

times_to_predict = [datetime(2008, 1, 1, 0, 0, 0), datetime(2022, 1, 1, 1, 0, 0)]

# Loop through each file
for fileName in fileList:
    # Build the full path to the current file
    filePath = os.path.join(folder, fileName)

    # Extract latitude and longitude from the file name
    latLong = [float(val) for val in fileName.replace('tidal_data_point_', '').replace('.txt', '').split('_')]
    latitude, longitude = latLong[0], latLong[1]

    # Read the data from the file
    data = pd.read_csv(filePath)
    
    # Extract necessary columns (Harmonics, Amplitude, Phase)
    constituents = data['Harmonics']
    amplitude = data['Amplitude']
    phase = data['Phase']

    start_time = datetime(2008, 1, 1, 0, 0, 0)
    
    assert(len(constituents) == len(phase) == len(amplitude))
    model_dtype = np.dtype([('constituent', object), ('amplitude', float), ('phase', float)])
    model = np.zeros(len(constituents),dtype=model_dtype)
    
    model['constituent'] = constituents
    model['amplitude'] = amplitude
    model['phase'] = phase
     
    model = np.array(model, dtype=model_dtype) #class 'numpy.ndarray'

    tides = Tide(model = model, radians = False)
    print (tides)
    sys.exit()            

    predictions = Tide.at(times_to_predict)

    print(predictions)

But I have an error related to this line:

tides = Tide(model = model, radians = False)

Traceback (most recent call last):
  File "D:\DOUTORAMENTO\Tide\Tide_Extractor\predict_tidal_signal.py", line 45, in <module>
    tides = Tide(model = model, radians = False)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'module' object is not callable

My model is like this when I ask to print:

type: class 'numpy.ndarray'

[('2N2', 4.02765703e-02, 223.80827332)
 ('EPS2', 1.02526951e-02, 224.80706787)
 ('J1', 4.72657561e-03, 292.99295044) ('K1', 9.98897171e-02, 267.67913055)
 ('K2', 1.18295145e-01, 279.90310669) ('L2', 4.70057392e-02, 256.31581879)
 ('LDA2', 1.46631300e-02, 252.01350403)
 ('M2', 1.37648560e+00, 252.48448181) ('M3', 2.19242319e-03, 240.24809265)
 ('M4', 1.31006300e-02,  33.69418335) ('M6', 6.39132857e-03, 338.52811813)
 ('M8', 9.20476615e-04, 330.58880234) ('MF', 1.67496669e-02, 355.84327459)
 ('MKS2', 6.67944312e-03,  81.92492676)
 ('MM', 6.83901906e-03, 342.84502792)
 ('MN4', 1.72060204e-02, 183.27008057)
 ('MS4', 2.27821088e-02, 224.65895081)
 ('MSF', 5.90452015e-03, 204.38130188)
 ('MSQM', 6.90834969e-04,  27.4557972 )
 ('MTM', 3.43513519e-03,   3.78309369)
 ('MU2', 4.13350296e-02, 261.06427765)
 ('N2', 2.81557713e-01, 237.32936859) ('N4', 3.15371335e-03, 212.82427979)
 ('NU2', 5.81390858e-02, 231.98982239)
 ('O1', 8.83778286e-02, 239.85449982) ('P1', 2.96782804e-02, 266.59375   )
 ('Q1', 1.93028224e-02, 221.46240234) ('R2', 3.97391945e-03, 284.24746704)
 ('S1', 5.46410382e-03, 209.51295471) ('S2', 4.25421562e-01, 283.40975189)
 ('S4', 3.13920379e-03, 353.3689189 ) ('SA', 2.72539277e-04,  83.92623901)
 ('SSA', 7.11118400e-03, 358.94577336)
 ('T2', 2.91298413e-02, 284.75843048)]

So I am not sure if this is the right...
I would be very glad if someone could help me!

Thanks in advance,
Débora

Hello,

What python version do you use? if you use python >3.10, you can try to modify the "tide.py" file. change: from collections import OrderedDict, Iterable to: from collections import OrderedDict from collections.abc import Iterable

Or downgrade the python to 3.9.

Best wishes.

Okay, so I found the alterations made by others in the init file, such as:

from . import tide
from . import astro
from . import constituent
from . import nodal_corrections

or
__all__ = ['tide', 'astro', 'constituent', 'nodal_corrections']
but I still have issues:

Traceback (most recent call last):
  File "D:\DOUTORAMENTO\Tide\Tide_Extractor\predict_tidal_signal.py", line 2, in <module>
    import pytides
  File "C:\Users\Debora\anaconda3\envs\tide\Lib\site-packages\pytides\__init__.py", line 3, in <module>
    from . import tide
  File "C:\Users\Debora\anaconda3\envs\tide\Lib\site-packages\pytides\tide.py", line 2, in <module>
    from collections import OrderedDict, Iterable
ImportError: cannot import name 'Iterable' from 'collections' (C:\Users\Debora\anaconda3\envs\tide\Lib\collections\__init__.py)

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

2 participants