utils
Utility functions shared between pydantic models.
calculate_ctf_filter_stack(template_shape, optics_group, defocus_offsets, pixel_size_offsets)
Calculate searched CTF filter values for a given shape and optics group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template_shape
|
tuple[int, int]
|
Desired output shape for the filter, in real space. |
required |
optics_group
|
OpticsGroup
|
OpticsGroup object containing the optics defining the CTF parameters. |
required |
defocus_offsets
|
Tensor
|
Tensor of defocus offsets to search over, in Angstroms. |
required |
pixel_size_offsets
|
Tensor
|
Tensor of pixel size offsets to search over, in Angstroms. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Tensor of CTF filter values for the specified shape and optics group. Will have shape (num_pixel_sizes, num_defocus_offsets, h, w // 2 + 1) |
Source code in src/leopard_em/pydantic_models/utils.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
calculate_ctf_filter_stack_full_args(template_shape, defocus_u, defocus_v, defocus_offsets, pixel_size_offsets, **kwargs)
Calculate a CTF filter stack for a given set of parameters and search offsets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template_shape
|
tuple[int, int]
|
Desired output shape for the filter, in real space. |
required |
defocus_u
|
float
|
Defocus along the major axis, in Angstroms. |
required |
defocus_v
|
float
|
Defocus along the minor axis, in Angstroms. |
required |
defocus_offsets
|
Tensor
|
Tensor of defocus offsets to search over, in Angstroms. |
required |
pixel_size_offsets
|
Tensor
|
Tensor of pixel size offsets to search over, in Angstroms. |
required |
**kwargs
|
Any
|
Additional keyword to pass to the calculate_ctf_2d function. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
Tensor of CTF filter values for the specified shape and parameters. Will have shape (num_pixel_sizes, num_defocus_offsets, h, w // 2 + 1) |
# Raises
|
|
# ------
|
|
# ValueError
|
|
# If not all the required parameters are passed as additional keyword arguments.
|
|
Source code in src/leopard_em/pydantic_models/utils.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
cs_to_pixel_size(cs_vals, nominal_pixel_size, nominal_cs=2.7)
Convert Cs values to pixel sizes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cs_vals
|
Tensor
|
The Cs (spherical aberration) values. |
required |
nominal_pixel_size
|
float
|
The nominal pixel size. |
required |
nominal_cs
|
float
|
The nominal Cs value, by default 2.7. |
2.7
|
Returns:
Type | Description |
---|---|
Tensor
|
The pixel sizes. |
Source code in src/leopard_em/pydantic_models/utils.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
get_cs_range(pixel_size, pixel_size_offsets, cs=2.7)
Get the Cs values for a range of pixel sizes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pixel_size
|
float
|
The nominal pixel size. |
required |
pixel_size_offsets
|
Tensor
|
The pixel size offsets. |
required |
cs
|
float
|
The Cs (spherical aberration) value, by default 2.7. |
2.7
|
Returns:
Type | Description |
---|---|
Tensor
|
The Cs values for the range of pixel sizes. |
Source code in src/leopard_em/pydantic_models/utils.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
get_search_tensors(min_val, max_val, step_size, skip_enforce_zero=False)
Get the search tensors (pixel or defocus) for a given range and step size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_val
|
float
|
The minimum value. |
required |
max_val
|
float
|
The maximum value. |
required |
step_size
|
float
|
The step size. |
required |
skip_enforce_zero
|
bool
|
Whether to skip enforcing a zero value, by default False. |
False
|
Returns:
Type | Description |
---|---|
tensor
|
The search tensors. |
Source code in src/leopard_em/pydantic_models/utils.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
preprocess_image(image_rfft, cumulative_fourier_filters, bandpass_filter)
Preprocesses and normalizes the image based on the given filters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_rfft
|
Tensor
|
The real Fourier-transformed image (unshifted). |
required |
cumulative_fourier_filters
|
Tensor
|
The cumulative Fourier filters. Multiplication of the whitening filter, phase randomization filter, bandpass filter, and arbitrary curve filter. |
required |
bandpass_filter
|
Tensor
|
The bandpass filter used for the image. Used for dimensionality normalization. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Preprocessed and normalized image in Fourier space |
Source code in src/leopard_em/pydantic_models/utils.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
setup_images_filters_particle_stack(particle_stack, preprocessing_filters, template)
Extract and preprocess particle images and calculate filters.
This function extracts particle images from a particle stack, performs FFT, applies filters, and prepares the template for further processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particle_stack
|
ParticleStack
|
The particle stack containing images to process. |
required |
preprocessing_filters
|
PreprocessingFilters
|
Filters to apply to the particle images. |
required |
template
|
Tensor
|
The 3D template volume. |
required |
Returns:
Type | Description |
---|---|
tuple[Tensor, Tensor, Tensor]
|
A tuple containing: - particle_images_dft: The particle images in Fourier space - template_dft: The Fourier transformed template - projective_filters: Filters applied to the template |
Source code in src/leopard_em/pydantic_models/utils.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
|
setup_particle_backend_kwargs(particle_stack, template, preprocessing_filters, euler_angles, euler_angle_offsets, defocus_offsets, pixel_size_offsets, device_list)
Create common kwargs dictionary for template backend functions.
This function extracts the common code between RefineTemplateManager and OptimizeTemplateManager's make_backend_core_function_kwargs methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particle_stack
|
ParticleStack
|
The particle stack containing images to process. |
required |
template
|
Tensor
|
The 3D template volume. |
required |
preprocessing_filters
|
PreprocessingFilters
|
Filters to apply to the particle images. |
required |
euler_angles
|
Tensor
|
The set of Euler angles to use. |
required |
euler_angle_offsets
|
Tensor
|
The relative Euler angle offsets to search over. |
required |
defocus_offsets
|
Tensor
|
The relative defocus values to search over. |
required |
pixel_size_offsets
|
Tensor
|
The relative pixel size values to search over. |
required |
device_list
|
list
|
List of computational devices to use. |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Dictionary of keyword arguments for backend functions. |
Source code in src/leopard_em/pydantic_models/utils.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
|
volume_to_rfft_fourier_slice(volume)
Prepares a 3D volume for Fourier slice extraction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
volume
|
Tensor
|
The input volume. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The prepared volume in Fourier space ready for slice extraction. |
Source code in src/leopard_em/pydantic_models/utils.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|