jswhit / pyspharm

Automatically exported from code.google.com/p/pyspharm
Other
33 stars 18 forks source link

Minor incompatibility with xarray data arrays & suggested fix #9

Closed ajenney closed 1 month ago

ajenney commented 1 year ago

Passing a 2D xarray data array to the spharm.regrid function raises the following error

ValueError: dimensions ('latitude', 'longitude') must have the same length as the number of data dimensions, ndim=3

which can be traced back to this line in grdin.grdtospec:

datagrid = numpy.reshape(datagrid, (nlat,nlon,1))

This can be easily fixed without causing any changes to the speed or functionality of the code by replacing this line in grdin.grdtospec with the following:

datagrid = numpy.expand_dims(datagrid, axis=2)

Note: I've noticed the offending line is in multiple places throughout spharm. Might be worth addressing?

DWesl commented 2 months ago

Does #18 fix your issue?