Changeset ac3353d in sasview
- Timestamp:
- Aug 23, 2016 7:11:28 AM (8 years ago)
- 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:
- 9ddffe0
- Parents:
- 0fcb097
- Location:
- src/sas/sascalc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
r0fcb097 rac3353d 193 193 elif key == u'Title' and self.parent_class == u'SASsample': # CanSAS 2.0 format 194 194 self.current_datainfo.sample.name = data_point 195 elif key == u' name' and self.parent_class == u'SASsample': # NXcanSAS format195 elif key == u'ID' and self.parent_class == u'SASsample': # NXcanSAS format 196 196 self.current_datainfo.sample.name = data_point 197 197 elif key == u'thickness' and self.parent_class == u'SASsample': -
src/sas/sascalc/file_converter/nxcansas_writer.py
ra14fa99 rac3353d 44 44 return np.array([np.string_(string)]) 45 45 46 def _write_h5_string(entry, value, key): 47 entry[key] = _h5_string(value) 48 49 46 50 def _h5_float(x): 47 51 if not (isinstance(x, list)): 48 52 x = [x] 49 53 return np.array(x, dtype=np.float32) 54 55 def _write_h5_float(entry, value, key): 56 entry.create_dataset(key, data=_h5_float(value)) 57 58 def _write_h5_vector(entry, vector, names=['x_position', 'y_position'], 59 units=None, write_fn=_write_h5_string): 60 if len(names) < 2: 61 raise ValueError("Length of names must be >= 2.") 62 63 if vector.x is not None: 64 write_fn(entry, vector.x, names[0]) 65 if units is not None: 66 entry[names[0]].attrs['units'] = units 67 if vector.y is not None: 68 write_fn(entry, vector.y, names[1]) 69 if units is not None: 70 entry[names[1]].attrs['units'] = units 71 if len(names) == 3 and vector.z is not None: 72 write_fn(entry, vector.z, names[2]) 73 if units is not None: 74 entry[names[2]].attrs['units'] = units 50 75 51 76 valid_data = all([issubclass(d.__class__, (Data1D, Data2D)) for d in dataset]) … … 83 108 84 109 data_info = dataset[0] 110 # Sample metadata 85 111 sample_entry = sasentry.create_group('sassample') 86 112 sample_entry.attrs['canSAS_class'] = 'SASsample' 87 sample_entry[' name'] = _h5_string(data_info.sample.name)88 sample_attrs = ['thickness', 'temperature' ]113 sample_entry['ID'] = _h5_string(data_info.sample.name) 114 sample_attrs = ['thickness', 'temperature', 'transmission'] 89 115 for key in sample_attrs: 90 116 if getattr(data_info.sample, key) is not None: 91 117 sample_entry.create_dataset(key, 92 118 data=_h5_float(getattr(data_info.sample, key))) 93 119 _write_h5_vector(sample_entry, data_info.sample.position) 120 _write_h5_vector(sample_entry, data_info.sample.orientation, 121 names=['polar_angle', 'azimuthal_angle']) 122 123 # Instrumment metadata 94 124 instrument_entry = sasentry.create_group('sasinstrument') 95 125 instrument_entry.attrs['canSAS_class'] = 'SASinstrument' 96 126 instrument_entry['name'] = _h5_string(data_info.instrument) 97 127 128 # Source metadata 98 129 source_entry = instrument_entry.create_group('sassource') 99 130 source_entry.attrs['canSAS_class'] = 'SASsource' … … 103 134 source_entry['radiation'] = _h5_string(data_info.source.radiation) 104 135 136 # Collimation metadata 105 137 if len(data_info.collimation) > 0: 106 138 i = 1 … … 110 142 collimation_entry.attrs['canSAS_class'] = 'SAScollimation' 111 143 if coll_info.length is not None: 112 collimation_entry['SDD'] = _h5_float(coll_info.length)144 _write_h5_float(collimation_entry, coll_info.length, 'SDD') 113 145 collimation_entry['SDD'].attrs['units'] = coll_info.length_unit 114 146 if coll_info.name is not None: 115 147 collimation_entry['name'] = _h5_string(coll_info.name) 116 148 else: 149 # Create a blank one - at least 1 set of collimation metadata 150 # required by format 117 151 collimation_entry = instrument_entry.create_group('sascollimation01') 118 152 153 # Detector metadata 119 154 if len(data_info.detector) > 0: 120 155 i = 1 … … 124 159 detector_entry.attrs['canSAS_class'] = 'SASdetector' 125 160 if det_info.distance is not None: 126 detector_entry['SDD'] = _h5_float(det_info.distance)161 _write_h5_float(detector_entry, det_info.distance, 'SDD') 127 162 detector_entry['SDD'].attrs['units'] = det_info.distance_unit 128 163 if det_info.name is not None: … … 130 165 else: 131 166 detector_entry['name'] = _h5_string('') 167 if det_info.slit_length is not None: 168 _write_h5_float(detector_entry, det_info.slit_length, 'slit_length') 169 detector_entry['slit_length'].attrs['units'] = det_info.slit_length_unit 170 _write_h5_vector(detector_entry, det_info.offset) 171 _write_h5_vector(detector_entry, det_info.orientation, 172 names=['polar_angle', 'azimuthal_angle']) 173 _write_h5_vector(detector_entry, det_info.beam_center, 174 names=['beam_center_x', 'beam_center_y'], 175 write_fn=_write_h5_float, units=det_info.beam_center_unit) 176 _write_h5_vector(detector_entry, det_info.pixel_size, 177 names=['x_pixel_size', 'y_pixel_size'], 178 write_fn=_write_h5_float, units=det_info.pixel_size_unit) 179 132 180 i += 1 133 181 else: 182 # Create a blank one - at least 1 detector required by format 134 183 detector_entry = instrument_entry.create_group('sasdetector01') 135 184 detector_entry.attrs['canSAS_class'] = 'SASdetector'
Note: See TracChangeset
for help on using the changeset viewer.