SHTOOLS / SHTOOLS

SHTOOLS - Spherical Harmonic Tools
https://shtools.github.io/SHTOOLS/
BSD 3-Clause "New" or "Revised" License
359 stars 106 forks source link

Matrix support for pysh.legendre.pl... #475

Open abbyazari opened 4 months ago

abbyazari commented 4 months ago

Recently I found a 'user error' bug in which passing an array instead of a float to z in pysh.legendre.plschmidt_d1 returns only the plm values for the first value of the array (e.g. only the values for z[0]) but it does not throw a user error or a warning.

I'm logging this as a feature request since it's more of a 'it would be nice if in the future if' request than a error report.

It could be useful in the future to:

Reference: https://shtools.github.io/SHTOOLS/pyplschmidt_d1.html

abbyazari commented 4 months ago

e.g. possibly something of the style of the following for now.

if not isinstance(z, (np.floating, float)):
        raise TypeError(
            "z must be a float type")
            )            
MarkWieczorek commented 4 months ago

It would be great to validate all the input parameters. I've tried to do this as much as possible with the various classes that we define, but the routine you are referring to is a fortran function that is called from python. That doesn't mean that its not possible to do, its just a little more complicated and would probably involve writing some kind of decorator that is applied to the wrapped function.

If anyone wants to try doing this, that would be great! The first step would probably first come up with a generic approach that works with all the various legendre function routines, as the parameters are all the same.

abbyazari commented 4 months ago

Thank you @MarkWieczorek! I can only think of specific fixes (e.g. check length once passed to fortran) but this is less generic than an ideal solution.

For anyone who finds this issue in the future: