Hi, I recently needed to get the JSON data embedded in Micro-manager.org .tiff files into IDL. I was given some help on Micro-manager forum to get this data and would like to post the script here for others to use. It is a great example of using the JSON_PARSE function.
; docformat = 'rst'
;+
; :Description:
; takes a micro-manager tiff file and prints the
; EM Gain, Preamp Gain and Readout Mode. This assumes
; a Micro-manager file stack is given, will not check, however. Requires
; idl 8.2 in order to use the JSON_PARSE function and put the
; micro-manager JSON data in a hash variable. Any key can be printed once
; read.
;
; :Params:
; file:
; in, .tiff file from micromanager
;
;
; :Author: jpskinner
;-
pro cameraSettings, file
compile_opt idl2
openr, 1, file
; Determine endian status
stat = read_binary(1, data_dims=2)
if string(stat) eq 'MM' then e='big' else e='little'
; Get the offset to the first IFD
point_lun, 1, 4
ifd_loc = read_binary(1, data_dims=1, data_type=13, endian=e)
print, 'First IFD location: ', ifd_loc
;go to tag 17 which should be 51123
point_lun, 1, ifd_loc+2+16*12
tag = read_binary(1, data_dims=1, data_type=12, endian=e)
if tag ne 51123 then begin
print, 'Tag not present in file.'
print, 'Found tag: ', tag
close, 1
return
endif
type = read_binary(1, data_dims=1, data_type=2, endian=e)
n = read_binary(1, data_dims=1, data_type=13, endian=e)
offset = read_binary(1, data_dims=1, data_type=13, endian=e)
; Go to the micro-manager metadata.
point_lun, 1, offset
data = read_binary(1, data_dims=n, endian=e)
close, 1
metaData = json_parse(string(data))
;Print the info desired.
print, 'Gain: ', metaData['Andor iXon-Gain']
print, 'Readout: ', metaData['Andor iXon-ReadoutMode']
print, 'Pre-Amp: ', metaData['Andor iXon-Pre-Amp-Gain']
end
|