colorlab

Conventions

«  Software   ::   Contents   ::   Tips and Tricks  »

Conventions

Some remarks on the conventions we (try to) stick to in the color laboratory. You can find more remarks on work flow and some convenient ways how to handle things in the Tips and Tricks section.

Python

We try to comply with the conventions of the Python Styling Guide [pep8] as well as with the corresponding Docstring [pep257] and reST [pep287] conventions. Additionally, [numpydoc] is a nice read. The most important conventions are:

  • variable_names are in lower case with underscores

  • functionNames begin with lower case and are camelCase (this is NOT pep8 compliant)

  • ClassNames begin with upper case and are CamelCase

  • Docstrings are mandatory and must contain a short description of one sentence; then have an empty line; then can contain a more explicit description. In functions the parameters and the values that are normally returned should be shortly explained in the longer description. See [numpydoc] for a good way of doing this.

  • folder names are in lower case without underscores, dots, hyphens...

  • file names are in lower case without underscores, dots, hyphens...

  • Comments:

    # comments are used to explain what the code should do. Only use comments
    # if the code is not self explaining. So if you have to comment much, that
    # means your code is not good ;).
    
  • Files:

    • encoding: utf-8
    • UNIX like line breaks
    • maximum of 80 characters per line

Docstring Example

An example docstring:

class Calibrate(object):
    """
    Calibrate capsulates the hardware dependencies to the photometer and to
    the tubes and the monitor.

    This class also implements the calibration procedure. This calibration
    starts, when calibrateColorTable or calibrateColorEntry are called.

    1. test if the tubes are calibrated, if not abort
    2. test if the color entry was measured at the monitor, if not skip this
       color entry value
    3. guess starting voltages from color entry values (or use given)
    4. start adjustManualPlot so that you can adjust the tubes by hand and
       see your result measured with the photometer
    5. start adjustManualVision to check if the achieved calibration is
       satisfactory and adjust if necessary
    6. store final calibration in color entry

    Example:

    >>> from achrolab.eyeone.eyeone import EyeOne
    >>> from achrolab.calibmonitor import CalibMonitor
    >>> from achrolab.calibtubes import CalibTubes
    >>> from achrolab.colortable import ColorTable
    >>> from achrolab.colorentry import ColorEntry
    >>> eyeone = EyeOne()
    >>> calibmonitor = CalibMonitor(eyeone)
    >>> calibtubes = CalibTubes(eyeone)
    >>> calibtubes.calibrate(imi=0.1, n=4, each=1) #doctest: +ELLIPSIS
    <BLANKLINE>
            Note:
            The tubes must be switched on for at least four (!!) hours in
            order to radiate a stable amount of light.
    <BLANKLINE>
    Measurement mode set to SingleEmission.
    Color space set to CIExyY.
    <BLANKLINE>
    Please put i1 Pro on calibration plate and press key to start
    calibration. Calibration of i1 Pro done.
    <BLANKLINE>
    Please put i1 Pro in measurement positionand hit button to start
    measurement.
    <BLANKLINE>
    Please put i1 Pro in measurement position and press key to start
    measurement.
    <BLANKLINE>
    Turn off blue and green tubes!
    Press key to start measurement of RED tubes.
    Starting measurement...
    (1024, 4095, 4095)
    (2047, 4095, 4095)
    (3070, 4095, 4095)
    (4093, 4095, 4095)
    <BLANKLINE>
    Turn off red and blue tubes!
    Press key to start measurement of GREEN tubes.
    Starting measurement...
    (4095, 1024, 4095)
    (4095, 2047, 4095)
    (4095, 3070, 4095)
    (4095, 4093, 4095)
    <BLANKLINE>
    Turn off red and green tubes!
    Press key to start measurement of BLUE tubes.
    Starting measurement...
    (4095, 4095, 1024)
    (4095, 4095, 2047)
    (4095, 4095, 3070)
    (4095, 4095, 4093)
    <BLANKLINE>
    Turn ON red, green and blue tubes!
    Press key to start measurement of ALL tubes.
    Starting measurement...
    (1024, 1024, 1024)
    (2047, 2047, 2047)
    (3070, 3070, 3070)
    (4093, 4093, 4093)
    Measurement finished.
    ...
    ...
    >>> calibtubes.is_calibrated = True
    >>> calibrate = Calibrate(calibmonitor, calibtubes)
    <BLANKLINE>
    Initializing search mode complete.
    >>> colortable = ColorTable()
    >>> color1 = ColorEntry("darkgreen", patch_stim_value=(0,100,0))
    >>> color2 = ColorEntry("darkred", patch_stim_value=(100,0,0))
    >>> colortable.addColorEntry(color1)
    >>> colortable.addColorEntry(color2)
    >>> calibrate.calibrateColorTable(colortable)
    >>> print(colortable.color_list[0].monitor_xyY) #doctest: +ELLIPSIS
    (..., ..., ...)
    >>> print(colortable.color_list[0].voltages) #doctest: +ELLIPSIS
    (..., ..., ...)
    >>> print(colortable.color_list[0].tubes_xyY) #doctest: +ELLIPSIS
    (..., ..., ...)

    """
    # code starts here
    # ...

Git and Github

Git Conventions

  • names of folders in English, lower case and words separated by underscores
  • try to use utf-8 coding
  • try to use UNIX line breaks
  • usernames: first two letters of first and last name in lower case, e.g. Nora Umbach—noum
  • useful commit messages in English (DO NOT forget!)

«  Software   ::   Contents   ::   Tips and Tricks  »