Skip to content

Commit

Permalink
python 3 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
rutgerfick committed Feb 2, 2018
1 parent 599335f commit 2d5f734
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
22 changes: 11 additions & 11 deletions dmipy/core/modeling_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def _prepare_model_properties(self):

def _check_for_double_model_class_instances(self):
"Checks all models have unique class instances."
if len(self.models) != len(np.unique(self.models)):
if len(self.models) != len(set(self.models)):
msg = "Each model in the multi-compartment model must be "
msg += "instantiated separately. For example, to make a model "
msg += "with two sticks, the models must be given as "
Expand Down Expand Up @@ -641,8 +641,8 @@ def fit(self, acquisition_scheme, data, parameter_initial_guess=None,
if number_of_processors is None:
number_of_processors = cpu_count()
pool = pp.ProcessPool(number_of_processors)
print ('Using parallel processing with {} workers.').format(
number_of_processors)
print ('Using parallel processing with {} workers.'.format(
number_of_processors))
else:
fitted_parameters_lin = np.empty(
np.r_[N_voxels, N_parameters], dtype=float)
Expand All @@ -665,12 +665,12 @@ def fit(self, acquisition_scheme, data, parameter_initial_guess=None,
self, self.scheme,
parameter_initial_guess, Ns, N_sphere_samples)
fit_func = Brute2FineOptimizer(self, self.scheme, Ns)
print ('Setup brute2fine optimizer in {} seconds').format(
time() - start)
print ('Setup brute2fine optimizer in {} seconds'.format(
time() - start))
elif solver == 'mix':
fit_func = MixOptimizer(self, self.scheme, maxiter)
print ('Setup MIX optimizer in {} seconds').format(
time() - start)
print ('Setup MIX optimizer in {} seconds'.format(
time() - start))

start = time()
for idx, pos in enumerate(zip(*mask_pos)):
Expand All @@ -690,10 +690,10 @@ def fit(self, acquisition_scheme, data, parameter_initial_guess=None,
[p.get() for p in fitted_parameters_lin])

fitting_time = time() - start
print ('Fitting of {} voxels complete in {} seconds.').format(
len(fitted_parameters_lin), fitting_time)
print ('Average of {} seconds per voxel.').format(
fitting_time / N_voxels)
print ('Fitting of {} voxels complete in {} seconds.'.format(
len(fitted_parameters_lin), fitting_time))
print ('Average of {} seconds per voxel.'.format(
fitting_time / N_voxels))

fitted_parameters = np.zeros_like(x0_, dtype=float)
fitted_parameters[mask_pos] = (
Expand Down
4 changes: 2 additions & 2 deletions dmipy/core/tests/test_acquisition_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def test_shell_indices_with_vayring_diffusion_times(Nsamples=10):
# time are correctly classified in different shells
bvalues = np.tile(1e9, Nsamples)
delta = 0.01
Delta = np.hstack([np.tile(0.01, len(bvalues) / 2),
np.tile(0.03, len(bvalues) / 2)])
Delta = np.hstack([np.tile(0.01, len(bvalues) // 2),
np.tile(0.03, len(bvalues) // 2)])
gradient_directions = np.tile(np.r_[1., 0., 0.], (Nsamples, 1))
scheme = acquisition_scheme_from_bvalues(
bvalues, gradient_directions, delta, Delta)
Expand Down
2 changes: 1 addition & 1 deletion dmipy/distributions/distribute_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DistributedModel:

def _check_for_double_model_class_instances(self):
"Checks if there are no models with the same class instantiation."
if len(self.models) != len(np.unique(self.models)):
if len(self.models) != len(set(self.models)):
msg = "Each model in the multi-compartment model must be "
msg += "instantiated separately. For example, to make a model "
msg += "with two sticks, the models must be given as "
Expand Down
2 changes: 1 addition & 1 deletion dmipy/distributions/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
SPHERE_SPHERICAL = utils.cart2sphere(SPHERE_CARTESIAN)
log_bingham_normalization_splinefit = np.load(
join(DATA_PATH,
"bingham_normalization_splinefit.npz"))['arr_0']
"bingham_normalization_splinefit.npz"), encoding='bytes')['arr_0']

inverse_sh_matrix_kernel = {
sh_order: np.linalg.pinv(real_sym_sh_mrtrix(
Expand Down
6 changes: 3 additions & 3 deletions dmipy/optimizers/brute2fine.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ def precompute_signal_grid(self, model, x0_vector, Ns, N_sphere_samples):
mu = cart2mu(sphere_vertices)
grids_per_mu = []
N_model_fracts = 0
parameter_cardinality_items = model.parameter_cardinality.items()
parameter_cardinality_items = list(model.parameter_cardinality.items())
if len(model.models) > 1:
N_model_fracts = len(model.models)
parameter_cardinality_items = parameter_cardinality_items[
:-N_model_fracts
]

max_cardinality = np.max(model.parameter_cardinality.values())
max_cardinality = np.max(list(model.parameter_cardinality.values()))
for card_counter in range(max_cardinality):
per_parameter_vectors = []
counter = 0
Expand Down Expand Up @@ -143,7 +143,7 @@ def precompute_signal_grid(self, model, x0_vector, Ns, N_sphere_samples):
np.r_[[fract[i] for fract in lin_nested_fractions]])

counter = 0
for name, card in model.parameter_cardinality.items()[
for name, card in list(model.parameter_cardinality.items())[
-N_model_fracts:]:
param_dict[name] = lin_fractions[:, counter]
counter += 1
Expand Down

0 comments on commit 2d5f734

Please sign in to comment.