Convert Private Tiff Tag Into Python Dict
I am trying to read the metadata of this file: https://drive.google.com/file/d/10ZTLRazYbgm4pYEc3M7J7bP6590ZjNtY/view?usp=sharing It is saved in a private tag (34682, see python Ti
Solution 1:
The string you got here turns out to be encoded as xml. You can have a look here on how to convert an xml-string to dict: How to convert an XML string to a dictionary?
Using one of the answers there, I did the following:
In [6]: from xml.etree import cElementTree as ET
In [7]: ET.XML(tif_tags["FEI_TITAN"])
Out[7]: <Element 'Metadata' at 0x7f9be8207630>
In [8]: from copy import copy
...:
...: defdictify(r,root=True):
...: if root:
...: return {r.tag : dictify(r, False)}
...: d=copy(r.attrib)
...: if r.text:
...: d["_text"]=r.text
...: for x in r.findall("./*"):
...: if x.tag notin d:
...: d[x.tag]=[]
...: d[x.tag].append(dictify(x,False))
...: return d
...:
In [9]: dictify(ET.XML(tif_tags["FEI_TITAN"]))
Out[9]:
{'Metadata': {'_text': '\n ',
'Core': [{'_text': '\n ',
'Guid': [{'_text': '9b7da5e1-be22-4c15-9ea6-3ed4300318c5'}],
'UserID': [{'_text': 'Supervisor'}],
'ApplicationSoftware': [{'_text': 'xT'}],
'ApplicationSoftwareVersion': [{'_text': '0'}]}],
'Instrument': [{'_text': '\n ',
'ControlSoftwareVersion': [{'_text': '20.1.0.7012'}],
'Manufacturer': [{'_text': 'FEI Company'}],
'InstrumentClass': [{'_text': 'Aquilos'}],
'InstrumentID': [{'_text': '9925851'}],
'ComputerName': [{'_text': 'AS-MPC'}]}],
'Acquisition': [{'_text': '\n ',
'AcquisitionDatetime': [{'_text': '2021-10-12T12:27:43'}],
'BeamType': [{'_text': 'Ion'}],
'ColumnType': [{'_text': 'Sidewinder'}]}],
'Optics': [{'_text': '\n ',
'Apertures': [{'_text': '\n ',
'Aperture': [{'_text': '\n ',
'Number': [{'_text': '1'}],
'Diameter': [{'_text': '2.5E-05'}]}]}],
'AccelerationVoltage': [{'_text': '30000'}],
'SpotSize': [{'_text': '1.7E-08'}],
'BeamCurrent': [{'_text': '3E-11'}],
'FullScanFieldOfView': [{'_text': '\n ',
'X': [{'_text': '4.8020873382767222E-05'}],
'Y': [{'_text': '3.2013915588511481E-05'}]}],
'ScanFieldOfView': [{'_text': '\n ',
'X': [{'_text': '4.8020873382767222E-05'}],
'Y': [{'_text': '3.2013915588511481E-05'}]}],
'WorkingDistance': [{'_text': '0.018943079512039922'}],
'BeamShift': [{'_text': '\n ',
'X': [{'_text': '-7.4036727128018167E-07'}],
'Y': [{'_text': '7.8283358087907821E-07'}]}],
'StigmatorRaw': [{'_text': '\n ',
'X': [{'_text': '0'}],
'Y': [{'_text': '0'}]}]}],
'StageSettings': [{'_text': '\n ',
'StagePosition': [{'_text': '\n ',
'X': [{'_text': '-0.0030654519456763526'}],
'Y': [{'_text': '0.0027469495002475459'}],
'Z': [{'_text': '0.018902786052566539'}],
'Rotation': [{'_text': '-1.256433216129438'}],
'Tilt': [{'_text': '\n ',
'Alpha': [{'_text': '0.27925259026082394'}],
'Beta': [{'_text': '0'}]}]}]}],
'ScanSettings': [{'_text': '\n ',
'DwellTime': [{'_text': '5E-07'}],
'ScanSize': [{'_text': '\n ',
'Width': [{'_text': '1536'}],
'Height': [{'_text': '1024'}]}],
'ScanArea': [{'_text': '\n ',
'X': [{'_text': '0'}],
'Y': [{'_text': '0'}],
'Width': [{'_text': '1536'}],
'Height': [{'_text': '1024'}]}],
'LineTime': [{'_text': '0.00078449999999999993'}],
'LineIntegrationCount': [{'_text': '1'}],
'LineInterlacing': [{'_text': '1'}],
'FrameTime': [{'_text': '0.80332799999999993'}],
'ScanRotation': [{'_text': '3.1415926535897931'}]}],
'VacuumProperties': [{'_text': '\n ',
'SamplePressure': [{'_text': '0.00011099999999999989'}],
'ElectronSourcePressure': [{'_text': '4.0754869701231304E-08'}],
'ElectronColumnPressure': [{'_text': '1.5793422392106776E-07'}]}],
'Detectors': [{'_text': '\n ',
'ScanningDetector': [{'_text': '\n ',
'DetectorName': [{'_text': 'ETD'}],
'DetectorType': [{'_text': 'ETD'}],
'Signal': [{'_text': 'SE'}],
'Gain': [{'_text': '8.5319006280647329'}],
'Offset': [{'_text': '-1.6069335895422618'}],
'GridVoltage': [{'_text': '600'}],
'ContrastNormalized': [{'_text': '61.334819889093154'}],
'BrightnessNormalized': [{'_text': '43.305104160356954'}]},
{'_text': '\n ',
'DetectorName': [{'_text': 'ICE'}],
'DetectorType': [{'_text': 'ICE'}],
'Signal': [{'_text': 'SE'}],
'Gain': [{'_text': '54.199464921714458'}],
'Offset': [{'_text': '0.47536486052042992'}],
'GridVoltage': [{'_text': '600'}],
'ContrastNormalized': [{'_text': '45.384756674519814'}],
'BrightnessNormalized': [{'_text': '54.754484092327296'}]}]}],
'GasInjectionSystems': [{'_text': '\n ',
'Gis': [{'_text': '\n ',
'PortName': [{'_text': 'Port1'}],
'NeedleState': [{'_text': 'Retracted'}],
'Gases': [{'_text': '\n ',
'Gas': [{'_text': '\n ', 'GasType': [{'_text': 'G1'}]}]}]},
{'_text': '\n ',
'PortName': [{'_text': 'Port2'}],
'NeedleState': [{'_text': 'Retracted'}],
'Gases': [{'_text': '\n ',
'Gas': [{'_text': '\n ', 'GasType': [{'_text': 'G2'}]}]}]}]}],
'BinaryResult': [{'_text': '\n ',
'AcquisitionUnit': [{'_text': 'Pixel'}],
'CompositionType': [{'_text': 'Single'}],
'ImageSize': [{'_text': '\n ',
'X': [{'_text': '1536'}],
'Y': [{'_text': '1024'}]}],
'FilterType': [{'_text': 'Integrate'}],
'FilterFrameCount': [{'_text': '1'}],
'PixelSize': [{'_text': '\n ',
'X': [{'unit': 'm',
'unitPrefixPower': '1',
'_text': '3.1263589441905743E-08'}],
'Y': [{'unit': 'm',
'unitPrefixPower': '1',
'_text': '3.1263589441905743E-08'}]}],
'IntensityScale': [{'_text': '1'}],
'IntensityOffset': [{'_text': '0'}],
'Gamma': [{'_text': '1'}],
'AcquisitionArea': [{'_text': '\n ',
'X': [{'_text': '0'}],
'Y': [{'_text': '0'}],
'Width': [{'_text': '1'}],
'Height': [{'_text': '1'}]}]}],
'CustomSectionGroup': [{'_text': '\n ',
'CustomSection': [{'scope': 'StageCollection',
'_text': '\n ',
'StageCollection': [{'_text': '\n ',
'Stage': [{'_text': '\n ',
'Type': [{'_text': 'BulkStage'}],
'X': [{'_text': '-3.57633333333333 mm'}],
'Y': [{'_text': '3.30025 mm'}],
'Z': [{'_text': '36.2439236111111 mm'}],
'R': [{'_text': '288.011679475735 °'}],
'AT': [{'_text': '15.9999948400413 °'}],
'BT': [{}]}]}]},
{'scope': 'ApplicationInfo',
'_text': '\n ',
'ApplicationInfo': [{'_text': '\n ',
'AutomationCoreVersion': [{'_text': '1.675.2'}],
'AutomationCoreCommitId': [{'_text': '61efd0fd6a1b26289090960a7798059b497eeb42]'}],
'ApplicationName': [{}],
'ApplicationVersion': [{}],
'ApplicationCommitId': [{}]}]}]}]}}
Post a Comment for "Convert Private Tiff Tag Into Python Dict"