Changeset 83c09af in sasview for src/sas/sascalc/dataloader


Ignore:
Timestamp:
Jan 3, 2017 1:12:00 PM (8 years ago)
Author:
krzywon
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:
af08e55
Parents:
c1681ea
Message:

Fit states and projects are now able to save 2D data. Loading is still not working. #827

Location:
src/sas/sascalc/dataloader/readers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    r0639476 r83c09af  
    2020import inspect 
    2121# For saving individual sections of data 
    22 from sas.sascalc.dataloader.data_info import Data1D, DataInfo, plottable_1D 
    23 from sas.sascalc.dataloader.data_info import Collimation, TransmissionSpectrum, Detector, Process, Aperture 
    24 from sas.sascalc.dataloader.data_info import combine_data_info_with_plottable as combine_data 
     22from sas.sascalc.dataloader.data_info import Data1D, Data2D, DataInfo, \ 
     23    plottable_1D 
     24from sas.sascalc.dataloader.data_info import Collimation, TransmissionSpectrum, \ 
     25    Detector, Process, Aperture 
     26from sas.sascalc.dataloader.data_info import \ 
     27    combine_data_info_with_plottable as combine_data 
    2528import sas.sascalc.dataloader.readers.xml_reader as xml_reader 
    2629from sas.sascalc.dataloader.readers.xml_reader import XMLreader 
     
    792795        :param datainfo: Data1D object 
    793796        """ 
    794         if not issubclass(datainfo.__class__, Data1D): 
    795             raise RuntimeError, "The cansas writer expects a Data1D instance" 
     797        if issubclass(datainfo.__class__, Data2D): 
     798            is_2d = True 
    796799 
    797800        # Get PIs and create root element 
     
    813816        self._write_run_names(datainfo, entry_node) 
    814817        # Add Data info to SASEntry 
    815         self._write_data(datainfo, entry_node) 
     818        if is_2d: 
     819            self._write_data_2d(datainfo, entry_node) 
     820        else: 
     821            self._write_data(datainfo, entry_node) 
    816822        # Transmission Spectrum Info 
    817823        self._write_trans_spectrum(datainfo, entry_node) 
     
    907913    def _write_data(self, datainfo, entry_node): 
    908914        """ 
    909         Writes the I and Q data to the XML file 
     915        Writes 1D I and Q data to the XML file 
    910916 
    911917        :param datainfo: The Data1D object the information is coming from 
     
    935941                self.write_node(point, "dQl", datainfo.dxl[i], 
    936942                                {'unit': datainfo.x_unit}) 
     943 
     944    def _write_data_2d(self, datainfo, entry_node): 
     945        """ 
     946        Writes 2D data to the XML file 
     947 
     948        :param datainfo: The Data2D object the information is coming from 
     949        :param entry_node: lxml node ElementTree object to be appended to 
     950        """ 
     951        node = self.create_element("SASdata") 
     952        self.append(node, entry_node) 
     953 
     954        for i in range(len(datainfo.data)): 
     955            point = self.create_element("Idata") 
     956            node.append(point) 
     957            self.write_node(point, "Qx", datainfo.qx_data[i], 
     958                            {'unit': datainfo._xunit}) 
     959            self.write_node(point, "Qy", datainfo.qy_data[i], 
     960                            {'unit': datainfo._yunit}) 
     961            self.write_node(point, "I", datainfo.data[i], 
     962                            {'unit': datainfo._zunit}) 
     963            if datainfo.err_data is not None and len(datainfo.err_data) > i: 
     964                self.write_node(point, "Idev", datainfo.err_data[i], 
     965                                {'unit': datainfo._zunit}) 
     966            if datainfo.dqy_data is not None and len(datainfo.dqy_data) > i: 
     967                self.write_node(point, "Qydev", datainfo.dqy_data[i], 
     968                                {'unit': datainfo._yunit}) 
     969            if datainfo.dqx_data is not None and len(datainfo.dqx_data) > i: 
     970                self.write_node(point, "Qxdev", datainfo.dqx_data[i], 
     971                                {'unit': datainfo._xunit}) 
     972            if datainfo.mask is not None and len(datainfo.mask) > i: 
     973                self.write_node(point, "Mask", datainfo.err_data[i]) 
    937974 
    938975    def _write_trans_spectrum(self, datainfo, entry_node): 
  • src/sas/sascalc/dataloader/readers/schema/cansas1d_invalid_v1_0.xsd

    r250fec92 r83c09af  
    2424 
    2525        <complexType name="IdataType"> 
     26                <xsd:choice> 
    2627                <sequence> 
    2728                        <element name="Q" minOccurs="1" maxOccurs="1"    type="tns:floatUnitType" /> 
     
    4041                        <xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax" namespace="##other" /> 
    4142                </sequence> 
     43                <sequence> 
     44                        <element name="Qx" minOccurs="1" maxOccurs="1"    type="tns:floatUnitType" /> 
     45                        <element name="Qy" minOccurs="1" maxOccurs="1"    type="tns:floatUnitType" /> 
     46                        <element name="I" minOccurs="1" maxOccurs="1"    type="tns:floatUnitType" /> 
     47                        <element name="Idev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 
     48                        <element name="Qydev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 
     49                        <element name="Qxdev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 
     50                        <element name="Mask" minOccurs="0" maxOccurs="1" type="string" default="0" /> 
     51                </sequence> 
     52                </xsd:choice> 
    4253        </complexType> 
    4354         
  • src/sas/sascalc/dataloader/readers/schema/cansas1d_invalid_v1_1.xsd

    r250fec92 r83c09af  
    2424 
    2525        <complexType name="IdataType"> 
     26                <xsd:choice> 
    2627                <sequence> 
    2728                        <element name="Q" minOccurs="1" maxOccurs="1"    type="tns:floatUnitType" /> 
     
    4041                        <xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax" namespace="##other" /> 
    4142                </sequence> 
     43                <sequence> 
     44                        <element name="Qx" minOccurs="1" maxOccurs="1"    type="tns:floatUnitType" /> 
     45                        <element name="Qy" minOccurs="1" maxOccurs="1"    type="tns:floatUnitType" /> 
     46                        <element name="I" minOccurs="1" maxOccurs="1"    type="tns:floatUnitType" /> 
     47                        <element name="Idev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 
     48                        <element name="Qydev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 
     49                        <element name="Qxdev" minOccurs="0" maxOccurs="1" type="tns:floatUnitType" default="0" /> 
     50                        <element name="Mask" minOccurs="0" maxOccurs="1" type="string" default="0" /> 
     51                </sequence> 
     52                </xsd:choice> 
    4253        </complexType> 
    4354         
Note: See TracChangeset for help on using the changeset viewer.