def _load_asc(self, filename): """Load a single scan file from ascii data.""" with open(filename, "r") as data: if not data.readline().startswith("# Daisy frame view snapshot"): raise ValueError(f"{filename} lacked the correct header line") tmp = ImageFile() for line in data: if not line.startswith("# "): break parts = [x.strip() for x in line[2:].strip().split(":")] key = parts[0] value = ":".join(parts[1:]) units = PARAM_RE.match(value) if units and units.groups()[1]: key += f" [{units.groups()[1]}]" value = units.groups()[0] tmp.metadata[key] = value xpx = tmp["x-pixels"] ypx = tmp["y-pixels"] metadata = tmp.metadata tmp.image = genfromtxt(filename).reshape((xpx, ypx)) tmp.metadata = metadata tmp.filename = tmp["display"] self.append(tmp) return self
from Stoner.Image import ImageFile, ImageFolder, ImageStack import numpy as np import unittest import os import Stoner Stoner.Options.multiprocessing = False testdir = os.path.join(os.path.dirname(__file__), "coretestdata", "testims") istack2 = ImageStack() 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) i.filename = "Angle {}".format(theta) istack2.insert(0, i) class ImageStackTest(unittest.TestCase): 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 def test_ImageStack(self): self.assertTrue( self.istack2.shape == (91, 100, 100), "ImageStack.shape wrong at {}".format(self.istack2.shape))
@author: phygbu """ from Stoner.Image import ImageFile,ImageFolder, ImageStack import numpy as np import unittest import os testdir=os.path.join(os.path.dirname(__file__),"coretestdata","testims") istack2=ImageStack() 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) i.filename="Angle {}".format(theta) istack2.insert(0,i) class ImageStack2Test(unittest.TestCase): 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 def test_ImageStack2(self): self.assertTrue(self.istack2.shape==(91,100,100),"ImageStack2.shape wrong at {}".format(self.istack2.shape)) i=ImageFile(np.zeros((100,100))).draw.circle(50,50,25) self.m1=self.istack2.mean()