Changeset 0836f77 in sasview for src/sas/sascalc/file_converter


Ignore:
Timestamp:
Aug 23, 2016 9:34:13 AM (8 years ago)
Author:
lewis
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
7fce2bc
Parents:
9ddffe0
Message:

Write source metadata to NXcanSAS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/file_converter/nxcansas_writer.py

    r9ddffe0 r0836f77  
    4747            entry[key] = _h5_string(value) 
    4848 
    49  
    5049        def _h5_float(x): 
    5150            if not (isinstance(x, list)): 
     
    5857        def _write_h5_vector(entry, vector, names=['x_position', 'y_position'], 
    5958            units=None, write_fn=_write_h5_string): 
     59            """ 
     60            Write a vector to an h5 entry 
     61 
     62            :param entry: The H5Py entry to write to 
     63            :param vector: The Vector to write 
     64            :param names: What to call the x,y and z components of the vector 
     65                when writing to the H5Py entry 
     66            :param units: The units of the vector (optional) 
     67            :param write_fn: A function to convert the value to the required 
     68                format and write it to the H5Py entry, of the form 
     69                f(entry, value, name) (optional) 
     70            """ 
    6071            if len(names) < 2: 
    6172                raise ValueError("Length of names must be >= 2.") 
     
    121132        # and yaw. The _write_h5_vector method writes vector.y, but we 
    122133        # need to write vector.z for yaw 
    123         data_info.sample.orientation.y = data_info.orientation.z 
     134        data_info.sample.orientation.y = data_info.sample.orientation.z 
    124135        _write_h5_vector(sample_entry, data_info.sample.orientation, 
    125136            names=['polar_angle', 'azimuthal_angle']) 
     137        if data_info.sample.details is not None\ 
     138            and data_info.sample.details != []: 
     139            details = reduce(lambda x,y: x + "\n" + y, data_info.sample.details) 
     140            sample_entry['details'] = _h5_string(details) 
    126141 
    127142        # Instrumment metadata 
     
    137152        else: 
    138153            source_entry['radiation'] = _h5_string(data_info.source.radiation) 
     154        if data_info.source.beam_shape is not None: 
     155            source_entry['beam_shape'] = _h5_string(data_info.source.beam_shape) 
     156        wavelength_keys = { 'wavelength': 'incident_wavelength', 
     157            'wavelength_min':'wavelength_min', 
     158            'wavelength_max': 'wavelength_max', 
     159            'wavelength_spread': 'incident_wavelength_spread' } 
     160        for sasname, nxname in wavelength_keys.iteritems(): 
     161            value = getattr(data_info.source, sasname) 
     162            units = getattr(data_info.source, sasname + '_unit') 
     163            if value is not None: 
     164                source_entry[nxname] = _h5_float(value) 
     165                source_entry[nxname].attrs['units'] = units 
     166        _write_h5_vector(source_entry, data_info.source.beam_size, 
     167            names=['beam_size_x', 'beam_size_y'], 
     168            units=data_info.source.beam_size_unit, write_fn=_write_h5_float) 
     169 
    139170 
    140171        # Collimation metadata 
Note: See TracChangeset for help on using the changeset viewer.