-
Notifications
You must be signed in to change notification settings - Fork 0
reduced 1-D data in NX file for uascan (step scan) #588
Comments
Yet. |
Example of current data file: Al7075FbMap1_10_0056.zip |
The livedata code reduces the 1-D data from the SPEC file: def reduce_uascan(sds):
'''data reduction of an uascan (in a SPEC file)
:params obj sds: spec2nexus.spec.SpecDataFileScan object
:returns: dictionary of title and R(Q)
'''
# get the raw data from the data file
created_by_bluesky = sds.header.comments[0].startswith("Bluesky ")
if not created_by_bluesky: # SPEC created this data file
wavelength = float(sds.metadata['DCM_lambda'])
ar = numpy.array(sds.data['ar'])
seconds = numpy.array(sds.data['seconds'])
pd = numpy.array(sds.data['pd_counts'])
I0 = numpy.array(sds.data['I0'])
I0_amplifier_gain = numpy.array(sds.metadata['I0AmpGain'])
pd_range = numpy.array(sds.data['pd_range'], dtype=int)
ar_center = float(sds.metadata['arCenter']) This is done by intent: step scans could be done by either SPEC or Bluesky and would receive equal treatment. |
@jilavsky : SPEC does not create a NeXus file for step scans. Shall we add the 1-D data reduction to the NeXus files from Bluesky |
This is when the code starts to be repeated since |
One particular problem may come up. Since the NeXus file is written by a callback, executed while the plan is running from bluesky, we might have difficulty in writing additional content until the run is finished (and the file is closed by the callback). First off, I've added |
This diagnostic, added at the same point, will inform us if we can add the reduced 1-D data to the NeXus file after the scan ends but before the from ..callbacks import nxwriter
print(f"nxwriter is open: {nxwriter.id.valid == 1} with {nxwriter.mode=}") |
Do we need to test this on live hardware? This afternoon would be a good time if so. An alternative, selfish solution would be for me to import a |
@pbeaucage : Do what you need for the today problem. Long term, the livedata code will be upgraded to Py3.8+. With the diagnostic code added today, I'm hopeful we learn how quickly we can integrate writing of reduced data. I've got time 2-4 today. |
With APS-U, this software should be installed as packages, in various modules, so the same code can be used in the multiple contexts (data recording, visualization, ...) of the USAXS instrument. |
I added a few lines of code to the |
The timing could be off to write reduced data at this point because the |
If it's a problem to reduce at this point in the plan, then we rethink the idea and write the reduced data from the nxwriter callback by adding lines here: https://github.com/APS-USAXS/usaxs-bluesky/blob/e07cb8d9689c9224d9c659125433e974e320f60d/instrument/callbacks/nxwriter_usaxs.py#L136-L142 specifically after |
Adding this code in the callback, must test that it does not cause other problems (such as if this code is used by other plans). |
Since there is an upgrade to the NXWriter that avoids a certain deadlock (involving a special case we do not have here with a uascan), the new code will run the writer in a background thread. Short story: we should not modify the At this point, all the data we will need has been written to the file (which we know is still open for write access). In the future, we'll need to |
Note: (bluesky_2023_1) bash-4.4$ git grep NXWriter
instrument/callbacks/nxwriter.py:from .nxwriter_usaxs import NXWriterUascan
instrument/callbacks/nxwriter.py:nxwriter = NXWriterUascan()
instrument/callbacks/nxwriter_usaxs.py: # "NXWriterFlyScan", # not yet tested
instrument/callbacks/nxwriter_usaxs.py: "NXWriterUascan",
instrument/callbacks/nxwriter_usaxs.py: # "NXWriterSaxsWaxs", # not yet tested
instrument/callbacks/nxwriter_usaxs.py:from apstools.callbacks import NXWriterAPS
instrument/callbacks/nxwriter_usaxs.py:class OurCustomNXWriterBase(NXWriterAPS):
instrument/callbacks/nxwriter_usaxs.py: customize the NXWriter for this instrument
instrument/callbacks/nxwriter_usaxs.py: def write_monochromator( # override NXWriterAPS
instrument/callbacks/nxwriter_usaxs.py:class NXWriterFlyScan(OurCustomNXWriterBase):
instrument/callbacks/nxwriter_usaxs.py:class NXWriterSaxsWaxs(OurCustomNXWriterBase):
instrument/callbacks/nxwriter_usaxs.py:class NXWriterUascan(OurCustomNXWriterBase): In this issue, we focus on the |
Looks promising:
|
I'm making progress on pulling the reduction code from livedata. Next, will need to get the code that writes it into the correct group(s). |
Here's a fragment of the structure of reduced Fly scan data in one of our NeXus files:
Hint: We're not using NXcanSAS here, just an ordinary NXdata group. |
We did NOT capture any error messages in the log files. Maybe something was shown onscreen but I did not see it when we tested. Pivot the |
After a restart, I'm getting the TODO now, and I have Victory? |
Victory! |
Does it suit your needs? Anything else to be done here? |
I see the pattern done here could also be applied to Fly Scans, in the other class in the same file. |
On a separate issue, that is. |
I think this covers it! The only other thing would be filtering intensity dropouts during range switches, but that's there in the webplot code too. I think I can deal with it on my end. Thanks for the help! |
Users report they cannot find reduced 1-D data in NeXus file from
uascan
step scans.Thanks to Peter Beaucage, @jilavsky for spotting this.
The text was updated successfully, but these errors were encountered: