Skip to content

Commit d359217

Browse files
authored
Merge pull request #827 from ComputationalCryoEM/develop
Develop ~~> Master v0.10.1 Updates
2 parents 007204f + dbe04ae commit d359217

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1966
-1052
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: ASPIRE Python Daily Build CI
2+
3+
on:
4+
schedule:
5+
-cron: '0 0 * * *'
6+
7+
jobs:
8+
dev_docs:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
with:
13+
ref: develop
14+
- name: Setup Python
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: '3.7'
18+
- name: Install Dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install -e ".[dev]"
22+
- name: Build Sphinx docs
23+
run: |
24+
make clean
25+
sphinx-apidoc -f -o ./source ../src -H Modules
26+
make html
27+
working-directory: ./docs
28+
- name: Archive Sphinx docs
29+
uses: actions/upload-artifact@v3
30+
with:
31+
name: sphinx-docs
32+
path: docs
33+
retention-days: 7

gallery/experiments/simulated_abinitio_pipeline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from aspire.basis import FFBBasis2D, FFBBasis3D
2525
from aspire.classification import BFSReddyChatterjiAverager2D, RIRClass2D
2626
from aspire.denoising import DenoiserCov2D
27-
from aspire.noise import AnisotropicNoiseEstimator
27+
from aspire.noise import AnisotropicNoiseEstimator, CustomNoiseAdder
2828
from aspire.operators import FunctionFilter, RadialCTFFilter
2929
from aspire.reconstruction import MeanEstimator
3030
from aspire.source import Simulation
@@ -81,7 +81,7 @@ def noise_function(x, y):
8181
return (alpha * f1 + beta * f2) / 2.0
8282

8383

84-
custom_noise_filter = FunctionFilter(noise_function)
84+
custom_noise = CustomNoiseAdder(noise_filter=FunctionFilter(noise_function))
8585

8686
logger.info("Initialize CTF filters.")
8787
# Create some CTF effects
@@ -104,7 +104,7 @@ def noise_function(x, y):
104104
L=v.resolution,
105105
n=num_imgs,
106106
vols=v,
107-
noise_filter=custom_noise_filter,
107+
noise_adder=custom_noise,
108108
unique_filters=ctf_filters,
109109
dtype=v.dtype,
110110
)

gallery/tutorials/basic_image_array.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
from scipy import misc
1515

1616
from aspire.image import Image
17-
from aspire.image.xform import NoiseAdder
18-
from aspire.noise import AnisotropicNoiseEstimator
19-
from aspire.operators import FunctionFilter, ScalarFilter
17+
from aspire.noise import AnisotropicNoiseEstimator, CustomNoiseAdder, WhiteNoiseAdder
18+
from aspire.operators import FunctionFilter
2019
from aspire.source import ArrayImageSource
2120

2221
# %%
@@ -46,19 +45,18 @@
4645
# Construct the Image class by passing it an array of data.
4746
img = Image(stock_img)
4847
# Downsample (just to speeds things up)
49-
new_resolution = img.res // 4
48+
new_resolution = img.resolution // 4
5049
img = img.downsample(new_resolution)
5150

5251

5352
# We will begin processing by adding some noise.
5453
# We would like to create uniform noise for a 2d image with prescibed variance,
5554
noise_var = np.var(img.asnumpy()) * 5
56-
noise_filter = ScalarFilter(dim=2, value=noise_var)
5755

58-
# Then create a NoiseAdder.
59-
noise = NoiseAdder(seed=123, noise_filter=noise_filter)
56+
# Then create a WhiteNoiseAdder.
57+
noise = WhiteNoiseAdder(var=noise_var, seed=123)
6058

61-
# We can apply the NoiseAdder to our image data.
59+
# We can apply the WhiteNoiseAdder to our image data.
6260
img_with_noise = noise.forward(img)
6361

6462
# We will plot the original and first noisy image,
@@ -83,7 +81,7 @@
8381
# with each image just being a copy of the data from ``img``.
8482

8583
n_imgs = 128
86-
imgs_data = np.empty((n_imgs, img.res, img.res), dtype=np.float64)
84+
imgs_data = np.empty((n_imgs, img.resolution, img.resolution), dtype=np.float64)
8785
for i in range(n_imgs):
8886
imgs_data[i] = img[0]
8987
imgs = Image(imgs_data)
@@ -98,7 +96,7 @@ def noise_function(x, y):
9896
# We can create a custom filter from that function.
9997
f = FunctionFilter(noise_function)
10098
# And use the filter to add the noise to our stack of images.
101-
noise_adder = NoiseAdder(seed=123, noise_filter=f)
99+
noise_adder = CustomNoiseAdder(noise_filter=f, seed=123)
102100
imgs_with_noise = noise_adder.forward(imgs)
103101

104102
# Let's see the first two noisy images.

