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.

247 lines
4.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. import six
  2. import struct
  3. import re
  4. class LabelMap(object):
  5. """Contains pointers to metadata. This might only be valid for V3 files.
  6. """
  7. def __init__(self, raw_binary_data):
  8. self._data = raw_binary_data
  9. self._image_data = {}
  10. def image_attributes(self):
  11. """
  12. Returns:
  13. """
  14. return self._get_location(six.b("ImageAttributesLV!"))
  15. def _get_location(self, label):
  16. try:
  17. label_location = self._data.index(label) + len(label)
  18. return self._parse_data_location(label_location)
  19. except ValueError:
  20. return None
  21. def _parse_data_location(self, label_location):
  22. location, length = struct.unpack("QQ", self._data[label_location: label_location + 16])
  23. return location
  24. @property
  25. def image_text_info(self):
  26. """
  27. Returns:
  28. """
  29. return self._get_location(six.b("ImageTextInfoLV!"))
  30. @property
  31. def image_metadata(self):
  32. """
  33. Returns:
  34. """
  35. return self._get_location(six.b("ImageMetadataLV!"))
  36. @property
  37. def image_metadata_sequence(self):
  38. # there is always only one of these, even though it has a pipe followed by a zero, which is how they do indexes
  39. """
  40. Returns:
  41. """
  42. return self._get_location(six.b("ImageMetadataSeqLV|0!"))
  43. def get_image_data_location(self, index):
  44. """
  45. Args:
  46. index:
  47. Returns:
  48. """
  49. if not self._image_data:
  50. regex = re.compile(six.b("""ImageDataSeq\|(\d+)!"""))
  51. for match in regex.finditer(self._data):
  52. if match:
  53. location = self._parse_data_location(match.end())
  54. self._image_data[int(match.group(1))] = location
  55. return self._image_data[index]
  56. @property
  57. def image_calibration(self):
  58. """
  59. Returns:
  60. """
  61. return self._get_location(six.b("ImageCalibrationLV|0!"))
  62. @property
  63. def image_attributes(self):
  64. """
  65. Returns:
  66. """
  67. return self._get_location(six.b("ImageAttributesLV!"))
  68. @property
  69. def x_data(self):
  70. """
  71. Returns:
  72. """
  73. return self._get_location(six.b("CustomData|X!"))
  74. @property
  75. def y_data(self):
  76. """
  77. Returns:
  78. """
  79. return self._get_location(six.b("CustomData|Y!"))
  80. @property
  81. def z_data(self):
  82. """
  83. Returns:
  84. """
  85. return self._get_location(six.b("CustomData|Z!"))
  86. @property
  87. def roi_metadata(self):
  88. """
  89. Information about any regions of interest (ROIs) defined in the nd2 file
  90. Returns:
  91. """
  92. return self._get_location(six.b("CustomData|RoiMetadata_v1!"))
  93. @property
  94. def pfs_status(self):
  95. """
  96. Returns:
  97. """
  98. return self._get_location(six.b("CustomData|PFS_STATUS!"))
  99. @property
  100. def pfs_offset(self):
  101. """
  102. Returns:
  103. """
  104. return self._get_location(six.b("CustomData|PFS_OFFSET!"))
  105. @property
  106. def guid(self):
  107. """
  108. Returns:
  109. """
  110. return self._get_location(six.b("CustomData|GUIDStore!"))
  111. @property
  112. def description(self):
  113. """
  114. Returns:
  115. """
  116. return self._get_location(six.b("CustomData|CustomDescriptionV1_0!"))
  117. @property
  118. def camera_exposure_time(self):
  119. """
  120. Returns:
  121. """
  122. return self._get_location(six.b("CustomData|Camera_ExposureTime1!"))
  123. @property
  124. def camera_temp(self):
  125. """
  126. Returns:
  127. """
  128. return self._get_location(six.b("CustomData|CameraTemp1!"))
  129. @property
  130. def acquisition_times(self):
  131. """
  132. Returns:
  133. """
  134. return self._get_location(six.b("CustomData|AcqTimesCache!"))
  135. @property
  136. def acquisition_times_2(self):
  137. """
  138. Returns:
  139. """
  140. return self._get_location(six.b("CustomData|AcqTimes2Cache!"))
  141. @property
  142. def acquisition_frames(self):
  143. """
  144. Returns:
  145. """
  146. return self._get_location(six.b("CustomData|AcqFramesCache!"))
  147. @property
  148. def lut_data(self):
  149. """
  150. Returns:
  151. """
  152. return self._get_location(six.b("CustomDataVar|LUTDataV1_0!"))
  153. @property
  154. def grabber_settings(self):
  155. """
  156. Returns:
  157. """
  158. return self._get_location(six.b("CustomDataVar|GrabberCameraSettingsV1_0!"))
  159. @property
  160. def custom_data(self):
  161. """
  162. Returns:
  163. """
  164. return self._get_location(six.b("CustomDataVar|CustomDataV2_0!"))
  165. @property
  166. def app_info(self):
  167. """
  168. Returns:
  169. """
  170. return self._get_location(six.b("CustomDataVar|AppInfo_V1_0!"))