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.

118 lines
3.1 KiB

9 years ago
9 years ago
9 years ago
9 years ago
  1. import six
  2. class Metadata(object):
  3. """ A simple container for ND2 metadata. """
  4. def __init__(self, height, width, channels, date, fields_of_view, frames, z_levels, total_images_per_channel):
  5. self._height = height
  6. self._width = width
  7. self._channels = channels
  8. self._date = date
  9. self._fields_of_view = fields_of_view
  10. self._frames = frames
  11. self._z_levels = z_levels
  12. self._total_images_per_channel = total_images_per_channel
  13. @property
  14. def height(self):
  15. """
  16. The image height in pixels.
  17. :rtype: int
  18. """
  19. return self._height
  20. @property
  21. def width(self):
  22. """
  23. The image width in pixels.
  24. :rtype: int
  25. """
  26. return self._width
  27. @property
  28. def date(self):
  29. """
  30. The date and time when acquisition began.
  31. :rtype: datetime.datetime() or None
  32. """
  33. return self._date
  34. @property
  35. def channels(self):
  36. """
  37. These are labels created by the NIS Elements user. Typically they may a short description of the filter cube
  38. used (e.g. "bright field", "GFP", etc.)
  39. :rtype: list
  40. """
  41. return self._channels
  42. @property
  43. def fields_of_view(self):
  44. """
  45. The metadata contains information about fields of view, but it contains it even if some fields
  46. of view were cropped. We can't find anything that states which fields of view are actually
  47. in the image data, so we have to calculate it. There probably is something somewhere, since
  48. NIS Elements can figure it out, but we haven't found it yet.
  49. :rtype: list
  50. """
  51. return self._fields_of_view
  52. @property
  53. def frames(self):
  54. """
  55. The number of cycles.
  56. :rtype: list
  57. """
  58. return self._frames
  59. @property
  60. def z_levels(self):
  61. """
  62. The different levels in the Z-plane. Just a sequence from 0 to n.
  63. :rtype: list
  64. """
  65. return self._z_levels
  66. @property
  67. def total_images_per_channel(self):
  68. """
  69. The total number of images of a particular channel (wavelength, filter, etc) in the entire ND2.
  70. :rtype: int
  71. """
  72. return self._total_images_per_channel
  73. class CameraSettings(object):
  74. def __init__(self, name, id, exposure, x_binning, y_binning, channel_name):
  75. self.name = name.decode("utf8")
  76. self.id = id.decode("utf8")
  77. self.exposure = exposure
  78. self.x_binning = int(x_binning)
  79. self.y_binning = int(y_binning)
  80. self.channel_name = channel_name
  81. if six.PY3:
  82. self.channel_name = self.channel_name.decode("utf8") if channel_name is not None else None
  83. def __repr__(self):
  84. return "\n".join(["<Camera Settings: %s>" % self.channel_name,
  85. "Camera: %s" % self.name,
  86. "Camera ID: %s" % self.id,
  87. "Exposure Time (ms): %s" % self.exposure,
  88. "Binning: %sx%s" % (self.x_binning, self.y_binning)
  89. ])