Commit a8488af0 authored by Josef Brandt's avatar Josef Brandt

SampleResult has attribute numVariations

for each numVariation, the filter is rotated a bit and any method can be applied again to the same sample
parent f83f5d56
......@@ -7,7 +7,6 @@ from scipy import spatial
from itertools import combinations
from random import sample
import time
import sys
sys.path.append("C://Users//xbrjos//Desktop//Python")
from gepard.analysis.particleContainer import ParticleContainer
......
import copy
import numpy as np
import sys
sys.path.append("C://Users//xbrjos//Desktop//Python")
from gepard.analysis.particleContainer import ParticleContainer
from cythonModules import rotateContour
class ParticleVariations(object):
def __init__(self, particleContainer: ParticleContainer, numVariations: int = 10) -> None:
super(ParticleVariations, self).__init__()
self.origParticleContainer = particleContainer
self.numVariations = numVariations
def get_particleContainer_variations(self) -> ParticleContainer:
if self.numVariations > 0:
partContainer: ParticleContainer = self.origParticleContainer
contours: list = partContainer.getParticleContours()
center: tuple = round(np.mean(contours[:][0][0])),\
round(np.mean(contours[:][0][1]))
center: np.ndarray = np.array(center, dtype=np.int32)
angles = self._get_angles()
for i in range(self.numVariations):
if i > 0:
partContainer = copy.deepcopy(self.origParticleContainer)
for particle in partContainer.particles:
contour = np.int32(particle.contour)
particle.contour = rotateContour.rotate_contour_around_point(contour,
center, np.float(angles[i]))
yield partContainer
def _get_angles(self) -> np.ndarray:
angleIncrement: float = 360 / self.numVariations
return np.arange(self.numVariations) * angleIncrement
This diff is collapsed.
......@@ -14,7 +14,7 @@ class SubsamplingMethod(object):
def __init__(self, particleConatainer, desiredFraction: float = 0.2):
super(SubsamplingMethod, self).__init__()
self.particleContainer = particleConatainer
self.fraction = desiredFraction
self.fraction: float = desiredFraction
@property
def label(self) -> str:
......
import numpy as np
import sys
sys.path.append("C://Users//xbrjos//Desktop//Python")
import gepard
from gepard.analysis.particleContainer import ParticleContainer
def get_default_ParticleContainer() -> ParticleContainer:
particleContainer: ParticleContainer = ParticleContainer(None)
particleContainer.initializeParticles(4)
contours: list = []
for i in range(4):
x = 10*i
contours.append(np.array([[[x, 0]], [[x+10, 0]], [[x+10, 10]], [[x, 10]]], dtype=np.int32))
particleContainer.setParticleContours(contours)
return particleContainer
import unittest
import numpy as np
import sys
sys.path.append("C://Users//xbrjos//Desktop//Python")
from gepard.analysis.particleContainer import ParticleContainer
from datasetOperations import ParticleVariations
from helpers_for_test import get_default_ParticleContainer
class TestParticleVariations(unittest.TestCase):
def test_get_particleContainer_variations(self):
particleContainer: ParticleContainer = get_default_ParticleContainer()
contours = particleContainer.getParticleContours()
center: tuple = round(np.mean(contours[:][0][0])), \
round(np.mean(contours[:][0][1]))
center: np.ndarray = np.array(center, dtype=np.int32)
for numVariations in [0, 1, 10, 20]:
particleVariations: ParticleVariations = ParticleVariations(particleContainer, numVariations)
foundContours: list = []
if numVariations == 0:
self.assertEqual(len(list(particleVariations.get_particleContainer_variations())), 0)
else:
for index, partContainer in enumerate(particleVariations.get_particleContainer_variations()):
if index == 0:
self.assertTrue(partContainer is particleContainer)
else:
self.assertFalse(partContainer is particleContainer)
contours = []
for particle in partContainer.particles:
contours.append(particle.contour)
contourHash = hash(particle.contour.tostring())
self.assertTrue(contourHash not in foundContours)
foundContours.append(contourHash)
self.assertEqual(index, numVariations-1)
def test_get_angles(self):
particleVariations: ParticleVariations = ParticleVariations(None, 2)
angles: list = list(particleVariations._get_angles())
self.assertEqual(angles, [0, 180])
particleVariations.numVariations = 4
angles: list = list(particleVariations._get_angles())
self.assertEqual(angles, [0, 90, 180, 270])
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment