예제 #1
0
	def testInitECalibrationSpectrumRange(self): 
		try:
			eels = SpectrumImage.EELSSpectrumImage(self.data, ZLP=False, dispersion=None, SpectrumRange=np.array([0, 1, 2, 3, 4]), channel_eV=None)
		except ValueError:
			self.fail("Got value error, didn't want one anyway " + traceback.format_exc())
		self.assertEqual(eels.dispersion, 1)
		self.assertArraysEqual(eels.SpectrumRange, np.array([0, 1, 2, 3, 4]))
예제 #2
0
 def testDictifyMultipleLevels(self):
     self.assertEqual(
         SpectrumImage.make_dict_from_tags(['root.foo.bar = 12']),
         {'root': {
             'foo': {
                 'bar': '12'
             }
         }})
예제 #3
0
 def testInitECalibrationChanneleVwrong(self):
     with self.assertRaisesRegexp(ValueError,
                                  'channel_eV must have length 2!'):
         eels = SpectrumImage.EELSSpectrumImage(self.data,
                                                ZLP=False,
                                                SpectrumRange=None,
                                                dispersion=0.3,
                                                channel_eV=[2, 0.5, 1])
예제 #4
0
 def testInitECalibrationZLPnoDispersion(self):
     with self.assertRaisesRegexp(ValueError,
                                  'Dispersion needs to be a real number!'):
         eels = SpectrumImage.EELSSpectrumImage(self.data,
                                                ZLP=True,
                                                SpectrumRange=None,
                                                dispersion=None,
                                                channel_eV=None)
예제 #5
0
	def testInitECalibrationChanneleV(self):
		try:
			eels = SpectrumImage.EELSSpectrumImage(self.data, ZLP=False, dispersion=0.3, SpectrumRange=None, channel_eV=[2, 0.5])
		except ValueError:
			self.fail("Got value error, didn't want one anyway")
		self.assertEqual(eels.dispersion, 0.3)
		self.assertAlmostEqual(eels.SpectrumRange[2], 0.5)
		self.assertArraysEqual(eels.data, self.data)
예제 #6
0
 def testInitECalibrationNone(self):
     with self.assertRaisesRegexp(
             ValueError, 'You need to input an energy calibration!'):
         eels = SpectrumImage.EELSSpectrumImage(self.data,
                                                ZLP=False,
                                                SpectrumRange=None,
                                                dispersion=None,
                                                channel_eV=None)
예제 #7
0
	def testInitECalibrationZLP(self):
		try:
			eels = SpectrumImage.EELSSpectrumImage(self.data, ZLP=True, dispersion=0.3, SpectrumRange=None, channel_eV=None)
		except ValueError:
			self.fail("Got value error, didn't want one anyway")
		self.assertEqual(eels.dispersion, 0.3)
		self.assertTrue(eels.ZLP)
		self.assertArraysEqual(eels.data, self.data)
예제 #8
0
	def __init__(self, SI = np.array([]), Wavelengths = np.array([]), SEM=np.array([]), survey=np.array([]), fuzzing=False):
		self.fuzzing = fuzzing
		self.SI = SpectrumImage.CLSpectrumImage(SI, Wavelengths)
		self.SEM = SEM
		self.survey = survey
		if self.fuzzing:
			reshapedSEM = np.reshape(self.SEM.data, [int(self.SEM.size[0]/4), 4, int(self.SEM.size[1]/4), 4])
			self.unfuzzedSEM = Image(np.sum(np.sum(reshapedSEM, axis=1), axis=-1), calibration=self.SEM.calibration*4)
		else:
			self.unfuzzedSEM = self.SEM
예제 #9
0
 def __init__(self,
              SI=np.array([]),
              Wavelengths=np.array([]),
              SEM=np.array([]),
              survey=np.array([]),
              fuzzing=False):
     self.fuzzing = fuzzing
     self.SI = SpectrumImage.CLSpectrumImage(SI, Wavelengths * 1e9)
     self.SEM = Image(SEM)
     self.survey = Image(survey)
예제 #10
0
 def testZLPandSpectrumRange(self):
     with self.assertRaisesRegexp(
             ValueError,
             "You don't need to define a SpectrumRange and ZLP/dispersion!"
     ):
         eels = SpectrumImage.EELSSpectrumImage(self.data,
                                                ZLP=True,
                                                SpectrumRange=np.array(
                                                    [0, 1, 2, 4, 5]),
                                                dispersion=0.3,
                                                channel_eV=None)
예제 #11
0
 def testSpectrumRangeWrongLength(self):
     with self.assertRaisesRegexp(
             ValueError,
             "Your SpectrumRange is not the same size as your energy axis!"
     ):
         eels = SpectrumImage.EELSSpectrumImage(self.data,
                                                ZLP=False,
                                                SpectrumRange=np.array(
                                                    [0, 1, 2, 4]),
                                                dispersion=None,
                                                channel_eV=None)
예제 #12
0
 def testDictifyCollision(self):
     self.assertEqual(
         SpectrumImage.make_dict_from_tags(['bar = 10', 'bar = 12']),
         {'bar': '10'})
예제 #13
0
## Testing ImagePlotter
#Im = np.random.random((2000,2000))
#a = ImagePlotter.ImagePlotter(ax, Im)

#### Testing SIPlotter
#SIdata = np.random.random(size = (20,30,50))
#SIdata[:, :, 10] = 2
#SI = SpectrumImage.EELSSpectrumImage(SIdata, dispersion=0.01)
#plotter=SpectrumImagePlotter.SpectrumImagePlotter(SI)
#plt.show()

