Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi slice: simulate image from exit wave (apply ctf, detector dqe, ntf, poisson shot noise) #3

Merged
merged 24 commits into from
Aug 19, 2021

Conversation

geoffwoollard
Copy link
Contributor

I use ioSPI/ioSPI/fourier.py in simSPI/src/multislice.py

I'm not sure how to import fourier into multislice.py, so just put https://github.com/geoffwoollard/simSPI/blob/multi_slice/src/multislice.py#L1 for now

If I have functions to test in simSPI/src/multislice.py

  • can I put the tests in simSPI/tests/test_multislice.py?
  • how should I import the functions to test?

Once this PR is working, I can remove fourier.py and other things around. But let's just get things working in simSPI first, and then I'll make some other branches on ioSPI and compSPI and clean things up.

@geoffwoollard
Copy link
Contributor Author

I looked through the deepsource failures. Is there an automated tool for style I can use in git hub?

Copy link
Contributor

@ninamiolane ninamiolane left a comment

Choose a reason for hiding this comment

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

Very nice! It would have been better to split this into 2 PRs:

  • one with the files about the continuous integration
  • one with the science files.
    But this is fine for this one!

I've put some comments but they're very minor.

About DeepSource:

  • you can use flake8 in your command line to spot deepsource errors in advance
  • you can use black and isort to automatically correct your files for these errors (isort focuses on cleaning the import order).

It can be that deepsource and the formatting by black or isort

    1. are not equal: i.e. deepsource could be more restrictive
    1. disagree.
      If this is the case, can you let me know? We would need to clean up the infrastructure of the package in this case.

We don't know at this point if the unit-tests pass, since you have just added the .yml file. When we merge this PR, we should see what they give and be ready to submit a followup HOTFIX" PR if any of the tests fail.

Thank you very much, this is great! 🎉

matrix:
os: [ubuntu-18.04]
python-version: [3.7,3.8,3.9]
test-folder : ['tests.test_multislice']
Copy link
Contributor

Choose a reason for hiding this comment

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

test_multisclice.py is a file.py and a folder, thus I don't really know if this will work, but let's try!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there's actually just tests/tests_multislice.py, so I will change it to test-folder : ['tests']. I misread the template yml I was using: https://github.com/compSPI/ioSPI/blob/master/.github/workflows/build.yml#L27

"""Exit wave to image (ctf, detector dqe/ntf, and poisson shot noise).

Convolution of (ctf, detector dqe/ntf,) with exit wave.
Incorporates Poisson shot noise and the collapse of the wave function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok!

Parameters
----------
exit_wave_f : numpy.ndarray, shape (N,N)
exit wave array.
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: Uppercase letter on the description of the parameters: we are just enforcing this so that all the docstrings parameters descriptions have the same convention, because that's how the (future) doc website will look clean too.

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e. Exit wave array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok!

@ninamiolane
Copy link
Contributor

@geoffwoollard another very minor comment : next time, could you put a PR's title and description that are a bit more informative? This will help

  • the code reviewers to understand a bit better what is happening in the code
  • the future maintainers to go back to this PR if they need to, by searching through PR's titles.
    Thanks!

@geoffwoollard geoffwoollard changed the title Multi slice Multi slice: simulate image from exit wave (apply ctf, detector dqe, ntf, poisson shot noise) Aug 18, 2021
@geoffwoollard
Copy link
Contributor Author

geoffwoollard commented Aug 18, 2021

I fixed most of the style issues with black and isort. I think it should be good enough.

I made the PR title more informative.

I still need direction on how to import from ioSPI. I can do a separate PR for that, where I actually move the files around, once I know where everything should go. As things are, I think all the tests will fail, because they rely on fourier from ioSPI, but what I put in (from ioSPI import fourier) won't work.

@geoffwoollard
Copy link
Contributor Author

@fredericpoitevin should I merge the pull request?

@ninamiolane
Copy link
Contributor

@geoffwoollard looking great! Let's ignore the deepsource issues:

  • Assert statement used outside of tests
  • Missing module/function docstring
    but can you address the remaining ones?

@ninamiolane
Copy link
Contributor

To import from ioSPI, add a line in the build.yml to import ioSPI from its github. You can find inspiration here:
https://adamj.eu/tech/2019/03/11/pip-install-from-a-git-repository/
in "Installing via Git"

Basically, we want the unit tests to know about the github master of ioSPI, so we need to installing via Git in the build.yml

Copy link
Contributor

@ninamiolane ninamiolane left a comment

Choose a reason for hiding this comment

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

Actually, instead of hard-coding the import of ioSPI in the build.yml, you can install it via the simSPI.yml

- name: install dependencies
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
$CONDA/bin/conda env update --file simSPI.yml --name base
Copy link
Contributor

Choose a reason for hiding this comment

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

@geoffwoollard you can install ioSPI as a dependenci in simSPI.yml using pip.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So under dependencies in simSPI.yml I'm adding git+https://github.com/comSPI/ioSPI.git, where something like numpy would usually go. This will need me to put in fourier.py into that, and make sure it installs (add in dependencies, etc)... I'll get another PR going for that.

Copy link
Member

@fredericpoitevin fredericpoitevin left a comment

Choose a reason for hiding this comment

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

Looking good! I haven't tried to simulate anything yet, but the code is very readable, thanks

assert np.allclose(i / high_dose, exit_wave, atol=1e-4)


test_exit_wave_to_image()
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to execute the function explicitely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove that. I see you didn't do that in https://github.com/compSPI/ioSPI/blob/master/tests/test_iotools/test_atomic_models.py

I didn't make it a class...

@fredericpoitevin
Copy link
Member

Actually, instead of hard-coding the import of ioSPI in the build.yml, you can install it via the simSPI.yml

I meant to work on this before, did not find the time yet. Once we are happy with a mechanism to have the various compSPI repos working with one another, we can document it in compSPI/compSPI.

@fredericpoitevin
Copy link
Member

fredericpoitevin commented Aug 19, 2021

@geoffwoollard looking great! Let's ignore the deepsource issues:

  • Assert statement used outside of tests
  • Missing module/function docstring
    but can you address the remaining ones?

I'm confused, I do not see those issues... See below what I can see:
image

@geoffwoollard I think those issues could be addressed prior merging.
In any case, I agree with @ninamiolane: thanks for the great contribution, please merge when you are happy :)

@geoffwoollard
Copy link
Contributor Author

I think the assert in tests was removed somehow. I used to see it, but it went away.

I resolved all deepsourse issues that I can see.

@geoffwoollard geoffwoollard merged commit 9bbcf3c into compSPI:master Aug 19, 2021
@ninamiolane
Copy link
Contributor

@geoffwoollard @fredericpoitevin yes I made deepsource ignored these errors automatically

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.

3 participants