Skip to content

Commit

Permalink
Update MITgcmutils for numpy 2.0.0 and bug fix (MITgcm#897)
Browse files Browse the repository at this point in the history
* Update MITgcmutils for numpy 2.0.0

* Fix two bugs

* MITgcmutils now always requires matplotlib

* adjust warning statement

* Bump MITgcmutils version number

* MITgcmutils: fix bug in negative salinity check

* document fix in utils/python

---------

Co-authored-by: Martin Losch <[email protected]>
Co-authored-by: Jean-Michel Campin <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2024
1 parent c908a60 commit 83a5371
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
2 changes: 2 additions & 0 deletions doc/tag-index
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Notes on tags used in MITgcmUV
==============================

o utils/python:
- make MITgcmutils compatible with numpy 2.0.0 again.
o testreport:
- improve way of sending results tar file with "scp", now allowing to combine
"ssh" then "scp".
Expand Down
4 changes: 2 additions & 2 deletions utils/python/MITgcmutils/MITgcmutils/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ def pfromz(rC, rF0=0.0, lat=None, rhoConst=1.0275e+3, eosRefP0=1.01325e+5,
>>> pfromz(-1000,lat=[70,90])
1009.6304, 1010.2562
"""
z = np.asfarray(rC)
z = np.asarray(rC, dtype=np.float64)

assert np.all(z<=0), 'input_error: values cannot be positive'

if lat is None:
gravity = 9.81
else:
lat = np.asfarray(lat)
lat = np.asarray(lat, dtype=np.float64)
if lat.ndim == 1 and z.ndim == 1:
lat,z = np.meshgrid(lat,z)

Expand Down
49 changes: 25 additions & 24 deletions utils/python/MITgcmutils/MITgcmutils/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
def _check_salinity(s):

sneg = s<0
if not np.any(sneg):
warnings.warn('found negative salinity values, reset them to NaN')
# s[sneg] = np.NaN
if np.any(sneg):
warnings.warn('found negative salinity values')
# warnings.warn('found negative salinity values, reset them to nan')
# s[sneg] = np.nan

return s

Expand Down Expand Up @@ -105,8 +106,8 @@ def linear(salt,theta,
"""

# make sure arguments are floating point
s = np.asfarray(salt)
t = np.asfarray(theta)
s = np.asarray(salt, dtype=np.float64)
t = np.asarray(theta, dtype=np.float64)

_check_dimensions(s,t)

Expand Down Expand Up @@ -152,8 +153,8 @@ def poly3(poly3,salt,theta):
- Converted to python by Gavilan on 2024-07-18
"""
# make sure arguments are floating point
s = np.asfarray(salt)
t = np.asfarray(theta)
s = np.asarray(salt, dtype=np.float64)
t = np.asarray(theta, dtype=np.float64)
coeffs=poly3[:,3:]


Expand Down Expand Up @@ -249,9 +250,9 @@ def jmd95(salt,theta,p):
"""

# make sure arguments are floating point
s = np.asfarray(salt)
t = np.asfarray(theta)
p = np.asfarray(p)
s = np.asarray(salt, dtype=np.float64)
t = np.asarray(theta, dtype=np.float64)
p = np.asarray(p, dtype=np.float64)

_check_dimensions(s,t,p)

Expand Down Expand Up @@ -299,9 +300,9 @@ def bulkmodjmd95(salt,theta,p):
""" Compute bulk modulus
"""
# make sure arguments are floating point
s = np.asfarray(salt)
t = np.asfarray(theta)
p = np.asfarray(p)
s = np.asarray(salt, dtype=np.float64)
t = np.asarray(theta, dtype=np.float64)
p = np.asarray(p, dtype=np.float64)

# coefficients in pressure coordinates for
# 3. secant bulk modulus K of fresh water at p = 0
Expand Down Expand Up @@ -424,9 +425,9 @@ def unesco(salt,theta,p):
"""

# make sure arguments are floating point
s = np.asfarray(salt)
t = np.asfarray(theta)
p = np.asfarray(p)
s = np.asarray(salt, dtype=np.float64)
t = np.asarray(theta, dtype=np.float64)
p = np.asarray(p, dtype=np.float64)

_check_dimensions(s,t,p)

Expand Down Expand Up @@ -473,9 +474,9 @@ def bulkmodunesco(salt,theta,p):
""" Compute bulk modulus
"""
# make sure arguments are floating point
s = np.asfarray(salt)
t = np.asfarray(theta)
p = np.asfarray(p)
s = np.asarray(salt, dtype=np.float64)
t = np.asarray(theta, dtype=np.float64)
p = np.asarray(p, dtype=np.float64)

# 3. secant bulk modulus K of fresh water at p = 0
eosJMDCKFw = [ 1.965221e+04,
Expand Down Expand Up @@ -600,7 +601,7 @@ def mdjwf(salt,theta,p,epsln=0):
"""

# make sure arguments are floating point
s = np.asarray(s, dtype=np.float64)
s = np.asarray(salt, dtype=np.float64)
t = np.asarray(theta, dtype=np.float64)
p = np.asarray(p, dtype=np.float64)

Expand Down Expand Up @@ -667,7 +668,7 @@ def mdjwf(salt,theta,p,epsln=0):
)

denom = 1.0/(epsln+den)
rho = rhoNum*denom
rho = num*denom

return rho

Expand Down Expand Up @@ -704,9 +705,9 @@ def teos10(salt,theta,p,epsln=0):
"""

# make sure arguments are floating point
sa = np.asfarray(salt)
ct = np.asfarray(theta)
p = np.asfarray(p)
sa = np.asarray(salt, dtype=np.float64)
ct = np.asarray(theta, dtype=np.float64)
p = np.asarray(p, dtype=np.float64)

_check_dimensions(sa,ct,p)

Expand Down
7 changes: 2 additions & 5 deletions utils/python/MITgcmutils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="MITgcmutils",
version="0.2",
version="0.2.1",
author="MITgcm Developers and Contributors",
author_email="[email protected]",
description="Python utilities for MITgcm",
Expand All @@ -19,8 +19,5 @@
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
install_requires=["numpy"],
extras_require={
"plot": ["matplotlib"],
}
install_requires=["numpy","matplotlib"],
)

0 comments on commit 83a5371

Please sign in to comment.