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.

269 lines
7.0 KiB

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