Skip to content
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 example writing NeXus file from EPICS area detector using Python #606

Closed
prjemian opened this issue Dec 13, 2017 · 5 comments
Closed
Assignees
Milestone

Comments

@prjemian
Copy link
Contributor

No description provided.

@prjemian prjemian self-assigned this Dec 13, 2017
@prjemian
Copy link
Contributor Author

Both #605 & #606 result from recent email discussions about how-to

@prjemian
Copy link
Contributor Author

This will be done as part of #605. Closing here as duplicate.

@prjemian prjemian added this to the NXDL 2018.1 milestone Dec 19, 2017
@rayosborn
Copy link
Contributor

rayosborn commented Dec 19, 2017

I'm partly reopening this to suggest that there is a case for doing this with the nexusformat API. The write_nexus_file function would look like this:

def write_nexus_file(fname, image, md={}):
    """
    write the image to a NeXus HDF5 data file

    Parameters
    ----------
    fname : str
        name of the file (relative or absolute) to be written
    image : numpy array
        the image data
    md : dictionary
        key: value where value is something that can be written by h5py
             (such as str, int, float, numpy array, ...)
    """
    nx = NXroot()
    nx['/entry'] = NXentry(NXinstrument(NXdetector()))
    nx['entry/instrument/detector/image'] = NXfield(image, units='counts',
                                                    compression='gzip')
    nx['entry/data'] = NXdata()
    nx['entry/data'].makelink(nx['entry/instrument/detector/image'])
    nx['entry/data'].nxsignal = nx['entry/data/image']

    if len(md) > 0:
        # /entry/instrument/metadata (optional, for metadata)
        metadata = nx['/entry/instrument/metadata'] = NXcollection()
        for k, v in md.items():
            metadata[k] = v

    nx.save(fname, 'w')

i.e., 16 lines of code as opposed to 45.

The other reason for reopening is to ask whether there is a case for putting the metadata NXcollection group into the NXdetector group, since I presume that it is detector information that AreaDetector is providing. Otherwise, the metadata could apply to any other part of the instrument.

@rayosborn rayosborn reopened this Dec 19, 2017
@prjemian
Copy link
Contributor Author

I'll add your code as an additional example rather than a replacement. One thing I've learned is that people want to see exactly how something is done without the use of additional libraries, thus the full example without import nexusformat.

Since this is an example, the metadata shown is optional and may or may not be associated with the detector. The bitcoin value has nothing to do with the image and was just a playful insertion.

@rayosborn
Copy link
Contributor

I guessed that the AreaDetector software wasn't issuing Bitcoins (although I wouldn't object if any came my way), but if there is metadata associated with the detector, such as pixel sizes or exposure times, it ought to go in the NXdetector group, so it might be safer to make the example do the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants