Skip to content

Commit

Permalink
fix numpy v1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Dalton committed Jun 24, 2024
1 parent cdf53c5 commit 88f1caa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion reciprocalspaceship/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,11 @@ def hkl_to_asu(self, inplace=False, anomalous=False):
# Compute new HKLs and phase shifts
hkls = dataset.get_hkls()
compressed_hkls, inverse = np.unique(hkls, axis=0, return_inverse=True)
inverse = inverse.squeeze(-1)

# The behavior of np.unique changed with v2.0. This block maintains v1 compatibility
if inverse.shape[-1] == 1:
inverse = inverse.squeeze(-1)

asu_hkls, isym, phi_coeff, phi_shift = hkl_to_asu(
compressed_hkls, dataset.spacegroup, return_phase_shifts=True
)
Expand Down
6 changes: 5 additions & 1 deletion reciprocalspaceship/utils/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def compute_dHKL(H, cell):
# Compress the hkls so we don't do redudant computation
H = np.array(H, dtype=np.float32)
hkls, inverse = np.unique(H, axis=0, return_inverse=True)
inverse = inverse.squeeze(-1)

# The behavior of np.unique changed with v2.0. This block maintains v1 compatibility
if inverse.shape[-1] == 1:
inverse = inverse.squeeze(-1)

F = np.array(cell.fractionalization_matrix.tolist()).astype(np.float64)
dhkls = np.reciprocal(np.linalg.norm((hkls @ F), 2, 1)).astype(np.float32)
return dhkls[inverse]
Expand Down
6 changes: 5 additions & 1 deletion reciprocalspaceship/utils/structurefactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ def is_centric(H, spacegroup):
"""
group_ops = spacegroup.operations()
hkl, inverse = np.unique(H, axis=0, return_inverse=True)
inverse = inverse.squeeze(-1)

# The behavior of np.unique changed with v2.0. This block maintains v1 compatibility
if inverse.shape[-1] == 1:
inverse = inverse.squeeze(-1)

centric = group_ops.centric_flag_array(hkl)
return centric[inverse]

Expand Down

0 comments on commit 88f1caa

Please sign in to comment.