Example #1
0
	def test_importBrukerSpectra_malformederetic(self):
		from nPYc.utilities._importBrukerSpectrum import importBrukerSpectra

		Attributes = dict()
		Attributes['variableSize'] = numpy.random.randint(10000, high=50000, size=None)

		Attributes['bounds'] = [-0.5, 10]

		Attributes['alignTo'] = 'singlet'
		Attributes['calibrateTo'] = 0
		Attributes['ppmSearchRange'] = [-0.3, 0.3]

		Attributes['LWpeakRange'] = [-0.3, 0.3]
		Attributes['LWpeakMultiplicity'] = 'singlet'
		Attributes['LWpeakIntesityFraction'] = 1e-4

		with self.assertWarnsRegex(UserWarning, 'Error parsing `QuantFactorSample`'):
			intensityData, ppm, metadata = importBrukerSpectra(os.path.join('..', '..', 'npc-standard-project',
																			'Raw_Data', 'nmr', 'UnitTest1',
																			'UnitTest1_Urine_Rack1_SLL_270814', '10'),
																			'noesypr1d', 1, Attributes)

		expectedWarningText = 'Error calculating ERETIC integral'
		self.assertEqual(metadata.loc[0, 'Warnings'], expectedWarningText)

		expectedERETIC = numpy.nan
		numpy.testing.assert_allclose(metadata.loc[0, 'ERETIC Integral'], expectedERETIC)
    def test_importBrukerSpectra_pdata(self):
        from nPYc.utilities._importBrukerSpectrum import importBrukerSpectra

        Attributes = dict()
        Attributes['variableSize'] = numpy.random.randint(10000,
                                                          high=50000,
                                                          size=None)

        lowBound = (-0.5 - -2) * numpy.random.random_sample() + -2
        highBound = (14.5 - 10) * numpy.random.random_sample() + 10
        Attributes['bounds'] = [lowBound, highBound]

        Attributes['alignTo'] = 'singlet'
        Attributes['calibrateTo'] = (
            0.5 - -0.5) * numpy.random.random_sample() + -0.5
        offset = Attributes['calibrateTo']
        Attributes['ppmSearchRange'] = [-0.5, -0.5]

        Attributes['LWpeakRange'] = [-0.5 + offset, 0.5 + offset]
        Attributes['LWpeakMultiplicity'] = 'singlet'
        Attributes['LWpeakIntesityFraction'] = 1e-4

        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            intensityData, ppm, metadata = importBrukerSpectra(
                os.path.join('..', '..', 'npc-standard-project', 'Raw_Data',
                             'nmr', 'UnitTest1'), 'noesygppr1d', 2, Attributes)
        ##
        # Sort to account for filesystem ordering
        ##
        metadata.sort_values('Sample File Name', inplace=True)
        sortIndex = metadata.index.values
        intensityData = intensityData[sortIndex, :]
        metadata = metadata.reset_index(drop=True)

        warningsCol = pandas.Series([''], name='Warnings', dtype='str')
        pandas.util.testing.assert_series_equal(metadata['Warnings'],
                                                warningsCol)

        sampleName = pandas.Series(['UnitTest1_Urine_Rack1_SLL_270814/30'],
                                   name='Sample File Name',
                                   dtype='str')
        pandas.util.testing.assert_series_equal(metadata['Sample File Name'],
                                                sampleName)

        self.assertEqual(len(ppm), Attributes['variableSize'])
        numpy.testing.assert_allclose(numpy.min(ppm), Attributes['bounds'][0])
        numpy.testing.assert_allclose(numpy.max(ppm), Attributes['bounds'][1])

        expectedLW = 0.7083017156078231
        numpy.testing.assert_allclose(metadata.loc[0, 'Line Width (Hz)'],
                                      expectedLW,
                                      atol=0.01)

        expectedERETIC = 152106691.42761227
        numpy.testing.assert_allclose(metadata.loc[0, 'ERETIC Integral'],
                                      expectedERETIC)
Example #3
0
	def test_importBrukerSpectra(self):
		from nPYc.utilities._importBrukerSpectrum import importBrukerSpectra

		Attributes = dict()
		Attributes['variableSize'] = numpy.random.randint(10000, high=50000, size=None)

		lowBound = (-0.5 - -5) * numpy.random.random_sample() + -5
		highBound = (19 - 10) * numpy.random.random_sample() + 10
		Attributes['bounds'] = [lowBound, highBound]

		Attributes['alignTo'] = 'doublet'
		Attributes['calibrateTo'] = (6 - 4.5) * numpy.random.random_sample() + 4.5
		offset = 5.233 - Attributes['calibrateTo']
		Attributes['ppmSearchRange'] = [4.9, 5.733]

		Attributes['LWpeakRange'] = [4.08 - offset, 4.14 - offset]
		Attributes['LWpeakMultiplicity'] = 'quartet'
		Attributes['LWpeakIntesityFraction'] = 1e-4

		with warnings.catch_warnings():
			warnings.simplefilter("ignore")
			intensityData, ppm, metadata = importBrukerSpectra(os.path.join('..', '..', 'npc-standard-project',
																			'Raw_Data', 'nmr', 'UnitTest3',
																			'UnitTest3_Serum_Rack01_RCM_190116'),
																			'noesygppr1d', 1, Attributes)

		##
		# Sort to account for filesystem ordering
		##
		metadata.sort_values('Sample File Name', inplace=True)
		sortIndex = metadata.index.values
		intensityData = intensityData[sortIndex, :]
		metadata = metadata.reset_index(drop=True)

		warningsCol = pandas.Series(['',
									'Error loading file',
									'Error loading file',
									'Error loading file',
									'Error loading file',
									'Error loading file',
									'Error loading file',
									'Error loading file',
									'Error loading file',
									'Error loading file'],
									name='Warnings',
									dtype='str')
		pandas.util.testing.assert_series_equal(metadata['Warnings'], warningsCol)

		sampleName = pandas.Series(['UnitTest3_Serum_Rack01_RCM_190116/10',
									'UnitTest3_Serum_Rack01_RCM_190116/100',
									'UnitTest3_Serum_Rack01_RCM_190116/110',
									'UnitTest3_Serum_Rack01_RCM_190116/120',
									'UnitTest3_Serum_Rack01_RCM_190116/130',
									'UnitTest3_Serum_Rack01_RCM_190116/140',
									'UnitTest3_Serum_Rack01_RCM_190116/150',
									'UnitTest3_Serum_Rack01_RCM_190116/160',
									'UnitTest3_Serum_Rack01_RCM_190116/170',
									'UnitTest3_Serum_Rack01_RCM_190116/180'],
									name='Sample File Name',
									dtype='str')
		pandas.util.testing.assert_series_equal(metadata['Sample File Name'], sampleName)

		sumFailedImports = numpy.sum(intensityData[1:, :])
		numpy.testing.assert_allclose(sumFailedImports, 0)

		self.assertEqual(len(ppm), Attributes['variableSize'])
		numpy.testing.assert_allclose(numpy.min(ppm), Attributes['bounds'][0])
		numpy.testing.assert_allclose(numpy.max(ppm), Attributes['bounds'][1])

		expectedLW = 0.97083128379560091
		numpy.testing.assert_allclose(metadata.loc[0, 'Line Width (Hz)'], expectedLW)

		expectedERETIC = 181331824.09952235
		numpy.testing.assert_allclose(metadata.loc[0, 'ERETIC Integral'], expectedERETIC)