Changeset 94f4518 in sasview for src/sas/sasgui/perspectives/file_converter
- Timestamp:
- Jul 21, 2016 11:53:53 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:
- a3c538e1
- Parents:
- eb8da5f
- Location:
- src/sas/sasgui/perspectives/file_converter
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/file_converter/cansas_writer.py
reb8da5f r94f4518 55 55 self._write_run_names(datainfo, entry_node) 56 56 # Add Data info to SASEntry 57 self._write_data(frame_data, entry_node) 57 for data_info in frame_data: 58 self._write_data(data_info, entry_node) 58 59 # Transmission Spectrum Info 59 60 self._write_trans_spectrum(datainfo, entry_node) … … 77 78 return doc, entry_node 78 79 79 def _write_data(self, frame_data, entry_node):80 def _write_data(self, datainfo, entry_node): 80 81 """ 81 82 Writes the I and Q data to the XML file … … 84 85 :param entry_node: lxml node ElementTree object to be appended to 85 86 """ 86 for datainfo in frame_data: 87 node = self.create_element("SASdata") 88 self.append(node, entry_node) 87 node = self.create_element("SASdata") 88 self.append(node, entry_node) 89 89 90 for i in range(len(datainfo.x)): 91 point = self.create_element("Idata") 92 node.append(point) 93 self.write_node(point, "Q", datainfo.x[i], 90 for i in range(len(datainfo.x)): 91 point = self.create_element("Idata") 92 node.append(point) 93 self.write_node(point, "Q", datainfo.x[i], 94 {'unit': datainfo.x_unit}) 95 if len(datainfo.y) >= i: 96 self.write_node(point, "I", datainfo.y[i], 97 {'unit': datainfo.y_unit}) 98 if datainfo.dy != None and len(datainfo.dy) > i: 99 self.write_node(point, "Idev", datainfo.dy[i], 100 {'unit': datainfo.y_unit}) 101 if datainfo.dx != None and len(datainfo.dx) > i: 102 self.write_node(point, "Qdev", datainfo.dx[i], 94 103 {'unit': datainfo.x_unit}) 95 if len(datainfo.y) >= i: 96 self.write_node(point, "I", datainfo.y[i], 97 {'unit': datainfo.y_unit}) 98 if datainfo.dy != None and len(datainfo.dy) > i: 99 self.write_node(point, "Idev", datainfo.dy[i], 100 {'unit': datainfo.y_unit}) 101 if datainfo.dx != None and len(datainfo.dx) > i: 102 self.write_node(point, "Qdev", datainfo.dx[i], 103 {'unit': datainfo.x_unit}) 104 if datainfo.dxw != None and len(datainfo.dxw) > i: 105 self.write_node(point, "dQw", datainfo.dxw[i], 106 {'unit': datainfo.x_unit}) 107 if datainfo.dxl != None and len(datainfo.dxl) > i: 108 self.write_node(point, "dQl", datainfo.dxl[i], 109 {'unit': datainfo.x_unit}) 104 if datainfo.dxw != None and len(datainfo.dxw) > i: 105 self.write_node(point, "dQw", datainfo.dxw[i], 106 {'unit': datainfo.x_unit}) 107 if datainfo.dxl != None and len(datainfo.dxl) > i: 108 self.write_node(point, "dQl", datainfo.dxl[i], 109 {'unit': datainfo.x_unit}) -
src/sas/sasgui/perspectives/file_converter/converter_panel.py
reb8da5f r94f4518 73 73 self.Layout() 74 74 75 def convert_to_cansas(self, frame_data, filename ):75 def convert_to_cansas(self, frame_data, filename, single_file): 76 76 reader = CansasWriter() 77 77 entry_attrs = None 78 78 if self.run_name is not None: 79 79 entry_attrs = { 'name': self.run_name } 80 reader.write(filename, frame_data, 81 sasentry_attrs=entry_attrs) 80 if single_file: 81 reader.write(filename, frame_data, 82 sasentry_attrs=entry_attrs) 83 else: 84 # strip extension from filename 85 ext = "." + filename.split('.')[-1] 86 name = filename.replace(ext, '') 87 for i in range(len(frame_data)): 88 f_name = "{}{}{}".format(name, i+1, ext) 89 reader.write(f_name, [frame_data[i]], 90 sasentry_attrs=entry_attrs) 82 91 83 92 def extract_data(self, filename): … … 111 120 frames = None 112 121 increment = None 122 single_file = True 113 123 while not valid_input: 114 124 if dlg.ShowModal() == wx.ID_OK: … … 118 128 last_frame = int(dlg.last_input.GetValue()) 119 129 increment = int(dlg.increment_input.GetValue()) 130 single_file = dlg.single_btn.GetValue() 120 131 if last_frame < 0 or first_frame < 0: 121 132 msg = "Frame values must be positive" … … 136 147 StatusEvent(status=msg)) 137 148 else: 138 return [], 0149 return { 'frames': [], 'inc': None, 'file': single_file } 139 150 frames = range(first_frame, last_frame + increment, 140 151 increment) 141 return frames, increment152 return { 'frames': frames, 'inc': increment, 'file': single_file } 142 153 143 154 def on_convert(self, event): … … 159 170 frames = [iqdata.shape[0]] 160 171 increment = 1 172 single_file = True 161 173 if frames[0] > 3: 162 frames, increment = self.ask_frame_range(frames[0]) 174 params = self.ask_frame_range(frames[0]) 175 frames = params['frames'] 176 increment = params['inc'] 177 single_file = params['file'] 163 178 if frames == []: return 164 179 except Exception as ex: … … 191 206 data = Data1D(x=qdata, y=iqdata[i]) 192 207 frame_data.append(data) 193 # Only need to set metadata on first Data1D object 194 frame_data[0].filename = output_path.split('\\')[-1] 195 for key, value in metadata.iteritems(): 196 setattr(frame_data[0], key, value) 197 198 self.convert_to_cansas(frame_data, output_path) 208 if single_file: 209 # Only need to set metadata on first Data1D object 210 frame_data[0].filename = output_path.split('\\')[-1] 211 for key, value in metadata.iteritems(): 212 setattr(frame_data[0], key, value) 213 else: 214 # Need to set metadata for all Data1D objects 215 for datainfo in frame_data: 216 datainfo.filename = output_path.split('\\')[-1] 217 for key, value in metadata.iteritems(): 218 setattr(datainfo, key, value) 219 220 221 self.convert_to_cansas(frame_data, output_path, single_file) 199 222 wx.PostEvent(self.parent.manager.parent, 200 223 StatusEvent(status="Conversion completed.")) -
src/sas/sasgui/perspectives/file_converter/frame_select_dialog.py
reb8da5f r94f4518 13 13 "format").format(n_frames) 14 14 instructions_label = wx.StaticText(self, -1, instructions) 15 instructions_label.Wrap(self.GetSize().width - 20)15 instructions_label.Wrap(self.GetSize().width - 10) 16 16 sizer.Add(instructions_label, (y,0), (1,2), wx.ALL, 5) 17 17 y += 1 18 18 19 first_label = wx.StaticText(self, -1, "First Frame (0-{}): ".format(n_frames-1)) 19 first_label = wx.StaticText(self, -1, 20 "First Frame (0-{}): ".format(n_frames-1)) 20 21 sizer.Add(first_label, (y,0), (1,1), wx.ALL, 5) 21 22 … … 24 25 y += 1 25 26 26 last_label = wx.StaticText(self, -1, "Last Frame (0-{}): ".format(n_frames-1)) 27 last_label = wx.StaticText(self, -1, 28 "Last Frame (0-{}): ".format(n_frames-1)) 27 29 sizer.Add(last_label, (y,0), (1,1), wx.ALL, 5) 28 30 … … 38 40 y += 1 39 41 42 export_label = wx.StaticText(self, -1, "Export each frame to:") 43 sizer.Add(export_label, (y,0), (1,1), wx.LEFT | wx.RIGHT | wx.TOP, 5) 44 y += 1 45 46 self.single_btn = wx.RadioButton(self, -1, label="The same file", 47 style=wx.RB_GROUP) 48 sizer.Add(self.single_btn, (y,0), (1,1), 49 wx.LEFT | wx.RIGHT | wx.BOTTOM, 5) 50 51 multiple_btn = wx.RadioButton(self, -1, label="Multiple files") 52 sizer.Add(multiple_btn, (y,1), (1,1), 53 wx.LEFT | wx.RIGHT | wx.BOTTOM, 5) 54 y += 1 55 40 56 done_btn = wx.Button(self, wx.ID_OK) 41 sizer.Add(done_btn, (y,0), (1,1), wx.LEFT | wx. TOP | wx.BOTTOM, 15)57 sizer.Add(done_btn, (y,0), (1,1), wx.LEFT | wx.BOTTOM, 15) 42 58 43 59 cancel_btn = wx.Button(self, wx.ID_CANCEL) 44 sizer.Add(cancel_btn, (y,1), (1,1), wx. ALL, 15)60 sizer.Add(cancel_btn, (y,1), (1,1), wx.LEFT | wx.RIGHT | wx.BOTTOM, 15) 45 61 46 62 self.SetSizer(sizer) 63 64 size = self.GetSize() 65 size.height += 35 66 self.SetSize(size) -
src/sas/sasgui/perspectives/file_converter/media/file_converter_help.rst
reb8da5f r94f4518 12 12 The input files can be: 13 13 14 * Single column ASCII data, with lines that end with a digit , comma or15 semi-colon.14 * Single column ASCII data, with lines that end with a digit (no delimiter), 15 comma or semi-colon. 16 16 * `BSL/OTOKO formatted 17 17 <http://www.diamond.ac.uk/Beamlines/Soft-Condensed-Matter/small-angle/ … … 29 29 5) Click *Convert* to save the converted file to disk 30 30 31 **Note**: If a BSL/OTOKO file with multiple frames is selected for the 32 intensity-axis file, a dialog will appear asking which frames you would like 33 converted. You may enter a start frame, end frame & increment, and all frames 34 in that subset will be converted. For example: entering 0, 50 and 10 for the 35 first frame, last frame, and increment respectively will convert frames 0, 10, 36 20, 30, 40 & 50. To convert a single frame, enter the same value for first 37 frame & last frame, and 1 as the increment. 31 Files With Multiple Frames 32 ^^^^^^^^^^^^^^^^^^^^^^^^^^ 33 34 If a BSL/OTOKO file with multiple frames is selected for the intensity-axis 35 file, a dialog will appear asking which frames you would like converted. You 36 may enter a start frame, end frame & increment, and all frames in that subset 37 will be converted. For example: entering 0, 50 and 10 for the first frame, last 38 frame, and increment respectively will convert frames 0, 10, 20, 30, 40 & 50. 39 To convert a single frame, enter the same value for first frame & last frame, 40 and 1 as the increment. 41 42 There is also the option to output the data as multiple frames in a single 43 CanSAS file, or multiple files with one frame each. The single file option will 44 produce one file with multiple `<SASdata>` elements. The multiple file option 45 will output a file for each frame; each file will have one `<SASdata>` element, 46 and the frame number will appended to the file name.
Note: See TracChangeset
for help on using the changeset viewer.