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.

270 lines
7.0 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
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 _get_location(self, label):
  11. try:
  12. label_location = self._data.index(label) + len(label)
  13. return self._parse_data_location(label_location)
  14. except ValueError:
  15. return None
  16. def _parse_data_location(self, label_location):
  17. location, length = struct.unpack("QQ", self._data[label_location: label_location + 16])
  18. return location
  19. @property
  20. def image_text_info(self):
  21. """Get the location of the textual image information
  22. Returns:
  23. int: The location of the textual image information
  24. """
  25. return self._get_location(six.b("ImageTextInfoLV!"))
  26. @property
  27. def image_metadata(self):
  28. """Get the location of the image metadata
  29. Returns:
  30. int: The location of the image metadata
  31. """
  32. return self._get_location(six.b("ImageMetadataLV!"))
  33. @property
  34. def image_events(self):
  35. """Get the location of the image events
  36. Returns:
  37. int: The location of the image events
  38. """
  39. return self._get_location(six.b("ImageEventsLV!"))
  40. @property
  41. def image_metadata_sequence(self):
  42. """Get the location of the image metadata sequence. There is always only one of these, even though it has a pipe
  43. followed by a zero, which is how they do indexes.
  44. Returns:
  45. int: The location of the image metadata sequence
  46. """
  47. return self._get_location(six.b("ImageMetadataSeqLV|0!"))
  48. def get_image_data_location(self, index):
  49. """Get the location of the image data
  50. Returns:
  51. int: The location of the image data
  52. """
  53. if not self._image_data:
  54. regex = re.compile(six.b("""ImageDataSeq\|(\d+)!"""))
  55. for match in regex.finditer(self._data):
  56. if match:
  57. location = self._parse_data_location(match.end())
  58. self._image_data[int(match.group(1))] = location
  59. return self._image_data[index]
  60. @property
  61. def image_calibration(self):
  62. """Get the location of the image calibration
  63. Returns:
  64. int: The location of the image calibration
  65. """
  66. return self._get_location(six.b("ImageCalibrationLV|0!"))
  67. @property
  68. def image_attributes(self):
  69. """Get the location of the image attributes
  70. Returns:
  71. int: The location of the image attributes
  72. """
  73. return self._get_location(six.b("ImageAttributesLV!"))
  74. @property
  75. def x_data(self):
  76. """Get the location of the custom x data
  77. Returns:
  78. int: The location of the custom x data
  79. """
  80. return self._get_location(six.b("CustomData|X!"))
  81. @property
  82. def y_data(self):
  83. """Get the location of the custom y data
  84. Returns:
  85. int: The location of the custom y data
  86. """
  87. return self._get_location(six.b("CustomData|Y!"))
  88. @property
  89. def z_data(self):
  90. """Get the location of the custom z data
  91. Returns:
  92. int: The location of the custom z data
  93. """
  94. return self._get_location(six.b("CustomData|Z!"))
  95. @property
  96. def roi_metadata(self):
  97. """Information about any regions of interest (ROIs) defined in the nd2 file
  98. Returns:
  99. int: The location of the regions of interest (ROIs)
  100. """
  101. return self._get_location(six.b("CustomData|RoiMetadata_v1!"))
  102. @property
  103. def pfs_status(self):
  104. """Get the location of the perfect focus system (PFS) status
  105. Returns:
  106. int: The location of the perfect focus system (PFS) status
  107. """
  108. return self._get_location(six.b("CustomData|PFS_STATUS!"))
  109. @property
  110. def pfs_offset(self):
  111. """Get the location of the perfect focus system (PFS) offset
  112. Returns:
  113. int: The location of the perfect focus system (PFS) offset
  114. """
  115. return self._get_location(six.b("CustomData|PFS_OFFSET!"))
  116. @property
  117. def guid(self):
  118. """Get the location of the image guid
  119. Returns:
  120. int: The location of the image guid
  121. """
  122. return self._get_location(six.b("CustomData|GUIDStore!"))
  123. @property
  124. def description(self):
  125. """Get the location of the image description
  126. Returns:
  127. int: The location of the image description
  128. """
  129. return self._get_location(six.b("CustomData|CustomDescriptionV1_0!"))
  130. @property
  131. def camera_exposure_time(self):
  132. """Get the location of the camera exposure time
  133. Returns:
  134. int: The location of the camera exposure time
  135. """
  136. return self._get_location(six.b("CustomData|Camera_ExposureTime1!"))
  137. @property
  138. def camera_temp(self):
  139. """Get the location of the camera temperature
  140. Returns:
  141. int: The location of the camera temperature
  142. """
  143. return self._get_location(six.b("CustomData|CameraTemp1!"))
  144. @property
  145. def acquisition_times(self):
  146. """Get the location of the acquisition times, block 1
  147. Returns:
  148. int: The location of the acquisition times, block 1
  149. """
  150. return self._get_location(six.b("CustomData|AcqTimesCache!"))
  151. @property
  152. def acquisition_times_2(self):
  153. """Get the location of the acquisition times, block 2
  154. Returns:
  155. int: The location of the acquisition times, block 2
  156. """
  157. return self._get_location(six.b("CustomData|AcqTimes2Cache!"))
  158. @property
  159. def acquisition_frames(self):
  160. """Get the location of the acquisition frames
  161. Returns:
  162. int: The location of the acquisition frames
  163. """
  164. return self._get_location(six.b("CustomData|AcqFramesCache!"))
  165. @property
  166. def lut_data(self):
  167. """Get the location of the LUT data
  168. Returns:
  169. int: The location of the LUT data
  170. """
  171. return self._get_location(six.b("CustomDataVar|LUTDataV1_0!"))
  172. @property
  173. def grabber_settings(self):
  174. """Get the location of the grabber settings
  175. Returns:
  176. int: The location of the grabber settings
  177. """
  178. return self._get_location(six.b("CustomDataVar|GrabberCameraSettingsV1_0!"))
  179. @property
  180. def custom_data(self):
  181. """Get the location of the custom user data
  182. Returns:
  183. int: The location of the custom user data
  184. """
  185. return self._get_location(six.b("CustomDataVar|CustomDataV2_0!"))
  186. @property
  187. def app_info(self):
  188. """Get the location of the application info metadata
  189. Returns:
  190. int: The location of the application info metadata
  191. """
  192. return self._get_location(six.b("CustomDataVar|AppInfo_V1_0!"))