Skip to content

Show 2d dataclass overhaul#202

Open
arthurmccray wants to merge 10 commits intodevfrom
show_2d_dataclass_overhaul
Open

Show 2d dataclass overhaul#202
arthurmccray wants to merge 10 commits intodevfrom
show_2d_dataclass_overhaul

Conversation

@arthurmccray
Copy link
Copy Markdown
Collaborator

@arthurmccray arthurmccray commented Mar 24, 2026

What does this PR do?

This PR improves how show_2d accepts normalization and scalebar settings by introducing a small, autocomplete-friendly API, while keeping existing dict/string usage working.

Primarily it adds ShowParams with nested ShowParams.Norm and ShowParams.Scalebar dataclasses so users can discover fields via the editor instead of ad hoc dicts.

Tutorial notebook and examples: quantem-tutorials PR #7 (to be merged once this is)

What should the reviewer(s) do?

  • Run the tutorial notebook and suggest any changes to either the notebook itself or the API.

  • Review show_params.py, visualization.py, custom_normalizations.py, and visualization_utils.py for API clarity and backward compatibility.

  • This PR introduces a public-facing change (e.g., API, CLI input/output).

    • For functional and algorithmic changes, tests are written or updated.
    • Documentation (e.g., tutorials, examples, README) has been updated (via quantem-tutorials#7).

Reviewer checklist

  • Tests pass and are appropriate for the changes
  • Documentation and examples are sufficient and clear
  • Imported or adapted code has a compatible license
  • The implementation matches the stated intent of the contribution

@arthurmccray arthurmccray marked this pull request as ready for review March 24, 2026 23:46
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.

just adding a missing validator and fixing a couple linter errors

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.

The main contribution--the ShowParams class. Written to be a wrapper and therefore not break existing workflows or change the underlying viz stuff that @gvarnavi wrote.

logarithmic_index: float = 1000.0
asinh_linear_range: float = 0.1

def __post_init__(self) -> None:
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.

This got pretty long once I added warnings for adding incompatible args. The alternative would be to further nest the different interval or stretch types, but that would be worse I think.

if TYPE_CHECKING:
from quantem.core.datastructures import Dataset2d

ArrayLike: TypeAlias = Union[NDArray, torch.Tensor, "Dataset2d"] # union required here
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.

So show_2d doesn't give linter errors when directly passing tensors and such.

Comment on lines +404 to +407
norm: NormalizationConfig
| ShowParams.Norm
| dict
| str
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.

the type hinting is really messy... there's probably a way to clean it up but idk what it would be.

@arthurmccray
Copy link
Copy Markdown
Collaborator Author

Tagging @cophus @gvarnavi @bobleesj and @cedriclim1 so that you can take a look and/or review.

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.

2 participants