Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce SCALE memory usage #632

Merged
merged 3 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions nimare/meta/cbma/ale.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,18 +541,23 @@ def _scale_to_p(self, stat_values, scale_values):
-----
This method also uses the "histogram_bins" element in the null_distributions_ attribute.
"""
scale_zeros = scale_values == 0
n_zeros = np.sum(scale_zeros, axis=0)
scale_values[scale_values == 0] = np.nan
scale_hists = np.zeros(
((len(self.null_distributions_["histogram_bins"]),) + n_zeros.shape)
)
scale_hists[0, :] = n_zeros
scale_hists[1:, :] = np.apply_along_axis(self._make_hist, 0, scale_values)
p_values = np.empty_like(stat_values)

for i_voxel in range(stat_values.shape[0]):
voxel_null = scale_values[:, i_voxel]
scale_zeros = voxel_null == 0
n_zeros = np.sum(scale_zeros)
voxel_null[scale_zeros] = np.nan
scale_hist = np.empty(len(self.null_distributions_["histogram_bins"]))
scale_hist[0] = n_zeros
scale_hist[1:] = self._make_hist(voxel_null)

p_values[i_voxel] = nullhist_to_p(
stat_values[i_voxel],
scale_hist,
self.null_distributions_["histogram_bins"],
)

p_values = nullhist_to_p(
stat_values, scale_hists, self.null_distributions_["histogram_bins"]
)
z_values = p_to_z(p_values, tail="one")
return p_values, z_values

Expand Down
2 changes: 1 addition & 1 deletion nimare/meta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def get_ale_kernel(img, sample_size=None, fwhm=None):
uncertain_subjects = (11.6 / (2 * np.sqrt(2 / np.pi)) * np.sqrt(8 * np.log(2))) / np.sqrt(
sample_size
) # pylint: disable=no-member
fwhm = np.sqrt(uncertain_subjects ** 2 + uncertain_templates ** 2)
fwhm = np.sqrt(uncertain_subjects**2 + uncertain_templates**2)

fwhm_vox = fwhm / np.sqrt(np.prod(img.header.get_zooms()))
sigma_vox = (
Expand Down
2 changes: 1 addition & 1 deletion nimare/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def pearson(x, y):
data = np.vstack((x, y))
ms = data.mean(axis=1)[(slice(None, None, None), None)]
datam = data - ms
datass = np.sqrt(np.sum(datam ** 2, axis=1))
datass = np.sqrt(np.sum(datam**2, axis=1))
temp = np.dot(datam[1:], datam[0].T)
rs = temp / (datass[1:] * datass[0])
return rs
Expand Down
2 changes: 1 addition & 1 deletion nimare/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def se_to_varcope(se):
-----
Sampling variance is standard error squared.
"""
varcope = se ** 2
varcope = se**2
return varcope


Expand Down
8 changes: 4 additions & 4 deletions nimare/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,12 +711,12 @@ def memmap_context(self, *args, **kwargs):


BYTE = 2
KILOBYTE = BYTE ** 10
KILOBYTE = BYTE**10
BYTE_CONVERSION = {
"kb": KILOBYTE,
"mb": KILOBYTE ** 2,
"gb": KILOBYTE ** 3,
"tb": KILOBYTE ** 4,
"mb": KILOBYTE**2,
"gb": KILOBYTE**3,
"tb": KILOBYTE**4,
}


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ install_requires =
requests
scikit-learn
scipy
statsmodels
statsmodels<0.13.2 # This version doesn't install properly
tqdm
packages = find:
include_package_data = False
Expand Down