Skip to content

Commit

Permalink
Resolve merge conflict by incorporating both suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
knaidoo29 committed Nov 28, 2024
2 parents 0a8ff3f + 6248952 commit 17cc70e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ mistree/levy_flight/*.pyc
mistree/mst/*.pyc
mistree/tests/*.pyc
mistree/tests/__pycache__/*
.pytest_cache/*
.eggs/*

*__pycache__

Expand Down
4 changes: 2 additions & 2 deletions mistree/coords/coordinate_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def spherical_2_unit_sphere(phi, theta, units='degrees'):
x, y, z : array
cartesian coordinates.
"""
if np.isscalar(phi) is True:
if np.isscalar(phi) == True:
return spherical_2_cartesian(1., phi, theta, units=units)
else:
return spherical_2_cartesian(np.ones(len(phi)), phi, theta, units=units)
Expand All @@ -127,7 +127,7 @@ def celestial_2_unit_sphere(ra, dec, units='degrees', output='both'):
x, y, z : array
'cartesian': cartesian coordinates.
"""
if np.isscalar(ra) is True:
if np.isscalar(ra) == True:
return celestial_2_cartesian(1., ra, dec, units=units, output=output)
else:
return celestial_2_cartesian(np.ones(len(ra)), ra, dec, units=units, output=output)
Expand Down
4 changes: 2 additions & 2 deletions mistree/levy_flight/levy_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def get_levy_flight(size, mode='3D', periodic=True, box_size=75., t_0=0.2, alpha
"""
_u = np.random.uniform(0., 1., size - 1)
_steps = t_0 / (1. - _u) ** (1. / alpha)
if periodic is False:
if periodic == False:
box_size = None
if mode == '2D':
x, y = get_random_flight(_steps, mode='2D', box_size=box_size)
Expand Down Expand Up @@ -175,7 +175,7 @@ def get_adjusted_levy_flight(size, mode='3D', periodic=True, box_size=75.,
_steps = (t_0 - t_s) * (_u / beta) ** (1. / gamma) + t_s
condition = np.where(_u >= beta)[0]
_steps[condition] = t_0*(1.+((beta-_u[condition])/(1.-beta)))**(-1./alpha)
if periodic is False:
if periodic == False:
box_size = None
if mode == '2D':
x, y = get_random_flight(_steps, mode='2D', box_size=box_size)
Expand Down
8 changes: 4 additions & 4 deletions mistree/mst/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_branch_index_sub_divide(sub_divisions, edge_index, edge_degree, box_size
yy = np.arange(y_min, y_max + dy, dy)
xx_mid = 0.5 * (xx[1:len(xx)] + xx[0:len(xx) - 1])
yy_mid = 0.5 * (yy[1:len(yy)] + yy[0:len(yy) - 1])
if two_dimension is True:
if two_dimension == True:
x_div, y_div = np.meshgrid(xx_mid, yy_mid, indexing='ij')
x_div = np.ndarray.flatten(x_div)
y_div = np.ndarray.flatten(y_div)
Expand Down Expand Up @@ -215,11 +215,11 @@ def get_branch_index_sub_divide(sub_divisions, edge_index, edge_degree, box_size
length = len(phi_div)
total_mask = np.ones(len(edge_phi[0]))
for k in range(0, length):
if mode == 'Euclidean' and two_dimension is True:
if mode == 'Euclidean' and two_dimension == True:
xd, yd = x_div[k], y_div[k]
condition = np.where((total_mask == 1.) & ((edge_x[0] >= xd - dx / 2.) | (edge_x[0] <= xd + dx / 2.) |
(edge_y[0] >= yd - dx / 2.) | (edge_y[0] <= yd + dx / 2.)))[0]
elif mode == 'Euclidean' and two_dimension is False:
elif mode == 'Euclidean' and two_dimension == False:
xd, yd, zd = x_div[k], y_div[k], z_div[k]
condition = np.where((total_mask == 1.) & ((edge_x[0] >= xd - dx / 2.) | (edge_x[0] <= xd + dx / 2.) |
(edge_y[0] >= yd - dx / 2.) | (edge_y[0] < yd + dx / 2.) | (edge_z[0] >= zd - dx / 2.)
Expand All @@ -235,7 +235,7 @@ def get_branch_index_sub_divide(sub_divisions, edge_index, edge_degree, box_size
branch_index_cut_corrected = [np.ndarray.tolist(condition[i]) for i in branch_index_cut]
branch_index_total = branch_index_total + branch_index_cut_corrected
total_mask[[item for sublist in branch_index_total for item in sublist]] = 0.
if len(branch_index_rejected_cut) is not 0:
if len(branch_index_rejected_cut) != 0:
branch_index_rejected_total = branch_index_rejected_total + \
np.ndarray.tolist(condition[branch_index_rejected_cut])
total_mask[branch_index_rejected_total] = 0.
Expand Down
12 changes: 6 additions & 6 deletions mistree/mst/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ def construct_mst(x, y, z=None, k_neighbours=20, two_dimensions=False, scale_cut
num_removed_edges : int, optional
Number of removed edges. Only given and applicable if scale_cut_length is given.
"""
if two_dimensions is True:
if two_dimensions == True:
vertices = np.array([x, y]).T
else:
vertices = np.array([x, y, z]).T
if scale_cut_length != 0.:
if two_dimensions is True:
if two_dimensions == True:
x, y, k_nearest_neighbour_graph, num_removed_edges = \
scale_cut.k_nearest_neighbour_scale_cut(x, y, scale_cut_length, k_neighbours)
else:
x, y, z, k_nearest_neighbour_graph, num_removed_edges = \
scale_cut.k_nearest_neighbour_scale_cut(x, y, scale_cut_length, k_neighbours, z=z)
else:
k_nearest_neighbour_graph = kneighbors_graph(vertices, n_neighbors=k_neighbours, mode='distance')
if is_tomo is True:
if is_tomo == True:
k_nearest_neighbour_graph = tomo.convert_tomo_knn_length2angle(k_nearest_neighbour_graph, len(x))
tree = minimum_spanning_tree(k_nearest_neighbour_graph, overwrite=True)
tree = tree.tocoo()
Expand All @@ -62,18 +62,18 @@ def construct_mst(x, y, z=None, k_neighbours=20, two_dimensions=False, scale_cut
y1 = y[index1]
y2 = y[index2]
edge_y = np.array([y1, y2])
if two_dimensions is False:
if two_dimensions == False:
z1 = z[index1]
z2 = z[index2]
edge_z = np.array([z1, z2])
edge_index = np.array([index1, index2])
if scale_cut_length == 0.:
if two_dimensions is True:
if two_dimensions == True:
return edge_length, edge_x, edge_y, edge_index
else:
return edge_length, edge_x, edge_y, edge_z, edge_index
else:
if two_dimensions is True:
if two_dimensions == True:
return edge_length, edge_x, edge_y, edge_index, num_removed_edges
else:
return edge_length, edge_x, edge_y, edge_z, edge_index, num_removed_edges
4 changes: 2 additions & 2 deletions mistree/mst/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def variable_vs_density(x, y, dx, x_param, y_param, param, box_size, z=None, z_p
x_div, y_div = np.meshgrid(xx, xx, indexing='ij')
x_div, y_div = np.ndarray.flatten(x_div), np.ndarray.flatten(y_div)
mean_param = utility_density.get_param_2d(x_param, y_param, param, dx, length, len(x_div), len(x_param))
if get_density is True:
if get_density == True:
counts = utility_density.get_counts_2d(x, y, dx, length, len(x_div), len(x))
density = counts / np.mean(counts)
return mean_param, density
Expand All @@ -55,7 +55,7 @@ def variable_vs_density(x, y, dx, x_param, y_param, param, box_size, z=None, z_p
x_div, y_div, z_div = np.ndarray.flatten(x_div), np.ndarray.flatten(y_div), np.ndarray.flatten(z_div)
mean_param = utility_density.get_param_3d(x_param, y_param, z_param, param, dx, length, len(x_div),
len(x_param))
if get_density is True:
if get_density == True:
counts = utility_density.get_counts_3d(x, y, z, dx, length, len(x_div), len(x))
density = counts / np.mean(counts)
return mean_param, density
Expand Down
20 changes: 10 additions & 10 deletions mistree/mst/get_mst_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, x=None, y=None, z=None, phi=None, theta=None, ra=None, dec=No
self._mode = 'tomographic celestial'
else:
self._mode = 'spherical polar celestial'
if do_print is True:
if do_print == True:
print('MST mode: ', self._mode, ' coordinates')
self.k_neighbours = 20
self.edge_length = None
Expand Down Expand Up @@ -188,15 +188,15 @@ def get_branches(self, box_size=None, sub_divisions=1):
The number of divisions used to divide the data set in each axis. Used for speeding up the branch
finding algorithm when using many points (> 100000).
"""
if sub_divisions is 1:
if sub_divisions == 1:
branch_index, rejected_branch_index = branches.get_branch_index(self.edge_index, self.edge_degree)
else:
if self._mode is '2D':
if self._mode == '2D':
branch_index, rejected_branch_index = \
branches.get_branch_index_sub_divide(sub_divisions, self.edge_index, self.edge_degree,
box_size=box_size, edge_x=self.edge_x, edge_y=self.edge_y,
mode='Euclidean', two_dimension=True)
elif self._mode is '3D':
elif self._mode == '3D':
branch_index, rejected_branch_index = \
branches.get_branch_index_sub_divide(sub_divisions, self.edge_index, self.edge_degree,
box_size=box_size, edge_x=self.edge_x, edge_y=self.edge_y,
Expand All @@ -207,8 +207,8 @@ def get_branches(self, box_size=None, sub_divisions=1):
box_size=None, phi=self.phi, theta=self.theta,
edge_phi=self.edge_phi, edge_theta=self.edge_theta, mode='spherical')
self.branch_index = branch_index
if len(rejected_branch_index) is not 0:
if self.do_print is True:
if len(rejected_branch_index) != 0:
if self.do_print == True:
print(str(float(len(rejected_branch_index))) + ' branches were incompleted.')
branch_length = [np.sum(self.edge_length[i]) for i in branch_index]
self.branch_length = np.array(branch_length)
Expand Down Expand Up @@ -306,7 +306,7 @@ def output_stats(self, include_index=False):
branch_index : list, optional
A list of branches, where each branch is given as a list of the indexes of the member edges.
"""
if include_index is True:
if include_index == True:
return self.degree, self.edge_length, self.branch_length, self.branch_shape, self.edge_index, \
self.branch_index
else:
Expand Down Expand Up @@ -452,7 +452,7 @@ def get_stats(self, include_index=False, sub_divisions=1, k_neighbours=None,
self.__init__(ra=all_ra[group_indices], dec=all_dec[group_indices], r=all_r[group_indices])
else:
pass
if include_index is False:
if include_index == False:
_degree, _edge_length , _branch_length, _branch_shape = \
self._get_stats(sub_divisions=sub_divisions, k_neighbours=k_neighbours, scale_cut_length=scale_cut_length)
else:
Expand All @@ -468,10 +468,10 @@ def get_stats(self, include_index=False, sub_divisions=1, k_neighbours=None,
edge_length = np.concatenate([edge_length, _edge_length])
branch_length = np.concatenate([branch_length, _branch_length])
branch_shape = np.concatenate([branch_shape, _branch_shape])
if include_index is True:
if include_index == True:
edge_index.append(_edge_index)
branch_index.append(_branch_index)
if include_index is True:
if include_index == True:
return degree, edge_length, branch_length, branch_shape, edge_index, branch_index, groups
else:
return degree, edge_length, branch_length, branch_shape
Expand Down

0 comments on commit 17cc70e

Please sign in to comment.