Coverage for /Users/Newville/Codes/xraylarch/larch/io/xrd_hdf5.py: 38%

24 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-11-09 10:08 -0600

1#!/usr/bin/python 

2""" 

3 

4""" 

5import numpy as np 

6import time 

7import h5py 

8import sys 

9import os 

10 

11from larch import Group 

12 

13def read_xrd_hdf5(fname, verbose=False): 

14 # Reads a HDF5 file created for XRD mapping 

15 h5file = h5py.File(fname, 'r') 

16 

17 addr = 'entry/data/data' 

18 for section in ('entry/data/data_000001', 

19 'entry/instrument/detector/data'): 

20 if section in h5file: 

21 addr = section 

22 break 

23 xrd_data = h5file[addr][()] 

24 

25 ## Forces data into 3D shape 

26 shape = xrd_data.shape ## (no_images,pixels_x,pixels_y) 

27 if len(shape) == 2: 

28 print('Reshaping to (%i, %i, %i)' % (1, shape[0], shape[1])) 

29 xrd_data.shape = (1, shape[0], shape[1]) 

30 return xrd_data 

31 

32def test_read(fname): 

33 print( fname, os.stat(fname)) 

34 fd = read_xrd_hdf5(fname, verbose=True) 

35 print(fd.counts.shape)