Skip to content

Error when run aspire.cov3d with cupy #1115

@ThinkJanice

Description

@ThinkJanice

Describe the bug:
Dear ASPIRE-Python Development Team,
I am specifically working with the cov3d module from the ASPIRE package. However, after modifying the config.yaml file as shown below,
截屏2024-05-08 下午3 57 18

I encountered the following error.
截屏2024-05-08 下午3 57 08

Despite extensive research and troubleshooting attempts online, I have not found a viable solution to this issue.
I apologize for the direct approach, but I would greatly appreciate any guidance or insights you could provide on this matter. Your support would be incredibly helpful to my research.

To Reproduce:
import logging
import numpy as np
from scipy.cluster.vq import kmeans2
import starfile
import pandas as pd
import os

from aspire.basis import FFBBasis3D
from aspire.covariance import CovarianceEstimator
from aspire.noise import AnisotropicNoiseEstimator, WhiteNoiseEstimator
from aspire.reconstruction import MeanEstimator
from aspire.source.relion import RelionSource
from aspire.utils import eigs
from aspire.source.simulation import Simulation
from aspire.denoising import src_wiener_coords
from aspire.volume import Volume
from aspire.utils.random import Random

from aspire.utils import RelionStarFile
from aspire.operators import CTFFilter

logger = logging.getLogger(name)

Set input path and files and initialize other parameters

DATA_FOLDER = "xx"
STARFILE = "xx"
PIXEL_SIZE = 0.85
MAX_ROWS = None
MAX_RESOLUTION = 16
CG_TOL = 1e-5
num_vols = 2
batchsize = 500

Set number of eigen-vectors to keep

NUM_EIGS = 32

Create a source object for experimental 2D images with estimated rotation angles, relionsource only cpu

print(f"Read in images from {STARFILE} and preprocess the images.")
source = RelionSource(
STARFILE, data_folder=DATA_FOLDER, pixel_size=PIXEL_SIZE, max_rows=MAX_ROWS
)

#source.images[:].asnumpy() = source.images[:].asnumpy().astype(np.float32)
print("The dtype of source is", source.dtype)

Downsample the images

print(f"Set the resolution to {MAX_RESOLUTION} X {MAX_RESOLUTION}")
if MAX_RESOLUTION < source.L:
source = source.downsample(MAX_RESOLUTION)

Specify the fast FB basis method for expanding the 2D images

basis = FFBBasis3D((MAX_RESOLUTION, MAX_RESOLUTION, MAX_RESOLUTION), dtype=source.dtype)
print("The dtype of basis is", basis.dtype)

Estimate the noise of images

print("Estimate the noise of images using AnisotropicNoiseEstimator")
noise_estimator = AnisotropicNoiseEstimator(source, batchSize=batchsize) #check also

Whiten the noise of images

print("Whiten the noise of images from the noise estimator")
source = source.whiten(noise_estimator)
#for l in range(0, batch_num):

source = np.load('{}{:04}_rwts_mat_l.npy'.format(ffbbasis_out,l), allow_pickle=True).astype(dtype)

Estimate the noise variance. This is needed for the covariance estimation step below.

noise_variance = noise_estimator.estimate()
print(f"Noise Variance = {noise_variance}")

mean_estimator = MeanEstimator(source, basis = basis, batch_size=batchsize) # adjust the batch_size
mean_est = mean_estimator.estimate()

Passing in a mean_kernel argument to the following constructor speeds up some calculations

covar_estimator = CovarianceEstimator(source, basis = basis, mean_kernel=mean_estimator.kernel)
covar_est = covar_estimator.estimate(mean_est, noise_variance, tol=CG_TOL)

Extract the top eigenvectors and eigenvalues of the covariance estimate.

eigs_est, lambdas_est = eigs(covar_est, NUM_EIGS)
for i in range(NUM_EIGS):
print(f"Top {i}th eigen value: {lambdas_est[i, i]}")

Expected behavior:
I hope to finish 3d mean and covariance estimation

Environment (please complete the following information):

  • OS: [HPC]
  • Python: [ Python 3.8]
  • ASPIRE Version: [12.0, develop]
  • GPU Extensions: [yes]

Additional context:
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions