Update py-bkerror Python scripts from Python 2 to Python 3#93
Update py-bkerror Python scripts from Python 2 to Python 3#93
Conversation
Agent-Logs-Url: https://github.com/NOAA-EMC/GSI-utils/sessions/4102bfae-4d3d-4d95-903c-4e805bd823d0 Co-authored-by: RussTreadon-NOAA <26926959+RussTreadon-NOAA@users.noreply.github.com>
Agent-Logs-Url: https://github.com/NOAA-EMC/GSI-utils/sessions/4102bfae-4d3d-4d95-903c-4e805bd823d0 Co-authored-by: RussTreadon-NOAA <26926959+RussTreadon-NOAA@users.noreply.github.com>
|
@copilot : The changes in this PR were tested with the following modules loaded
How do we fix this? |
Agent-Logs-Url: https://github.com/NOAA-EMC/GSI-utils/sessions/4df7bcc8-1e9a-4af9-a70b-1a1fde057bbc Co-authored-by: RussTreadon-NOAA <26926959+RussTreadon-NOAA@users.noreply.github.com>
There was a bug in I also added If the f2py error you saw is different from what's described above, could you share the complete traceback? The comment appears to have been cut off after |
Summary
Updates all Python scripts in
src/NMC_Bkerror/py-bkerror/for compatibility with Python 3 (target: Python 3.8.6–3.12.0), and fixes related issues incompile.csh.Changes
All 5 Python scripts
#!/usr/bin/env pythonto#!/usr/bin/env python3printstatements toprint()function callsndarray.tostring()(returnsbytesin Python 3) withndarray.tobytes().decode('ascii')to correctly parse variable names from the binary file headerinterp_bkerror.py(additional changes)np.floatwithfloat(np.floatwas deprecated in NumPy 1.20 and removed in 1.24)scipy.interpolate.interp2d(deprecated in scipy 1.10, removed in 1.14) with a_interp2d()wrapper backed byscipy.interpolate.RegularGridInterpolator. The wrapper preserves the same call signature (f(x_new, y_new)returning shape(len(y_new), len(x_new))), so all downstream interpolation calls are unchanged. Cubic interpolation requires scipy ≥ 1.9.compile.csh(build script fixes)--fcompiler=$FC(e.g.,--fcompiler=ifort) instead of--fcompiler=$compiler(e.g.,--fcompiler=intel). numpy.distutils only recognizes its own compiler class names — not raw compiler executable names — so this caused f2py to fail. Lines 42–43 already used$compilercorrectly; only line 45 was wrong.ifxFortran compiler (./compile.csh build ifx), using--f90exec=ifx --f77exec=ifxsince numpy.distutils does not have a built-inifxcompiler class.