Esempio n. 1
0
    def check_FID(self, ppmlim=(.2, 4.2), repair=False):
        """
           Check if FID needs to be conjugated
           by looking at total power within ppmlim range

        Parameters
        ----------
        ppmlim : list
        repair : if True applies conjugation to FID

        Returns
        -------
        0 if check successful and -1 if not (also issues warning)

        """
        first, last = self.ppmlim_to_range(ppmlim)
        Spec1 = np.real(misc.FIDToSpec(self.FID))[first:last]
        Spec2 = np.real(misc.FIDToSpec(np.conj(self.FID)))[first:last]

        if np.linalg.norm(misc.detrend(Spec1, deg=4)) < np.linalg.norm(
                misc.detrend(Spec2, deg=4)):
            if repair is False:
                warnings.warn('YOU MAY NEED TO CONJUGATE YOUR FID!!!')
                return -1
            else:
                self.conj_FID()
                return 1

        return 0
Esempio n. 2
0
def test_FIDToSpec_SpecToFID():
    testFID, hdr = synth.syntheticFID(amplitude=[10],
                                      chemicalshift=[0],
                                      phase=[0],
                                      damping=[20])

    # SVS case
    spec = misc.FIDToSpec(testFID[0])
    reformedFID = misc.SpecToFID(spec)
    assert np.allclose(reformedFID, testFID)

    testMRSI = np.tile(testFID, (4, 4, 4, 1)).T
    testspec = misc.FIDToSpec(testMRSI)
    assert np.argmax(np.abs(testspec[:, 2, 2, 2])) == 1024

    testspec = misc.FIDToSpec(testMRSI.T, axis=3)
    assert np.argmax(np.abs(testspec[2, 2, 2, :])) == 1024

    reformedFID = misc.SpecToFID(testspec, axis=3)
    assert np.allclose(reformedFID, testMRSI.T)

    reformedFID = misc.SpecToFID(testspec.T)
    assert np.allclose(reformedFID, testMRSI)

    # Odd number of points - guard against fftshift/ifftshift errors
    testFID, hdr = synth.syntheticFID(amplitude=[1],
                                      chemicalshift=[0],
                                      phase=[0],
                                      damping=[20],
                                      points=1025)
    assert np.allclose(misc.SpecToFID(misc.FIDToSpec(testFID[0])), testFID)
Esempio n. 3
0
 def set_FID(self, FID):
     """
       Sets the FID and calculates spectrum
     """
     if FID.ndim > 1:
         raise ValueError(
             f'MRS objects only handle one FID at a time. FID shape is {FID.shape}.'
         )
     self.FID = FID.copy()
     self.numPoints = self.FID.size
     self.Spec = misc.FIDToSpec(self.FID)
Esempio n. 4
0
    def check_Basis(self, ppmlim=(.2, 4.2), repair=False):
        """
           Check if Basis needs to be conjugated
           by looking at total power within ppmlim range

        Parameters
        ----------
        ppmlim : list
        repair : if True applies conjugation to basis

        Returns
        -------
        0 if check successful and -1 if not (also issues warning)

        """
        first, last = self.ppmlim_to_range(ppmlim)

        conjOrNot = []
        for b in self.basis.T:
            Spec1 = np.real(misc.FIDToSpec(b))[first:last]
            Spec2 = np.real(misc.FIDToSpec(np.conj(b)))[first:last]
            if np.linalg.norm(misc.detrend(Spec1, deg=4)) < np.linalg.norm(
                    misc.detrend(Spec2, deg=4)):
                conjOrNot.append(1.0)
            else:
                conjOrNot.append(0.0)

        if (sum(conjOrNot) / len(conjOrNot)) > 0.5:
            if repair is False:
                warnings.warn('YOU MAY NEED TO CONJUGATE YOUR BASIS!!!')
                return -1
            else:
                self.conj_Basis()
                return 1

        return 0
Esempio n. 5
0
 def modify_basis(mrs, gamma, eps):
     bs = mrs.basis * np.exp(-(gamma + 1j * eps) * mrs.timeAxis)
     bs = misc.FIDToSpec(bs, axis=0)
     bs = bs[first:last, :]
     return np.concatenate((np.real(bs), np.imag(bs)), axis=0)
Esempio n. 6
0
 def conj_FID(self):
     """
     Conjugate FID and recalculate spectrum
     """
     self.FID = np.conj(self.FID)
     self.Spec = misc.FIDToSpec(self.FID)
Esempio n. 7
0
 def getSpectrum(self, ppmlim=None, shift=True):
     spectrum = misc.FIDToSpec(self.FID)
     f, l = self.ppmlim_to_range(ppmlim, shift=shift)
     return spectrum[f:l]