Closed climeyG closed 4 months ago
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)
Thanks. That sorts it out. Is it indicative of an install issue on my side?
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!
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.
@climeyG can you please check which version of numpy you are running.
In Anaconda Prompt type:
conda activate coastsat
conda list numpy
version 2.0.0
yep that makes sense. can you check where np.math.atan2
has ended in numpy 2.0.0?
Hi Kilian
Sorry, you're dealing with someone with no coding background, bumbling along. How would I do that? I can trace this back to the init.py module, but that's as far as my limited knowledge goes.
Gerard
On Fri, 12 Jul 2024 at 04:32, Kilian Vos @.***> wrote:
yep that makes sense. can you check where np.math.atan2 has ended in numpy 2.0.0?
— Reply to this email directly, view it on GitHub https://github.com/kvos/CoastSat/issues/515#issuecomment-2224314277, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUX4A2K5WFU67SIUGOMXZ63ZL455TAVCNFSM6AAAAABKSQK4FKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRUGMYTIMRXG4 . You are receiving this because you were mentioned.Message ID: @.***>
Hello, i check where np.math.atan2 has ended in numpy 2.0.0 with that AI generated code
import numpy as np
x = 3 y = 4
result_scalar = np.math.atan2(y, x) print("Result for scalars with np.math.atan2:", result_scalar)
x_array = np.array([3, 1, -1, -3]) y_array = np.array([4, 2, -2, -4])
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
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.
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
ok so np.arctan2()
is the solution? if you want to PR this one too that would be great, otherwise I'll make the update. Thanks again for looking into this!
Yes, in my opinion, using np.arctan2()
is the appropriate solution because deltax
and deltay
are of type np.float64
. This ensures better compatibility and avoids potential issues that could arise from using the standard library's math.atan2()
.
I've created a PR to address this issue: https://github.com/kvos/CoastSat/pull/520 , thanks again for that amazing project !
When I run the reference shoreline process, I end up with the error: AttributeError: module 'numpy' has no attribute 'math'. Assistance will be appreciated.