-
Notifications
You must be signed in to change notification settings - Fork 0
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
How to write a NeXus metadata file with the lambda2m? #13
Comments
def my_plan():
yield from bp.count([lambda2m]) then |
Template with NeXus writing:. Since we are using the NXWriter from apstools, there is no existing documentation how to customize yet. Here is the guide demonstrating the NXWriter: https://bcda-aps.github.io/apstools/dev/examples/fw_nxwriter.html Instead of NXWriter, we're using NXWriterAPS since it understands the APS. The other is for use outside of APS beamlines. |
In a related issue, writing the run metadata could use standardized methods. We identified in our conf call today that the standardized methods could be more general. The related issue (BCDA-APS/bluesky_training#244) attempts to generalize the standardized methods. @qzhang234 asked:
Once this generalized method is implemented in the XPCS |
@prjemian I see. So should I add this part to my Bluesky plan and then proceed to the normal |
That's not the way it works. This part:
configures the session to record a new NeXus file with every run. So if you called
you would get a NeXus file. Then if you called
you'd get another NeXus file. Same for
you'd get yet another NeXus file. No extra setup code needed. |
As we discussed on Friday, the default behavior of the NXWriter() will try to copy the area detector image from the EPICS IOC-created file into the bluesky-created NeXus file. That's not what we want for XPCS. We'll need to provide some local changes to the standard NXWriter code. |
Note for me: |
Not sure we want this as the final code in the MyNXWriter class, but it is a starting point: def write_stream_external(self, parent, d, subgroup, stream_name, k, v):
resource_id = self.get_unique_resource(d)
fname = self.getResourceFile(resource_id)
ds = subgroup.create_dataset("file", data=fname.name)
h5addr = "/entry/data/data"
ds.attrs["target"] = ds.name
ds.attrs["source_file"] = str(fname)
ds.attrs["source_address"] = h5addr
ds.attrs["resource_id"] = resource_id
ds.attrs["shape"] = v.get("shape", "")
subgroup["external"] = h5py.ExternalLink(str(fname), h5addr)
def get_unique_resource(self, d):
# count number of unique resources (expect only 1)
resource_id_list = []
for datum_id in d:
resource_id = self.externals[datum_id]["resource"]
if resource_id not in resource_id_list:
resource_id_list.append(resource_id)
if len(resource_id_list) != 1:
# fmt: off
raise ValueError(
f"{len(resource_id_list)}"
f" unique resource UIDs: {resource_id_list}"
)
# fmt: on
return resource_id_list[0] On my local workstation, it results in this HDF5 structure:
|
Note |
@prjemian This is fantastic! Should I do a Also, per our discussion today, how do I unsubscribe nxwriter? Not super important at this moment, just curious |
Nothing to pull well use the old copy and paste technique. To unsubscribe, we need the integer key that was returned to us when we first subscribed. Since we did not store that key, it's not easy to get it later. That's why I had you comment out that part in the setup. |
revision to one of the above methods: def write_stream_external(self, parent, d, subgroup, stream_name, k, v):
resource_id = self.get_unique_resource(d)
fname = self.getResourceFile(resource_id)
h5addr = "/entry/data/data"
ds = h5py.ExternalLink(str(fname), h5addr) # TODO: check the path
ds.attrs["target"] = ds.name
ds.attrs["source_file"] = str(fname)
ds.attrs["source_address"] = h5addr
ds.attrs["resource_id"] = resource_id
ds.attrs["shape"] = v.get("shape", "")
subgroup["value"] = ds |
@qzhang234 asks (on Teams):
The text was updated successfully, but these errors were encountered: