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

SDS_preprocess reference shoreline numpy error #515

Open
climeyG opened this issue Jul 9, 2024 · 11 comments
Open

SDS_preprocess reference shoreline numpy error #515

climeyG opened this issue Jul 9, 2024 · 11 comments

Comments

@climeyG
Copy link

climeyG commented Jul 9, 2024

When I run the reference shoreline process, I end up with the error: AttributeError: module 'numpy' has no attribute 'math'. Assistance will be appreciated.

Numpy math

@thekester
Copy link

Hello, you could add import math on SDS_preprocess.py and replace phi = np.pi/2 - np.math.atan2(deltax, deltay) by phi = np.pi/2 - math.atan2(deltax, deltay)

@climeyG
Copy link
Author

climeyG commented Jul 9, 2024

Thanks. That sorts it out. Is it indicative of an install issue on my side?

@climeyG climeyG closed this as completed Jul 9, 2024
@thekester
Copy link

Since numpy doesn't often have an attribute called "math," I'm honestly not sure why np.math works for me. It's a mystery of Python!

@kvos
Copy link
Owner

kvos commented Jul 9, 2024

numpy released version 2.0 a few weeks ago, that's probably what's causing the issue. Will check what has changed and adjust the toolbox.

@kvos kvos reopened this Jul 10, 2024
@kvos
Copy link
Owner

kvos commented Jul 10, 2024

@climeyG can you please check which version of numpy you are running.
In Anaconda Prompt type:
conda activate coastsat
conda list numpy

@climeyG
Copy link
Author

climeyG commented Jul 10, 2024

version 2.0.0

@kvos
Copy link
Owner

kvos commented Jul 12, 2024

yep that makes sense. can you check where np.math.atan2 has ended in numpy 2.0.0?

@climeyG
Copy link
Author

climeyG commented Jul 12, 2024 via email

@climeyG
Copy link
Author

climeyG commented Jul 12, 2024 via email

@thekester
Copy link

thekester commented Jul 12, 2024

Hello, i check where np.math.atan2 has ended in numpy 2.0.0 with that AI generated code

#import math
import numpy as np

Scalar values

x = 3
y = 4

Using math.atan2 via np.math

result_scalar = np.math.atan2(y, x)
print("Result for scalars with np.math.atan2:", result_scalar)

Array values

x_array = np.array([3, 1, -1, -3])
y_array = np.array([4, 2, -2, -4])

Using numpy.arctan2 for arrays

result_array = np.arctan2(y_array, x_array)
print("Result for arrays with np.arctan2:", result_array)

When i try to execute the code, i got:

DeprecationWarning: np.math is a deprecated alias for the standard library math module (Deprecated Numpy 1.25). Replace usages of np.math with math

depreciationwarningnpmath

By the way, if you try np.atan2 you got an AttributeError.

File "C:\Users\Avenel\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy_init_.py", line 347, in getattr
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'atan2'. Did you mean: 'arctan2'?

To conclude, if x and y are scalar values you should use math.atan2(x,y) but if x and y are arrays you should use np.arctan2(x,y).

Hope this will help.

@thekester
Copy link

thekester commented Jul 12, 2024

When i execute the script i got the following error Traceback (most recent call last):
File "/home/athena/Document/coastsatv2/CoastSat-master/CoastSat-master/example.py", line 108, in
settings['reference_shoreline'] = SDS_preprocess.get_reference_sl(metadata, settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/athena/Document/coastsatv2/CoastSat-master/CoastSat-master/coastsat/SDS_preprocess.py", line 942, in get_reference_sl
phi = np.pi/2 - np.math.atan2(deltax, deltay)
^^^^^^^
File "/home/athena/miniconda3/envs/coastsat/lib/python3.12/site-packages/numpy/init.py", line 410, in getattr
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'math'. Did you mean: 'emath'?
Type of deltax
<class 'numpy.float64'>
Type of deltay
<class 'numpy.float64'>
phi = np.pi/2 - np.arctan2(deltax, deltay) solve the numpy error in SDS_preprocess reference shoreline

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