Skip to content

Import SAXSLAB Ganesha tiff files containing both headers #336

@mmarras

Description

@mmarras

I am using pyfai for my datareduction of SAXSLAB Ganesha / pilatus tiff files and, thus, fabio for the image import.

The tiff-file contains two sets of x-ray relevant meta data tags. One for the pilatus detector saved in tag 270 and one for the SAXSLAB machine data which is provided in a html format.

Using PIL I found that the SAXSLAB html meta data is saved in tag 315.

I also managed to parse the html meta data into a dict. However, I am not familiar enough with fabio (but I am willing to learn) to inject this so that I can expose a complemented header consisting of both the Pilatus meta data and the SAXSLAB meta data in fabio.tifimage.TifImage.header.

Here is my code to parse the SAXSLAB meta data using PIL instead of fabio.

import pathlib
import PIL
from html.parser import HTMLParser
from  collections import OrderedDict

file = pathlib.Path(r"D:\Data\Ganesha\Dummy.tiff")

fig = PIL.Image.open(str(file))

class MyHTMLParser(HTMLParser):
    store = OrderedDict()

    def handle_starttag(self, tag, attrs):
        for attr in attrs:
            self.store[attr[1]]=None

    def handle_data(self, data):
        self.store[list(self.store.keys())[-1]] = data

    def get_header_ordered(self):
        return self.store

    def get_header(self):
        return dict(self.store)

parser = MyHTMLParser()
parser.feed(fig.tag[315][0])
parser.get_header()

which returns:

{'det_pixel_size': '172e-6 172e-6',
 'det_thickness': '0.000320',
 'det_exposure_time': '900.000000',
 'det_exposure_period': '906.000000',
 'det_tau': '383.8e-09',
 'det_count_cutoff': '1077896',
 'det_threshold_setting': '4024',
 'det_n_excluded_pixels': '14',
 'det_excluded_pixels': 'badpix_mask.tif',
 'det_flat_field': 'FF_p300k0149_E8048_T4024_vrf_m0p15.tif',
 'det_trim_directory': 'p300k0149_E8048_T4024_vrf_m0p15.bin',
 'datatype': 'tiff',
 'detectortype': 'PILATUS 300K',
 'detector_sn': 'dec427',
 'meastype': None,
 'start_timestamp': 'Thu Apr 12 13:07:51 2018',
 'end_timestamp': None,
 'save_timestamp': None,
 'realtime': None,
 'livetime': '900.00',
 'pixelsize': '0.172 0.172',
 'beamcenter_nominal': '350.01    438.50',
 'beamcenter_actual': '350.00    438.46',
 'data_mean': None,
 'data_min': None,
 'data_max': None,
 'data_rms': None,
 'data_p10': None,
 'data_p90': None,
 'calibrationtype': 'geom',
 'kcal': None,
 'pixelcal': None,
 'koffset': None,
 'wavelength': '1.5418',
 'detector_dist': None,
 'saxsconf_r1': '0.4500',
 'saxsconf_r2': '2.0000',
 'saxsconf_r3': '0.3500',
 'saxsconf_l1': '725',
 'saxsconf_l2': '400',
 'saxsconf_l3': '129.9995',
 'saxsconf_wavelength': '1.5418',
 'saxsconf_dwavelength': '0.004',
 'saxsconf_Imon': None,
 'saxsconf_Ieff': '1.12500',
 'saxsconf_Izero': None,
 'saxsconf_det_offx': '0',
 'saxsconf_det_offy': '0',
 'saxsconf_det_rotx': '0',
 'saxsconf_det_roty': '0',
 'saxsconf_det_pixsizez': '0.172',
 'saxsconf_det_pixsizey': '0.172',
 'saxsconf_det_resx_0': None,
 'saxsconf_det_resy_0': None,
 'saxsconf_abs_int_fact': None,
 'sample_transfact': None,
 'sample_thickness': None,
 'sample_ypos': '-12.900',
 'sample_zpos': '10.000',
 'sample_angle1': '-0.000',
 'sample_angle2': None,
 'sample_angle3': None,
 'sample_temp': None,
 'sample_pressure': None,
 'sample_strain': None,
 'sample_stress': None,
 'sample_shear_rate': None,
 'sample_concentration': None,
 'sample_buffer': None,
 'sample_ID': None,
 'hg1': '0.899987',
 'hp1': '-0.028385',
 'vg1': '0.899987',
 'vp1': '-0.074980',
 'hg2': '4.000000',
 'hp2': '0.000010',
 'vg2': '4.000000',
 'vp2': '0.000000',
 'hg3': '0.700000',
 'hp3': '-0.000719',
 'vg3': '0.700000',
 'vp3': '0.041246',
 'ysam': '-12.900000',
 'zsam': '10.000000',
 'thsam': '-0.000008',
 'detx': '4.999530',
 'dety': '-38.688969',
 'detz': '-2.897927',
 'bstop': '-67.456255',
 'pd': '0.700000',
 'source_type': 'GENIX3D',
 'source_runningtime': None,
 'source_kV': '49.93',
 'source_ma': '0.60',
 'xaxis': None,
 'xaxisfull': None,
 'yaxis': None,
 'error_norm_fact': '1',
 'xaxisbintype': 'lin',
 'log': 'log',
 'reduction_type': 's',
 'reduction_state': None,
 'raw_filename': None,
 'bsmask_configuration': '0    350.01    438.50 28.0     19.10 14.0',
 'mask_filename': None,
 'flatfield_filename': None,
 'empty_filename': None,
 'solvent_filename': None,
 'darkcurrent_filename': None,
 'readoutnoise_filename': None,
 'zinger_removal': '0',
 'data_added_constant': '0',
 'data_multiplied_constant': '1',
 'Img.Class': None,
 'Img.MonitorMethod': None,
 'Img.ImgType': '2D',
 'Img.Site': 'TUM',
 'Img.Group': None,
 'Img.Researcher': None,
 'Img.Operator': None,
 'Img.Administrator': None,
 'Meas.Description': '1: 10132-ATSL-S1-E; conf 21, T=0.000000, Time=900'}

Here is a link to a dummy SAXSLAB Ganesha file: Dummy.tiff

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions