示例#1
0
def convert_QE(entry, dQ, dE):
    """Convert S(phi,eps) to S(Q,eps)"""
    az = entry.data.azimuthal.nxdata[:]
    pol = entry.data.polar.nxdata[:]
    pol, en = centers(entry.data.nxsignal, entry.data.nxaxes)
    data = entry.data.data.nxdata[:]
    errors = entry.data.errors.nxdata[:]

    Ei = entry.instrument.monochromator.incident_energy.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])
    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)
    histe, hbin = np.histogramdd((Ein, Qin),
                                 bins=(Eb, Qb),
                                 weights=errorsin * errorsin)
    histe = histe**0.5

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

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

    return NXdata(I, (Eb, Qb), errors=NXfield(err))
示例#2
0
def convert_QE(entry, dQ, dE):
    """Convert S(phi,eps) to S(Q,eps)"""
    az = entry.data.azimuthal.nxdata[:]
    pol = entry.data.polar.nxdata[:]
    pol, en = centers(entry.data.nxsignal, entry.data.nxaxes)
    data = entry.data.data.nxdata[:]
    errors = entry.data.errors.nxdata[:]

    Ei = entry.instrument.monochromator.incident_energy.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])
    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)
    histe, hbin = np.histogramdd((Ein,Qin), bins=(Eb,Qb), weights=errorsin*errorsin)
    histe = histe**0.5

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

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

    return NXdata(I, (Eb, Qb), errors=NXfield(err))
示例#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
示例#4
0
文件: convert_qe.py 项目: nexpy/nexpy
    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