-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add spectrum reading to FormatNXmx and fix noncontiguous mask arrays #538
Conversation
Ran out of time to get the SwissFEL data with spectra uploaded. I'll try again early next week. |
Would it be possible to construct a self-contained minimal example in the tests, as done e.g. here? We've tried where possible to make sure that the core functionality of the new NXmx code is covered by self-contained test that don't have dependencies on a huge array of different datasets. Although it would still be useful to have a full dataset on Zenodo for full testing and to better understand what the file structure looks like. |
From Dials core: found the cache that was causing the handle to be closed. Should be fixable. Also, change the variant reading to return the newest version of the spectrum, not the oldest. |
Dataset reimported using new off by one pixel correction fix in FormatNexus from cctbx/dxtbx#538
@ndevenish @rjgildea re-reading the original code, I was wrong about the variant behavior. It bails out as soon as it finds a valid set of spectra. It doesn't go to the next one in the chain. So that's not a concern. Additionally, I've uploaded a 4 image dataset with spectra here: |
Ok this is ready for review. Here is the order of things to review and merge.
Only thing left to consider is adding a test to specifically test the second Zenodo dataset, with spectra. That would add about 200 MB between the two tests to an Azure footprint. Might be better to switch the test added in #541 to use the second Zenodo dataset. But regardless, these PRs are ready for review. Thanks folks. |
Codecov Report
@@ Coverage Diff @@
## main #538 +/- ##
==========================================
+ Coverage 40.67% 40.85% +0.18%
==========================================
Files 176 176
Lines 15552 15613 +61
Branches 2806 2818 +12
==========================================
+ Hits 6325 6378 +53
- Misses 8664 8666 +2
- Partials 563 569 +6 |
@ndevenish not sure what these MacOS test failures are about. Maybe it just needs to be re-run? |
* Add 4 image SwissFEL JF16M dataset * Add lysozyme_JF16M_4img imported.expt file Made using FormatNexus as a baseline to compare to FormatNXmx * Update to new version Dataset reimported using new off by one pixel correction fix in FormatNexus from cctbx/dxtbx#538 * Add further JF16M dataset, this one with per-shot spectra
This is mostly a port (copy) of the spectrum reading code from FormatNexus. I imagine we'll want to eliminate one of the two copies at some point.
Needed since new implementation of beam/spectra needs access to the file handle outside of get_raw_data
Test now reads the JF16M data using FormatNXmx, but there is a one pixel offset compared to FormatNexus
Two problems here when constructing the panel object as a leaf of the detector hierarchy using the fast_pixel_direction NeXus field. The fast and slow directions are ready out correctly, but the origin was read out using get_cumulative_change_of_basis in order to include any offsets. However, since the pixel size is the value of this field, it was included as an offset, leading to an extra pixel added in the fast direction. Additionally, get_cumulative_change_of_basis relies on the equipment_component chain, which fast_pixel_direction doesn't use, so only the fast_pixel_direction offset was picked up. This is why there isn't an extra pixel in the slow direciton. Fix is to not include fast_pixel_direction field value when reading out the offset and to explicitly also read the slow_pixel_direction offset.
Off-by-one error fixed in in FormatNexus
(these are ususually 0)
Uses the in memory version of testing. Tests both a single spectra for a dataset and a set of 3 spectra using variants derived from calibrated energies.
Co-authored-by: Graeme Winter <[email protected]>
1ed46e4
to
6f7a104
Compare
Rebased onto main to pick up #541 |
Again, I think the build failure is the same one that @ndevenish reported in #548 (comment) which is known and unrelated so I presume this is safe to merge Merging after confirming this is ok with @graeme-winter. Thanks everyone for the review on this. |
This is mostly a port (copy) of the spectrum reading code from FormatNexus. I imagine we'll want to eliminate one of the two copies at some point.
@rjgildea this was my first time reading FormatNXmx.py and nexus/nxmx.py in detail. I like the
H5Mapping
class, which maps strings as handle names to h5 fields while doing unit conversion. However it breaks down for the variants available for incident_wavelength that we are using for SwissFEL data. These data have both a calibrated wavelength derived (I think) from analyzing the spectrum and doing some fitting, and they also have the full spectra available. Therefore, the way I set this up in NeXus is using these three datasets:The dataset has 1448 images and the calibrated wavelengths are in
incident_wavelength
. That field has an attributevariant=incident_wavelength_1Dspectrum
, which represents the spectrum that the wavelengths were derived from, one for each image. For each spectrum, the 2560 channels are the same. Therefore the weights array for the spectra is of shape Nimages, Nchannels.This is implemented in FormatNexus by checking for the different permutations available for 0D, 1D and 2D wavelength arrays with possible variants. Note however that the key
incident_wavelength_1Dspectrum
isn't in the NXmx spec, as it's just presumed that this is how variants work. Because of this we can't use a direct mapping like theH5Mapping
class does.This is a draft PR because things are not quite working yet. This is fine:
Output:
Note the beam wavelength comes from the calibrated array, which is different than the weighted wavelength from the spectrum.
The image viewer is failing with
when reading
incident_wavelength
fromnxbeam.handle
. Inspecting the handle it is being reported as closed. IsCachedWavelengthBeamFactory
closing the handle somewhere that I can't see?Thanks, and feel free to revise the PR to better match FormatNXmx as desired (especially dropping my use of convert_units from FormatNexus). I'll try to get SwissFEL test data with spectra uploaded to Zenodo tomorrow.
When merged, this will close #537.