diff --git a/pyproject.toml b/pyproject.toml index bc38fbffd..abc627939 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,31 +9,46 @@ description = "Python bindings for the SPM software." readme = "README.md" license = {file = "LICENSE"} authors = [ - {name = "Johan Medrano", email = "johan.medrano@ucl.ac.uk"}, - {name = "Yael Balbastre", email = "y.balbastre@ucl.ac.yk"}] -requires-python = ">=3.9,<3.13" + {name = "Johan Medrano", email = "johan.medrano@ucl.ac.uk"}, + {name = "Yael Balbastre", email = "y.balbastre@ucl.ac.uk"}] +requires-python = ">=3.6,<3.13" classifiers = [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", ] dependencies = [ - "numpy", - "mpython-core" + "mpython-core", + "spm-runtime-R2024b; python_version>='3.9' and python_version<'3.13'", + "spm-runtime-R2023a; python_version=='3.8'", + "spm-runtime-R2021b; python_version=='3.7'", + "spm-runtime-R2020b; python_version=='3.6'", ] +[project.optional-dependencies] +latest = ["spm-runtime"] +R2024b = ["spm-runtime-R2024b"] +R2024a = ["spm-runtime-R2024a"] +R2023b = ["spm-runtime-R2023b"] +R2023a = ["spm-runtime-R2023a"] +R2022b = ["spm-runtime-R2022b"] +R2022a = ["spm-runtime-R2022a"] +R2021b = ["spm-runtime-R2021b"] +R2021a = ["spm-runtime-R2021a"] +R2020b = ["spm-runtime-R2020b"] + [project.urls] Repository = "https://github.com/spm/spm-python" [tool.setuptools.packages] find = {} -[tool.setuptools.package-data] -spm = ["_spm/_spm.ctf"] - [tool.setuptools.dynamic] version = {attr = "spm._version.__version__"} diff --git a/spm/__init__.py b/spm/__init__.py index bd37baa29..f39f2d29c 100644 --- a/spm/__init__.py +++ b/spm/__init__.py @@ -1,5 +1,4 @@ from mpython import ( - Runtime, MatlabClass, MatlabFunction, Cell, @@ -7,6 +6,7 @@ Array, SparseArray, ) +from ._runtime import Runtime from ._version import __version__ from .file_array import file_array from .gifti import gifti diff --git a/spm/_runtime.py b/spm/_runtime.py new file mode 100644 index 000000000..b25d7e66c --- /dev/null +++ b/spm/_runtime.py @@ -0,0 +1,23 @@ +from mpython.runtime import Runtime as RuntimeBase + + +class Runtime(RuntimeBase): + """ + Runtime specialization that imports the correct CTF. + """ + + @classmethod + def _import_runtime(cls): + import spm_runtime + return spm_runtime + + +class RuntimeMixin: + """ + Mixin that SPM classes must inherit so that they can call the + correct runtime. + """ + + @classmethod + def _runtime(cls): + return Runtime diff --git a/spm/spm_pca_get_transforms.py b/spm/spm_pca_get_transforms.py deleted file mode 100644 index 775cb6448..000000000 --- a/spm/spm_pca_get_transforms.py +++ /dev/null @@ -1,12 +0,0 @@ -from spm.__wrapper__ import Runtime - - -def spm_pca_get_transforms(*args, **kwargs): - """z are latent vectors describing the space in which the MRI lives : vector of 100 elements - also get a copy of nativeMRI in template space in output_folder (optional) - - - [Link to the Matlab implementation.](https://github.com/spm/spm/blob/main/spm_pca_get_transforms.m) - """ - - return Runtime.call("spm_pca_get_transforms", *args, **kwargs) diff --git a/spm/spm_pca_project_velocity.py b/spm/spm_pca_project_velocity.py deleted file mode 100644 index ffa539f06..000000000 --- a/spm/spm_pca_project_velocity.py +++ /dev/null @@ -1,18 +0,0 @@ -from spm.__wrapper__ import Runtime - - -def spm_pca_project_velocity(*args, **kwargs): - """FORMAT z = project_velocity(v, [fmodel], [fsubspace]) - v - [Nx Ny Nz 3] Initial velocity - fmodel - Path to the model parameters {'model/model_variables.mat'} - fsubspace - Path to the scaled subspace {'model/subspace_scaled.nii'} - z - [M 1] Latent code - Yael Balabastre 2024 - ------------------------------------------------------------------------- - Path to model file - - - [Link to the Matlab implementation.](https://github.com/spm/spm/blob/main/spm_pca_project_velocity.m) - """ - - return Runtime.call("spm_pac_project_velocity", *args, **kwargs) diff --git a/spm/spm_pca_sample_brains.py b/spm/spm_pca_sample_brains.py deleted file mode 100644 index 7c39c48b9..000000000 --- a/spm/spm_pca_sample_brains.py +++ /dev/null @@ -1,24 +0,0 @@ -from spm.__wrapper__ import Runtime - - -def spm_pca_sample_brains(*args, **kwargs): - """FORMAT spm_pca_sample_brains(Nb, PC, sp, output_folder, template_folder,template_meshfiles,randseed) - Nb - Number of brains to make - PC- vector of indices principal components to use eg [8:100] - some PC indices can be negative meaning their pca components (2) will be linearly shifted in opposite direction - i.e. [1 2] and [1 -2] are two different trajectories where 2nd component moves in opposite direction - sp- span in terms of z eg 3 gives range z=-3 -> +3 - output_folder - Folder where to write generated gifti files {'.'} - template_folder- folder where the template brain principalc components - are stored - template_mesh_files- optional- defaults to cortex, but could also supply - inner-skull mesh to be deformed etc - rand_seed- optional unique file identifier (eg for different distortion - trajectories) - Jose David Lopez, Yael Balbastre, Gareth Barnes 2024 - - - [Link to the Matlab implementation.](https://github.com/spm/spm/blob/main/spm_pca_sample_brains.m) - """ - - return Runtime.call("spm_pca_sample_brains", *args, **kwargs) diff --git a/spm/spm_pca_sample_deformation.py b/spm/spm_pca_sample_deformation.py deleted file mode 100644 index 38438ef5a..000000000 --- a/spm/spm_pca_sample_deformation.py +++ /dev/null @@ -1,17 +0,0 @@ -from spm.__wrapper__ import Runtime - - -def spm_pca_sample_deformation(*args, **kwargs): - """FORMAT [iy,y] = sample_deformation([z0], [fname]) - z0 - [M 1] Latent code. NaN values will be sampled from the - distribution {default: NaN} - fname - Path to the scaled subspace fail {'model/subspace_scaled.nii'} - iy - [Nx Ny Nz 3] Inverse deformation (used to forward deform meshes) - y - [Nx Ny Nz 3] Forward deformation (used to forward deform volumes) - z - [M 1] Sampled latent code - - - [Link to the Matlab implementation.](https://github.com/spm/spm/blob/main/spm_pca_sample_deformation.m) - """ - - return Runtime.call("spm_pac_sample_deformation", *args, **kwargs) diff --git a/spm/spm_pca_transform_mesh.py b/spm/spm_pca_transform_mesh.py deleted file mode 100644 index 2ae58b516..000000000 --- a/spm/spm_pca_transform_mesh.py +++ /dev/null @@ -1,23 +0,0 @@ -from spm.__wrapper__ import Runtime - - -def spm_pca_transform_mesh(*args, **kwargs): - """FORMAT wf = transform_mesh(f, iy, [M]) - f - Input mesh (gifti object) - iy - Transformation [Mx My Mz 3] - M - Voxel-to-world matrix of the transformation {default: eye(4)} - wf - Warped mesh (gifti object) - - FORMAT wf = transform_mesh(f, T, [iy], [M]) - T - World-to-world transformation to apply to the mesh first. - - . The transformation (iy) should be expressed in millimetres, that is, - each voxel contains a millimetric coordinate in world space. - . The voxel-to-world matrix (M) should map voxels to mm. - . The affine transformation matrix (T) should map mm to mm. - - - [Link to the Matlab implementation.](https://github.com/spm/spm/blob/main/spm_pca_transform_mesh.m) - """ - - return Runtime.call("spm_pac_transform_mesh", *args, **kwargs) diff --git a/spm/spm_pca_transform_volume.py b/spm/spm_pca_transform_volume.py deleted file mode 100644 index e00b85ba4..000000000 --- a/spm/spm_pca_transform_volume.py +++ /dev/null @@ -1,20 +0,0 @@ -from spm.__wrapper__ import Runtime - - -def spm_pca_transform_volume(*args, **kwargs): - """FORMAT wf = transform_volume(f, y, [itrp], [bnd]) - f - Input volume [Nx Ny Nz ...] - y - Transformation [Mx My Mz 3] - itrp - Interpolation order {default: 1} - bnd - Boundary conditions {default: 0 = no wrapping around} - wf - Warped volume [Mx My Mz ...] - - Note that the transformation must map two voxel spaces, so it should have - already been composed with voxel-to-world affine matrices. - Yael Balbastre 2024 - - - [Link to the Matlab implementation.](https://github.com/spm/spm/blob/main/spm_pca_transform_volume.m) - """ - - return Runtime.call("spm_pac_transform_volume", *args, **kwargs) diff --git a/spm/spm_pca_warps.py b/spm/spm_pca_warps.py deleted file mode 100644 index 6fc8670a7..000000000 --- a/spm/spm_pca_warps.py +++ /dev/null @@ -1,26 +0,0 @@ -from spm.__wrapper__ import Runtime - - -def spm_pca_warps(*args, **kwargs): - """__________________________________________________________________________ - Collection of tools for manipulating non-linear transformations (warps). - - FORMAT out = warps(('warp'), in, y, (vs_in), (itrp), (bnd)) - FORMAT y = warps('compose', y_1, (vs_1), ..., y_n, (vs_n), (itrp)) - FORMAT y = warps('identity', lat_dim, (lat_vs)) - FORMAT y = warps('translation', T, lat_dim, (lat_vs)) - FORMAT y = warps('linear', L, lat_dim, (lat_vs)) - FORMAT y = warps('affine', A, lat_dim, (lat_vs)) - FORMAT y = warps('mm2vox', y, vs) - FORMAT y = warps('transform', A, y) - - FORMAT help warps>function - Returns the help file of the selected function. - __________________________________________________________________________ - Copyright (C) 2017 Wellcome Trust Centre for Neuroimaging - - - [Link to the Matlab implementation.](https://github.com/spm/spm/blob/main/spm_pca_warps.m) - """ - - return Runtime.call("spm_pac_warps", *args, **kwargs)