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.

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