def test_CorrelationDistributionDecoder_smoke(testdata_laird, tmp_path_factory): """Smoke test for continuous.CorrelationDistributionDecoder.""" tmpdir = tmp_path_factory.mktemp("test_CorrelationDistributionDecoder") testdata_laird = testdata_laird.copy() features = testdata_laird.get_labels(ids=testdata_laird.ids[0])[:5] decoder = continuous.CorrelationDistributionDecoder(features=features) # No images of the requested type with pytest.raises(ValueError): decoder.fit(testdata_laird) # Let's add the path testdata_laird.update_path(tmpdir) # Then let's make some images to decode kern = kernel.MKDAKernel(r=10, value=1) dset = kern.transform(testdata_laird, return_type="dataset") # And now we have images we can use for decoding! decoder = continuous.CorrelationDistributionDecoder( features=features, target_image=kern.image_type, ) decoder.fit(dset) # Make an image to decode meta = mkda.KDA(null_method="approximate") res = meta.fit(testdata_laird) img = res.get_map("stat") decoded_df = decoder.transform(img) assert isinstance(decoded_df, pd.DataFrame)
def test_MKDAKernel_smoke(testdata_cbma): """Smoke test for nimare.meta.kernel.MKDAKernel, using Dataset object.""" kern = kernel.MKDAKernel() ma_maps = kern.transform(testdata_cbma, return_type="image") assert len(ma_maps) == len(testdata_cbma.ids) - 2 ma_maps = kern.transform(testdata_cbma.coordinates, testdata_cbma.masker, return_type="array") assert ma_maps.shape[0] == len(testdata_cbma.ids) - 2
def test_mkda_density_kernel_instance(testdata_cbma): """ Smoke test for MKDADensity with a kernel transformer object. """ kern = kernel.MKDAKernel(r=5) meta = mkda.MKDADensity(kern) res = meta.fit(testdata_cbma) assert isinstance(res, nimare.results.MetaResult)
def test_mkda_density_kernel_instance_with_kwargs(testdata_cbma): """ Smoke test for MKDADensity with a kernel transformer object, with kernel arguments provided, which should result in a warning, but the original object's parameters should remain untouched. """ kern = kernel.MKDAKernel(r=2) meta = mkda.MKDADensity(kern, kernel__r=6) assert meta.kernel_transformer.get_params().get("r") == 2
def test_MKDAKernel_2mm(testdata_cbma): """Centers of mass of MKDA kernel maps should match the foci fed in. This assumes the focus isn't masked out and spheres don't overlap. Test on 2mm template. """ id_ = "pain_03.nidm-1" kern = kernel.MKDAKernel(r=4, value=1) ma_maps = kern.transform(testdata_cbma.coordinates, testdata_cbma.masker, return_type="image") ijk = testdata_cbma.coordinates.loc[testdata_cbma.coordinates["id"] == id_, ["i", "j", "k"]] ijk = np.squeeze(ijk.values.astype(int)) kern_data = ma_maps[0].get_fdata() com = np.array(center_of_mass(kern_data)).astype(int).T com = np.squeeze(com) assert np.array_equal(ijk, com)
def test_MKDAKernel_inputdataset_returndataset(testdata_cbma, tmp_path_factory): """Check that all return types produce equivalent results (minus the masking element).""" tmpdir = tmp_path_factory.mktemp("test_MKDAKernel_inputdataset_returndataset") testdata_cbma.update_path(tmpdir) kern = kernel.MKDAKernel(r=4, value=1) ma_maps = kern.transform(testdata_cbma, return_type="image") ma_arr = kern.transform(testdata_cbma, return_type="array") dset = kern.transform(testdata_cbma, return_type="dataset") ma_maps_from_dset = kern.transform(dset, return_type="image") ma_arr_from_dset = kern.transform(dset, return_type="array") dset_from_dset = kern.transform(dset, return_type="dataset") ma_maps_arr = testdata_cbma.masker.transform(ma_maps) ma_maps_from_dset_arr = dset.masker.transform(ma_maps_from_dset) ids = dset.coordinates["id"].unique() ma_maps_dset = testdata_cbma.masker.transform(dset.get_images(ids=ids, imtype=kern.image_type)) assert isinstance(dset_from_dset, Dataset) assert np.array_equal(ma_arr, ma_maps_arr) assert np.array_equal(ma_arr, ma_maps_dset) assert np.array_equal(ma_arr, ma_maps_from_dset_arr) assert np.array_equal(ma_arr, ma_arr_from_dset)
# # ## CBMA kernels # # CBMA kernels are available as {py:class}`~nimare.meta.kernel.KernelTransformer`s in the {py:mod}`nimare.meta.kernel` module. # There are three standard kernels that are currently available: {py:class}`~nimare.meta.kernel.MKDAKernel`, {py:class}`~nimare.meta.kernel.KDAKernel`, and {py:class}`~nimare.meta.kernel.ALEKernel`. # Each class may be configured with certain parameters when a new object is initialized. # For example, `MKDAKernel` accepts an `r` parameter, which determines the radius of the spheres that will be created around each peak coordinate. # `ALEKernel` automatically uses the sample size associated with each experiment in the `Dataset` to determine the appropriate full-width-at-half-maximum of its Gaussian distribution, as described in {cite:t}`EICKHOFF20122349`; however, users may provide a constant `sample_size` or `fwhm` parameter when sample size information is not available within the `Dataset` metadata. # # Here we show how these three kernels can be applied to the same `Dataset`. # In[2]: from nimare.meta import kernel mkda_kernel = kernel.MKDAKernel(r=10) mkda_ma_maps = mkda_kernel.transform(sleuth_dset1) kda_kernel = kernel.KDAKernel(r=10) kda_ma_maps = kda_kernel.transform(sleuth_dset1) ale_kernel = kernel.ALEKernel(sample_size=20) ale_ma_maps = ale_kernel.transform(sleuth_dset1) # In[3]: # Here we delete the recent variables for the sake of reducing memory usage del mkda_kernel, kda_kernel, ale_kernel # In[4]: # Generate figure study_idx = 10 # a study with overlapping kernels