insarlab / PySolid

A Python wrapper for solid Earth tides
GNU General Public License v3.0
62 stars 7 forks source link

grid: reshape error with numpy=1.22 #27

Closed yunjunz closed 2 years ago

yunjunz commented 2 years ago

With the latest release of numpy 1.22, pysolid now has a reshape error for the pysolid.grid module as below:

python ${HOME}/tools/PySolid/tests/test_SET_grid.py
Test solid Earth tides calculation for a spatial grid at a specific time
PYSOLID: ----------------------------------------
PYSOLID: datetime: 2020-12-25T14:07:44
PYSOLID: SNWE: (33.4666668, 33.8, -118.2, -117.7833335)
SOLID  : calculate solid Earth tides in east/north/up direction
SOLID  : shape: (36, 45), step size: -0.0092 by 0.0092 deg
SOLID  : calculating / writing data to txt file: /root/tools/PySolid/solid.txt
PYSOLID: read data from text file: /root/tools/PySolid/solid.txt
Traceback (most recent call last):
  File "/root/tools/PySolid/tests/test_SET_grid.py", line 34, in <module>
    tide_u) = pysolid.calc_solid_earth_tides_grid(dt_obj, atr, verbose=True)
  File "/root/tools/miniconda3/lib/python3.9/site-packages/pysolid/grid.py", line 101, in calc_solid_earth_tides_grid
    tide_e = fc[:, 0].reshape(length, width)
ValueError: cannot reshape array of size 1614 into shape (36,45)

If I pin the numpy version to <1.22, there is no issue. Thus, this seems to be an f2py module behavior change introduced in numpy 1.22 release.

yunjunz commented 2 years ago

The cause of the issue seems to be the behavior change of the numpy.loadtxt(max_rows), which used to not count the lines of comments, and now it does count. The PR above use a more relaxed call of the max num of rows, instead of the exact num of rows, to be robust against both old and new numpy behaviors.