Esempio n. 1
0
    def set_header(self, top_left_x, top_left_y, bottom_right_x,
                   bottom_right_y):
        """
        Saves the *approximate* coordinates of the notches of the top left and bottom right catch channels.

        """
        self._top_left = Coordinates(x=top_left_x, y=top_left_y)
        self._bottom_right = Coordinates(x=bottom_right_x, y=bottom_right_y)
Esempio n. 2
0
 def _parse_header(self, line):
     match = self._header_regex.match(line)
     if not match:
         raise Exception("Invalid channel location line: %s" % line)
     top_left = Coordinates(x=match.group("top_left_x"),
                            y=match.group("top_left_y"))
     bottom_right = Coordinates(x=match.group("bottom_right_x"),
                                y=match.group("bottom_right_y"))
     return top_left, bottom_right
Esempio n. 3
0
 def _parse_line(self, line):
     match = self._line_regex.match(line)
     if match:
         channel_number = int(match.group("channel_number"))
         notch = Coordinates(x=match.group("notch_x"),
                             y=match.group("notch_y"))
         tube = Coordinates(x=match.group("tube_x"),
                            y=match.group("tube_y"))
         return channel_number, (notch, tube)
     match = self._skipped_regex.match(line)
     if match:
         return int(match.group("channel_number")), "skipped"
     raise Exception("Invalid channel location line: %s" % line)
Esempio n. 4
0
    def set_channel_location(self, channel_number, notch_x, notch_y, tube_x,
                             tube_y):
        """
        Saves the coordinates of a single catch channel.

        :param channel_number: identifier of the channel, an integer from 1 to 28
        :param notch_x: number of pixels from the left where the notch of the catch channel is located
        :param notch_y: number of pixels from the top where the notch of the catch channel is located
        :param tube_x: number of pixels from the left where the end of the catch channel is located
        :param tube_y: number of pixels from the top where the end of the catch channel is located

        """
        self._channels[channel_number] = (Coordinates(x=notch_x, y=notch_y),
                                          Coordinates(x=tube_x, y=tube_y))
Esempio n. 5
0
    def get_child_coordinates(self, parent_coordinates):
        """
        Take coordinates from a superset of this image and figure out where they belong on the image slice image.

        """
        return Coordinates(x=parent_coordinates.x - self._top_left.x,
                           y=parent_coordinates.y - self._top_left.y + self._y_margin)
Esempio n. 6
0
    def get_parent_coordinates(self, local_coordinates):
        """
        Takes an x,y coordinate in the image slice and determines where that coodinate is in the parent image.

        """
        return Coordinates(x=local_coordinates.x + self._top_left.x,
                           y=local_coordinates.y + self._top_left.y - self._y_margin)
Esempio n. 7
0
 def load_from_text(self, line):
     index = AnnotationLine.index_regex.match(line)
     self.index = index.group("index")
     self.time_period = index.group("time_period")
     raw_coodinates = AnnotationLine.coordinate_regex.findall(line)
     # raw_coordinates is a list of tuples like ('1.123', '4.536')
     for pair in raw_coodinates:
         self._coodinates.append(Coordinates(x=float(pair[0]), y=float(pair[1])))
Esempio n. 8
0
 def test_load(self):
     data = [
         "3.444 7.888 9.888 24.222", "1 skipped",
         "2 4.444 4.444 8.888 12.222", "3 skipped", "4 skipped"
     ]
     self.location.load(data)
     expected = {
         1: "skipped",
         2: (Coordinates(4.444, 4.444), Coordinates(8.888, 12.222)),
         3: "skipped",
         4: "skipped"
     }
     for i in (1, 3, 4):
         self.assertEqual(expected[i], self.location._channels[i])
     self.assertEqual(expected[2][0].x, 4.444)
     self.assertEqual(expected[2][0].y, 4.444)
     self.assertEqual(expected[2][1].x, 8.888)
     self.assertEqual(expected[2][1].y, 12.222)
     self.assertEqual(self.location._top_left.x, 3.444)
     self.assertEqual(self.location._top_left.y, 7.888)
     self.assertEqual(self.location._bottom_right.x, 9.888)
     self.assertEqual(self.location._bottom_right.y, 24.222)
Esempio n. 9
0
 def test_lines(self):
     self.location._top_left = Coordinates(1.222, 2.222)
     self.location._bottom_right = Coordinates(4.444, 8.888)
     self.location._channels = {
         3: "skipped",
         4: (Coordinates(4.666, 7.888), Coordinates(9.999, 0.000)),
         1: (Coordinates(14.666, 17.888), Coordinates(19.999, 10.000)),
         2: (Coordinates(24.666, 27.888), Coordinates(29.999, 20.000))
     }
     lines = [line for line in self.location.lines]
     self.assertEqual(lines[0], "1.222 2.222 4.444 8.888")
     self.assertEqual(lines[1], "1 14.666 17.888 19.999 10.0")
     self.assertEqual(lines[2], "2 24.666 27.888 29.999 20.0")
     self.assertEqual(lines[3], "3 skipped")
     self.assertEqual(lines[4], "4 4.666 7.888 9.999 0.0")
Esempio n. 10
0
    def __init__(self, x, y, width, height, fliplr=False):
        """
        :param width:       how wide the slice should be, in pixels
        :type width:        int
        :param height:      how high the slice should be, in pixels
        :type height:       int
        :param x:           the x-coordinate of the TOP LEFT CORNER of the desired image slice
        :type x:            int
        :param y:           the y-coordinate of the TOP LEFT CORNER of the desired image slice
        :type y:            int
        :param fliplr:      whether the image should be inverted on the horizontal axis
        :type fliplr:       bool

        """
        self._top_left = Coordinates(x=x, y=y)
        self._width = width
        self._height = height
        self._image_data = None
        self._fliplr = fliplr
        self._y_margin = 0
Esempio n. 11
0
 def test_data(self):
     self.location._channels = {
         3: "skipped",
         4: (Coordinates(4.666, 7.888), Coordinates(9.999, 0.000)),
         1: (Coordinates(14.666, 17.888), Coordinates(19.999, 10.000)),
         2: (Coordinates(24.666, 27.888), Coordinates(29.999, 20.000))
     }
     data = iter(self.location.data)
     header = next(data)
     location_data = [(channel_number, location[0].x, location[0].y,
                       location[1].x, location[1].y)
                      for channel_number, location in data]
     self.assertTupleEqual(location_data[0],
                           (1, 14.666, 17.888, 19.999, 10.000))
     self.assertTupleEqual(location_data[1],
                           (2, 24.666, 27.888, 29.999, 20.000))
     self.assertTupleEqual(location_data[2],
                           (4, 4.666, 7.888, 9.999, 0.000))
Esempio n. 12
0
 def coordinates(self):
     return Coordinates(x=self._x, y=self._y)
Esempio n. 13
0
 def _add_point(self, x, y, marker='ro'):
     self._points.append(plt.plot(x, y, marker))
     self._coordinates.append(Coordinates(x=x, y=y))
     plt.draw()