colour.io Package — Colour 0.3.0 documentation

# colour.io Package

## Sub-Modules

- colour.io.common Module
  - Input / Output Common Utilities
- colour.io.tabular Module
  - CSV Tabular Data Input / Output

## Module Contents

`colour.io.` `read_spectral_data_from_csv_file`(path, delimiter=u', ', fields=None, default=0)

  Reads the spectral data from given CSV file in the following form:

  390, 4.15003E-04, 3.68349E-04, 9.54729E-03 395, 1.05192E-03, 9.58658E-04, 2.38250E-02 400, 2.40836E-03, 2.26991E-03, 5.66498E-02 ... 830, 9.74306E-07, 9.53411E-08, 0.00000

  and returns it as ad dict of dict as follows:

  {‘field’: {‘wavelength’: ‘value’, ..., ‘wavelength’: ‘value’}, ..., ‘field’: {‘wavelength’: ‘value’, ..., ‘wavelength’: ‘value’}

  Parameters: | path (unicode) – Absolute CSV file path. delimiter (unicode, optional) – CSV file content delimiter. fields (array_like, optional) – CSV file spectral data fields names. If no value is provided the first line of the file will be used as spectral data fields names. default (numeric, optional) – Default value for fields row with missing value.
  Returns: | CSV file content.
  Return type: | dict
  Raises: | `RuntimeError` – If the CSV spectral data file doesn’t define the appropriate fields.

  Notes

  - A “CSV” spectral data file should define at least define two fields: one for the wavelengths and one for the associated values of one spectral power distribution.
  - If no value is provided for the fields names, the first line of the file will be used as spectral data fields names.

  Examples

      >>> import os
      >>> from pprint import pprint
      >>> csv_file = os.path.join(
      ...     os.path.dirname(__file__),
      ...     'tests',
      ...     'resources',
      ...     'colorchecker_n_ohta.csv')
      >>> spds_data = read_spectral_data_from_csv_file(csv_file)
      >>> pprint(sorted(spds_data.keys()))
      ['1',
       '10',
       '11',
       '12',
       '13',
       '14',
       '15',
       '16',
       '17',
       '18',
       '19',
       '2',
       '20',
       '21',
       '22',
       '23',
       '24',
       '3',
       '4',
       '5',
       '6',
       '7',
       '8',
       '9']

`colour.io.` `read_spds_from_csv_file`(path, delimiter=u', ', fields=None, default=0)

  Reads the spectral data from given CSV file and return its content as a dict of `colour.colorimetry.spectrum.TriSpectralPowerDistribution` classes.

  Parameters: | path (unicode) – Absolute CSV file path. delimiter (unicode, optional) – CSV file content delimiter. fields (array_like, optional) – CSV file spectral data fields names. If no value is provided the first line of the file will be used for as spectral data fields names. default (numeric) – Default value for fields row with missing value.
  Returns: | `colour.colorimetry.spectrum.TriSpectralPowerDistribution` classes of given CSV file.
  Return type: | dict

  Examples

      >>> import os
      >>> from pprint import pprint
      >>> csv_file = os.path.join(
      ...     os.path.dirname(__file__),
      ...     'tests',
      ...     'resources',
      ...     'colorchecker_n_ohta.csv')
      >>> spds = read_spds_from_csv_file(csv_file)
      >>> pprint(sorted(spds.items()))
      [('1',
        <...SpectralPowerDistribution object at 0x...>),
       ('10',
        <...SpectralPowerDistribution object at 0x...>),
       ('11',
        <...SpectralPowerDistribution object at 0x...>),
       ('12',
        <...SpectralPowerDistribution object at 0x...>),
       ('13',
        <...SpectralPowerDistribution object at 0x...>),
       ('14',
        <...SpectralPowerDistribution object at 0x...>),
       ('15',
        <...SpectralPowerDistribution object at 0x...>),
       ('16',
        <...SpectralPowerDistribution object at 0x...>),
       ('17',
        <...SpectralPowerDistribution object at 0x...>),
       ('18',
        <...SpectralPowerDistribution object at 0x...>),
       ('19',
        <...SpectralPowerDistribution object at 0x...>),
       ('2',
        <...SpectralPowerDistribution object at 0x...>),
       ('20',
        <...SpectralPowerDistribution object at 0x...>),
       ('21',
        <...SpectralPowerDistribution object at 0x...>),
       ('22',
        <...SpectralPowerDistribution object at 0x...>),
       ('23',
        <...SpectralPowerDistribution object at 0x...>),
       ('24',
        <...SpectralPowerDistribution object at 0x...>),
       ('3',
        <...SpectralPowerDistribution object at 0x...>),
       ('4',
        <...SpectralPowerDistribution object at 0x...>),
       ('5',
        <...SpectralPowerDistribution object at 0x...>),
       ('6',
        <...SpectralPowerDistribution object at 0x...>),
       ('7',
        <...SpectralPowerDistribution object at 0x...>),
       ('8',
        <...SpectralPowerDistribution object at 0x...>),
       ('9',
        <...SpectralPowerDistribution object at 0x...>)]

`colour.io.` `write_spds_to_csv_file`(spds, path, delimiter=u', ', fields=None)

  Writes the given spectral power distributions to given CSV file.

  Parameters: | spds (dict) – Spectral power distributions to write. path (unicode) – Absolute CSV file path. delimiter (unicode, optional) – CSV file content delimiter. fields (array_like, optional) – CSV file spectral data fields names. If no value is provided the order of fields will be the one defined by the sorted spectral power distributions dict.
  Returns: | Definition success.
  Return type: | bool
  Raises: | `RuntimeError` – If the given spectral power distributions have different shapes.