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.

125 lines
3.7 KiB

  1. import six
  2. import struct
  3. import re
  4. class LabelMap(object):
  5. """
  6. Contains pointers to metadata. This might only be valid for V3 files.
  7. """
  8. def __init__(self, raw_binary_data):
  9. self._data = raw_binary_data
  10. self._image_data = {}
  11. def image_attributes(self):
  12. return self._get_location(six.b("ImageAttributesLV!"))
  13. def _get_location(self, label):
  14. try:
  15. label_location = self._data.index(label) + len(label)
  16. return self._parse_data_location(label_location)
  17. except ValueError:
  18. return None
  19. def _parse_data_location(self, label_location):
  20. location, length = struct.unpack("QQ", self._data[label_location: label_location + 16])
  21. return location
  22. @property
  23. def image_text_info(self):
  24. return self._get_location(six.b("ImageTextInfoLV!"))
  25. @property
  26. def image_metadata(self):
  27. return self._get_location(six.b("ImageMetadataLV!"))
  28. @property
  29. def image_metadata_sequence(self):
  30. # there is always only one of these, even though it has a pipe followed by a zero, which is how they do indexes
  31. return self._get_location(six.b("ImageMetadataSeqLV|0!"))
  32. def get_image_data_location(self, index):
  33. if not self._image_data:
  34. regex = re.compile(six.b("""ImageDataSeq\|(\d+)!"""))
  35. for match in regex.finditer(self._data):
  36. if match:
  37. location = self._parse_data_location(match.end())
  38. self._image_data[int(match.group(1))] = location
  39. return self._image_data[index]
  40. @property
  41. def image_calibration(self):
  42. return self._get_location(six.b("ImageCalibrationLV|0!"))
  43. @property
  44. def image_attributes(self):
  45. return self._get_location(six.b("ImageAttributesLV!"))
  46. @property
  47. def x_data(self):
  48. return self._get_location(six.b("CustomData|X!"))
  49. @property
  50. def y_data(self):
  51. return self._get_location(six.b("CustomData|Y!"))
  52. @property
  53. def z_data(self):
  54. return self._get_location(six.b("CustomData|Z!"))
  55. @property
  56. def roi_metadata(self):
  57. return self._get_location(six.b("CustomData|RoiMetadata_v1!"))
  58. @property
  59. def pfs_status(self):
  60. return self._get_location(six.b("CustomData|PFS_STATUS!"))
  61. @property
  62. def pfs_offset(self):
  63. return self._get_location(six.b("CustomData|PFS_OFFSET!"))
  64. @property
  65. def guid(self):
  66. return self._get_location(six.b("CustomData|GUIDStore!"))
  67. @property
  68. def description(self):
  69. return self._get_location(six.b("CustomData|CustomDescriptionV1_0!"))
  70. @property
  71. def camera_exposure_time(self):
  72. return self._get_location(six.b("CustomData|Camera_ExposureTime1!"))
  73. @property
  74. def camera_temp(self):
  75. return self._get_location(six.b("CustomData|CameraTemp1!"))
  76. @property
  77. def acquisition_times(self):
  78. return self._get_location(six.b("CustomData|AcqTimesCache!"))
  79. @property
  80. def acquisition_times_2(self):
  81. return self._get_location(six.b("CustomData|AcqTimes2Cache!"))
  82. @property
  83. def acquisition_frames(self):
  84. return self._get_location(six.b("CustomData|AcqFramesCache!"))
  85. @property
  86. def lut_data(self):
  87. return self._get_location(six.b("CustomDataVar|LUTDataV1_0!"))
  88. @property
  89. def grabber_settings(self):
  90. return self._get_location(six.b("CustomDataVar|GrabberCameraSettingsV1_0!"))
  91. @property
  92. def custom_data(self):
  93. return self._get_location(six.b("CustomDataVar|CustomDataV2_0!"))
  94. @property
  95. def app_info(self):
  96. return self._get_location(six.b("CustomDataVar|AppInfo_V1_0!"))