###Testing SIPlotter with real data!
folder = '/home/isobel/Documents/McMaster/EELS/2016-07-28/Sq2R_(1,7)/'
filebase = 'EELS Spectrum Image (dark ref corrected).dm3'
s = hp.load(folder + filebase)
eels = SpectrumImage.EELSSpectrumImage(s.data)
#PSF = Spectrum.EELSSpectrum.LoadFromCSV('/home/isobel/Documents/McMaster/EELS/2016-07-27/SI3/Processed/Spectrum_ZLP.csv')
#print(np.shape(PSF.intensity))
p1 = SpectrumImagePlotter.SpectrumImagePlotter(eels, filepath=folder)
#eels2 = eels.RLDeconvolution(2, PSF)
#p2 = SpectrumImagePlotter.SpectrumImagePlotter(eels2)
p1.ShowPlot()

folderCL = '/home/isobel/Documents/McMaster/CL/T9-3_Sq1A_(1,3)/'
fileCL = 'T9-3_Sq1A_(1,3)h_Gr800at750_30keV_Ap3Spot4_2s_noQWP_noPol_full2.h5'
cl = CLSpectrumData.CLDataSet.LoadFromFile(folderCL + fileCL)

plotter = SpectrumImagePlotter.SpectrumImagePlotter(cl.SI)

plt.show()
#plotter.extractedim.SaveImgAsPNG('/home/isobel/Documents/McMaster/PythonCodes/DataAnalysis/testIm.png', plotter.extractedim.Imglim)
예제 #14
0
 def testDictifyOneLevel(self):
     self.assertEqual(SpectrumImage.make_dict_from_tags(['root = 65']),
                      {'root': '65'})
예제 #15
0
#		raise ValueError("No intersection! Fix it!")

#	h_edge = sorted((r1.xmin, r1.xmax, r2.xmin, r2.xmax))
#	v_edge = sorted((r1.ymin, r1.ymax, r2.ymin, r2.ymax))
#	return Rectangle(h_edge[1], v_edge[1], h_edge[2], v_edge[2])

#print("Will's rectangle stuff")
#r1=Rectangle(0,0,10,10)
#r2=Rectangle(2,2,17,17)
#print(FindRectangleIntersectionWillsWay(r1, r2))
################End of Will's thing

#maxcorners = np.roll(np.transpose((p1.size, p2.size, p3.size, p4.size)), 1, axis = 0)
#overlapcorners = (np.max(offsets, axis = 1), np.min(maxcorners+offsets, axis = 1))
#p2_alignedtest = p2.data[overlapcorners[0][1] - offsets[1][1]:overlapcorners[1][1]-offsets[1][1], overlapcorners[0][0] - offsets[0][1]:overlapcorners[1][0] - offsets[0][1]]
#print(offsets)
AlignCrop.AlignCrop((p1, p2, SpectrumImage.SpectrumImage(data.chelsea(), 'nm'),
                     SpectrumImage.SpectrumImage(data.astronaut(), 'nm')),
                    offsets)

fig = plt.figure()
ax = plt.axes([0, 0, 1, 1])
ax.imshow(p3.data, interpolation='none', cmap='gray')
ax.imshow(p1.data, interpolation='none', cmap='Reds', alpha=0.2)
#ax.imshow(p4_aligned, interpolation = 'none', cmap = 'hot', alpha = 0.2)
#ax.imshow(p1_aligned, alpha = 0.2, cmap = 'Blues', interpolation = 'none')
#ax.imshow(mask, cmap = 'gray', alpha = 0.8)
ax.axis('off')

plt.show()
예제 #16
0
 def testDictifyEmptyValue(self):
     self.assertEqual(SpectrumImage.make_dict_from_tags(['root = ']),
                      {'root': ''})
예제 #17
0
        raise ValueError("No intersection! Fix it!")

    h_edge = sorted((r1.xmin, r1.xmax, r2.xmin, r2.xmax))
    v_edge = sorted((r1.ymin, r1.ymax, r2.ymin, r2.ymax))
    return Rectangle(h_edge[1], v_edge[1], h_edge[2], v_edge[2])


#print "Will's rectangle stuff"
#r1=Rectangle(0,0,10,10)
#r2=Rectangle(2,2,17,17)
#print FindRectangleIntersectionWillsWay(r1, r2)
################End of Will's thing

#maxcorners = np.roll(np.transpose((p1.size, p2.size, p3.size, p4.size)), 1, axis = 0)
#overlapcorners = (np.max(offsets, axis = 1), np.min(maxcorners+offsets, axis = 1))
#p2_alignedtest = p2.data[overlapcorners[0][1] - offsets[1][1]:overlapcorners[1][1]-offsets[1][1], overlapcorners[0][0] - offsets[0][1]:overlapcorners[1][0] - offsets[0][1]]
print(offsets)
AlignCrop.AlignCrop((p1, p2, SpectrumImage.SpectrumImage(
    data.chelsea()), SpectrumImage.SpectrumImage(data.astronaut())), offsets)

fig = plt.figure()
ax = plt.axes([0, 0, 1, 1])
ax.imshow(p3.data, interpolation='none', cmap='gray')
ax.imshow(p1.data, interpolation='none', cmap='Reds', alpha=0.2)
#ax.imshow(p4_aligned, interpolation = 'none', cmap = 'hot', alpha = 0.2)
#ax.imshow(p1_aligned, alpha = 0.2, cmap = 'Blues', interpolation = 'none')
#ax.imshow(mask, cmap = 'gray', alpha = 0.8)
ax.axis('off')

plt.show()
예제 #18
0
 def testDictifyMultipleValues(self):
     self.assertEqual(
         SpectrumImage.make_dict_from_tags(['foo = 12', 'bar = 16']), {
             'foo': '12',
             'bar': '16'
         })