Skip to content

Commit

Permalink
ref: use negative indexing for np array shape
Browse files Browse the repository at this point in the history
  • Loading branch information
Eoghan O'Connell committed Nov 8, 2024
1 parent 2468569 commit 7d9f1ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions qpretrieve/fourier/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ def filter(self, filter_name: str, filter_size: float,
# only take shape of a single fft
fft_shape=self.fft_origin.shape[-2:])
fft_filtered = self.fft_origin * filt_array
px = int(freq_pos[0] * self.shape[0])
py = int(freq_pos[1] * self.shape[1])
px = int(freq_pos[0] * self.shape[-2])
py = int(freq_pos[1] * self.shape[-1])
fft_used = np.roll(np.roll(fft_filtered, -px, axis=0), -py, axis=1)
if scale_to_filter:
# Determine the size of the cropping region.
# We compute the "radius" of the region, so we can
# crop the data left and right from the center of the
# Fourier domain.
osize = fft_filtered.shape[0] # square shaped
osize = fft_filtered.shape[-2] # square shaped
crad = int(np.ceil(filter_size * osize * scale_to_filter))
ccent = osize // 2
cslice = slice(ccent - crad, ccent + crad)
Expand Down
6 changes: 3 additions & 3 deletions qpretrieve/interfere/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ def compute_filter_size(self, filter_size, filter_size_interpretation,
# filter size given in Fourier index (number of Fourier pixels)
# The user probably does not know that we are padding in
# Fourier space, so we use the unpadded size and translate it.
if filter_size <= 0 or filter_size >= self.fft.shape[0] / 2:
if filter_size <= 0 or filter_size >= self.fft.shape[-2] / 2:
raise ValueError("For frequency index interpretation, "
+ "`filter_size` must be between 0 and "
+ f"{self.fft.shape[0] / 2}, got "
+ f"{self.fft.shape[-2] / 2}, got "
+ f"'{filter_size}'!")
# convert to frequencies (compatible with fx and fy)
fsize = filter_size / self.fft.shape[0]
fsize = filter_size / self.fft.shape[-2]
else:
raise ValueError("Invalid value for `filter_size_interpretation`: "
+ f"'{filter_size_interpretation}'")
Expand Down

0 comments on commit 7d9f1ae

Please sign in to comment.