You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
2.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. import logging
  2. from nd2reader.service import BaseNd2
  3. from nd2reader.model import Image, ImageSet
  4. log = logging.getLogger(__name__)
  5. log.setLevel(logging.DEBUG)
  6. class Nd2(BaseNd2):
  7. def __init__(self, filename):
  8. super(Nd2, self).__init__(filename)
  9. def get_image(self, time_index, fov, channel_name, z_level):
  10. image_set_number = self._calculate_image_set_number(time_index, fov, z_level)
  11. timestamp, raw_image_data = self._reader.get_raw_image_data(image_set_number, self.channel_offset[channel_name])
  12. return Image(timestamp, raw_image_data, fov, channel_name, z_level, self.height, self.width)
  13. def __iter__(self):
  14. """
  15. Just return every image in order (might not be exactly the order that the images were physically taken, but it will
  16. be within a few seconds). A better explanation is probably needed here.
  17. """
  18. for i in range(self._image_count):
  19. for fov in range(self.field_of_view_count):
  20. for z_level in range(self.z_level_count):
  21. for channel in self.channels:
  22. image = self.get_image(i, fov, channel.name, z_level)
  23. if image.is_valid:
  24. yield image
  25. def image_sets(self, field_of_view, time_indices=None, channels=None, z_levels=None):
  26. """
  27. Gets all the images for a given field of view and
  28. """
  29. timepoint_set = xrange(self.time_index_count) if time_indices is None else time_indices
  30. channel_set = [channel.name for channel in self.channels] if channels is None else channels
  31. z_level_set = xrange(self.z_level_count) if z_levels is None else z_levels
  32. for timepoint in timepoint_set:
  33. image_set = ImageSet()
  34. for channel_name in channel_set:
  35. for z_level in z_level_set:
  36. image = self.get_image(timepoint, field_of_view, channel_name, z_level)
  37. if image.is_valid:
  38. image_set.add(image)
  39. yield image_set