-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
8d3b79f
9601658
5741d3b
05aeaac
9861978
3f8031d
97a2028
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]' | ||
|
@@ -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' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]" | ||
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain why we should change from np.float to float? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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) | ||
|
@@ -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'), | ||
|
@@ -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'), | ||
|
@@ -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'), | ||
|
@@ -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'), | ||
|
@@ -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'), | ||
|
@@ -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 | ||
|
||
|
There was a problem hiding this comment.
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")?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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