testhelpers.py 1.67 KB
Newer Older
Josef Brandt's avatar
Josef Brandt committed
1
import logging
2
import numpy as np
3
from typing import TYPE_CHECKING
Josef Brandt's avatar
Josef Brandt committed
4
from ..dataset import DataSet
5 6
from ..analysis.particleContainer import ParticleContainer
from ..analysis.particleAndMeasurement import Particle, Measurement
Josef Brandt's avatar
Josef Brandt committed
7
from ..__main__ import GEPARDMainWindow
8 9
if TYPE_CHECKING:
    from ..sampleview import SampleView
Josef Brandt's avatar
Josef Brandt committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29


def getDefaultLogger() -> logging.Logger:
    logger: logging.Logger = logging.getLogger('test')
    logger.addHandler(logging.StreamHandler())
    logger.setLevel(logging.INFO)
    return logger


def getDefaultDataset() -> DataSet:
    dset: DataSet = DataSet('test')
    dset.imagescanMode = 'df'
    dset.pixelscale_bf = dset.pixelscale_df = 1.0
    return dset


def getDefaultMainWin() -> GEPARDMainWindow:
    gepard: GEPARDMainWindow = GEPARDMainWindow(getDefaultLogger())
    gepard.view.dataset = getDefaultDataset()
    gepard.view.pyramid.fromDataset(gepard.view.dataset)
30
    gepard.view._setUpToDataset()
Josef Brandt's avatar
Josef Brandt committed
31
    return gepard
32 33 34 35 36


def getDefaultSampleview() -> 'SampleView':
    gepard: GEPARDMainWindow = getDefaultMainWin()
    return gepard.view
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51


def getDefaultParticleContainer(numParticles: int = 4) -> ParticleContainer:
    partContainer: ParticleContainer = ParticleContainer()
    partContainer.initializeParticles(numParticles)
    contours: list = []
    for i in range(numParticles):
        x = 10*i
        contours.append(np.array([[[x, 0]], [[x+10, 0]], [[x+10, 10]], [[x, 10]]], dtype=np.int32))
    partContainer.setParticleContours(contours)
    partContainer.particles[0].color = 'red'
    partContainer.particles[1].color = 'blue'
    partContainer.particles[2].color = 'green'
    partContainer.particles[3].color = 'transparent'
    return partContainer