Skip to content

dp_augmentor update#130

Open
NJMarchese wants to merge 9 commits into
devfrom
dp_augmentor
Open

dp_augmentor update#130
NJMarchese wants to merge 9 commits into
devfrom
dp_augmentor

Conversation

@NJMarchese

Copy link
Copy Markdown
Collaborator

Added an option to apply the background to the labels as well (this was implemented for purpose of adding to the background label image, so amorphous halos + background). The background_label_application is a boolean list (or None) that indicates which label channels to apply the background to if apply_background_to_label is true.

Added gaussian noise, with parameters relative to electron dose.

Implemented ability to work with multichannel labels.

Added preliminary sections for apertures.

Nicholas Marchese added 2 commits December 5, 2025 11:19
…re settings. Implemented compatibility with multichannel labels.
Comment thread src/quantem/core/utils/augment_dp.py Outdated
Comment thread src/quantem/core/utils/augment_dp.py Outdated
Comment thread src/quantem/core/utils/augment_dp.py Outdated
Comment thread src/quantem/core/utils/augment_dp.py Outdated
Comment thread src/quantem/core/utils/augment_dp.py Outdated
Comment thread src/quantem/core/utils/augment_dp.py Outdated
Comment thread src/quantem/core/utils/augment_dp.py Outdated
Comment thread src/quantem/core/utils/augment_dp.py Outdated
Comment thread src/quantem/core/utils/augment_dp.py
Comment thread src/quantem/core/utils/augment_dp.py

@arthurmccray arthurmccray left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Main things are whether the background_label_application flag should exist and the order of when to apply_bkg. Also please attach the updated tutorial notebook to the PR.

@bobleesj

bobleesj commented Dec 7, 2025

Copy link
Copy Markdown
Collaborator

If I may, would there be a quick and dirty notebook? Love to try this class

Nicholas Marchese added 2 commits December 16, 2025 08:25
…ion and implemented that functionality in apply_background_to_label, which is now either list or None to reflect this. If None, will not apply, otherwise will apply background to labels according to boolean list. Updated _apply_bkg to incorporate ZiXi's correction for shifts. Changed defaults of gaussian noise to be 0 for mu, 1e-5 for std, and updated docstring to reflect that this scaling is based on total electron dose. Changed application order to be elastic->background. Added aperature related attributes to docstring, and fixed typo in docstring. Added warning if single channel passed to multichannel functions.
@gvarnavi

Copy link
Copy Markdown
Collaborator

Heads-up: you'll need to pull dev into the PR to enable the updated automated checks.

@arthurmccray

Copy link
Copy Markdown
Collaborator

@NJMarchese also just a note/reminder to also update the tutorial

Comment thread src/quantem/core/utils/augment_dp.py
Comment thread src/quantem/core/utils/augment_dp.py Outdated
…ft to coordinates in Fourier space if apply_shift is true. Also removed aperture code as beyond current scope of PR.
@NJMarchese NJMarchese requested a review from arthurmccray May 29, 2026 18:31
@arthurmccray

arthurmccray commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Please update the tutorial so that the code can be tested/validated, and please also respond to the remaining comments. Also consider writing a few pytests (or more realistically, having an LLM do so)

@arthurmccray arthurmccray left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above comments, realized i didn't officially "submit review" yet

@NJMarchese NJMarchese left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured out that comments won't be visible until review submitted

Comment thread src/quantem/core/utils/augment_dp.py
Comment thread src/quantem/core/utils/augment_dp.py
Comment thread src/quantem/core/utils/augment_dp.py Outdated
Comment thread src/quantem/core/utils/augment_dp.py Outdated
Comment thread src/quantem/core/utils/augment_dp.py
Comment thread src/quantem/core/utils/augment_dp.py Outdated
Comment thread src/quantem/core/utils/augment_dp.py
Comment thread src/quantem/core/utils/augment_dp.py

@arthurmccray arthurmccray left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool almost there! Just a couple things I found when trying to run the notebook (which failed at first due to an import error). Also please include the outputs of the notebook on the github, it's very useful so that people can see online what it does!

--edit-- actually the notebook isn't running? Errors in the 1a cell:

  • and maybe don't use pandas, just numpy to read the csv since that's a dependency already?

ValueError Traceback (most recent call last)
Cell In[4], line 3
1 aug_90 = DPAugmentor(add_flipshift=True, free_rotation=False, rng=0)
2 dp_90 = aug_90.augment(dp)
----> 3 aug_90.print_params()
5 aug_free = DPAugmentor(add_flipshift=True, free_rotation=True,
6 rotation_range=[-180, 180], rng=1)
7 dp_free = aug_free.augment(dp)

File ~/code/quantem/src/quantem/core/utils/augment_dp.py:340, in DPAugmentor.print_params(self, print_all)
314 print(">" * 32)
316 params = [
317 (
318 "Inelastic background",
(...)
337 ("Gaussian blur", self.add_blur, f"Sigma: {self.blur_sigma:.2f}"),
338 ]
--> 340 for name, enabled, details in params:
341 print(f"{name}: {enabled}")
342 if (enabled or print_all) and details:

ValueError: too many values to unpack (expected 3)


from quantem.core import config
from quantem.core.utils import array_funcs as af
from quantem.core.utils.utils import RNGMixin

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fails--RNGMixin is in quantem.core.utils.rng, not sure how it was able to run on your end.

Comment on lines 14 to 20
if TYPE_CHECKING:
import torch
import torch.nn.functional as F

if config.get("has_torch"):
import torch
import torch.nn.functional as F

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torch is a required dependency now, you can just import torch normally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants