-
Notifications
You must be signed in to change notification settings - Fork 2
WIP: Model based on new temgym_core #54
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
base: main
Are you sure you want to change the base?
Conversation
Basics already work; currently adding a ton of tests (WIP)
for more information, see https://pre-commit.ci
Simulate point charge displacement vector field in detector coordinates with model and validate by guessing CoM parameters with `libertem.udf.com.guess_corrections()`
See LiberTEM/LiberTEM#1775 for discussion! * Undo sign change between column and pixel y coordinates since that was ineffective. * Add tests to confirm correct behavior of the model * Add additional tests for CoM consistency * Make inverted sign the expected behavior
Some functions in TemGymCore rely on `PixelsXY` and `CoordsYX` being arrays, so we use newly introduced single types here
* Extract mapping matrix from model * Fast forward simulation with that matrix * Tests WIP
This allows to better simulate a real scan shift, rotation and scale where the scan changes relative to the object. Previously, the scan coordinaates vs. simulated object coordinates were fixed and always identical. Fix handling of semiconv. Introduce many tests, incl descan error moving aperture outlines.
|
Suggestion by @DavidLanders95 to improve numerical precision instead of Alternatively, one can also write down the inverse explicitly since it is not a complicated transformation. |
Enable float64 everywhere and manually specify inverses for good measure
WIP, flake8 skipped
* Tests for correction and back-projetion * Adapt OverfocusUDF to work again FIXME: How to update the parameters of an UDF without changing it? Important to keep plots alive!
* Update UDF to use new functions * Adapt notebooks to new parameters * Update tests * Simulation now includes semiconv, will be important for descan error optimization
The solver converges extremely quickly
The idea is a series of calibration functions to obtain a fully calibrated parameter set from a number of test measurements. * Wrapper function to run optax.lbfgs, which works EXTREMELY well on the model. * High level functions that take meaningful input parameters and starting parameters, and return updated parameters. TODO perhaps include the residual in the return value? * Descan error is WIP, will be based on measurements at different camera lengths. * Overfocus, rotation and flip TBD, in particular relative to descan error.
One will first have to compensate descan error, and then adjust other parameters such as flip_y, rotations etc. This change starts adding functions that allow setting these parameters while keeping the effect of descan error compensation wrt scan and detector coordinates the same. The transformations should be very fast for interactive use. For that reason they are implemented directly instead of using the solver method. TODO complete and add tests.
The `adjust_*()` methods allow first compensating the descan error based on incorrect model parameters, and then adjusting other model parameters while keeping the descan error compensated, i.e. they change the descan parameters in such a way that their effect relative to scan and detector pixel coordinates remains the same. This is helpful since e.g. calibrating camera length based on known diffraction angles may need descan compensation if position-averaged diffraction patterns from a 4D STEM dataset are to be used, and coordinate system calibration for scan step, scan rotation etc is easier as well if descan error is removed first. These methods are implemented as direct transformations rather than using a solver since they need to be fast enough for immediate response in interactive use.
Also adding a trace() function to reduce boilerplate since we are just interested in the tracing result from parameters in most cases. Refactoring all tests WIP
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #54 +/- ##
============================================
- Coverage 100.00% 51.36% -48.64%
============================================
Files 5 7 +2
Lines 190 1248 +1058
Branches 18 72 +54
============================================
+ Hits 190 641 +451
- Misses 0 601 +601
- Partials 0 6 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Works in principle, but can confuse downstream users. I guess it could be better to try preserve the original type of the input parameter to the optimization routine, but later(TM).
Descan error correction for single camera length works!
Currently some issue with the backprojection, details TBD...
* Include relevant projections in GUI * Introduce corrected picking UDF * Use stock UDFs where possible instead of re-implementing; remove unnecessary buffers * Use flip_factor from (-1., 1.) instead of boolean flip_y to aid numerical solving. To be tested further! Final user-facing solution TB
* Modify the coordinate refinement to work with reference on both specimen and detector * Complicate the GUI further TODO: Tests for new optimization methods
Basics already work; currently adding a ton of tests (WIP)
Next steps after that: Port the previous code to the new model