Changeset 9e9f848 in sasview


Ignore:
Timestamp:
Aug 9, 2016 4:41:12 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:
5451a78
Parents:
ba65aff
Message:

When exporting to multiple files, append frame number to filenames

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/file_converter/converter_panel.py

    rba65aff r9e9f848  
    8585        self.Layout() 
    8686 
    87     def convert_to_cansas(self, frame_data, filename, single_file): 
     87    def convert_to_cansas(self, frame_data, filepath, single_file): 
    8888        """ 
    8989        Saves an array of Data1D objects to a single CanSAS file with multiple 
     
    9191        <SasData> element. 
    9292 
    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 
    9596        :param single_file: If true, array is saved as a single file, if false, 
    9697        each item in the array is saved to it's own file 
     
    100101        if self.run_name is not None: 
    101102            entry_attrs = { 'name': self.run_name } 
     103         
    102104        if single_file: 
    103             writer.write(filename, frame_data, 
     105            writer.write(filepath, frame_data, 
    104106                sasentry_attrs=entry_attrs) 
    105107        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], 
    117116                    sasentry_attrs=entry_attrs) 
    118117 
     
    315314        } 
    316315 
    317         frame_data = [] 
     316        frame_data = {} 
    318317        for i in frames: 
    319318            data = Data1D(x=qdata, y=iqdata[i]) 
    320             frame_data.append(data) 
     319            frame_data[i] = data 
    321320        if single_file: 
    322321            # Only need to set metadata on first Data1D object 
     322            frame_data = frame_data.values() # Don't need to know frame numbers 
    323323            frame_data[0].filename = output_path.split('\\')[-1] 
    324324            for key, value in metadata.iteritems(): 
     
    326326        else: 
    327327            # Need to set metadata for all Data1D objects 
    328             for datainfo in frame_data: 
     328            for datainfo in frame_data.values(): 
    329329                datainfo.filename = output_path.split('\\')[-1] 
    330330                for key, value in metadata.iteritems(): 
Note: See TracChangeset for help on using the changeset viewer.