<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

from LedStrip_WS2801 import LedStrip_WS2801, LedStrip_WS2801_FileBased
import numpy as np
from PIL import Image

class WS2801_Matrix:
    def __init__(self, indexes):
        self.indexes = np.array(indexes)
        num_leds = self.indexes.shape[0] * self.indexes.shape[1]
        self.strip = LedStrip_WS2801(num_leds)

    @property
    def height(self):
        return self.indexes.shape[0]

    @property
    def width(self):
        return self.indexes.shape[1]

    """
    Get the led's index from its xy coords
    """
    def getIndex(self, x, y):
        return self.indexes[y][x]

    """
    Set a pixel to a specific color by its coordinates
    """
    def setPixel(self, x, y, color):
        index = self.getIndex(x, y)
        # print "x=%i, y=%i, index=%i, color=%s" % (x, y, index, color)
        self.strip.setPixel(index, color)
        self.strip.update()

    """
    Replace all pixels with new values
    """
    def writeArray(self, array):
        for x, y in self.iterPixels():
            self.setPixel(x, y, array[y][x])

    """
    An iterator over all pixels as (x, y) tuple.
    """
    def iterPixels(self):
        for x in xrange(0, self.width):
            for y in xrange(0, self.height):
                yield (x, y)

    """
    Write an image from file to the matrix. Image
    dimensions must match the matrix dimensions.
    """
    def writeImageFile(self, path):
        image = Image.open(path)
        image_array = np.array(image)
        if image_array.shape[0:2] != self.indexes.shape[0:2]:
            raise DimensionsMismatch()
        else:
            self.writeArray(image_array)


class DimensionsMismatch(Exception):
    pass
<commit_msg>Bugfix<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

from LedStrip_WS2801 import LedStrip_WS2801, LedStrip_WS2801_FileBased
import numpy as np
from PIL import Image

class WS2801_Matrix:
    def __init__(self, indexes):
        self.indexes = np.array(indexes)
        num_leds = self.indexes.shape[0] * self.indexes.shape[1]
        self.strip = LedStrip_WS2801(num_leds)

    @property
    def height(self):
        return self.indexes.shape[0]

    @property
    def width(self):
        return self.indexes.shape[1]

    """
    Get the led's index from its xy coords
    """
    def getIndex(self, x, y):
        return self.indexes[y][x]

    """
    Set a pixel to a specific color by its coordinates
    """
    def setPixel(self, x, y, color):
        index = self.getIndex(x, y)
        # print "x=%i, y=%i, index=%i, color=%s" % (x, y, index, color)
        self.strip.setPixel(index, color)
        self.strip.update()

    """
    Replace all pixels with new values
    """
    def writeArray(self, array):
        for x, y in self.iterPixels():
            self.setPixel(x, y, array[y][x])

    """
    An iterator over all pixels as (x, y) tuple.
    """
    def iterPixels(self):
        for x in xrange(0, self.width):
            for y in xrange(0, self.height):
                yield (x, y)

    """
    Write an image from file to the matrix. Image
    dimensions must match the matrix dimensions.
    """
    def writeImageFile(self, path):
        image = Image.open(path)
        image_array = np.array(image, dtype=int)
        if image_array.shape[0:2] != self.indexes.shape[0:2]:
            raise DimensionsMismatch()
        else:
            self.writeArray(image_array)


class DimensionsMismatch(Exception):
    pass

{'fraction_non_alphanumeric': 0.12129840546697039, 'fraction_numerical': 0.01765375854214123, 'mean_word_length': 2.3267045454545454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3035699', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1151, 'n_words': 311}