コード例 #1
0
    def test_load_simple(self):
        # AR background data
        dcalib = numpy.zeros((512, 1024), dtype=numpy.uint16)
        md = {
            model.MD_SW_VERSION: "1.0-test",
            model.MD_HW_NAME: "fake ccd",
            model.MD_DESCRIPTION: "AR",
            model.MD_ACQ_DATE: time.time(),
            model.MD_BPP: 12,
            model.MD_BINNING: (1, 1),  # px, px
            model.MD_SENSOR_PIXEL_SIZE: (13e-6, 13e-6),  # m/px
            model.MD_PIXEL_SIZE: (1e-6, 2e-5),  # m/px
            model.MD_POS: (1.2e-3, -30e-3),  # m
            model.MD_EXP_TIME: 1.2,  # s
            model.MD_AR_POLE: (253.1, 65.1),
            model.MD_LENS_MAG: 60,  # ratio
        }
        calib = model.DataArray(dcalib, md)

        # Give one DA, the correct one, so expect to get it back
        out = calibration.get_ar_data([calib])
        numpy.testing.assert_equal(out, calib)

        # More DataArrays, just to make it slightly harder to find the data
        data1 = model.DataArray(numpy.ones((1, 1, 1, 520, 230),
                                           dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        data2 = model.DataArray(17 * numpy.ones((1, 1), dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        out = calibration.get_ar_data([data1, calib, data2])
        numpy.testing.assert_equal(out, calib)
コード例 #2
0
ファイル: calibration_test.py プロジェクト: arijitxx/odemis
    def test_load_simple(self):
        # AR background data
        dcalib = numpy.zeros((512, 1024), dtype=numpy.uint16)
        md = {model.MD_SW_VERSION: "1.0-test",
             model.MD_HW_NAME: "fake ccd",
             model.MD_DESCRIPTION: "AR",
             model.MD_ACQ_DATE: time.time(),
             model.MD_BPP: 12,
             model.MD_BINNING: (1, 1), # px, px
             model.MD_SENSOR_PIXEL_SIZE: (13e-6, 13e-6), # m/px
             model.MD_PIXEL_SIZE: (1e-6, 2e-5), # m/px
             model.MD_POS: (1.2e-3, -30e-3), # m
             model.MD_EXP_TIME: 1.2, # s
             model.MD_AR_POLE: (253.1, 65.1),
             model.MD_LENS_MAG: 60, # ratio
            }
        calib = model.DataArray(dcalib, md)

        # Give one DA, the correct one, so expect to get it back
        out = calibration.get_ar_data([calib])
        numpy.testing.assert_equal(out, calib)

        # More DataArrays, just to make it slightly harder to find the data
        data1 = model.DataArray(numpy.ones((1, 1, 1, 520, 230), dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        data2 = model.DataArray(17 * numpy.ones((1, 1), dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        out = calibration.get_ar_data([data1, calib, data2])
        numpy.testing.assert_equal(out, calib)
コード例 #3
0
    def test_load_simple_arpol(self):
        # AR polarimetry background data

        metadata = []
        pol_positions = list(POL_POSITIONS)
        qwp_positions = [0.0, 1.570796, 0.785398, 2.356194, 0.0, 0.0]
        linpol_positions = [
            0.0, 1.570796, 0.785398, 2.356194, 0.785398, 2.356194
        ]

        # ARPOL metadata
        for idx in range(len(pol_positions)):
            metadata.append({
                model.MD_SW_VERSION: "1.0-test",
                model.MD_HW_NAME: "fake ccd",
                model.MD_DESCRIPTION: "ARPOL",
                model.MD_ACQ_DATE: time.time(),
                model.MD_BPP: 12,
                model.MD_BINNING: (1, 1),  # px, px
                model.MD_SENSOR_PIXEL_SIZE: (13e-6, 13e-6),  # m/px
                model.MD_PIXEL_SIZE: (2e-5, 2e-5),  # m/px
                model.MD_POS: (1.2e-3, -30e-3),  # m
                model.MD_EXP_TIME: 1.2,  # s
                model.MD_AR_POLE: (253.1, 65.1),
                model.MD_LENS_MAG: 0.4,  # ratio
                model.MD_POL_MODE: pol_positions[idx],
                model.MD_POL_POS_LINPOL: qwp_positions[idx],  # rad
                model.MD_POL_POS_QWP: linpol_positions[idx],  # rad
            })

        bg_data = []  # list of background images
        for idx in range(len(pol_positions)):
            dcalib = numpy.ones(
                (1, 1, 1, 512, 1024),
                dtype=numpy.uint16) + idx  # different bg image for each pol
            calib = model.DataArray(dcalib, metadata[idx])
            bg_data.append(calib)

        # Give one DA, the correct one, so expect to get it back
        out = calibration.get_ar_data(bg_data)

        # Check the expected and return lists contain the same DataArrays
        self.assertEqual(len(bg_data), len(out))
        for da in out:
            self.assertTrue(any(numpy.array_equal(da, bg) for bg in bg_data))

        # More DataArrays, just to make it slightly harder to find the data
        data1 = model.DataArray(numpy.ones((1, 1, 1, 520, 230),
                                           dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        data2 = model.DataArray(17 * numpy.ones((1, 1), dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        bg_data_new = [data1, data2] + bg_data
        out = calibration.get_ar_data(bg_data_new)

        # Check the expected and return lists contain the same DataArrays
        self.assertEqual(len(bg_data), len(out))
        for da in out:
            self.assertTrue(any(numpy.array_equal(da, bg) for bg in bg_data))
コード例 #4
0
    def test_load_full(self):
        """
        Check the whole sequence: saving calibration data to file, loading it
        back from file, finding it.
        """
        # AR background data
        dcalib = numpy.zeros((512, 1024), dtype=numpy.uint16)
        md = {
            model.MD_SW_VERSION: "1.0-test",
            model.MD_HW_NAME: "fake ccd",
            model.MD_DESCRIPTION: "AR",
            model.MD_ACQ_DATE: time.time(),
            model.MD_BPP: 12,
            model.MD_BINNING: (1, 1),  # px, px
            model.MD_SENSOR_PIXEL_SIZE: (13e-6, 13e-6),  # m/px
            model.MD_PIXEL_SIZE: (1e-6, 2e-5),  # m/px
            model.MD_POS: (1.2e-3, -30e-3),  # m
            model.MD_EXP_TIME: 1.2,  # s
            model.MD_AR_POLE: (253.1, 65.1),
            model.MD_LENS_MAG: 60,  # ratio
        }
        calib = model.DataArray(dcalib, md)

        # Give one DA, the correct one, so expect to get it back
        out = calibration.get_ar_data([calib])
        numpy.testing.assert_equal(out, calib)

        # More DataArrays, just to make it slightly harder to find the data
        data1 = model.DataArray(numpy.ones((1, 1, 1, 520, 230),
                                           dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        data2 = model.DataArray(17 * numpy.ones((1, 1), dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        # RGB image
        thumb = model.DataArray(numpy.ones((520, 230, 3), dtype=numpy.uint8))

        full_data = [data1, calib, data2]

        for fmt in dataio.get_available_formats(os.O_WRONLY):
            exporter = dataio.get_converter(fmt)
            logging.info("Trying to export/import with %s", fmt)
            fn = u"test_ar" + exporter.EXTENSIONS[0]
            exporter.export(fn, full_data, thumb)

            if fmt in dataio.get_available_formats(os.O_RDONLY):
                idata = exporter.read_data(fn)
                icalib = calibration.get_ar_data(idata)
                icalib2d = img.ensure2DImage(icalib)
                numpy.testing.assert_equal(icalib2d, calib)
                numpy.testing.assert_almost_equal(
                    icalib.metadata[model.MD_AR_POLE],
                    calib.metadata[model.MD_AR_POLE])
            try:
                os.remove(fn)
            except OSError:
                logging.exception("Failed to delete the file %s", fn)
コード例 #5
0
ファイル: calibration_test.py プロジェクト: ktsitsikas/odemis
    def test_load_full(self):
        """
        Check the whole sequence: saving calibration data to file, loading it
        back from file, finding it.
        """
        # AR background data
        dcalib = numpy.zeros((512, 1024), dtype=numpy.uint16)
        md = {model.MD_SW_VERSION: "1.0-test",
             model.MD_HW_NAME: "fake ccd",
             model.MD_DESCRIPTION: "AR",
             model.MD_ACQ_DATE: time.time(),
             model.MD_BPP: 12,
             model.MD_BINNING: (1, 1), # px, px
             model.MD_SENSOR_PIXEL_SIZE: (13e-6, 13e-6), # m/px
             model.MD_PIXEL_SIZE: (1e-6, 2e-5), # m/px
             model.MD_POS: (1.2e-3, -30e-3), # m
             model.MD_EXP_TIME: 1.2, # s
             model.MD_AR_POLE: (253.1, 65.1),
             model.MD_LENS_MAG: 60, # ratio
            }
        calib = model.DataArray(dcalib, md)

        # Give one DA, the correct one, so expect to get it back
        out = calibration.get_ar_data([calib])
        numpy.testing.assert_equal(out, calib)

        # More DataArrays, just to make it slightly harder to find the data
        data1 = model.DataArray(numpy.ones((1, 1, 1, 520, 230), dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        data2 = model.DataArray(17 * numpy.ones((1, 1), dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        # RGB image
        thumb = model.DataArray(numpy.ones((520, 230, 3), dtype=numpy.uint8))

        full_data = [data1, calib, data2]

        for fmt in dataio.get_available_formats(os.O_WRONLY):
            exporter = dataio.get_converter(fmt)
            logging.info("Trying to export/import with %s", fmt)
            fn = u"test_ar" + exporter.EXTENSIONS[0]
            exporter.export(fn, full_data, thumb)

            if fmt in dataio.get_available_formats(os.O_RDONLY):
                idata = exporter.read_data(fn)
                icalib = calibration.get_ar_data(idata)
                icalib2d = img.ensure2DImage(icalib)
                numpy.testing.assert_equal(icalib2d, calib)
                numpy.testing.assert_almost_equal(icalib.metadata[model.MD_AR_POLE],
                                                  calib.metadata[model.MD_AR_POLE])
            try:
                os.remove(fn)
            except OSError:
                logging.exception("Failed to delete the file %s", fn)
コード例 #6
0
ファイル: calibration_test.py プロジェクト: delmic/odemis
    def test_load_simple_arpol(self):
        # AR polarimetry background data

        metadata = []
        pol_positions = list(POL_POSITIONS)
        qwp_positions = [0.0, 1.570796, 0.785398, 2.356194, 0.0, 0.0]
        linpol_positions = [0.0, 1.570796, 0.785398, 2.356194, 0.785398, 2.356194]

        # ARPOL metadata
        for idx in range(len(pol_positions)):
            metadata.append({model.MD_SW_VERSION: "1.0-test",
                             model.MD_HW_NAME: "fake ccd",
                             model.MD_DESCRIPTION: "ARPOL",
                             model.MD_ACQ_DATE: time.time(),
                             model.MD_BPP: 12,
                             model.MD_BINNING: (1, 1),  # px, px
                             model.MD_SENSOR_PIXEL_SIZE: (13e-6, 13e-6),  # m/px
                             model.MD_PIXEL_SIZE: (2e-5, 2e-5),  # m/px
                             model.MD_POS: (1.2e-3, -30e-3),  # m
                             model.MD_EXP_TIME: 1.2,  # s
                             model.MD_AR_POLE: (253.1, 65.1),
                             model.MD_LENS_MAG: 0.4,  # ratio
                             model.MD_POL_MODE: pol_positions[idx],
                             model.MD_POL_POS_LINPOL: qwp_positions[idx],  # rad
                             model.MD_POL_POS_QWP: linpol_positions[idx],  # rad
                             })

        bg_data = []  # list of background images
        for idx in range(len(pol_positions)):
            dcalib = numpy.ones((1, 1, 1, 512, 1024), dtype=numpy.uint16) + idx  # different bg image for each pol
            calib = model.DataArray(dcalib, metadata[idx])
            bg_data.append(calib)

        # Give one DA, the correct one, so expect to get it back
        out = calibration.get_ar_data(bg_data)
        numpy.testing.assert_equal(out, bg_data)  # all bg images should have same shape

        # More DataArrays, just to make it slightly harder to find the data
        data1 = model.DataArray(numpy.ones((1, 1, 1, 520, 230), dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        data2 = model.DataArray(17 * numpy.ones((1, 1), dtype=numpy.uint16),
                                metadata={model.MD_POS: (1.2e-3, -30e-3)})
        bg_data_new = [data1, data2] + bg_data
        out = calibration.get_ar_data(bg_data_new)
        numpy.testing.assert_equal(out, bg_data)
コード例 #7
0
ファイル: ar_to_csv.py プロジェクト: effting/odemis
def main(args):
    """
    Handles the command line arguments
    args is the list of arguments passed
    return (int): value to return to the OS as program exit code
    """

    # arguments handling
    parser = argparse.ArgumentParser(
        description="Batch export of AR data to CSV")

    parser.add_argument("--background",
                        "-b",
                        dest="background",
                        help="Name of background data")

    parser.add_argument(dest="filenames",
                        nargs="+",
                        help="List of (HDF5) files containing the AR data")

    options = parser.parse_args(args[1:])

    try:
        if options.background:
            data = dataio.open_acquisition(options.background)
            if not data:
                return 1
            # will raise exception if doesn't contain good calib data
            bkg = calibration.get_ar_data(data)
        else:
            bkg = None

        if os.name == 'nt':
            # on Windows, the application is in charge of expanding "*".
            filenames = []
            for fn in options.filenames:
                filenames.extend(glob.glob(fn))
        else:
            filenames = options.filenames

        for fn in filenames:
            export_ar_to_csv(fn, bkg)

    except:
        logging.exception("Unexpected error while performing action.")
        return 127

    return 0