Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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)