gallery/tutorials/class_averaging.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
from aspire.classification import RIRClass2D, TopClassSelector
1515
from aspire.image import Image
16-
from aspire.image.xform import NoiseAdder
17-
from aspire.operators import ScalarFilter
16+
from aspire.noise import WhiteNoiseAdder
1817
from aspire.source import ArrayImageSource # Helpful hint if you want to BYO array.
1918
from aspire.utils import gaussian_2d
2019

@@ -139,11 +138,8 @@
139138
var = np.var(src.images[:].asnumpy())
140139
noise_var = var * 2**4
141140

142-
# We create a uniform noise to apply to the 2D images
143-
noise_filter = ScalarFilter(dim=2, value=noise_var)
144-
145-
# Then create noise with the ``NoiseAdder`` class.
146-
noise = NoiseAdder(seed=123, noise_filter=noise_filter)
141+
# Then create noise with the ``WhiteNoiseAdder`` class.
142+
noise = WhiteNoiseAdder(var=noise_var, seed=123)
147143

148144
# Add noise to the images by performing ``forward``
149145
noisy_im = noise.forward(src.images[:])

gallery/tutorials/configuration.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
# .. code-block:: yaml
5555
#
5656
# logging:
57-
# log_dir: /tmp/my_proj/logs
57+
# log_dir: /tmp/my_proj/aspire_logs
5858
#
5959
# This directory must then be set before invoking any code.
6060
#
@@ -120,6 +120,60 @@
120120
# You can also resolve the config in code
121121
print(aspire.config.dump())
122122

123+
# %%
124+
# Logging preferences
125+
# ---------
126+
# The "Logging" section contains options for controlling the verbosity and destination of log messages generated by ASPIRE.
127+
#
128+
# By default, the ``log_dir`` is a directory called ``logs`` within the current working directory from which ASPIRE was invoked, but
129+
# it can be changed to an absolute path (for instance, to go to the same folder as a custom configuration file stored elsewhere, such
130+
# as in the example above):
131+
#
132+
# .. code-block:: yaml
133+
#
134+
# logging:
135+
# log_dir=/tmp/my_proj/aspire_logs
136+
#
137+
# ASPIRE directs output streams to both the console and to a log file during each session. The logging verbosity for both of these
138+
# can be specified individually via ``console_level`` and ``log_file_level``. These levels are passed through to Python's logging
139+
# system, so the labels are the same: ``"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"``. In general, it may make sense to have the log file
140+
# store more verbose output than the console. By default, only ``INFO`` and above level messages are printed to the terminal, while
141+
# detailed ``DEBUG`` messages are saved to disk:
142+
#
143+
# .. code-block:: yaml
144+
#
145+
# logging:
146+
# console_level: INFO
147+
# log_file_level: DEBUG
148+
#
149+
# The following modification would save all ``DEBUG`` messages to the log file, but only print ``ERROR`` and ``CRITICAL`` messages
150+
# in the terminal:
151+
#
152+
# .. code-block:: yaml
153+
#
154+
# logging:
155+
# console_level: ERROR
156+
# log_file_level: DEBUG
157+
#
158+
# By default, the filename of the log file is ``aspire-{%Y-%m-%dT%H-%M-%S.%f}.log``. The prefix before the timestamp can be customized
159+
# via the ``log_prefix`` option.
160+
#
161+
# More details on logging behavior in Python can be found in the `Python logging HOWTO`_.
162+
163+
# %%
164+
# Advanced logging options
165+
# ---------
166+
# Users with sophisticated knowledge of Python's ``logging`` library are able to directly work with the ``logging.conf`` file stored in
167+
# ``src/aspire`` in the source.
168+
#
169+
# .. literalinclude:: ../../../src/aspire/logging.conf
170+
#
171+
# This file exposes options that ASPIRE's ``config.yaml`` does not, for example the precise formatting options for log messages. However,
172+
# values from ASPIRE's configuration are passed through this file, so caution is needed when modifying it.
173+
174+
175+
# %%
176+
# .. _Python logging HOWTO: https://docs.python.org/3/howto/logging.html
123177

124178
# %%
125179
# .. _confuse library: https://confuse.readthedocs.io/en/latest/index.html

gallery/tutorials/cov2d_simulation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
from aspire.basis import FFBBasis2D
1818
from aspire.covariance import RotCov2D
19-
from aspire.operators import RadialCTFFilter, ScalarFilter
19+
from aspire.noise import WhiteNoiseAdder
20+
from aspire.operators import RadialCTFFilter
2021
from aspire.source.simulation import Simulation
2122
from aspire.utils import anorm
2223
from aspire.volume import Volume
@@ -52,7 +53,7 @@
5253
# and initial noise inside the Simulation class.
5354

