Пример #1
0
 def test_frelon_splinefile(self):
     splineFile = UtilsTest.getimage("frelon.spline")
     detector = detectors.FReLoN(splineFile=splineFile)
     widget = DetectorSelectorDrop()
     widget.setDetector(detector)
     newDetector = widget.detector()
     self.assertEqual(detector, newDetector)
Пример #2
0
 def setUp(self):
     """Download files"""
     self.fit2dFile = UtilsTest.getimage(self.__class__.fit2d_cor)
     self.halfFrelon = UtilsTest.getimage(self.__class__.halfFrelon)
     self.splineFile = UtilsTest.getimage(self.__class__.splineFile)
     self.det = detectors.FReLoN(self.splineFile)
     self.dis = _distortion.Distortion(self.det)
     self.fit2d = fabio.open(self.fit2dFile).data
     self.raw = fabio.open(self.halfFrelon).data
Пример #3
0
 def readspline(self, splinefile):
     """read the spline """
     self.det = detectors.FReLoN(splinefile)
     self.dis = _distortion.Distortion(self.det)
     self.dis.calc_LUT_size()
     self.dis.calc_LUT()
     # remove the pixel size normalisation
     im = numpy.ones((2048, 2048), numpy.float32)
     im2 = self.dis.correct(im)
     im2 = numpy.where(im2 < 0.1, 1, im2)
     self.distnorm = 1 / im2
Пример #4
0
def test():
    import numpy
    buffer = numpy.empty((20, 20), dtype=numpy.float32)
    Q = Quad(buffer)
    Q.reinit(7.5, 6.5, 2.5, 5.5, 3.5, 1.5, 8.5, 1.5)
    Q.init_slope()
    #    print Q.calc_area_AB(Q.A0, Q.B0)
    #    print Q.calc_area_BC(Q.B0, Q.C0)
    #    print Q.calc_area_CD(Q.C0, Q.D0)
    #    print Q.calc_area_DA(Q.D0, Q.A0)
    print Q.calc_area()
    Q.populate_box()
    print Q
    #    print Q.get_box().sum()
    print buffer.sum()
    print("#" * 50)

    Q.reinit(8.5, 1.5, 3.5, 1.5, 2.5, 5.5, 7.5, 6.5)
    Q.init_slope()
    #    print Q.calc_area_AB(Q.A0, Q.B0)
    #    print Q.calc_area_BC(Q.B0, Q.C0)
    #    print Q.calc_area_CD(Q.C0, Q.D0)
    #    print Q.calc_area_DA(Q.D0, Q.A0)
    print Q.calc_area()
    Q.populate_box()
    print Q
    #    print Q.get_box().sum()
    print buffer.sum()

    Q.reinit(0.9, 0.9, 0.8, 6.9, 4.3, 3.9, 4.3, 0.9)
    #    Q = Quad((-0.3, 1.9), (-0.4, 2.9), (1.3, 2.9), (1.3, 1.9))
    Q.init_slope()
    print "calc_area_vectorial", Q.calc_area()
    #    print Q.A0, Q.A1, Q.B0, Q.B1, Q.C0, Q.C1, Q.D0, Q.D1
    #    print "Slope", Q.pAB, Q.pBC, Q.pCD, Q.pDA
    #    print Q.calc_area_AB(Q.A0, Q.B0), Q.calc_area_BC(Q.B0, Q.C0), Q.calc_area_CD(Q.C0, Q.D0), Q.calc_area_DA(Q.D0, Q.A0)
    print Q.calc_area()
    Q.populate_box()
    print buffer.T
    #    print Q.get_box().sum()
    print Q.calc_area()

    print("#" * 50)

    import fabio, numpy
    #    workin on 256x256
    #    x, y = numpy.ogrid[:256, :256]
    #    grid = numpy.logical_or(x % 10 == 0, y % 10 == 0) + numpy.ones((256, 256), numpy.float32)
    #    det = detectors.FReLoN("frelon_8_8.spline")

    #    # working with halfccd spline
    x, y = numpy.ogrid[:1024, :2048]
    grid = numpy.logical_or(x % 100 == 0, y % 100 == 0) + numpy.ones(
        (1024, 2048), numpy.float32)
    det = detectors.FReLoN("halfccd.spline")
    # working with halfccd spline
    #    x, y = numpy.ogrid[:2048, :2048]
    #    grid = numpy.logical_or(x % 100 == 0, y % 100 == 0).astype(numpy.float32) + numpy.ones((2048, 2048), numpy.float32)
    #    det = detectors.FReLoN("frelon.spline")

    print det, det.max_shape
    dis = Distortion(det)
    print dis
    lut = dis.calc_LUT_size()
    print dis.lut_size
    print lut.mean()

    dis.calc_LUT()
    out = dis.correct(grid)
    fabio.edfimage.edfimage(
        data=out.astype("float32")).write("test_correct.edf")

    print("*" * 50)

    #    x, y = numpy.ogrid[:2048, :2048]
    #    grid = numpy.logical_or(x % 100 == 0, y % 100 == 0)
    #    det = detectors.FReLoN("frelon.spline")
    #    print det, det.max_shape
    #    dis = Distortion(det)
    #    print dis
    #    lut = dis.calc_LUT_size()
    #    print dis.lut_size
    #    print "LUT mean & max", lut.mean(), lut.max()
    #    dis.calc_LUT()
    #    out = dis.correct(grid)
    #    fabio.edfimage.edfimage(data=out.astype("float32")).write("test2048.edf")
    import pylab
    pylab.imshow(out)  # , interpolation="nearest")
    pylab.show()
