Skip to content

Conversation

@chris-langfield
Copy link
Collaborator

@chris-langfield chris-langfield commented Apr 25, 2022

Closes #553

Enforcing the rule that evaluate should return an Image/Volume and evaluate_t should return a NumPy array means a few small changes are needed around the codebase.

#553 (comment)

So the idea here is that:

  • All evaluates should take an ndarray as input and output a Volume/Image
  • All evaluate_ts and expands should take an Volume/Image as input (but will cast an ndarray to the appropriate cast after logging the warning) and redurn an ndarray

Certain parts of this is implemented in certain Basis classes and other parts in other classes. To sort this out, the best way may be to define evaluate, evaluate_t, and expand in a superclass and have these do the necessary checks and casts, then call _evaluate, _evaluate_t, _expand, and so on that will be overriden in subclasses and operate on ndarrays. Obviously this would have to be somewhat smart in checking whether the basis is 2D (in which case we're dealing with Images) or 3D (in which case we're dealing with Volumes).

garrettwrong and others added 30 commits February 23, 2022 14:41
Merge pull request #584 from ComputationalCryoEM/develop
…imators (#550)

* changed self.L and self.n to self.src.L and self.src.n for estimators

* extraneous comma
…o second-level API access (#565)

* utils.coor_trans methods accessible from second level

* crop_2d method

* crop2d test

* clarify flooring behavior for centering and add apdding

* tests finished

* isort shenanigans

* fix even to odd n->n+1 padding bug

* slightly better comment

* better behavior for dtype

* remove mistaken characters

* fixes after merge

* last ensure removed

* rect tests

* padding tests and fill value test

* better comments

* even better comments

* np.diag

* crop_pad_2d

* clarifying comment when padding
* downsample tests

* cleanup and deleting test downsample from preprocess_pipeline

* remove hardcoded ds / whiten test

* flake8

* 3d volume downsample test

* remove redundant test from tests/test_preprocess.py

* remove unused import

* remove numbered tests for uniformity

* typo

* skip one of the ds tests

* use gaussian_3d to generate test volume

* isort

* checkCenterPoint

* max_resolution -> L_ds

* parametrize ds tests
* docstring for besselj_zeros

* rest of docstrings

* remove pdb import

* second order differences comment

* comments and docstring for num_besselj_zeros

* formatting

* tiny fixes;

* docstring fixes

* NumPy

* NumPy again

* sanity check

* parentheses inside sentence
* fix size checking bug

* fb2d

* fb3d and pswf2d

* dirac

* fpswf

* polar

* format

* sz -> size

* test init with int

* docstring

* typo

* the same typo
Cast `Images` to arrays when needed.
@chris-langfield
Copy link
Collaborator Author

Summary of changes:

Testing inputs and outputs of evaluate, evaluate_t and expand, and testing initialization with int moved up to _basis_util.py as part of the UniversalBasisMixin class.

DiracBasis removed.

[F]PSWFBasis2D knows its count now.

Most type checks and dtype warnings moved up to basis.py rather than the individual bases.

@chris-langfield chris-langfield requested a review from j-c-c June 16, 2022 15:46
Copy link
Collaborator

@j-c-c j-c-c left a comment

Choose a reason for hiding this comment

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

This looks good. The mixin definitely streamlines the tests. Just a couple small comments.

@chris-langfield chris-langfield marked this pull request as ready for review June 22, 2022 17:04
@chris-langfield chris-langfield requested a review from janden as a code owner June 22, 2022 17:04
Copy link
Collaborator

@janden janden left a comment

Choose a reason for hiding this comment

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

Just did a high-level overview to begin with so that we can iron out the details.

f"{self.__class__.__name__}::evaluate_t"
f" passed numpy array instead of {_class}."
)
v = _class(v)
Copy link
Collaborator

Choose a reason for hiding this comment

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

They way I read the intent of the PR was that the inner methods (_evaluate) and (_evaluate_t) should only deal with ndarrays. Why are we casting here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The evaluate_t methods for the various bases are a bit inconsistent as far as whether they expect Image/Volume or arrays. The choice was many modifications to all the specific functions versus just a few and passing an Image/Volume. I didn't initially intend to dig super deep into each individual method with this PR, just impose the overall structure and enforce the return / input types.

Do you think it would be better to make all those changes in this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok let's make an issue.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FFBBasis2D.evaluate() returns an Image but other bases return ndarray

5 participants