Changeset 802fc18 in sasview
- Timestamp:
- Nov 15, 2018 12:08:56 PM (6 years ago)
- Branches:
- master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249
- Children:
- a165bee
- Parents:
- c1dc994
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
rc1dc994 r802fc18 1 1 """ 2 CanSAS 2Ddata reader for reading HDF5 formatted CanSAS files.2 NXcanSAS data reader for reading HDF5 formatted CanSAS files. 3 3 """ 4 4 … … 22 22 class Reader(FileReader): 23 23 """ 24 A class for reading in CanSAS v2.0 data files. The existing iteration opens25 Mantid generated HDF5 formatted files with file extension .h5/.H5. Any26 number of data sets may be present within the file and any dimensionality27 of data may be used. Currently 1D and 2D SAS data sets are supported, but28 future implementations will include 1D and 2D SESANS data.29 30 Any number of SASdata sets may be present in a SASentry and the data within 31 can be either 1D I(Q) or 2D I(Qx, Qy).32 33 Also supports reading NXcanSAS formatted HDF5 files24 A class for reading in NXcanSAS data files. The current implementation has 25 been tested to load data generated by multiple facilities, all of which are 26 known to produce NXcanSAS standards compliant data. Any number of data sets 27 may be present within the file and any dimensionality of data may be used. 28 Currently 1D and 2D SAS data sets are supported, but should be immediately 29 extensible to SESANS data. 30 31 Any number of SASdata groups may be present in a SASentry and the data 32 within each SASdata group can be a single 1D I(Q), multi-framed 1D I(Q), 33 2D I(Qx, Qy) or multi-framed 2D I(Qx, Qy). 34 34 35 35 :Dependencies: 36 The CanSAS HDF5 reader requires h5py => v2.5.0 or later.36 The NXcanSAS HDF5 reader requires h5py => v2.5.0 or later. 37 37 """ 38 38 … … 102 102 self.data2d = [] 103 103 self.raw_data = None 104 self.multi_frame = False 105 self.data_frames = [] 106 self.data_uncertainty_frames = [] 104 107 self.errors = [] 105 108 self.logging = [] … … 150 153 self.add_data_set(key) 151 154 elif class_prog.match(u'SASdata'): 155 self._find_data_attributes(value) 152 156 self._initialize_new_data_set(value) 153 self._find_data_attributes(value)154 157 # Recursion step to access data within the group 155 158 self.read_children(value, parent_list) … … 252 255 """ 253 256 if key == self.i_name: 254 self.current_dataset.y = data_set.flatten() 255 self.current_dataset.yaxis("Intensity", unit) 257 if self.multi_frame: 258 for x in range(0, data_set.shape[0]): 259 self.data_frames.append(data_set[x].flatten()) 260 else: 261 self.current_dataset.y = data_set.flatten() 262 self.current_dataset.yaxis("Intensity", unit) 256 263 elif key == self.i_uncertainties_name: 264 if self.multi_frame: 265 for x in range(0, data_set.shape[0]): 266 self.data_uncertainty_frames.append(data_set[x].flatten()) 257 267 self.current_dataset.dy = data_set.flatten() 258 268 elif key in self.q_names: … … 517 527 self.data2d.append(self.current_dataset) 518 528 elif isinstance(self.current_dataset, plottable_1D): 519 self.data1d.append(self.current_dataset) 529 if self.multi_frame: 530 for x in range(0, len(self.data_frames) - 1): 531 self.current_dataset.y = self.data_frames[x] 532 if len(self.data_uncertainty_frames) > x: 533 self.current_dataset.dy = \ 534 self.data_uncertainty_frames[x] 535 self.data1d.append(self.current_dataset) 536 else: 537 self.data1d.append(self.current_dataset) 520 538 521 539 def final_data_cleanup(self): … … 598 616 if self.current_datainfo and self.current_dataset: 599 617 self.final_data_cleanup() 618 self.data_frames = [] 619 self.data_uncertainty_frames = [] 600 620 self.data1d = [] 601 621 self.data2d = [] … … 617 637 self.current_dataset = plottable_1D(x, y) 618 638 self.current_datainfo.filename = self.raw_data.filename 619 self.mask_name = u''620 self.i_name = u''621 self.i_node = u''622 self.i_uncertainties_name = u''623 self.q_names = []624 self.q_uncertainty_names = []625 self.q_resolution_names = []626 639 627 640 @staticmethod … … 645 658 :param value: SASdata/NXdata HDF5 Group 646 659 """ 660 # Initialize values to base types 661 self.mask_name = u'' 662 self.i_name = u'' 663 self.i_node = u'' 664 self.i_uncertainties_name = u'' 665 self.q_names = [] 666 self.q_uncertainty_names = [] 667 self.q_resolution_names = [] 668 # Get attributes 647 669 attrs = value.attrs 648 670 signal = attrs.get("signal", "I") … … 652 674 i_axes = self.check_is_list_or_array(i_axes) 653 675 keys = value.keys() 676 # Assign attributes to appropriate class variables 654 677 self.mask_name = attrs.get("mask") 655 678 for val in q_indices: … … 676 699 self.i_uncertainties_name = i_vals.attrs.get("uncertainty") 677 700 678 def _is2d(self, value, basename="I"):701 def _is2d(self, value, i_base="", q_base=[]): 679 702 """ 680 703 A private class to determine if the data set is 1d or 2d. 681 704 682 :param parent_list: List of parents nodes in the HDF5 file705 :param value: Nexus/NXcanSAS data group 683 706 :param basename: Approximate name of an entry to search for 684 707 :return: True if 2D, otherwise false 685 708 """ 686 687 vals = value.get(basename) 688 return (vals is not None and vals.shape is not None 689 and len(vals.shape) != 1) 709 i_basename = i_base if i_base != "" else self.i_name 710 i_vals = value.get(i_basename) 711 q_basename = q_base if q_base != [] else self.q_names 712 q_vals = value.get(q_basename[0]) 713 self.multi_frame = True if (i_vals is not None and q_vals is not None 714 and len(i_vals.shape) != 1 715 and len(q_vals.shape) == 1) else False 716 return (i_vals is not None and i_vals.shape is not None 717 and len(i_vals.shape) != 1 and not self.multi_frame) 690 718 691 719 def _create_unique_key(self, dictionary, name, numb=0):
Note: See TracChangeset
for help on using the changeset viewer.