Exemple #1
0
 def initialize_data(self, data):
     if isinstance(data, NXdata):
         if len(data.nxsignal.shape) > 1:
             raise NeXusError("Fitting only possible on one-dimensional arrays")
         fit_data = NXdata(data.nxsignal, data.nxaxes, title=data.nxtitle)
         if data.nxerrors:
             fit_data.errors = data.nxerrors
         return fit_data
     else:
         raise NeXusError("Must be an NXdata group")
 def initialize_data(self, data):
     if isinstance(data, NXdata):
         if len(data.nxsignal.shape) > 1:
             raise NeXusError(
                 "Fitting only possible on one-dimensional arrays")
         fit_data = NXdata(data.nxsignal, data.nxaxes, title=data.nxtitle)
         if data.nxerrors:
             fit_data.errors = data.nxerrors
         return fit_data
     else:
         raise NeXusError("Must be an NXdata group")
Exemple #3
0
    def convert_QE(self):
        """Convert S(phi,eps) to S(Q,eps)"""

        self.read_parameters()

        entry = self.root['entry']
        Ei = self.Ei
        dQ = self.dQ
        dE = self.dE

        pol, tof = centers(entry.data.nxsignal, entry.data.nxaxes)
        en = self.convert_tof(tof)

        idx_max = min(np.where(np.abs(en-0.75*Ei)<0.1)[0])

        en = en[:idx_max]

        data = entry.data.nxsignal.nxdata[:,:idx_max]
        if entry.data.nxerrors:
            errors = entry.data.nxerrors.nxdata[:]

        Q = np.zeros((len(pol), len(en)))
        E = np.zeros((len(pol), len(en)))

        for i in range(0,len(pol)):
            for j in range(0,len(en)):
                Q[i,j] = np.sqrt((2*Ei - en[j] - 2*np.sqrt(Ei*(Ei-en[j])) 
                                   * np.cos(pol[i]*np.pi/180.0))/2.0721)
                E[i,j]=en[j]

        s = Q.shape
        Qin = Q.reshape(s[0]*s[1])
        Ein = E.reshape(s[0]*s[1])
        datain = data.reshape(s[0]*s[1])
        if entry.data.nxerrors:
            errorsin = errors.reshape(s[0]*s[1])

        qmin = Q.min()
        qmax = Q.max()
        emin = E.min()
        emax = E.max()
        NQ = int((qmax-qmin)/dQ) + 1
        NE = int((emax-emin)/dE) + 1
        Qb = np.linspace(qmin, qmax, NQ)
        Eb = np.linspace(emin, emax, NE)
        #histogram and normalize 
        norm, nbin = np.histogramdd((Ein,Qin), bins=(Eb,Qb))
        hist, hbin = np.histogramdd((Ein,Qin), bins=(Eb,Qb), weights=datain)
        if entry.data.nxerrors:
            histe, hbin = np.histogramdd((Ein,Qin), bins=(Eb,Qb), weights=errorsin*errorsin)
            histe = histe**0.5
            err = histe/norm

        I = NXfield(hist/norm, name='S(Q,E)')

        Qb = NXfield(Qb[:-1]+dQ/2., name='Q')
        Eb = NXfield(Eb[:-1]+dE/2., name='E')

        result = NXdata(I, (Eb, Qb))
        if entry.data.nxerrors:
            result.errors = NXfield(err)
        return result
Exemple #4
0
    def convert_QE(self):
        """Convert S(phi,eps) to S(Q,eps)"""

        self.read_parameters()

        Ei = self.Ei
        dQ = self.dQ
        dE = self.dE

        signal = self.entry['data'].nxsignal
        pol = centers(self.entry['data/polar_angle'], signal.shape[0])
        tof = centers(self.entry['data/time_of_flight'], signal.shape[1])
        en = self.convert_tof(tof)

        idx_max = min(np.where(np.abs(en - 0.75 * Ei) < 0.1)[0])

        en = en[:idx_max]

        data = signal.nxdata[:, :idx_max]
        if self.entry['data'].nxerrors:
            errors = self.entry['data'].nxerrors.nxdata[:]

        Q = np.zeros((len(pol), len(en)))
        E = np.zeros((len(pol), len(en)))

        for i in range(0, len(pol)):
            p = pol[i]
            Q[i, :] = np.array(
                np.sqrt(
                    (2 * Ei - en -
                     2 * np.sqrt(Ei * (Ei - en)) * np.cos(p * np.pi / 180.0)) /
                    2.0721))
            E[i, :] = np.array(en)

        s = Q.shape
        Qin = Q.reshape(s[0] * s[1])
        Ein = E.reshape(s[0] * s[1])
        datain = data.reshape(s[0] * s[1])
        if self.entry['data'].nxerrors:
            errorsin = errors.reshape(s[0] * s[1])

        qmin = Q.min()
        qmax = Q.max()
        emin = E.min()
        emax = E.max()
        NQ = int((qmax - qmin) / dQ) + 1
        NE = int((emax - emin) / dE) + 1
        Qb = np.linspace(qmin, qmax, NQ)
        Eb = np.linspace(emin, emax, NE)
        # histogram and normalize
        norm, nbin = np.histogramdd((Ein, Qin), bins=(Eb, Qb))
        hist, hbin = np.histogramdd((Ein, Qin), bins=(Eb, Qb), weights=datain)
        if self.entry['data'].nxerrors:
            histe, hbin = np.histogramdd((Ein, Qin),
                                         bins=(Eb, Qb),
                                         weights=errorsin * errorsin)
            histe = histe**0.5
            err = histe / norm

        Ib = NXfield(hist / norm, name='S(Q,E)')

        Qb = NXfield(Qb[:-1] + dQ / 2., name='Q')
        Eb = NXfield(Eb[:-1] + dE / 2., name='E')

        result = NXdata(Ib, (Eb, Qb))
        if self.entry.data.nxerrors:
            result.errors = NXfield(err)
        return result