Changeset edf0e06 in sasview for src/sas/sasgui/perspectives/file_converter
- Timestamp:
- Aug 19, 2016 6:06:49 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:
- 9f4d891
- Parents:
- fe498b83
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/file_converter/converter_panel.py
rfe498b83 redf0e06 276 276 return { 'frames': frames, 'inc': increment, 'file': single_file } 277 277 278 def on_convert(self, event): 279 """Called when the Convert button is clicked""" 280 if not self.validate_inputs(): 281 return 282 283 self.sample.ID = self.title 284 285 try: 286 if self.data_type == 'ascii': 287 qdata = self.extract_ascii_data(self.q_input.GetPath()) 288 iqdata = np.array([self.extract_ascii_data(self.iq_input.GetPath())]) 289 elif self.data_type == 'otoko': 290 qdata, iqdata = self.extract_otoko_data(self.q_input.GetPath()) 291 else: # self.data_type == 'bsl' 292 293 dataset = self.extract_bsl_data(self.iq_input.GetPath()) 294 if dataset is None: 295 # Cancelled by user 296 return 297 298 w = NXcanSASWriter() 299 w.write(dataset, self.output.GetPath()) 300 301 wx.PostEvent(self.parent.manager.parent, 302 StatusEvent(status="Conversion completed.")) 303 return 304 305 except Exception as ex: 306 msg = str(ex) 307 wx.PostEvent(self.parent.manager.parent, 308 StatusEvent(status=msg, info='error')) 309 return 310 278 def get_metadata(self): 279 # Prepare the metadata for writing to a file 280 if self.run is None: 281 self.run = [] 282 elif not isinstance(self.run, list): 283 self.run = [self.run] 284 285 if self.title is None: 286 self.title = '' 287 288 metadata = { 289 'title': self.title, 290 'run': self.run, 291 'instrument': self.instrument, 292 'detector': [self.detector], 293 'sample': self.sample, 294 'source': self.source 295 } 296 297 return metadata 298 299 def convert_1d_data(self, qdata, iqdata): 300 """ 301 Formats a 1D array of q_axis data and a 2D array of I axis data (where 302 each row of iqdata is a separate row), into an array of Data1D objects 303 """ 311 304 frames = [] 312 305 increment = 1 … … 326 319 327 320 output_path = self.output.GetPath() 328 329 # Prepare the metadata for writing to a file 330 if self.run is None: 331 self.run = [] 332 elif not isinstance(self.run, list): 333 self.run = [self.run] 334 335 if self.title is None: 336 self.title = '' 337 338 metadata = { 339 'title': self.title, 340 'run': self.run, 341 'instrument': self.instrument, 342 'detector': [self.detector], 343 'sample': self.sample, 344 'source': self.source 345 } 321 metadata = self.get_metadata() 346 322 347 323 frame_data = {} … … 362 338 setattr(datainfo, key, value) 363 339 364 365 340 self.convert_to_cansas(frame_data, output_path, single_file) 341 342 def on_convert(self, event): 343 """Called when the Convert button is clicked""" 344 if not self.validate_inputs(): 345 return 346 347 self.sample.ID = self.title 348 349 try: 350 if self.data_type == 'ascii': 351 qdata = self.extract_ascii_data(self.q_input.GetPath()) 352 iqdata = np.array([self.extract_ascii_data(self.iq_input.GetPath())]) 353 self.convert_1d_data(qdata, iqdata) 354 elif self.data_type == 'otoko': 355 qdata, iqdata = self.extract_otoko_data(self.q_input.GetPath()) 356 self.convert_1d_data(qdata, iqdata) 357 else: # self.data_type == 'bsl' 358 dataset = self.extract_bsl_data(self.iq_input.GetPath()) 359 if dataset is None: 360 # Cancelled by user 361 return 362 363 metadata = self.get_metadata() 364 for key, value in metadata.iteritems(): 365 setattr(dataset[0], key, value) 366 367 w = NXcanSASWriter() 368 w.write(dataset, self.output.GetPath()) 369 except Exception as ex: 370 msg = str(ex) 371 wx.PostEvent(self.parent.manager.parent, 372 StatusEvent(status=msg, info='error')) 373 return 374 366 375 wx.PostEvent(self.parent.manager.parent, 367 376 StatusEvent(status="Conversion completed.")) … … 454 463 self.q_input.SetPath("") 455 464 self.q_input.Disable() 456 self.radiation_input.Disable()457 self.metadata_section.Collapse()458 self.on_collapsible_pane(None)459 self.metadata_section.Disable()465 # self.radiation_input.Disable() 466 # self.metadata_section.Collapse() 467 # self.on_collapsible_pane(None) 468 # self.metadata_section.Disable() 460 469 self.output.SetWildcard("NXcanSAS HDF5 File (*.h5)|*.h5") 461 470 else:
Note: See TracChangeset
for help on using the changeset viewer.