Skip to content
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ testpaths = ["tests"]
filterwarnings = [
"error",
"ignore::FutureWarning",
"ignore:.*torch.*:DeprecationWarning",
]
addopts = "-m 'not slow'" # Skip slow tests on default
markers = ["slow: marks test as slow"]
Expand Down
28 changes: 16 additions & 12 deletions src/leopard_em/pydantic_models/data_structures/particle_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ def construct_image_stack(
for img_path, indexes in image_index_groups.items():
img = load_mrc_image(img_path)

pos_y = self._df.loc[indexes, y_col].to_numpy()
pos_x = self._df.loc[indexes, x_col].to_numpy()
pos_y = self._df.loc[indexes, y_col].to_numpy().copy()
pos_x = self._df.loc[indexes, x_col].to_numpy().copy()

# If the position reference is "center", shift (x, y) by half the original
# template width/height so reference is now the top-left corner
Expand Down Expand Up @@ -571,8 +571,8 @@ def construct_cropped_statistic_stack(

# with reference to the exact pixel of the statistic (top-left)
# need to account for relative extracted box size
pos_y = self._df.loc[indexes, y_col].to_numpy()
pos_x = self._df.loc[indexes, x_col].to_numpy()
pos_y = self._df.loc[indexes, y_col].to_numpy().copy()
pos_x = self._df.loc[indexes, x_col].to_numpy().copy()

# NOTE: For both references, we need to shift both x and y
# by half the different of the original template shape and extracted box
Expand Down Expand Up @@ -620,7 +620,9 @@ def construct_filter_stack(
and (h, w) is the output shape.
"""
# Create an empty tensor to store the filter stack
filter_stack = torch.zeros((self.num_particles, *output_shape))
filter_stack = torch.zeros(
(self.num_particles, *output_shape), dtype=torch.complex64
)

# Find the indexes in the DataFrame that correspond to each unique image
image_index_groups = self._df.groupby("micrograph_path").groups
Expand Down Expand Up @@ -691,7 +693,7 @@ def get_relative_defocus(
else:
rel_defocus_col = "refined_relative_defocus"

return torch.tensor(self._df[rel_defocus_col].to_numpy())
return torch.tensor(self._df[rel_defocus_col].to_numpy().copy())

def get_absolute_defocus(
self, prefer_refined_defocus: bool = True
Expand All @@ -716,8 +718,10 @@ def get_absolute_defocus(
Angstroms.
"""
particle_defocus = self.get_relative_defocus(prefer_refined_defocus)
defocus_u = torch.tensor(self._df["defocus_u"].to_numpy()) + particle_defocus
defocus_v = torch.tensor(self._df["defocus_v"].to_numpy()) + particle_defocus
defocus_u = torch.tensor(self._df["defocus_u"].to_numpy().copy())
defocus_v = torch.tensor(self._df["defocus_v"].to_numpy().copy())
defocus_u = defocus_u + particle_defocus
defocus_v = defocus_v + particle_defocus

return defocus_u, defocus_v

Expand Down Expand Up @@ -760,7 +764,7 @@ def get_pixel_size(
else:
pixel_size_col = "refined_pixel_size"

return torch.tensor(self._df[pixel_size_col].to_numpy())
return torch.tensor(self._df[pixel_size_col].to_numpy().copy())

def get_euler_angles(self, prefer_refined_angles: bool = True) -> torch.Tensor:
"""Return the Euler angles (phi, theta, psi) of all particles as a tensor.
Expand Down Expand Up @@ -796,9 +800,9 @@ def get_euler_angles(self, prefer_refined_angles: bool = True) -> torch.Tensor:
psi_col = "refined_psi"

# Get the angles from the DataFrame
phi = torch.tensor(self._df[phi_col].to_numpy())
theta = torch.tensor(self._df[theta_col].to_numpy())
psi = torch.tensor(self._df[psi_col].to_numpy())
phi = torch.tensor(self._df[phi_col].to_numpy().copy())
theta = torch.tensor(self._df[theta_col].to_numpy().copy())
psi = torch.tensor(self._df[psi_col].to_numpy().copy())

return torch.stack((phi, theta, psi), dim=-1)

Expand Down