示例#1
0
    def fit(self):
        if self.get_calib_type() == "POLY":
            print("??? no fit needed fot POLY")
            return

        if self.get_reconstruction_method() != "POLYFIT":
            print("[xcalibu.py] hummm : fit not needed... (rec method=%s)" %
                  self.get_reconstruction_method())
            return

        _order = self.get_fit_order()
        self.coeffs = None
        self.coeffR = None

        _time0 = time.time()

        # Fits direct conversion.
        try:
            self.coeffs = numpy.polyfit(self.x_raw, self.y_raw, _order)
        except numpy.RankWarning:
            print("[xcalibu.py] not enought data")

        log.info("polynom coeffs = ")
        self.coeffs
        _o = 0
        for _c in reversed(self.coeffs):
            log.debug("Xcalibu -  polynom coeffs X%d = %s" % (_o, _c))
            _o += 1

        self.x_fitted = numpy.linspace(self.Xmin, self.Xmax, 50)
        self.y_fitted = numpy.linspace(-100, 100, 50)
        self.y_fitted = list(map(self.calc_poly_value, self.x_fitted))

        # Fits reciproque conversion.
        self.coeffR = numpy.polyfit(self.y_raw, self.x_raw, _order)

        self.x_fittedR = numpy.linspace(self.Ymin, self.Ymax, 50)
        self.y_fittedR = numpy.linspace(-100, 100, 50)
        self.y_fittedR = list(
            map(self.calc_fitted_reverse_value, self.x_fittedR))

        # Fit duration display.
        _fit_duration = time.time() - _time0

        if TIME_DISPLAY_FOUND:
            log.info("Fitting tooks %s" %
                     timedisplay.duration_format(_fit_duration))
        else:
            log.info("Fitting tooks %s" % _fit_duration)
示例#2
0
    def fit(self):
        if self.get_calib_type() == "POLY":
            print "??? no fit needed fot POLY"
            return

        if self.get_reconstruction_method() != "POLYFIT":
            print "[xcalibu.py] hummm : fit not needed... (rec method=%s)" % self.get_reconstruction_method()
            return

        _order = self.get_fit_order()
        self.coeffs = None
        self.coeffR = None

        _time0 = time.time()

        # Fits direct conversion.
        try:
            self.coeffs = numpy.polyfit(self.x_raw, self.y_raw, _order)
        except numpy.RankWarning:
            print "not enought data"

        log.info("Xcalibu - polynom coeffs = ")
        self.coeffs
        _o = 0
        for _c in reversed(self.coeffs):
            log.debug("Xcalibu -  polynom coeffs X%d = %s" % (_o, _c))
            _o += 1

        self.x_fitted = numpy.linspace(self.Xmin, self.Xmax, 50)
        self.y_fitted = numpy.linspace(-100, 100, 50)
        self.y_fitted = map(self.calc_poly_value, self.x_fitted)

        # Fits reciproque conversion.
        self.coeffR = numpy.polyfit(self.y_raw, self.x_raw, _order)

        self.x_fittedR = numpy.linspace(self.Ymin, self.Ymax, 50)
        self.y_fittedR = numpy.linspace(-100, 100, 50)
        self.y_fittedR = map(self.calc_fitted_reverse_value, self.x_fittedR)

        # Fit duration display.
        _fit_duration = time.time() - _time0
        log.info("Xcalibu - Fitting tooks %s" % timedisplay.duration_format(_fit_duration))
示例#3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# test_timedisplay.py
#
# Code samples to use timedisplay python module.
#

__author__ = "*****@*****.**"
__date__ = "2014-2019"
__version__ = "0.9.6"

import timedisplay
print("")
print("this code:")
print("  import timedisplay")
print("  print(timedisplay.duration_format(123.456789))")
print("")

