示例#1
0
 def setUp(self):
     self.td = ImageFolder(testdir, pattern='*.png')
     self.td = self.td.sort(key=lambda x: x.filename.lower())
     self.ks_dir = ImageStack(testdir)
     self.ks = ImageStack(self.td)  #load in two ways
     self.ks2_dir = ImageStack(testdir, pattern='*.png')
     self.ks2 = ImageStack(self.td)  #load in two ways
示例#2
0
 def setUp(self):
     self.td = ImageFolder(testdir, pattern='*.png')
     self.td=self.td.sort(key=lambda x:x.filename.lower())
     self.ks_dir = ImageStack(testdir)
     self.ks = ImageStack(self.td) #load in two ways
     self.ks2_dir = ImageStack2(testdir, pattern='*.png')
     self.ks2 = ImageStack2(self.td) #load in two ways
示例#3
0
 def setUp(self):
     self.td = ImageFolder(testdir, pattern='*.png')
     self.ks = ImageStack2(testdir)
     self.ks = ImageStack2(self.td) #load in two ways
     self.assertTrue(len(self.ks)==len(os.listdir(testdir)))
     self.istack2=ImageStack2()
     for theta in np.linspace(0,360,91):
         i=ImageFile(np.zeros((100,100)))
         x,y=10*np.cos(np.pi*theta/180)+50,10*np.sin(np.pi*theta/180)+50
         i.draw.circle(x,y,25)
         self.istack2.insert(0,i)
class ImageFolderTest(unittest.TestCase):
    def setUp(self):
        self.td = ImageFolder(testdir, pattern='*.png')
        self.td = self.td.sort(key=lambda x: x.filename.lower())
        self.ks = ImageStack(testdir)
        self.ks = ImageStack(self.td)  #load in two ways
        self.assertTrue(len(self.ks) == len(os.listdir(testdir)))

    def test_load(self):
        self.assertTrue(
            len(self.td) == len(os.listdir(testdir)),
            "Didn't find all the images")
        self.assertTrue(isinstance(self.td[0], ImageArray),
                        'Getting an image array from the ImageFolder failed'
                        )  #'{}, '.format(isinstance(self.td[0], ImageArray))#
        #self.assertTrue(self.td.slice_metadata(key='field',values_only=True)==knownfieldvals, 'slice metadata failed')

    def test_clone(self):
        c = self.ks.clone
        c.imarray[0, 0, 0] = 15.534
        self.assertFalse(np.array_equal(self.ks, c),
                         'clone failed to create new array')

    def test_imagestack(self):
        ks = self.ks.clone
        ks.append(self.ks[0].clone)
        self.assertTrue(
            len(ks) == len(self.ks) + 1, 'ImageStack append failed')
        self.assertTrue(
            len(ks.allmeta) == len(self.ks.allmeta) + 1,
            'ImageStack append failed')
        ks.insert(1, self.ks[0].clone)
        del (ks[1:3])
        self.assertTrue(
            len(ks) == len(self.ks), 'ImageStack insert or del failed')

    def test_kerrstack(self):
        ks = KerrStack(self.ks)
        self.assertTrue(
            np.min(ks.imarray) == 0.0 and np.max(ks.imarray) == 1.0,
            'KerrStack subtract failed min,max: {},{}'.format(
                np.min(ks.imarray), np.max(ks.imarray)))
        d = ks.hysteresis()
        self.assertTrue(isinstance(d, Data), 'hysteresis didnt return Data')
        self.assertTrue(d.data.shape == (len(ks), 2),
                        'hysteresis didnt return correct shape')
示例#5
0
class ImageFolderTest(unittest.TestCase):
    def setUp(self):
        self.td = ImageFolder(testdir, pattern='*.png')
        self.td = self.td.sort(key=lambda x: x.filename.lower())
        self.ks_dir = ImageStack(testdir)
        self.ks = ImageStack(self.td)  #load in two ways
        self.ks2_dir = ImageStack(testdir, pattern='*.png')
        self.ks2 = ImageStack(self.td)  #load in two ways

    def test_load(self):
        self.assertTrue(
            len(self.td) == len(os.listdir(testdir)),
            "Didn't find all the images")
        self.assertTrue(
            len(self.ks) == len(os.listdir(testdir)),
            "ImageStack conversion from ImageFolder failed")
        self.assertTrue(
            len(self.ks_dir) == len(os.listdir(testdir)),
            "IamgeStack read from directory failed")
        self.assertTrue(
            len(self.ks2) == len(os.listdir(testdir)),
            "ImageStack conversion from ImagerFolder failed")
        self.assertTrue(
            len(self.ks2_dir) == len(os.listdir(testdir)),
            "ImageStack read from directory failed.")

        self.assertTrue(
            isinstance(self.td[0], ImageArray),
            'Getting an image array from the ImageFolder failed type is {}'.
            format(type(self.td[0])
                   ))  #'{}, '.format(isinstance(self.td[0], ImageArray))#
        #self.assertTrue(self.td.slice_metadata(key='field',values_only=True)==knownfieldvals, 'slice metadata failed')

    def test_clone(self):
        c = self.ks.clone
        c.imarray[0, 0, 0] = 15.534
        self.assertFalse(np.array_equal(self.ks, c),
                         'clone failed to create new array')
