Пример #1
0
 def save(self, hdf_file, scan_list=[]):
     '''
     save the information in this SPEC data file to a NeXus HDF5 file
     
     Each scan in scan_list will be converted to a **NXentry** group.  
     Scan data will be placed in a **NXdata** group where the attribute **signal=1** is the 
     last column and the corresponding attribute **axes=<name of the first column>**.
     There are variations on this for 2-D and higher dimensionality data, such as mesh scans.
     
     In general, the tree structure of the NeXus HDF5 file is::
     
         hdf5_file: NXroot
             @default="S1"
             definition="NXspecdata"
             # attributes
             S1:NXentry
                 @default="data"
                 # attributes and metadata fields
                 data:NXdata
                     @signal=<name of signal field>
                     @axes=<name(s) of axes of signal>
                     @<axis>_indices=<list of indices in "axis1">
                     <signal_is_the_last_column>:NX_NUMBER[number of points] = ... data ...
                         @signal=1
                         @axes='<axis_is_name_of_first_column>'
                         @<axis>_indices=<list of indices in "axis1" used as dimension scales of the "signal">
                     <axis_is_name_of_first_column>:NX_NUMBER[number of points] = ... data ...
                     # other columns from the scan
     
     :param str hdf_file: name of NeXus/HDF5 file to be written
     :param [int] scanlist: list of scan numbers to be read
     '''
     root = eznx.makeFile(hdf_file, **self.root_attributes())
     pick_first_entry = True
     for key in scan_list:
         nxentry = eznx.makeGroup(root, 'S' + str(key), 'NXentry')
         eznx.makeDataset(
             nxentry,
             'definition',
             'NXspecdata',
             description='NeXus application definition (status pending)')
         self.save_scan(nxentry, self.spec.getScan(key))
         if pick_first_entry:
             pick_first_entry = False
             eznx.addAttributes(root, default='S' + str(key))
         if 'data' not in nxentry:
             # NXentry MUST have a NXdata group with data for default plot
             nxdata = eznx.makeGroup(
                 nxentry,
                 'data',
                 'NXdata',
                 signal='no_y_data',
                 axes='no_x_data',
                 no_x_data_indices=[
                     0,
                 ],
             )
             eznx.makeDataset(nxdata,
                              "no_x_data", (0, 1),
                              units='none',
                              long_name='no data points in this scan')
             eznx.makeDataset(nxdata,
                              "no_y_data", (0, 1),
                              units='none',
                              long_name='no data points in this scan')
     root.close()  # be CERTAIN to close the file
Пример #2
0
 def save(self, hdf_file, scan_list=[]):
     '''
     save the information in this SPEC data file to a NeXus HDF5 file
     
     Each scan in scan_list will be converted to a **NXentry** group.  
     Scan data will be placed in a **NXdata** group where the attribute **signal=1** is the 
     last column and the corresponding attribute **axes=<name of the first column>**.
     There are variations on this for 2-D and higher dimensionality data, such as mesh scans.
     
     In general, the tree structure of the NeXus HDF5 file is::
     
         hdf5_file: NXroot
             @default="S1"
             definition="NXspecdata"
             # attributes
             S1:NXentry
                 @default="data"
                 # attributes and metadata fields
                 data:NXdata
                     @signal=<name of signal field>
                     @axes=<name(s) of axes of signal>
                     @<axis>_indices=<list of indices in "axis1">
                     <signal_is_the_last_column>:NX_NUMBER[number of points] = ... data ...
                         @signal=1
                         @axes='<axis_is_name_of_first_column>'
                         @<axis>_indices=<list of indices in "axis1" used as dimension scales of the "signal">
                     <axis_is_name_of_first_column>:NX_NUMBER[number of points] = ... data ...
                     # other columns from the scan
     
     :param str hdf_file: name of NeXus/HDF5 file to be written
     :param [int] scanlist: list of scan numbers to be read
     '''
     root = eznx.makeFile(hdf_file, **self.root_attributes())
     pick_first_entry = True
     for key in scan_list:
         nxentry = eznx.makeGroup(root, 'S'+str(key), 'NXentry')
         eznx.makeDataset(nxentry, 
                          'definition', 
                          'NXspecdata', 
                          description='NeXus application definition (status pending)')
         self.save_scan(nxentry, self.spec.getScan(key))
         if pick_first_entry:
             pick_first_entry = False
             eznx.addAttributes(root, default='S'+str(key))
         if 'data' not in nxentry:
             # NXentry MUST have a NXdata group with data for default plot
             nxdata = eznx.makeGroup(nxentry, 
                                     'data', 
                                     'NXdata',
                                     signal='no_y_data',
                                     axes='no_x_data',
                                     no_x_data_indices=[0,],
                                     )
             eznx.makeDataset(nxdata, 
                              "no_x_data", 
                              (0, 1), 
                              units='none',
                              long_name='no data points in this scan')
             eznx.makeDataset(nxdata, 
                              "no_y_data", 
                              (0, 1), 
                              units='none',
                              long_name='no data points in this scan')
     root.close()    # be CERTAIN to close the file
Пример #3
0
17.92508    23819
17.92458    49087
17.92408    66802
17.92358    66206
17.92308    64129
17.92258    56795
17.92208    29315
17.92158    6622
17.92108    1321
'''
#---------------------------

tthData, countsData = zip(*[map(float,_.split()) for _ in I_v_TTH_DATA.strip().splitlines()])

f = eznx.makeFile(HDF5_FILE)  # create the HDF5 NeXus file
f.attrs['default'] = 'entry'

nxentry = eznx.makeGroup(f, 'entry', 'NXentry', default='data')
nxinstrument = eznx.makeGroup(nxentry, 'instrument', 'NXinstrument')
nxdetector = eznx.makeGroup(nxinstrument, 'detector', 'NXdetector')

tth = eznx.makeDataset(nxdetector, "two_theta", tthData, units='degrees')
counts = eznx.makeDataset(nxdetector, "counts", countsData, units='counts')

nxdata = eznx.makeGroup(nxentry, 'data', 'NXdata', 
                        signal=1, axes='two_theta', two_theta_indices=0)
eznx.makeLink(nxdetector, tth, nxdata.name+'/two_theta')
eznx.makeLink(nxdetector, counts, nxdata.name+'/counts')

f.close()    # be CERTAIN to close the file