print("will print: \"" + timedisplay.duration_format(123.456789) + "\"")
print("")
示例#4
0
def main(args):
    """
    Function main provided for demonstration and testing purposes.
    """
    print ""
    print "--------------------{ Xcalibu }----------------------------------"

    """
    arguments parsing
    """
    from optparse import OptionParser
    parser = OptionParser('xcalibu.py')
    parser.add_option('-d', '--debug', type='string',
                      help="Available levels are :\n CRITICAL(50)\n \
                      ERROR(40)\n WARNING(30)\n INFO(20)\n DEBUG(10)",
                      default='INFO')

    parser.add_option('-p', '--plot', action="store_true", dest="plot", default=False,
                      help="Plots calibration")

    # Gathers options and arguments.
    (options, args) = parser.parse_args()
    # print options
    # print args

    """
    Log level
    """
    try:
        loglevel = getattr(logging, options.debug.upper())
    except AttributeError:
        # print "AttributeError  o.d=",options.debug
        loglevel = {50: logging.CRITICAL,
                    40: logging.ERROR,
                    30: logging.WARNING,
                    20: logging.INFO,
                    10: logging.DEBUG,
                    }[int(options.debug)]

    print "Xcalibu - log level = %s (%d)" % (logging.getLevelName(loglevel), loglevel)
    logging.basicConfig(format=LOG_FORMAT, level=loglevel)

    if len(args) == 0:
        print "no arg file -> launch default demo"
        demo(options.plot)
    else:
        _calib_file = args[0]
        print "use \"%s\" argument as calib test file" % _calib_file

        # new way to load calibrations.
        myCalib = Xcalibu(calib_file_name=_calib_file,
                          fit_order=9,
                          reconstruction_method="POLYFIT")
        # reconstruction_method="INTERPOLATION")

        # Some calib parameters:
        _xmin = myCalib.min_x()
        _xmax = myCalib.max_x()
        _xrange = _xmax - _xmin

        # Example : caluculation of middel point of calibration.
        _xtest = (_xmin + _xmax) / 2
        _time0 = time.time()
        _ytest = myCalib.get_y(_xtest)
        _calc_duration = time.time() - _time0

        log.info("y value of %g = %g (%s)" % (_xtest, _ytest, timedisplay.duration_format(_calc_duration)))

        _NB_POINTS = 25
        # Example : calculation of _NB_POINTS points.
        _time0 = time.time()
        from numpy import arange
        for xx in arange(_xmin, _xmax, _xrange/_NB_POINTS):
            yy = myCalib.get_y(xx)
            # print " f(%06.3f)=%06.3f   "%(xx, yy),
        _Ncalc_duration = time.time() - _time0

        log.info("Calculation of %d values of y. duration : %s" %
                 (_NB_POINTS, timedisplay.duration_format(_Ncalc_duration)))

        sys.stdout.flush()

        if options.plot:
            myCalib.plot()
示例#5
0
def main():
    """
    main function is provided for demonstration and testing purposes.
    """
    print("")
    print(
        "------------------------{ Xcalibu }----------------------------------"
    )
    """
    arguments parsing
    """
    from optparse import OptionParser

    parser = OptionParser("xcalibu.py")
    parser.add_option(
        "-d",
        "--debug",
        type="string",
        help="Available levels are :\n CRITICAL(50)\n \
                      ERROR(40)\n WARNING(30)\n INFO(20)\n DEBUG(10)",
        default="INFO",
    )

    parser.add_option(
        "-p",
        "--plot",
        action="store_true",
        dest="plot",
        default=False,
        help="Plots calibration",
    )

    # Gathers options and arguments.
    (options, args) = parser.parse_args()
    # print(options)
    # print(args)
    """
    Log level
    """
    try:
        loglevel = getattr(logging, options.debug.upper())
    except AttributeError:
        # print "AttributeError  o.d=",options.debug
        loglevel = {
            50: logging.CRITICAL,
            40: logging.ERROR,
            30: logging.WARNING,
            20: logging.INFO,
            10: logging.DEBUG,
        }[int(options.debug)]

    print("[xcalibu] - log level = %s (%d)" %
          (logging.getLevelName(loglevel), loglevel))
    logging.basicConfig(format=LOG_FORMAT, level=loglevel)

    if len(args) == 0:
        parser.print_help()
        print("")
        print("Argument:")
        print("  demo                  Launches some examples of calibrations")
        print(
            "  <calib_file>          Launches demo using <calib_file> calibration file"
        )
        print("")
    else:

        if args[0] == "demo":
            demo(options.plot)

        else:
            print('use "%s" argument as calib test file' % args[0])
            # loads calibration from file.
            myCalib = Xcalibu(
                calib_file_name=args[0],
                fit_order=3,
                reconstruction_method="INTERPOLATION",
            )

            # Some calib parameters:
            _xmin = myCalib.min_x()
            _xmax = myCalib.max_x()
            _xrange = _xmax - _xmin

            # Example : calculation of middle point (X range) of calibration.
            _xtest = (_xmin + _xmax) / 2
            _time0 = time.time()
            _ytest = myCalib.get_y(_xtest)
            _calc_duration = time.time() - _time0

            if TIME_DISPLAY_FOUND:
                _calc_duration = timedisplay.duration_format(_calc_duration)

            log.info("y value of %g = %g (%s)" %
                     (_xtest, _ytest, _calc_duration))

            _NB_POINTS = 25
            # bench example : calculation of _NB_POINTS points.
            _time0 = time.time()
            for xx in numpy.arange(_xmin, _xmax, _xrange / _NB_POINTS):
                yy = myCalib.get_y(xx)
                # print( " f(%06.3f)=%06.3f   "%(xx, yy),)
            _Ncalc_duration = time.time() - _time0

            if TIME_DISPLAY_FOUND:
                _Ncalc_duration = timedisplay.duration_format(_Ncalc_duration)

            log.info("Calculation of %d values of y. duration : %s" %
                     (_NB_POINTS, _Ncalc_duration))

            sys.stdout.flush()

            if options.plot:
                myCalib.plot()