26 Commits
Author SHA1 Message Date
levita_a 211f0ac533 Apply a fix to the subpixel shifting for near-field ptycho to enable good position refinement 2026-07-11 07:14:48 +02:00
allevitan 4eb3a9879c Make the loading code for fancyptycho a bit more robust 2026-06-16 15:26:06 +02:00
allevitan 8ced842a58 Merge in master 2026-06-16 14:19:17 +02:00
levita_a a516f418b9 Fix a high priority bug where reconstructions will crash upon saving, and add test coverage to prevent a repeat 2026-04-20 15:40:55 +02:00
allevitanandClaude Sonnet 4.6 6aa5df081b Add from_results_dict / from_results_h5 model loading from saved h5 files
Adds two classmethods to CDIModel and its ptychography subclasses that
allow models to be reconstructed from saved .h5 result files without
needing the original dataset.

- CDIModel base class: add model_class and cdtools_version to
  save_results(); add _load_results_dict() helper (restores state_dict
  + training metadata); add from_results_dict() interface method and a
  concrete from_results_h5() that reads a file and delegates to
  from_results_dict() — subclasses inherit this for free.

- SimplePtycho: make save_results(dataset=None) optional (dataset was
  accepted but never used); add from_results_dict() which reconstructs
  from probe, obj, wavelength, probe_basis, and min_translation stored
  in the state_dict.

- FancyPtycho: add optional translations parameter to __init__,
  registered as original_translations buffer; update from_dataset to
  pass translations; make corrected_translations(dataset=None) fall back
  to self.original_translations when no dataset is provided; make
  save_results(dataset=None) use stored translations when no dataset is
  provided; add from_results_dict() that detects all optional features
  (mask, translation_offsets, weights, near-field propagators, etc.)
  from the state_dict and reconstructs the full model. Also fix a latent
  bug where background was passed to t.nn.Parameter() without
  t.as_tensor(), which now fails when given a numpy array.

All existing tests pass; new tests added for both models verifying that
state_dict, training metadata, and forward pass output are all restored
exactly after a round-trip through from_results_dict and from_results_h5.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 15:47:07 +02:00
levita_a 388d1669f3 Final checks to ensure all tests pass with the new scaling 2026-04-05 21:52:14 +02:00
levita_a 8ee8bf9237 Fix bug where fancyptycho test was not being run on GPU 2026-04-03 18:59:09 +02:00
levita_a b6553fd522 Update the example near field ptycho code to use Poisson NLL 2026-04-03 18:48:35 +02:00
allevitanandClaude Sonnet 4.6 3ccdc24d3f Restructure loss coverage in reconstruction tests
- Revert test_Adam_gold_balls to default amplitude_mse
- Add new test_intensity_MSE test (gold balls + AdamReconstructor)
- Update near_field threshold to 17 (poisson_nll scale)
Thresholds for test_intensity_MSE to be tuned after GPU run.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 18:46:27 +02:00
allevitanandClaude Sonnet 4.6 178e9a4e4e Add loss function coverage to slow reconstruction tests
Use poisson_nll in test_near_field_ptycho and intensity_mse in
test_Adam_gold_balls to exercise these loss paths end-to-end.
Thresholds left as-is pending re-running on a GPU machine.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 18:45:29 +02:00
levita_a d2c09acd44 Get all tests passing by updating the loss thresholds for the new normalizations, and add the new normalization to all models 2026-04-03 18:38:11 +02:00
Abe Levitan 3f028e2fbf Merge pull request #72 from cdtools-developers/feature/betterplots
A bunch of long overdue updates to the plotting system
2026-04-03 18:23:41 +02:00
allevitan 603486e824 Change the default colormap for exponentiated objects to match that for un-exponentiated objects, and also update test_fancy_ptycho to show all the plots (not just plot level 2) 2026-03-24 16:55:56 +01:00
allevitan ad2b09f2f0 Update the tests to work better when checking the model plotting, and make sure to cover panel_plot_mode=False 2026-03-24 16:19:26 +01:00
allevitan 4c89b3e46b Fix the bug with loading from datasets with intensity info when OPRP is on and add test coverage 2026-03-19 22:45:57 +01:00
levita_a a97e4cdf39 Add licensed near-field ptycho data to enable testing 2026-01-14 17:01:11 +01:00
levita_a e38ebd7372 Fix a high priority bug with the masking system which was introduced in the switch to reconstructors classes 2025-10-24 15:11:46 +02:00
levita_a f022b5e2c4 Get the tests passing again after the change of the optimization functions in the model classes 2025-10-16 15:58:28 +02:00
yoshikisd 1e7fe2eb5f Added pytests for reconstructors 2025-08-01 22:31:40 +00:00
gnzng 96d8b10792 linting test_fancy_ptycho.py 2025-07-07 14:11:50 -07:00
gnzng ecb8ee4864 linting test_simple_ptycho.py 2025-07-07 13:59:35 -07:00
yoshikisd 36de44565b Set fixed RNG seed for reconstruction pytests 2025-07-07 15:16:12 +00:00
levita_a b6bc7d95cc Change the behavior of FancyPtycho.center_probes to center the probe in real space even when fourier_probe is set to True 2025-06-10 13:57:03 +02:00
levita_a 2c2f2d2d93 Add a way to save and load the quantum efficiency masks, and add test coverage 2025-05-13 16:05:16 +02:00
Abe Levitan 13a2ba86df Make big changes to docs to update the tutorial section, and also to finally autoload the documentation of the models and datasets 2024-09-01 13:04:28 +02:00
levita_a 30a989fe3e Add first tests for models, and replace t.tensor with t.as_tensor in models 2024-08-30 16:10:26 +02:00