Commit Graph
143 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 fcd0b31b2c Fix a bug with the mask implementation for the normalizers conflicting with SimplePtycho, and update the thresholds to accomodate the new normalization with masks and for intensity_MSE 2026-04-13 15:44:52 +02:00
allevitan d8fade9f32 Update the amplitude MSE and intensity MSE loss to act equivalently - currently, the intensity MSE loss was by default a mean, but amplitude was by default a sum. Both functions now have a flag, use_sum=False, which is False by default. This changes the default behavior of amplitude_mse. All models, including the tutorial version of simple_ptycho, are updated accordingly and test coverage was added. 2026-04-13 14:34:23 +02:00
levita_a 3d10f36739 Fix a bug where the normalizers stopped the loss history from being saved as a numpy scalar, and added test coverage 2026-04-05 22:23:23 +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
allevitanandClaude Sonnet 4.6 d644782e94 Update poisson_nll test to match sum-based implementation
poisson_nll now returns a sum rather than a mean, consistent with the
normalizer pattern. Remove the per-pixel divisions from the numpy
reference calculations accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 18:44:04 +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
levita_a f55b35f0dd Stop stopping at each plot to show it 2026-03-24 16:56:44 +01: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
allevitanandClaude Sonnet 4.6 29e9fddd72 Add test coverage for plot_translations, plot_nanomap, and plot_nanomap_with_images
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 16:01:45 +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
gnzng f79836bfc2 Add tests for version existence and semantic format 2025-10-29 21:40:12 -07: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 7d39015719 response to dayne's review 2025-10-17 23:41:08 +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 82ce845385 Changed the names of the reconstructors and updated the old optimizer class documentation 2025-08-04 16:51:24 +00:00
yoshikisd 1e7fe2eb5f Added pytests for reconstructors 2025-08-01 22:31:40 +00:00
gnzng fc5a76ad61 linting test_plotting.py and test_propagators.py 2025-07-07 15:13:11 -07:00
gnzng 65e83753a8 linting test_interactions.py, test_losses.py, and test_measurements.py 2025-07-07 14:58:11 -07:00
gnzng 88df4c0794 linting test_image_processing.py and test_initializers.py 2025-07-07 14:40:17 -07:00
gnzng b00f39e1fe linting test_analysis.py and test_data.py 2025-07-07 14:28:23 -07: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
gnzng 745f7b73e6 Fix background calculation in test_Ptycho2DDataset_downsample 2025-07-07 13:55:54 -07:00
gnzng f463144347 linting test_datasets.py 2025-07-07 13:49:46 -07:00
gnzng 4d812db68a restructured conftest.py imports 2025-07-07 13:39:44 -07:00
gnzng 38be347a18 lint conftest.py 2025-07-07 13:38:52 -07:00
yoshikisd 36de44565b Set fixed RNG seed for reconstruction pytests 2025-07-07 15:16:12 +00:00
gnzng b189c3c2af Add warning for 64-bit float conversion in Ptycho2DDataset and added to tests 2025-06-17 11:01:30 -07:00
levita_a 4ecc782c28 Reply to Daynes comment's and slightly loosen a tolerance in one test that has been failing 2025-06-10 14:11:01 +02: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
levita_a 2fd917350d response to Dayne's review 2025-03-20 10:46:24 +01:00
levita_a 5b6fd79b28 Add tests for nested_dict_to_numpy and nested_dict_to_torch 2025-03-18 13:13:47 +01:00
levita_a a30930b082 Fix bug with loading h5 files including strings, and add test coverage for h5_to_nested_dict and nested_dict_to_h5 2025-03-18 11:54:06 +01:00
a7904491be Added a function to allow for deletion of translation positions with logical indexing (#16)
* Added a function to allow for deletion of translation positions via logical indexing
In ptycho_2d_dataset.py
- Created remove_translations_mask. This handles logical-indexing-based deletion of translation points
- Refactored crop_translations to be dependent on remove_translations_mask

* Add validation and tests for remove_translations_mask method in Ptycho2DDataset

* Switch mask to mask_remove

---------

Co-authored-by: gnzng <damian@guenzing.de>
Co-authored-by: Clemens Schmid <clemisch@tuta.io>
2025-02-26 06:52:04 +01:00
yoshikisd 1da20c8427 improvements: Implemented requested changes for PR13
For crop_translations in ptycho_2d_dataset.py
- crop_2d_translations is now crop_translations
- roi is now order-insensitive within the first and last pairs of elements.
- the definition of top, bottom, left, and right, are now consistent with figures generated by matplotlib.pyplot.imshow
- self.intensities is now updated

For tests_datasets.py
- the order-insensitivity of roi in crop_translation is tested, and tests for specific ordering of values in roi are removed.
2024-12-30 01:36:54 +00:00
yoshikisd 920f17bc66 Added a test for crop_2D_translations in Ptycho2DDataset. 2024-12-23 04:12:09 +00:00
levita_a ba7c8a17c6 Add a function to downsample a dataset by an integer factor 2024-12-06 15:59:56 +01:00