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

Update package name of ESMPy #18

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion IOsubset.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def find_subset_indices(grdMODEL, min_lat, max_lat, min_lon, max_lon):
grdMODEL.lon = np.where(grdMODEL.lon > 180, grdMODEL.lon - 360, grdMODEL.lon)

# Array to store the results returned from the function
res = np.zeros((Turns, 4), dtype=np.float)
res = np.zeros((Turns, 4), dtype=float)

lats = grdMODEL.lat[:, 0]
lons = grdMODEL.lon[0, :]
Expand Down
18 changes: 11 additions & 7 deletions atmosForcing.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you could ensure that the code change mentioned here works and if so remove the questions and comments concerned with your code change ("# Is 'grd.Grd' correct? used to be 'grd.grdClass'
# unfinished code; 'nor' & 'mytype' not defined")?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for looking at my suggested code changes!
I am trying to get the entire atmos running without errors, but I am not finished yet. I came further than this line now and I just made a new commit (also removing those vague comments). I will continue another time and will let you know here once I succeed (or not).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok sounds good. Let me know when you have updated the code to a version that is clean and runs and I will look at your changes again and merge your code with mine

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@

try:
import ESMF
except ImportError:
print("Could not find module ESMF. Required")
sys.exit()
except:
try:
# The module name for ESMPy was changed in v8.4.0 from “ESMF” to “esmpy”
import esmpy as ESMF
except ImportError:
raise ImportError("[atmosForcing]: Could not find module ESMF/esmpy. Required")
sys.exit()

_author_ = 'Trond Kristiansen'
_email_ = '[email protected]'
Expand Down Expand Up @@ -57,13 +61,13 @@ def createAtmosFileUV(confM2R):

if confM2R.show_progress is True:
import progressbar
progress = progressbar.ProgressBar(widgets=[progressbar.Percentage(), progressbar.Bar()], maxval=len(years)).start()
progress = progressbar.ProgressBar(widgets=[progressbar.Percentage(), progressbar.Bar()], maxval=len(confM2R.years)).start()

# Create the objects for source and destination grids
# getERA5Filename # unfinished (pseudo)code

getERA5_1DAYfilename

grdMODEL = grd.grdClass(nor, mytype, mytype, useESMF,'atmos')
grdMODEL = grd.Grd(nor, mytype, mytype, useESMF,'atmos') # Is 'grd.Grd' correct? used to be 'grd.grdClass'
# unfinished code; 'nor' & 'mytype' not defined

# Create the outputfile
outfilename= abbreviation + '_windUV_' + str(mytype) + '_' + str(startdate.year) + '_to_' + str(enddate.year) + '.nc'
Expand Down
9 changes: 6 additions & 3 deletions configM2R.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,14 @@ def create_grd_objects(self):
compile.compileallgfortran()

if self.create_atmos_forcing or self.create_ocean_forcing:

try:
import ESMF
except ImportError:
raise ImportError("Unable to import ESMF")
except:
try:
# The module name for ESMPy was changed in v8.4.0 from “ESMF” to “esmpy”
import esmpy as ESMF
except ImportError:
raise ImportError("[M2R_configRunM2R]: Unable to import ESMF/esmpy")
logging.info('[M2R_configRunM2R]==> Starting logfile for ESMF')
ESMF.Manager(debug=True)

Expand Down
10 changes: 9 additions & 1 deletion grd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
from zarr.convenience import consolidate_metadata
import IOverticalGrid
import xesmf as xe
import ESMF

try:
import ESMF
except:
try:
# The module name for ESMPy was changed in v8.4.0 from “ESMF” to “esmpy”
import esmpy as ESMF
except ImportError:
raise ImportError("[grd]: Could not find module ESMF/esmpy")

__author__ = 'Trond Kristiansen'
__email__ = '[email protected]'
Expand Down
12 changes: 8 additions & 4 deletions interp2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

try:
import ESMF
except ImportError:
logging.error("[M2R_interp2D] Could not find module ESMF")
pass
except:
try:
# The module name for ESMPy was changed in v8.4.0 from “ESMF” to “esmpy”
import esmpy as ESMF
except ImportError:
logging.error("[M2R_interp2D] Could not find module ESMF/esmpy")
pass

__author__ = "Trond Kristiansen"
__email__ = "[email protected]"
Expand Down Expand Up @@ -62,7 +66,7 @@ def do_hor_interpolation_regular_grid(confM2R, mydata, myvar):
pass

index_roms, toxi, toeta, mymask = setup_indexes(confM2R, myvar)
array1 = np.zeros(index_roms, dtype=np.float)
array1 = np.zeros(index_roms, dtype=float)

# 2D or 3D interpolation
depth_levels = confM2R.grdMODEL.nlevels
Expand Down
33 changes: 19 additions & 14 deletions model2roms.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why we should change from np.float to float?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the following error:

$ python runM2R.py
test
INFO:root:[M2R_run] Initialized logging
INFO:root:[M2R_run] Started model2roms
[...]
INFO:root:[M2R_interp2D] ==> regridSrc2Dst from RHO to U, V and RHO points
Traceback (most recent call last):
  File "/export/lv6/user/jscheen/code_other_repos/model2roms/runM2R.py", line 51, in <module>
    run()
  File "/export/lv6/user/jscheen/code_other_repos/model2roms/runM2R.py", line 34, in run
    model2roms.convert_MODEL2ROMS(confM2R)
  File "/export/lv6/user/jscheen/code_other_repos/model2roms/model2roms.py", line 416, in convert_MODEL2ROMS
    IOsubset.find_subset_indices(confM2R.grdMODEL, min_lat=confM2R.subset[0], max_lat=confM2R.subset[1],
  File "/export/lv6/user/jscheen/code_other_repos/model2roms/IOsubset.py", line 43, in find_subset_indices
    res = np.zeros((Turns, 4), dtype=np.float)                                     ^^^^^^^^
  File "/export/lv6/user/jscheen/.conda/envs/model2roms_env/lib/python3.12/site-packages/numpy/__init__.py", line 324, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations.

I followed the advice written there to change np.float into float. I believe the functioning is the same. Whether you get this error, probably depends on the numpy version. I am using numpy version 1.24.3

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@

try:
import ESMF
except ImportError:
print("Could not find module ESMF")
pass
except:
try:
# The module name for ESMPy was changed in v8.4.0 from “ESMF” to “esmpy”
import esmpy as ESMF
except ImportError:
print("[model2roms.py]: could not find module ESMF/esmpy.")
pass

__author__ = 'Trond Kristiansen'
__email__ = '[email protected]'
__created__ = datetime(2008, 8, 15)
Expand All @@ -40,7 +45,7 @@ def vertical_interpolation(myvar, array1, array2, grdROMS, grdMODEL):
if myvar in ['salinity', 'temperature', 'O3_c', 'O3_TA', 'N1_p', 'N3_n', 'N5_s', 'O2_o']:
logging.info(
'Start vertical interpolation for {} (dimensions={} x {})'.format(myvar, grdROMS.xi_rho, grdROMS.eta_rho))
outdata = np.empty((outINDEX_ST), dtype=np.float, order='F')
outdata = np.empty((outINDEX_ST), dtype=float, order='F')

outdata = interp.interpolation.dovertinter(np.asarray(outdata, order='F'),
np.asarray(array1, order='F'),
Expand All @@ -66,8 +71,8 @@ def vertical_interpolation(myvar, array1, array2, grdROMS, grdMODEL):

if myvar == 'vvel':
logging.info('Start vertical interpolation for uvel (dimensions={} x {})'.format(grdROMS.xi_u, grdROMS.eta_u))
outdataU = np.zeros((outINDEX_U), dtype=np.float)
outdataUBAR = np.zeros((outINDEX_UBAR), dtype=np.float)
outdataU = np.zeros((outINDEX_U), dtype=float)
outdataUBAR = np.zeros((outINDEX_UBAR), dtype=float)

outdataU = interp.interpolation.dovertinter(np.asarray(outdataU, order='F'),
np.asarray(array1, order='F'),
Expand All @@ -84,8 +89,8 @@ def vertical_interpolation(myvar, array1, array2, grdROMS, grdMODEL):
outdataU = np.ma.masked_where(abs(outdataU) > 1000, outdataU)

logging.info('Start vertical interpolation for vvel (dimensions={} x {})'.format(grdROMS.xi_v, grdROMS.eta_v))
outdataV = np.zeros((outINDEX_V), dtype=np.float)
outdataVBAR = np.zeros((outINDEX_VBAR), dtype=np.float)
outdataV = np.zeros((outINDEX_V), dtype=float)
outdataVBAR = np.zeros((outINDEX_VBAR), dtype=float)

outdataV = interp.interpolation.dovertinter(np.asarray(outdataV, order='F'),
np.asarray(array2, order='F'),
Expand All @@ -101,8 +106,8 @@ def vertical_interpolation(myvar, array1, array2, grdROMS, grdMODEL):

outdataV = np.ma.masked_where(abs(outdataV) > 1000, outdataV)

z_wu = np.zeros((grdROMS.nlevels + 1, grdROMS.eta_u, grdROMS.xi_u), dtype=np.float)
z_wv = np.zeros((grdROMS.nlevels + 1, grdROMS.eta_v, grdROMS.xi_v), dtype=np.float)
z_wu = np.zeros((grdROMS.nlevels + 1, grdROMS.eta_u, grdROMS.xi_u), dtype=float)
z_wv = np.zeros((grdROMS.nlevels + 1, grdROMS.eta_v, grdROMS.xi_v), dtype=float)

outdataUBAR = barotropic.velocity.ubar(np.asarray(outdataU, order='F'),
np.asarray(outdataUBAR, order='F'),
Expand Down Expand Up @@ -139,8 +144,8 @@ def rotate(grdROMS, grdMODEL, data, u, v):
the rho point values to U and V points and save the result
"""

urot = np.zeros((int(grdMODEL.nlevels), int(grdROMS.eta_rho), int(grdROMS.xi_rho)), np.float)
vrot = np.zeros((int(grdMODEL.nlevels), int(grdROMS.eta_rho), int(grdROMS.xi_rho)), np.float)
urot = np.zeros((int(grdMODEL.nlevels), int(grdROMS.eta_rho), int(grdROMS.xi_rho)), float)
vrot = np.zeros((int(grdMODEL.nlevels), int(grdROMS.eta_rho), int(grdROMS.xi_rho)), float)

urot, vrot = interp.interpolation.rotate(np.asarray(urot, order='F'),
np.asarray(vrot, order='F'),
Expand All @@ -154,8 +159,8 @@ def rotate(grdROMS, grdMODEL, data, u, v):


def interpolate2uv(grdROMS, grdMODEL, urot, vrot):
Zu = np.zeros((int(grdMODEL.nlevels), int(grdROMS.eta_u), int(grdROMS.xi_u)), np.float)
Zv = np.zeros((int(grdMODEL.nlevels), int(grdROMS.eta_v), int(grdROMS.xi_v)), np.float)
Zu = np.zeros((int(grdMODEL.nlevels), int(grdROMS.eta_u), int(grdROMS.xi_u)), float)
Zv = np.zeros((int(grdMODEL.nlevels), int(grdROMS.eta_v), int(grdROMS.xi_v)), float)

# Interpolate from RHO points to U and V points for velocities

Expand Down
5 changes: 3 additions & 2 deletions runM2R.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import configM2R
import decimateGrid
import model2roms
import atmosForcing
import logging

__author__ = 'Trond Kristiansen'
Expand Down Expand Up @@ -35,8 +36,8 @@ def run():

clim2bry.writebry(confM2R)

# if confM2R.createAtmosForcing:
# atmosForcing.createAtmosFileUV(confM2R)
if confM2R.create_atmos_forcing:
atmosForcing.createAtmosFileUV(confM2R)

if confM2R.decimate_gridfile:
decimateGrid.createGrid(confM2R.grdROMS, "/Users/trondkr/Projects/KINO/GRID/kino_1600m_18072015.nc",
Expand Down