3838import numpy as np
3939
4040from aspire .abinitio import CLSyncVoting
41- from aspire .noise import AnisotropicNoiseEstimator , WhiteNoiseEstimator
42- from aspire .operators import FunctionFilter , RadialCTFFilter , ScalarFilter
41+ from aspire .noise import (
42+ AnisotropicNoiseEstimator ,
43+ CustomNoiseAdder ,
44+ WhiteNoiseAdder ,
45+ WhiteNoiseEstimator ,
46+ )
47+ from aspire .operators import FunctionFilter , RadialCTFFilter
4348from aspire .source import RelionSource , Simulation
4449from aspire .utils import (
4550 Rotation ,
239244noise_variance = 100.0 * var
240245logger .info (f"noise var { noise_variance } " )
241246
242- # Then create a constant filter based on that variance
243- white_noise_filter = ScalarFilter ( dim = 2 , value = noise_variance )
247+ # Then create a CustomNoiseAdder based on that variance.
248+ white_noise_adder = WhiteNoiseAdder ( var = noise_variance )
244249# We can create a similar simulation with this additional noise_filter argument:
245- sim3 = Simulation (L = v2 .resolution , n = num_imgs , vols = v2 , noise_filter = white_noise_filter )
250+ sim3 = Simulation (L = v2 .resolution , n = num_imgs , vols = v2 , noise_adder = white_noise_adder )
246251sim3 .images [:10 ].show ()
247252# These should be rather noisy now ...
248253
314319
315320# Create another Simulation source to tinker with.
316321sim_wht = Simulation (
317- L = v2 .resolution , n = num_imgs , vols = v2 , noise_filter = white_noise_filter
322+ L = v2 .resolution , n = num_imgs , vols = v2 , noise_adder = white_noise_adder
318323)
319324
320325# Estimate the white noise.
@@ -337,12 +342,10 @@ def noise_function(x, y):
337342# In python, functions are first class objects.
338343# We take advantage of that to pass this function around as a variable.
339344# It will be evaluated later...
340- custom_noise_filter = FunctionFilter (noise_function )
345+ custom_noise = CustomNoiseAdder ( noise_filter = FunctionFilter (noise_function ) )
341346
342347# Create yet another Simulation source to tinker with.
343- sim4 = Simulation (
344- L = v2 .resolution , n = num_imgs , vols = v2 , noise_filter = custom_noise_filter
345- )
348+ sim4 = Simulation (L = v2 .resolution , n = num_imgs , vols = v2 , noise_adder = custom_noise )
346349sim4 .images [:10 ].show ()
347350
348351# %%
@@ -446,7 +449,7 @@ def noise_function(x, y):
446449 n = num_imgs ,
447450 vols = v2 ,
448451 unique_filters = filters ,
449- noise_filter = custom_noise_filter ,
452+ noise_adder = custom_noise ,
450453)
451454sim6 .images [:10 ].show ()
452455
0 commit comments