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.

130 lines
3.4 KiB

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