5455
noise_var = 1.3957e-4
55-
noise_filter = ScalarFilter(dim=2, value=noise_var)
56+
noise_adder = WhiteNoiseAdder(var=noise_var)
5657

5758
# %%
5859
# Specify the CTF Parameters
@@ -98,7 +99,7 @@
9899
offsets=0.0,
99100
amplitudes=1.0,
100101
dtype=dtype,
101-
noise_filter=noise_filter,
102+
noise_adder=noise_adder,
102103
)
103104

104105

gallery/tutorials/generating_volume_projections.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import numpy as np
1414

15-
from aspire.operators import ScalarFilter
15+
from aspire.noise import WhiteNoiseAdder
1616
from aspire.source.simulation import Simulation
1717
from aspire.utils import Rotation
1818
from aspire.volume import Volume
@@ -56,8 +56,8 @@
5656

5757
noise_variance = 1e-10 # Normally this would be derived from a desired SNR.
5858

59-
# Then create a constant filter based on that variance, which is passed to Simulation
60-
white_noise_filter = ScalarFilter(dim=2, value=noise_variance)
59+
# Then create a CustomNoiseAdder based on that variance, which is passed to Simulation.
60+
white_noise_adder = WhiteNoiseAdder(var=noise_variance)
6161

6262

6363
# %%
@@ -79,7 +79,7 @@
7979
amplitudes=amplitudes, # amplification ( 1 is identity)
8080
seed=12345, # RNG seed for reproducibility
8181
dtype=v.dtype, # match our datatype to the Volume.
82-
noise_filter=white_noise_filter, # optionally prescribe noise
82+
noise_adder=white_noise_adder, # optionally prescribe noise
8383
)
8484

8585
# %%

gallery/tutorials/lecture_feature_demo.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@
3838
import numpy as np
3939

4040
from 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
4348
from aspire.source import RelionSource, Simulation
4449
from aspire.utils import (
4550
Rotation,
@@ -239,10 +244,10 @@
239244
noise_variance = 100.0 * var
240245
logger.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)
246251
sim3.images[:10].show()
247252
# These should be rather noisy now ...
248253

@@ -314,7 +319,7 @@
314319

315320
# Create another Simulation source to tinker with.
316321
sim_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)
346349
sim4.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
)
451454
sim6.images[:10].show()
452455

gallery/tutorials/pipeline_demo.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ def download(url, save_path, chunk_size=1024 * 1024):
7272
# Gaussian white noise and ``RadialCTFFilter`` to generate a set of CTF filters with various defocus values.
7373

7474
# Create noise and CTF filters
75-
from aspire.operators import RadialCTFFilter, ScalarFilter
75+
from aspire.noise import WhiteNoiseAdder
76+
from aspire.operators import RadialCTFFilter
7677

7778
# Gaussian noise filter.
78-
# Note, the value supplied to the ``ScalarFilter``, chosen based on other parameters
79+
# Note, the value supplied to the ``WhiteNoiseAdder``, chosen based on other parameters
7980
# for this quick tutorial, can be changed to adjust the power of the noise.
80-
noise_filter = ScalarFilter(value=1e-5)
81+
noise_adder = WhiteNoiseAdder(var=1e-5)
8182

8283
# Radial CTF Filter
8384
defocus_min = 15000 # unit is angstroms
@@ -108,7 +109,7 @@ def download(url, save_path, chunk_size=1024 * 1024):
108109
n=n_imgs, # number of projections
109110
vols=vol, # volume source
110111
offsets=np.zeros((n_imgs, 2)), # Default: images are randomly shifted
111-
noise_filter=noise_filter,
112+
noise_adder=noise_adder,
112113
unique_filters=ctf_filters,
113114
)
114115

gallery/tutorials/preprocess_imgs_sim.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import matplotlib.pyplot as plt
1212
import numpy as np
1313

14-
from aspire.noise import WhiteNoiseEstimator
15-
from aspire.operators import RadialCTFFilter, ScalarFilter
14+
from aspire.noise import WhiteNoiseAdder, WhiteNoiseEstimator
15+
from aspire.operators import RadialCTFFilter
1616
from aspire.source.simulation import Simulation
1717
from aspire.volume import Volume
1818

@@ -32,7 +32,7 @@
3232

3333
# Set the noise variance and build the noise filter
3434
noise_variance = 4e-1
35-
noise_filter = ScalarFilter(dim=2, value=noise_variance)
35+
noise_adder = WhiteNoiseAdder(var=noise_variance)
3636

3737
# Specify the CTF parameters not used for this example
3838
# but necessary for initializing the simulation object
@@ -71,7 +71,7 @@
7171
n=num_imgs,
7272
vols=vols,
7373
unique_filters=ctf_filters,
74-
noise_filter=noise_filter,
74+
noise_adder=noise_adder,
7575
)
7676

7777
# %%

0 commit comments

Comments
 (0)