Skip to content

Add support for tensor-valued spherical functions in interp_rbf#3237

Merged
skoudoro merged 7 commits intodipy:masterfrom
kvttt:3236-interp-rbf
Jun 26, 2024
Merged

Add support for tensor-valued spherical functions in interp_rbf#3237
skoudoro merged 7 commits intodipy:masterfrom
kvttt:3236-interp-rbf

Conversation

@kvttt
Copy link
Copy Markdown
Contributor

@kvttt kvttt commented May 21, 2024

Fixes #3236.

This PR adds support for tensor-valued spherical functions in interp_rbf. When the user calls this function, specifying legacy=True internally uses scipy.interpolate.Rbf which is the original behavior; specifying legacy=False internally uses scipy.interpolate.RBFInterpolator, which allows data to have arbitrary dimensions.

It would be great if I could get some feedbacks on the following questions:

  • I saw the kwarg norm is already pending deprecation and is not used in scipy.interpolate.RBFInterpolator. As of my initial commit, norm is ignored when legacy=False. Do we still want to keep norm?
  • In the docstring, function is said to be one of {'multiquadric', 'inverse', 'gaussian'}, but both scipy.interpolate.Rbf and scipy.interpolate.RBFInterpolator support a little bit more than that (see here and here). Should I change the docstring?
  • In Rbf, when epsilon=None, it internally estimate the average distance between nodes. However, in RBFInterpolator, this behavior is gone. The user has to specify epsilon when kernel is not one of {'linear', 'thin_plate_spline', 'cubic', or 'quintic'}. Should I change the docstring to reflect this new behavior?

@kvttt kvttt marked this pull request as draft May 21, 2024 18:56
@codecov
Copy link
Copy Markdown

codecov bot commented May 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.67%. Comparing base (19ae6a6) to head (92bed94).
Report is 7 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3237   +/-   ##
=======================================
  Coverage   83.67%   83.67%           
=======================================
  Files         153      152    -1     
  Lines       21381    21373    -8     
  Branches     3458     3458           
=======================================
- Hits        17890    17884    -6     
+ Misses       2629     2627    -2     
  Partials      862      862           

see 15 files with indirect coverage changes

@kvttt kvttt marked this pull request as ready for review May 22, 2024 21:31
@kvttt
Copy link
Copy Markdown
Contributor Author

kvttt commented May 23, 2024

I am not sure how to fix the two failing checks.

@skoudoro
Copy link
Copy Markdown
Member

skoudoro commented Jun 4, 2024

Hi @kvttt,

Thank you for working on this!

I would recommend to create a new function named rbf_interpolation and deprecate the interp_rbf by adding our decorator (see an example here)

I do not see any benefit to keep all this different behaviors (if legacy or not )and add complexity to the maintenance. 1 function = 1 feature/task if possible.

Do we still want to keep norm?

no

Should I change the docstring?

Yes

Should I change the docstring to reflect this new behavior?

No, since we plan to remove this version and keep only your new version

Can you update this? Thank you !

@skoudoro
Copy link
Copy Markdown
Member

skoudoro commented Jun 4, 2024

I am not sure how to fix the two failing checks.

Concerning the checks, no worries concerning this 2 checks

@skoudoro skoudoro added the type:refactoring Improvement of existing methods or implementation, including reuse of code, simplification, etc. label Jun 4, 2024
Copy link
Copy Markdown
Member

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kvttt,

Overall, it looks good. see below my last quick comments.

@arokem or @jhlegarreta, can you have a look?

"dipy.core.interpolation.interp_rbf is deprecated, "
"Please use "
"dipy.core.interpolation.rbf_interpolation instead",
since="1.9",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.10.0 instead

"Please use "
"dipy.core.interpolation.rbf_interpolation instead",
since="1.9",
until="2.0",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.12.0 instead

Comment on lines +96 to +97
def rbf_interpolation(data, sphere_origin, sphere_target,
function='multiquadric', epsilon=None, smoothing=0.1):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use keyword-only.

def rbf_interpolation(data, sphere_origin, sphere_target, *, function='multiquadric', epsilon=None, smoothing=0.1): instead

sphere_target : Sphere
M positions on the unit sphere where the spherical function is interpolated.

function : {'linear', 'thin_plate_spline', 'cubic', 'quintic', 'multiquadric', 'inverse_multiquadric',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function: str, optional
      Radial basis function. Possible values :{'linear', 'thin_plate_spline', 'cubic', 'quintic', 'multiquadric', 'inverse_multiquadric', 'inverse_quadratic', 'gaussian'}

instead.

  • no need of default

function : {'linear', 'thin_plate_spline', 'cubic', 'quintic', 'multiquadric', 'inverse_multiquadric',
'inverse_quadratic', 'gaussian'}
Radial basis function. Default: `thin_plate_spline`.
epsilon : float
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float, optional. instead

Radial basis function spread parameter.
Defaults to 1 when `function` is 'linear', 'thin_plate_spline', 'cubic', or 'quintic'.
Otherwise, `epsilon` must be specified.
smoothing : float
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float, optional. instead

scipy.interpolate.RBFInterpolator

"""
from scipy.interpolate import RBFInterpolator
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we import this here and not at the top of the file?

I need to check but can you look at it also ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there any good reason to put the import in here (there's a high likelihood I originally did this).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kvttt .

Can you address thislast comment? Then it will be ready to go
Thanks!

"""
from scipy.interpolate import RBFInterpolator

last_dim_idx = len(data.shape) - 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(data.shape) == data.ndim. can you update?

@skoudoro
Copy link
Copy Markdown
Member

skoudoro commented Jun 5, 2024

Thank you for the quick update @kvttt!

is there any additional comment ? @arokem ? @Garyfallidis ? someone else ?

Copy link
Copy Markdown
Contributor

@arokem arokem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks good to me!

scipy.interpolate.RBFInterpolator

"""
from scipy.interpolate import RBFInterpolator
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there any good reason to put the import in here (there's a high likelihood I originally did this).

Copy link
Copy Markdown
Member

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this @kvttt!

merging

@skoudoro skoudoro merged commit eaae7ad into dipy:master Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:refactoring Improvement of existing methods or implementation, including reuse of code, simplification, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow interp_rbf to accept tensor-valued spherical functions

3 participants