示例#6
0
class ImageFolderTest(unittest.TestCase):

    def setUp(self):
        self.td = ImageFolder(testdir, pattern='*.png')
        self.td=self.td.sort(key=lambda x:x.filename.lower())
        self.ks_dir = ImageStack(testdir)
        self.ks = ImageStack(self.td) #load in two ways
        self.ks2_dir = ImageStack2(testdir, pattern='*.png')
        self.ks2 = ImageStack2(self.td) #load in two ways

    def test_load(self):
        self.assertTrue(len(self.td)==len(os.listdir(testdir)), "Didn't find all the images")
        self.assertTrue(len(self.ks)==len(os.listdir(testdir)),"ImageStack conversion from ImageFolder failed")
        self.assertTrue(len(self.ks_dir)==len(os.listdir(testdir)),"IamgeStack read from directory failed")
        self.assertTrue(len(self.ks2)==len(os.listdir(testdir)),"ImageStack2 conversion from ImagerFolder failed")
        self.assertTrue(len(self.ks2_dir)==len(os.listdir(testdir)),"ImageStack2 read from directory failed.")

        self.assertTrue(isinstance(self.td[0],ImageArray), 'Getting an image array from the ImageFolder failed type is {}'.format(type(self.td[0]))) #'{}, '.format(isinstance(self.td[0], ImageArray))#
        #self.assertTrue(self.td.slice_metadata(key='field',values_only=True)==knownfieldvals, 'slice metadata failed')

    def test_clone(self):
        c=self.ks.clone
        c.imarray[0,0,0] = 15.534
        self.assertFalse(np.array_equal(self.ks, c), 'clone failed to create new array')
示例#7
0
"""Demonstrate STXM Image Processing - G.Burnell Nov. 2017"""
# pylint: disable=invalid-name
from Stoner.Image import ImageFolder
from Stoner.HDF5 import STXMImage
from os.path import join, dirname
import numpy as np
import matplotlib.pyplot as plt
from lmfit.models import LorentzianModel
from types import MethodType

# Load the images
thisdir = dirname(__file__)

imgs = ImageFolder(type=STXMImage)
for fname in [
        "Sample_Image_2017-10-15_100.hdf5",
        "Sample_Image_2017-10-15_101.hdf5",
]:
    # Load the image
    img = STXMImage(join(thisdir, "..", "..", "..", "sample-data", fname))
    img.gridimage().crop(5, -15, 5, -5, _=True)  # regularise grid and crop
    imgs += img

# Align the two images
imgs.align(imgs[0], method="scharr", scale=4)
imgs.each.crop(2)

# Calculate the XMCD image and normalise it
xmcd = imgs[0] // imgs[1]
xmcd.normalise()
 def setUp(self):
     self.td = ImageFolder(testdir, pattern='*.png')
     self.td = self.td.sort(key=lambda x: x.filename.lower())
     self.ks = ImageStack(testdir)
     self.ks = ImageStack(self.td)  #load in two ways
     self.assertTrue(len(self.ks) == len(os.listdir(testdir)))
示例#9
0
 def setUp(self):
     self.td = ImageFolder(testdir, pattern='*.png')
     self.ks = ImageStack(testdir)
     self.ks = ImageStack(self.td)  #load in two ways
     self.assertTrue(len(self.ks) == len(os.listdir(testdir)))
     self.istack2 = istack2.clone
示例#10
0
"""Demonstrate STXM Image Processing - G.Burnell Nov. 2017"""
from Stoner.Image import ImageFile, ImageFolder
from Stoner.HDF5 import STXMImage
from os.path import join, dirname
import numpy as np
import matplotlib.pyplot as plt
from lmfit.models import LorentzianModel
from types import MethodType
#Load the images
thisdir = dirname(__file__)

imgs = ImageFolder(type=STXMImage)
for fname in [
        "Sample_Image_2017-10-15_100.hdf5", "Sample_Image_2017-10-15_101.hdf5"
]:
    #Load the image
    img = STXMImage(join(thisdir, "..", "..", "..", "sample-data", fname))
    img.gridimage().crop(5, -15, 5, -5, _=True)  # regularise grid and crop
    imgs += img

#Align the two images
imgs[1].align(imgs[0], method="scharr")

#Calculate the XMCD image and normalise it
xmcd = imgs[0] // imgs[1]
xmcd.normalise()

imgs += xmcd

strctural = (imgs[0] + imgs[1]) / 2
    Mode = input(
        "Would you like to:\n a) Sort hdf5 files by minorloop?\n OR \n b)process hdf5 files to make XMCD images & return metadata?\n"
    )
    if Mode.lower == "a":

        start_num, start_date, end_num, end_date, daychg_num = input(
            "Please enter the first image number and date, last image number and date, and day change number separated by spaces.\n"
        ).split()

        folder = os.path.join(fldr, input("Enter the folder name:\n"))

        os.chdir(folder)

        if os.path.exists(folder):
            IMG_FLDR = ImageFolder(folder, pattern="*.hdf5")
            string_file = IMG_FLDR.files
            num_files = len(string_file)
            print("Number of files=", num_files)
            for i in range(0, num_files):
                print(i + 1, " out of ", num_files)
                Date, img_num = get_params_from_name(string_file[i])
                img_num = int(img_num)

                MinorLoop_folder = os.path.join(
                    folder,
                    input(
                        "Please enter a folder name for this set of images:\n")
                )
                print(MinorLoop_folder)
            # if os.path.exists(field_folder)==True: