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

Updated multipeak capabilities (Dev) #22

Merged
merged 23 commits into from
Jan 30, 2024
Merged

Conversation

jacione
Copy link
Contributor

@jacione jacione commented Jan 30, 2024

This contains all the updates I've made in the last few months. I merged all the conflicts so that it is compatible with the current state of the Dev branch. All of the changes are summarized below.
 

Issues fixed

  • Fixed issue where a projection weight less than one would prevent the ER algorithm from completely suppressing the built-up feedback from the HIO algorithm. This was fixed by applying the support constraint to the full shared_image object when switching peaks after ER iterations.
  • Fixed incorrect normalization when projecting to each Bragg peak.

New features

  • Resampling is now included in phasing.py rather than in the preprocessing scripts.
  • Both the original (preprocessed) and resampled diffraction images are saved in the output directory.
  • Added an option to exclude one peak from the phasing process to use as a "control" for unbiased error calculations.
  • Added several new error metrics, including normalized mutual information (NMI) and expected histogram deviation (EHD).
  • Multipeak phasing now centers the reconstruction when switching peaks after an ER iteration.

New config_mp parameters

  • control_peak=[H,K,L] determines which peak is used as the control.
  • calc_strain=True, if False, skip the strain calculation (saves time on repeated reconstructions where only error metrics are examined)
  • fast_resample=True If False, resample the reconstruction (direct space) instead of the data (reciprocal space).

Devlib functions

  • amin(), find the minimum of an array
  • affine_transform(), transform an array using an affine transformation matrix
  • pad(), pad an array with zeros
  • histogram2d(), create a 2D histogram comparing two arrays (optional log-spaced bins)
  • calc_nmi(), calculate the normalized mutual information between two arrays
  • calc_ehd(), calculate the expected histogram deviation between two arrays

Changes made for compatibility

  • Moved image centering from the end of Rec.iterate() to the beginning of Rec.save_res(). The CoupledRec class inherits the iterate() method, and there were some compatibility issues between single-peak and multipeak centering. However, the save_res() method is overridden by CoupledRec, so the conflict is ok.

Known issues

  • The strain calculation is not optimized. I'm sure it could be done faster, but I don't know how, so I ended up just doing a for-loop over all the voxels, which is really slow.
  • Resampling in direct space (fast_resample=False) seems to cause compounding errors that prevent convergence. I have not gotten it to work, but I've left the option there for future work.
  • The additional functions have only been implemented in cplib.py. Function stubs have been added to the other libraries that just raise NotImplementedError.
  • I merged several commits that seemed to be related to the GA processes. These were merged without conflict, so they shouldn't cause a problem, but I haven't tested them.
  • As of right now, the only way to not use the control_peak feature is to remove the parameter from the configuration file. I'm sure there's a better way.

jacione and others added 23 commits March 27, 2023 13:49
…nted code that would implement the partial fourier constraint with free-varying pixels according to a preset mask.
Conflicts:
	cohere_core/controller/phasing.py
	cohere_core/lib/cplib.py
	docs/source/config_mp.rst
- diff
- gradient
- argmin
- take_along_axis
- moveaxis
- lstsq
- zeros
- indices
- concatenate

These methods have been implemented in cplib and nplib, but will raise NotImplementedError if called from torchlib or aflib.
Added fix for the handling og fast GA,
added notes for Windows installation.
…, pad(), histogram2d(), calc_nmi(), calc_ehd().

These have only been implemented in cplib, other libraries are only implemented as stubs.
- Resampling is now included in the phasing process.
- Added several new error metrics, including normalized mutual information (NMI) and expected histogram deviation (EHD)
- Apply the support constraint to the full object during ER iterations (to prevent buildup of HIO feedback)
- Fixed incorrect normalization when projecting to each Bragg peak.
- Added a "control_peak" option to exclude one peak from the phasing process to use for unbiased error calculations.
- Added a "calc_strain" option which can skip the slow strain calculation.
- Added a "fast_resample" option to toggle whether the original or resampled data is used.
# Conflicts:
#	cohere_core/controller/phasing.py
@bfrosik bfrosik merged commit 3e52924 into AdvancedPhotonSource:Dev Jan 30, 2024
bfrosik added a commit that referenced this pull request Apr 24, 2024
* Strain from CoupledRec (#16)

* Additional documentation for multipeak phasing

* Update setup.py

* Update meta.yaml

* Refactored get_centered to reduce number of numpy function calls.

* Added a bunch of functions to cplib.py

* Get strain from final reconstruction. This commit also contains commented code that would implement the partial fourier constraint with free-varying pixels according to a preset mask.

* Added several new methods to the cohlib signature:

- diff
- gradient
- argmin
- take_along_axis
- moveaxis
- lstsq
- zeros
- indices
- concatenate

These methods have been implemented in cplib and nplib, but will raise NotImplementedError if called from torchlib or aflib.

* Removed some experimental code that accidentally got included in this version.

---------

Co-authored-by: Barbara Frosik <[email protected]>

* fixed interface issue with cohere-ui after merge

* fixed interface issue after merge

* Delete reconstruction_GA_HPC.py

* moved cleaning memory to lib

* Delete reconstruction_HPC_GA.py

* fixed problrm with parameter

* fixed imoprt name

* fixed docs for developers

* supressed warnings in verifier when parsing device

* fixed crop issue in ui

* Autodata (#18)

* changes for autodata option

* synch with ui

---------

Co-authored-by: bfrosik <[email protected]>

* added debug option

* moved utils from cohere-ui to cohere core and cleane up

* cleaned up utils

* support for auto data for separate scan ranges

* aligned with cohere-ui

* align with cohere-ui

* relaxed verifier for auto data

* relaxed verifier

* aligning with ui

* added missing save_dir in reconstruction scripts

* added for hpc

* sync with cohere-ui module

* removed warning

* added cluster capability

* removed print statements

* cleaned up, bug fixes

* added description for cluster, fixed host naming issue

* fixed typo

* Update .readthedocs.yaml

* Update .readthedocs.yaml

* Update .readthedocs.yaml

* Update .readthedocs.yaml

* Update .readthedocs.yaml

* Update README.md

* Update README.md

* Update README.md

* fixed verifier, aligned cohere-ui

* aligned with cohere-ui module

* formatted text, fixed verifier for multipeak

* blocked auto binning for mp and aligned ui

* return correlation error in addition to aligned array

* aligned ui

* aligned with cohere-ui

* added description in verifier, aligned with ui

* Updated multipeak capabilities (Dev) (#22)

* Additional documentation for multipeak phasing

* Update setup.py

* Update meta.yaml

* Refactored get_centered to reduce number of numpy function calls.

* Added a bunch of functions to cplib.py

* Get strain from final reconstruction. This commit also contains commented code that would implement the partial fourier constraint with free-varying pixels according to a preset mask.

* Added several new methods to the cohlib signature:

- diff
- gradient
- argmin
- take_along_axis
- moveaxis
- lstsq
- zeros
- indices
- concatenate

These methods have been implemented in cplib and nplib, but will raise NotImplementedError if called from torchlib or aflib.

* Removed some experimental code that accidentally got included in this version.

* assigned release tag

* fixed doc for developers

* fixed crop issue in ui

* Added the following functions to cplib.py: amin(), affine_transform(), pad(), histogram2d(), calc_nmi(), calc_ehd().

These have only been implemented in cplib, other libraries are only implemented as stubs.

* Significant changes that should have been committed earlier:

- Resampling is now included in the phasing process.
- Added several new error metrics, including normalized mutual information (NMI) and expected histogram deviation (EHD)
- Apply the support constraint to the full object during ER iterations (to prevent buildup of HIO feedback)
- Fixed incorrect normalization when projecting to each Bragg peak.
- Added a "control_peak" option to exclude one peak from the phasing process to use for unbiased error calculations.
- Added a "calc_strain" option which can skip the slow strain calculation.
- Added a "fast_resample" option to toggle whether the original or resampled data is used.

---------

Co-authored-by: Barbara Frosik <[email protected]>

* aligned with ui

* updated torch lib

* fixed torchlib

* removed unused function, aligned ui

* synch ui

* revised fftconvolve function

* added comments to op flow, and simplified

* modified get_ratio

* removed defaults in cohere-core, added checks for misconfiguration

* added error checks and prints of error messages if fail

* removed code to activate lpf at last iteration

* aligned with cohere-ui

* added tqdm package in setup.py

* added example of different sw type in features

* moved checks based on type

* change definition of algorithms dict to include to_direct and to_reciprocal

* refactored cluster handling

* changed API to receive hostfile instead of arbitrary naming it

* changed api

* Removed Support class and moved support array to Rec

* renamed phase modulus to phase constrain

* change description, slightly modified code

* updated documentation

* corrected docs

* modified for new release

* modified to do beta buid

* refactored to set defaults through get, corrected decs

* modified doc conf.py

* modified doc conf.py

* updated docs

* cleaned up docs

* aligning with cohere-ui

---------

Co-authored-by: Nick Porter <[email protected]>
Co-authored-by: Barbara Frosik <[email protected]>
Co-authored-by: pfrosik <[email protected]>
Co-authored-by: cxduser <[email protected]>
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