ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
586 stars 161 forks source link

ENH: simpler imports, image decorator, and better code organization #637

Closed ncullen93 closed 1 month ago

ncullen93 commented 1 month ago

This PR signifcantly simplifies the import system, adds a clearer method for creating partial image functions (e.g., img.dosomething() instead of ants.dosomething(img)), and organizes the code a bit more into semantic groups.

For imports, all internal functions can now be used by calling import ants at the. top. This works because all functions are imported when ants is imported.

Now, to make a function available as a partial method to the ANTsImage class you can do the following:

from ants.decorators import image_method

@image_method
def myfunc(image):
    return image + 2

That will let you use this function as a chain on ANTsImage instances - e.g., image.myfunc().

Finally, there is a bit more code organization with some additional folders added -- label, math, and ops. The label folder is for anything with label images, the math folder is for any functions that take in an image and calculate some value, and the ops folder is for anything that takes in an image, manipulates it in some way, then returns an image.

All in all, these changes simplify development and help both users and potential contributors to better conceptualize the package. The contributors document will also be updated.

coveralls commented 1 month ago

Coverage Status

coverage: 81.148% (+0.2%) from 80.917% when pulling 0a5bf5fec39f10dcc591b4732ceb176d9a416401 on better-imports into fe4fbbb718effa0a44f4927f662f4896c79a210f on master.