Пример #5
0
def test():

    #    workin on 256x256
    #    x, y = numpy.ogrid[:256, :256]
    #    grid = numpy.logical_or(x % 10 == 0, y % 10 == 0) + numpy.ones((256, 256), numpy.float32)
    #    det = detectors.FReLoN("frelon_8_8.spline")

    #    # working with halfccd spline
    x, y = numpy.ogrid[:1024, :2048]
    grid = numpy.logical_or(x % 100 == 0, y % 100 == 0) + numpy.ones(
        (1024, 2048), numpy.float32)

    splineFilePath = "halfccd.spline"
    splineFile = UtilsTest.getimage(splineFilePath)
    det = detectors.FReLoN(splineFile)
    # working with halfccd spline
    #    x, y = numpy.ogrid[:2048, :2048]
    #    grid = numpy.logical_or(x % 100 == 0, y % 100 == 0).astype(numpy.float32) + numpy.ones((2048, 2048), numpy.float32)
    #    det = detectors.FReLoN("frelon.spline")

    print(det, det.max_shape)
    disLUT = _distortion.Distortion(det)
    print(disLUT)
    lut = disLUT.calc_LUT_size()
    print(disLUT.lut_size)
    print(lut.mean())

    disLUT.calc_LUT()
    outLUT = disLUT.correct(grid)
    fabio.edfimage.edfimage(
        data=outLUT.astype("float32")).write("test_correct_LUT.edf")

    print("*" * 50)

    print(det, det.max_shape)
    disCSR = _distortionCSR.Distortion(det, foo=64)
    print(disCSR)
    lut = disCSR.calc_LUT_size()
    print(disCSR.lut_size)
    print(lut.mean())

    disCSR.calc_LUT()
    outCSR = disCSR.correct(grid)
    fabio.edfimage.edfimage(
        data=outCSR.astype("float32")).write("test_correct_CSR.edf")

    print("*" * 50)

    disCSR.setDevice()
    outCSRocl = disCSR.correct(grid)
    fabio.edfimage.edfimage(
        data=outCSRocl.astype("float32")).write("test_correct_CSR.edf")

    print("*" * 50)

    print(det, det.max_shape)
    disLUTpy = distortion.Distortion(det)
    print(disLUTpy)
    lut = disLUTpy.calc_LUT_size()
    print(disLUTpy.lut_size)
    print(lut.mean())

    disLUTpy.calc_LUT()
    outLUTpy = disLUTpy.correct(grid)
    fabio.edfimage.edfimage(
        data=outLUTpy.astype("float32")).write("test_correct_LUT.edf")

    print("*" * 50)

    #    x, y = numpy.ogrid[:2048, :2048]
    #    grid = numpy.logical_or(x % 100 == 0, y % 100 == 0)
    #    det = detectors.FReLoN("frelon.spline")
    #    print( det, det.max_shape)
    #    dis = Distortion(det)
    #    print(dis
    #    lut = dis.calc_LUT_size()
    #    print(dis.lut_size
    #    print("LUT mean & max", lut.mean(), lut.max()
    #    dis.calc_LUT()
    #    out = dis.correct(grid)
    #    fabio.edfimage.edfimage(data=out.astype("float32")).write("test2048.edf")
    import pylab
    # pylab.imshow(outLUT)
    # pylab.show()
    # pylab.imshow(outCSR)  # , interpolation="nearest")
    # , interpolation="nearest")
    #    pylab.show()
    pylab.imshow(outCSRocl)
    pylab.show()
    # pylab.imshow(outLUTpy)
    # pylab.show()

    assert numpy.allclose(outLUT, outCSRocl)