- Timestamp:
- Aug 9, 2016 4:41:12 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:
- 5451a78
- Parents:
- ba65aff
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/file_converter/converter_panel.py
rba65aff r9e9f848 85 85 self.Layout() 86 86 87 def convert_to_cansas(self, frame_data, file name, single_file):87 def convert_to_cansas(self, frame_data, filepath, single_file): 88 88 """ 89 89 Saves an array of Data1D objects to a single CanSAS file with multiple … … 91 91 <SasData> element. 92 92 93 :param frame_data: The Data1D object to save 94 :param filename: Where to save the CanSAS file 93 :param frame_data: If single_file is true, an array of Data1D objects. 94 If single_file is false, a dictionary of the form frame_number: Data1D. 95 :param filepath: Where to save the CanSAS file 95 96 :param single_file: If true, array is saved as a single file, if false, 96 97 each item in the array is saved to it's own file … … 100 101 if self.run_name is not None: 101 102 entry_attrs = { 'name': self.run_name } 103 102 104 if single_file: 103 writer.write(file name, frame_data,105 writer.write(filepath, frame_data, 104 106 sasentry_attrs=entry_attrs) 105 107 else: 106 # strip extension from filename 107 ext = "." + filename.split('.')[-1] 108 name = filename.replace(ext, '') 109 for i in range(len(frame_data)): 110 # TODO: Change i to actual frame number, not consecutive numbers 111 # (maybe use info in params from frame select dialog, ie 112 # increment. Alternatively, change frame_data to a dictionary 113 # with the frame number as key and use frame_data.iteritems() 114 # (would need to update CansasWriter to deal with this) 115 f_name = name + str(i) + ext 116 writer.write(f_name, [frame_data[i]], 108 # Folder and base filename 109 [group_path, group_name] = os.path.split(filepath) 110 ext = "." + group_name.split('.')[-1] # File extension 111 for frame_number, frame_data in frame_data.iteritems(): 112 # Append frame number to base filename 113 filename = group_name.replace(ext, str(frame_number)+ext) 114 destination = os.path.join(group_path, filename) 115 writer.write(destination, [frame_data], 117 116 sasentry_attrs=entry_attrs) 118 117 … … 315 314 } 316 315 317 frame_data = []316 frame_data = {} 318 317 for i in frames: 319 318 data = Data1D(x=qdata, y=iqdata[i]) 320 frame_data .append(data)319 frame_data[i] = data 321 320 if single_file: 322 321 # Only need to set metadata on first Data1D object 322 frame_data = frame_data.values() # Don't need to know frame numbers 323 323 frame_data[0].filename = output_path.split('\\')[-1] 324 324 for key, value in metadata.iteritems(): … … 326 326 else: 327 327 # Need to set metadata for all Data1D objects 328 for datainfo in frame_data :328 for datainfo in frame_data.values(): 329 329 datainfo.filename = output_path.split('\\')[-1] 330 330 for key, value in metadata.iteritems():
Note: See TracChangeset
for help on using the changeset viewer.